//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.~r~n" + &
"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