cancel
Showing results for 
Search instead for 
Did you mean: 

PowerBuilder call sap rfc.

Former Member
0 Kudos

Hi gurus,

Does anybody tell could PoverBuilder call SAP R/3 FRC? If can, how to call? It's nice if show some code for connect SAP and call one RFC.

Thanks a lot!

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Here is a code, which will help u. Analyse this and use the same.

//Declaration

String ls_app_server, ls_client_id, ls_user_name, ls_user_pass, &

ls_sap_system, ls_appl_lang, ls_sys_num

boolean lb_success = false

integer li_rc

SetPointer(HourGlass!)

dw_1.AcceptText()

// Get Application Server Name

ls_app_server = trim(dw_1.Object.app_server[1])

If IsNull(ls_app_server) or Len(ls_app_server) <= 0 Then

MessageBox("Application Server", "Application Server cannot be blank.")

Return

End If

// Get Client info

ls_client_id = trim(dw_1.Object.client_id[1])

If IsNull(ls_client_id) or Len(ls_client_id) <= 0 Then

MessageBox("Client", "Client Id cannot be blank.")

Return

End If

// Get User Name

ls_user_name = trim(dw_1.Object.user_name[1])

If IsNull(ls_user_name) or Len(ls_user_name) <= 0 Then

MessageBox("User Name", "User Name cannot be blank.")

Return

End If

// Get User Password

ls_user_pass = trim(dw_1.Object.user_pass[1])

If IsNull(ls_user_pass) or Len(ls_user_pass) <= 0 Then

MessageBox("Password", "Password cannot be blank.")

Return

End If

// Get System number

ls_sys_num = trim(dw_1.Object.sys_num[1])

If IsNull(ls_sys_num) or Len(ls_sys_num) <= 0 Then

MessageBox("System Number", "System Number cannot be blank.")

Return

End If

// Create the Sap Connection Object

If Not IsValid(iole_SapConnection) Then

iole_SapConnection = Create OLEObject

// li_rc = iole_SapConnection.ConnectToNewObject("sap.bapi.1")

li_rc = iole_SapConnection.ConnectToNewObject("sap.functions")

End If

// check return code

// -1 Invalid Call: the argument is the Object property of a control

// -2 Class name not found

// -3 Object could not be created

// -4 Could not connect to object

// -9 Other error

If li_rc < 0 Then

MessageBox("SAP Connection Failure","Unable to connect to SAP. " + &

"Please verify that SAP is installed on this machine.rn" + &

"The return code is: " + string(li_rc))

Return -1

End If

// Create the connection object

If Not isvalid(iole_connection) Then

iole_connection = CREATE OLEObject

iole_connection = iole_SapConnection.Connection()

End If

If Not IsValid(iole_connection) Then MessageBox("Error","Error")

// Assign all Sap login connection properties.

iole_connection.applicationserver = ls_app_server

//iole_connection.Destination = "DS6"

iole_connection.User = ls_user_name

iole_connection.Password = ls_user_pass

iole_connection.Client = ls_client_id

//iole_connection.system = trim(dw_1.Object.sap_system[1])

iole_connection.Language = trim(dw_1.Object.appl_lang[1])

iole_connection.systemNumber = trim(dw_1.Object.sys_num[1])

//iole_connection.AutoLogon = True

// logon now (silently)

lb_success = iole_connection.logon(0, true)

// set instance

If lb_success Then

MessageBox("Congrats","Connected with SAP and Login successful.")

Else

MessageBox("Sorry","Login fail, Please check with the SAP Administrator")

If IsValid(iole_SapConnection) Then Destroy iole_SapConnection

If IsValid(iole_connection) Then Destroy iole_connection

Return

End If

OleObject lole_sapfunc, ITAB

lole_sapfunc = Create OleObject

ITAB = Create OleObject

String ls_frdate, ls_todate

Boolean lb_function

If lb_success Then

lole_sapfunc = iole_SapConnection.Add("ZBAPI_TEST_SAL") //'ZBAPIPRACT1'

lole_sapfunc.EXPORTS("IM_FDATE").Value = '05072008'

lole_sapfunc.EXPORTS("IM_TDATE").Value = '07072008'

lb_function = lole_sapfunc.call

If lb_function Then

ITAB = lole_sapfunc.TABLES.Item("T_OUT")

long ll_row = 0

For ll_row = 1 to ITAB.RowCount()

MessageBox(string(ll_row), string(ITAB.cell(ll_row,"MATNR")))

MessageBox(string(ll_row), string(ITAB.cell(ll_row,"EXNUM")))

MessageBox(string(ll_row), string(ITAB.cell(ll_row,"SOLD_TO")))

Next

Else

MessageBox("Error","SAP Function cannot call.")

End If

End If

iole_connection.Logoff

Destroy lole_sapfunc

Destroy lole_sapfunc

Destroy ITAB

Former Member
0 Kudos

HI Arbind.

I have to do the same kind of connection to SAP using PB, can you help with the pbl file that includes the code that you posted. I need to connect to SAP to make an inquiry and retrieve the data to one dw, i've already took a look of your code, but i dont have any experience using OLE objects and making connections to other systems.

Can you help me?

Thanks in advance for your help!!!

Jose R.

Former Member
0 Kudos

I try the code like following:

//connect to SAP system

Integer Destination_System,sapok

String compcode

long l_rowcnt

OleObject objBAPIControl //Function Control (Collective object)

OleObject sapConnection //Connection object

OleObject objUserList

OleObject st_rtn

objBAPIControl = Create OleObject

sapok = objBAPIControl.ConnectToNewObject( "SAP.Functions" )

sapConnection = objBAPIControl.Connection

sapConnection.Destination = "C02"

sapConnection.Client = "300"

sapConnection.Language = "EN"

sapConnection.System = "R/3"

sapConnection.SystemNumber = "00"

sapConnection.Applicationserver = "112.11.12.43"

sapConnection.User = "a0001"

sapConnection.Password = "35677"

sapConnection.AutoLogon = True

If sapConnection.Logon(0, True) <> True Then

MessageBox ("Cannot logon!","Logon Failed!")

Else

MessageBox ("Logon!","Logon Successful!")

End If

But sapConnection.Logon(0,True) = false, it means can't logon SAP system. Could you tell me where occures wrong?

Thank a lot!

Former Member
0 Kudos

Any ideas?