Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Stefan-Schnell
Active Contributor
0 Kudos
947
In the 3rd part now an example of an SAP server application. That means that you can use FreeBASIC functions from SAP via ABAP Call Function command.
'-Begin-----------------------------------------------------------------
'
' To know the gateway service (gwserv) and host (gwhost) use TAC SMGW
' and the menu Goto > Parameters > Display and look at the attribute
' entries gateway hostname and gateway service.
'
' Insert in the file Windows\system32\drivers\etc\services the entry
' sapgw00 with 3300/tcp for sapgw00, or e.g. for sapgw99 3399/tcp.
'
' Customize with TAC SM59 the RFC destination PBTESTPROGRAM
'
'-----------------------------------------------------------------------

'-Includes------------------------------------------------------------
#Include Once "sapnwrfc.inc"

'-Function ABAPCall---------------------------------------------------
Function ABAPCall(ByVal rfcHandle As Integer, _
ByVal funcHandle As Integer, errorInfo As RFC_ERROR_INFO) _
As Integer

MessageBox(null, "ABAP call", "", MB_OK Or MB_ICONINFORMATION)

Return RFC_OK
End Function

'-Variables-----------------------------------------------------------
Dim RfcErrorInfo As RFC_ERROR_INFO
Dim connParams(3) AS RFC_CONNECTION_PARAMETER
Dim As Integer hDesc, hConn, rc
Dim As WString * 16 nProgramID, nGWHost, nGWServ
Dim As WString * 16 vProgramID, vGWHost, vGWServ

'-Main----------------------------------------------------------------
nProgramID = "PROGRAM_ID" : vProgramID = "FBTESTPROGRAM"
nGWHost = "GWHOST" : vGWHost = "ABAP"
nGWServ = "GWSERV" : vGWServ = "sapgw00"

connParams(0).name = @nProgramID : connParams(0).value = @vProgramID
connParams(1).name = @nGWHost : connParams(1).value = @vGWHost
connParams(2).name = @nGWServ : connParams(2).value = @vGWServ

hDesc = RfcCreateFunctionDesc("ABAPCall", RfcErrorInfo)
RfcErrorHandler()

If hDesc <> 0 And RfcErrorInfo.code = RFC_OK Then

RfcInstallServerFunction "", hDesc, @ABAPCall, RfcErrorInfo
RfcErrorHandler()

If RfcErrorInfo.code = RFC_OK Then

hConn = RfcRegisterServer(@connParams(0), 3, RfcErrorInfo)
RfcErrorHandler()

If hConn <> 0 And RfcErrorInfo.code = RFC_OK Then

rc = RFC_OK
While rc = RFC_OK Or rc = RFC_RETRY
rc = RfcListenAndDispatch(hConn, 4, RfcErrorInfo)
Select Case rc
Case RFC_OK
OutputDebugString("RFC_OK")
Case RFC_RETRY
OutputDebugString("RFC_RETRY")
End Select
Wend

End If

End If

End If

'-End-------------------------------------------------------------------

 

At first we define the function in FreeBASIC which was called from ABAP, here ABAPCall. Now we define the connections parameters for the server registration. Parallel you must configure with the TAC SM59 your server program in the SAP system.

 



 

We create a function description via RfcCreateFunctionDesc and install our function via RfcInstallServerFunction. With RfcRegisterServer we register the server on the SAP system and with an endless loop we listen via RfcListenAndDispatch about our ABAP call to the FreeBASIC server application.

Here the ABAP program to call the FreeBASIC function:
"-Begin-----------------------------------------------------------------
Report zFBServerTest.

Call Function 'ABAPCall' Destination 'FBTESTPROGRAM'.

"-End-------------------------------------------------------------------

As you can see, it is also very easy to code a server application which uses FreeBASIC functions from an SAP system.

You find Part 1 here, and Part 2 here.
3 Comments
Labels in this area