From R/2 to an External Program (registered program) 
Purpose
An ABAP program in an R/2 System starts an ABAP program in an R/3 System or an non-SAP program, and exchanges data with this program.
You can start the target program from the R/2 host via an SAP communications program.
Communication is possible with the following external target programs:
Prerequisites
With this constellation, you must note the following guidelines:
The destination of the function call must match the corresponding entry in XCOM and RFCD.
:
#include "saprfc.h"
:
main(int argc,char **argv)
{
:
Rfc_Handle handle;
handle=RfcAccept(argv)
:
}
To link the C program, use the RFC library librfc.a.
:
Sub Main()
gCommand$ = Command$
:
hRfc = RfcAcceptExt(gCommand$)
:
End Sub
To link the Visual Basic program, use the librfc.lib (Windows) or ntlibrfc.lib libraries.
The following DLLs are used:
For more details on the RFC interface, refer to the documentation
Remote Communications.Non-registered program |
Registered Program |
. . . #define SOCK 1 #include "cpic.h" . . main(int argc,char **argv) { . . SAP_CMACCP(argv); . . CMACCP(..); . . } |
. . |
The function SAP_CMACCP is used to pass the parameters needed to establish the connection to the CPI-C interface.
If an error occurs, SAP_CMACCP gives a return code not equal to CM_OK. After calling SAP_CMACCP, you can use CPI-C programming as usual.

The pointer passed when SAP_CMACCP is called cannot point to data in the stack.
This is because the pointer is also used in the subsequent CPI-C functions.
IBM: |
The program runs under the user ID specified in the SNA definition, in the home directory of this user ID. |
HP: |
The program runs under the user ID sna (ID, under which the SNA kernel runs), in the directory containing the program. |

Special Features under BS2000
The tasks SAPGWHO (program gwhost) are started by the R/2 System at initialization. These tasks build the connection to an SAP Gateway under UNIX (not under BS2000).

IMS:
If you log on to an IMS security system, the session must not be closed. For this reason, the environment variable SAP_KEEP_SESSION was introduced.
For SAP_KEEP_SESSION=1, the session is retained despite the statement COMMUNICATION DEALLOCATE.
Process flow
The communication process depends on the host you are using:
R/2 System on MVS/VSE Host
The SAP communications program and the SAP Gateway must be on a UNIX host known in the SNA network. The target program, on the other hand, can be on a UNIX host not in the SNA network.
The process consists of the following steps:
The communications program simply passes on the data during the CPI-C dialog.
Side info files must be configured on the UNIX host known in the SNA network and on the Gateway host.
For details on the configuration of side info files, refer to the following topic in the documentation BC SAP Communication: Configuration:
R/2 System on BS2000 Host
In BS2000 the SAPGWHO jobs (program gwhost) perform the functions of the communications program when connection is set up by the R/2 System.
The process consists of the following steps:
Side info files must be configured on the UNIX host and on the BS2000 host.
For details on the configuration of side info files, refer to the following topic in the documentation BC SAP Communication: Configuration: under the topic:
Connection Setup by the R/2 System.