From an External Program to R/2 
Purpose
A non-SAP program uses an RFC or CPI-C call
CMINIT/CMALLC to start an ABAP program in an R/3 System, and exchanges data with the ABAP program.Prerequisites / Process flow
With this constellation, you must note the following guidelines:
The RFC interface is available for R/2 as of Release 5.0D.
:
#include "saprfc.h"
:
main(int argc,char **argv)
{
:
Rfc_Handle handle;
handle=RfcOpen(RFC_OPTIONS *options????)
:
}
To link the C program, use the RFC library librfc.a.
:
Sub Main()
gCommand$ = Command$
:
hRfc = RfcOpenExt(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.:
< poss. host type define, see
To link the C program, use the function library cpictlib.o.
Via
For communication with the gateway, you must use the function SAP_CMINIT to pass the following parameters to the CPI-C interface:
P2: |
Gateway host |
P3: |
Gateway service |
P4: |
Protocol type/topology of the target program: C, I or E |
C: |
Partner is the R/2 program |
I: |
Partner is the R/3 program and can be reached via TCP/IP |
E: |
Partner is an external program and can be reached via TCP/IP |
The necessary constants are defined in the C header cpic.h.
If an error occurs, SAP_CMINIT delivers a return code not equal to CM_OK.
Side Info File:
You can also maintain these parameters in the side information file. In this case, call the function SAP_CMINIT as follows:
SAP_CMINIT(argv,(PCPIC_CHAR)0,(PCPIC_CHAR)0,NO_PROTOCOL);
After calling SAP_CMINIT you can use CPI-C programming as usual.
You can also specify some parameters with SAP_CMINIT and read some from the side information file.
You must include target system and platform-dependent entries in the side information file.
For details on the configuration of the side information file, refer to the relevant topic in the following documentation:
If timeouts occur when establishing a connection, you can use the environment variable CPIC_TIMEOUT to extend the wait time. CPIC_TIMEOUT specifies the time in seconds, which the gateway waits for the external program logon.

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.