Get Example source ABAP code based on a different SAP table
ID COMMUNICATION • COMMUNICATION ABAP Statement • ID COMMUNICATION (obsolete)
COMMUNICATION> Short Reference >
ABAP_SYNTAX_OBS COMMUNICATION comstep> ID id $[ cpic_options>$].>
What does it do? This statement enables cross-system communication between two ABAP programs, or between an ABAP program and a program written in another programming language. The entire communication process takes place in individual communication steps, for which the COMMUNICATION> statement must be executed repeatedly with the corresponding additions comstep>>. 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:
Establishing, accepting, and closing a connection
Sending and receiving data Coordination of the individual communication steps, recording any errors that occur in the DDIC 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 DDIC 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. id> expects only flat> character-like data types, with a minimum length of eight digits. After initialization, the connection must be established. 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 structured 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 ABAP_ISESS > in the called program must not be changed. Screen output is ignored or, in the case of list output to the SAP spool system, is redirected if the statement NEW-PAGE> was entered beforehand. Messages> of types I, S, and W are ignored, while types A and E cause the program to terminate.
Latest notes:
The statement COMMUNICATION> is not supported in classes and should no longer occur in programs, since support for the direct programming of the CPI-C interface has largely been discontinued. Instead, only the RFC interface> is to be used for communication between programs. However, the function of the statement is maintained for supporting existing programs and for internal purposes.
The EBCDIC format is used in the first connection step because the CPI-C interface was mainly used for connections to R/2 systems. ABAP_HINT_END
Example ABAP Coding
In the simplest case, an ABAP program calls a subroutine in an ABAP program of another AS ABAP>. To enable this, the calling program must log on to 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 takes place 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 to 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 closed again and the content of the buffer (Answer >) is produced 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.>
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.>