COMMUNICATION comstep ID id [cpic_options].
This statement enables cross-system communication between two ABAP programs, or between an ABAP program and a program written in another programming language. The whole communication process takes place in individual communication steps, which involves repeated execution of the COMMUNICATION statement with the corresponding comstep additions. For both partner programs, communication is based on the CPI-C interface, which has been defined as a communication standard by IBM as a part of the SAA standard. This interface provides the following functions in the form of the CPI-C starter set:
Coordination of the individual communication steps, recording any errors that occur in the database table TCPIC and, if necessary, data conversion, take place in the individual programs themselves. The parameters that determined the physical partner system for a connection are administrated in the database table TXCOM.
Once the connection is initialized, the system writes an eight-digit connection number in the data object id. This number can be used to identify individual connections. As standard, 2**16 connections are possible for each calling program. For id, only flat character-type data types are permitted, with a minimum length of eight digits.
After initialization, the connection must be created. Then, in the first connection step, all the necessary administration data is sent to the partner system. The data sent in this connection step must have a specific structure and must be available in an EBCDIC format. The example below shows how a specifically formed structure can be converted into the EBCDIC format. The subsequent response also exists in EBCDIC format. After this initial connection has been established, data can be transferred without the need for further conversion.
During communication, the internal session in the called program must not be changed. Screen outputs are ignored or list outputs to the SAP Spool system are diverted if the NEW-PAGE statement is entered beforehand. Messages of types I, S and W are ignored, while types A and E cause the program to terminate.
In the simplest case, an ABAP program calls a subroutine in an ABAP program of another ABAP system. To enable this, the calling program must register on the other system by specifying the type of CPI-C service, the logon data, the programs and subroutines, and the type of error handling. The registration is performed by sending a specific structure to the other system in EBCDIC format.
The following example shows a schematic representation of the communication between two ABAP programs P1 and P2 without querying return values. The calling program P1 first creates the connection and sends a field connect_xstr that contains the content of the connect structure converted into EBCDIC format, with the necessary data. After the connection is confirmed by P2, P1 sends the actual, unconverted application data in the buffer b. When this data has been received, P2 sends a confirmation to P1. The connection from P1 is then recreated and the content of the buffer ("Answer") is issued as output.
PROGRAM p1.
DATA: d TYPE c LENGTH 8,
id TYPE c LENGTH 8,
b TYPE c LENGTH 10,
len TYPE x LENGTH 4,
dat TYPE xstring,
stat TYPE xstring,
BEGIN OF connect,
header TYPE c LENGTH 12 VALUE 'CONNCPIC1',
client TYPE c LENGTH 3 VALUE '001',
user TYPE c LENGTH 12 VALUE 'BONDJ',
password TYPE c LENGTH 8 VALUE '007',
language TYPE c LENGTH 1 VALUE 'E',
corr TYPE c LENGTH 1 VALUE ' ',
program TYPE c LENGTH 8 VALUE 'P2',
routine TYPE c LENGTH 30 VALUE 'CPIC_START',
END OF connect,
connect_str TYPE c LENGTH 75,
connect_xstr TYPE x LENGTH 75,
connect_ret TYPE x LENGTH 75,
converter TYPE REF TO cl_abap_conv_out_ce.
connect_str = connect.
converter = cl_abap_conv_out_ce=>create( encoding = '0101' ).
converter->write( data = connect_str ).
connect_xstr = converter->get_buffer( ).
d = ...
COMMUNICATION INIT
DESTINATION d
ID id.
COMMUNICATION ALLOCATE
ID id.
COMMUNICATION SEND
BUFFER connect_xstr
ID id.
PROGRAM p2.
DATA:
id TYPE c LENGTH 8,
b TYPE c LENGTH 10,
len TYPE x LENGTH 4,
dat TYPE xstring,
stat TYPE xstring.
FORM cpic_start.
COMMUNICATION ACCEPT
ID id.
COMMUNICATION RECEIVE
BUFFER connect_ret
DATAINFO dat
STATUSINFO stat
RECEIVED len
ID id.
b = 'Request'.
COMMUNICATION SEND
BUFFER b
ID id.
COMMUNICATION RECEIVE
BUFFER b
RECEIVED len
DATAINFO dat
STATUSINFO stat
ID id.
IF b = 'Request'.
b = 'Answer'.
ENDIF.
COMMUNICATION SEND
BUFFER b
ID id.
ENDFORM.
CLEAR b.
COMMUNICATION RECEIVE
BUFFER b
DATAINFO dat
STATUSINFO stat
RECEIVED len
ID id.
WRITE / b.
COMMUNICATION DEALLOCATE ID id.
Non-Catchable Exceptions