ERP Database - The Unofficial ERP Knowledge Base

Facebook Twitter del.icio.us Digg it
ERP Database contains a huge collection of articles related to ERP System and Software. Many of the articles are specifically related to SAP. All these ERP/SAP articles are freely available to everyone.

If you would like to submit an article or share any document related to ERP or any specific ERP software. Please mail it to support@erpdb.info. Please make sure that the documents are not copyrighted.
Social Bookmarks:

COMMUNICATION : ABAP Keywords a day

Print This Post Email This Post Written by admin on Nov 15th, 2007 | Filed under: ABAP Keywords

COMMUNICATION

Variants

1. COMMUNICATION INIT DESTINATION dest ID id.
2. COMMUNICATION ALLOCATE ID id.
3. COMMUNICATION ACCEPT ID id.
4. COMMUNICATION SEND ID id BUFFER f.
5. COMMUNICATION RECEIVE ID id
…BUFFER f
…DATAINFO d
…STATUSINFO s.
6. COMMUNICATION DEALLOCATE ID id.


The COMMUNICATION statement allows you to develop applications which perform direct program-to-program communication. The basis for this is CPI-C (Common Programming Interface – Coummunication), defined by IBM within the context of SAA standards as a standardized communications interface. The COMMUNICATION statement provides the essential parameters for implementing simple communication. Its starter set covers the following functionality:
Establishing a connection Accepting a communication Sending data Receiving data Closing a connection
The other essential part of such a communication is an ABAP/4 program containing a FORM routine which is executed when the connection has been established. This program may be in an R/3 System or an R/2> System. Here, you should be aware that the application programs themselves declare a protocol. In particular, logon to the partner SAP System must be performed in the calling program. The partner programs must also manage different character sets, e.g. ASCII – EBCDIC themselves. A facility known as the Remote Function Call ( RFC ) has now been developed to save users from having to deal with these problems. External programs (e.g. a program written in C on a UNIX workstation) can also be used as partner programs. For this purpose, SAP provides a platform-specific development library. For more detailed information about communication in the SAP System, you can refer to the manual
SAP Communication: Programming
Further information about communication can be found in any of the following literature:

IBM SAA
Common Programming Interface
Communication Reference
SC 26-4399

X/Open Developers’ Specification CPI-C
X/Open Company Ltd.
ISBN 1 872630 02 2
Variant 1
COMMUNICATION INIT DESTINATION dest ID id.
Addition
… RETURNCODE rc
Effect
Initializes a program-to-program connection.

The partner system is specified in the dest field. You can use any name you like, but it must be entered in the connection table TXCOM and can be no more than 8 characters long. This entry in TXCOM determines to which physical system a connection is established using the symbolic name of the target system.

In the field id , the system assigns an eight-character ID number of type C to the connection. The system field SY-SUBRC contains an appropriate return code value.
All return codes can be read using their symbolic names. For this purpose, you can use the program RSCPICDF which contains these names and can be included, if required.
Addition
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Variant 2
COMMUNICATION ALLOCATE ID id.
Addition
As for variant 1.
Effect
Sets up a program-to-program connection. The call must immediately follow COMMUNICATION INIT .
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Variant 3
COMMUNICATION ACCEPT ID id.
Addition
As for variant 1.
Effect
Accepts a connection requested by the partner program. id is a field of type C which is 8 characters long and contains the ID of the accepted connection after a successful call.
Example

FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.

Variant 4
COMMUNICATION SEND ID id BUFFER f.
Additions
1. … RETURNCODE rc
2. … LENGTH len
Effect
Sends data to the partner program. The data is stored in the field f which follows the key word parameter BUFFER . It is sent in the full length of the field f . If the partner program is part of a system which has a different character set, you must perform an appropriate conversion yourself. To do this, use the TRANSLATE statement.
Addition 1
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Addition 2
… LENGTH leng
Effect
Sends the contents of the field f to the partner program in the specified length.
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘C00′,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE
CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /’COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
RECORD = ‘The quick brown fox jumps over the lazy dog’.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Since the length is specified explicitly in this example, only the part ‘ The quick brown fox ‘ is transferred from the contents of the field RECORD .
Variant 5
COMMUNICATION RECEIVE ID id …BUFFER f …DATAINFO d …STATUSINFO s.
Additions
1. … RETURNCODE rc
2. … LENGTH leng
3. … RECEIVED m
4. … HOLD
Effect
Receives data in the field f . If no length is explicitly defined, the amount of data accepted depends on the length of the field. The fields d and s contain information about the receive process. You can address the contents of these using symbolic names in the include program RSCPICDF . The field d indicates whether the data was received in its entirety. The status field s informs the RECEIVE user of the status of the program. Here, it is important to know whether the program is in receive status or send status. It is, for example, not possible to send data if the program is in receive status.
For more detailed information about these protocol questions, refer to the manuals listed above.
Addition 1
… RETURNCODE rc
Effect
Stores the return code in the field rc .
Addition 2
… LENGTH leng
Effect
Receives data only in the specified length leng .
Addition 3
… RECEIVED m
Effect
After the call, m contains the number of bytes received by the partner program.
Addition 4
… HOLD
Effect
Normally, data is received asynchronously, i.e. the system performs a rollout. However, this may not be desirable if, for example, the data is received in a SELECT loop, the database cursor is lost due to the rollout and the loop is terminated. To prevent a rollout, you can use the addition HOLD . Then, the SAP process waits until the data has been received and is thus available for use by other users.
Note
The fields d , s and m which contain information about the outcome of the call must be of type X with length 4.
Example

FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
INCLUDE RSCPICDF.

COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.

COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.

Variant 6
COMMUNICATION DEALLOCATE ID id.
Addition

As for variant 1
Effect
Severs connection and releases all resources.
Example

TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
DEST TYPE DESTINATION VALUE ‘C00′.

DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.

INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
RECORD = ‘The quick brown fox jumps over the lazy dog’.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION DEALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

Note
The above examples illustrate the basic functionality of the key words. However, the example program can only have an external system as partner. If the partner is an SAP System, the calling program must first logon to the SAP System and receive an acknowledgement. Only then can you begin to transmit the actual data. When logging on to an R2 System and an R3 System, the logon data must be converted to EBCDIC . All user data should be converted according to the partner system. This is in the concluding example of an R/3 – R/2 connection.
Example

PROGRAM ZCPICTST.
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.

DATA: BEGIN OF CONNECT_STRING,
REQID(4) VALUE ‘CONN’,
TYPE(4) VALUE ‘CPIC’,
MODE(4) VALUE ’1 ‘,
MANDT(3) VALUE ’000′,
NAME(12) VALUE ‘CPICUSER’,
PASSW(8) VALUE ‘CPIC’,
LANGU(1) VALUE ‘D’,
KORRV(1),
REPORT(8) VALUE ‘ZCPICTST’,
FORM(30) VALUE ‘CPIC_EXAMPLE’,
END OF CONNECT_STRING.

DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE ‘R2-SYST’,
CPIC_RC TYPE RETURN_CODE,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.

DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.

COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION INIT, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

* Convert logon data to EBCDIC
TRANSLATE CONNECT_STRING TO CODE PAGE ’0100′.
COMMUNICATION SEND ID CONVID BUFFER CONNECT_STRING.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION ALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
* Receive acknowledgement of logon
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
DATAINFO DINFO
STATUSINFO SINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION RECEIVE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
* Convert acknowledgement to ASCII
TRANSLATE RECORD FROM CODE PAGE ’0100′.

* Now begin user-specific data exchange
RECORD = ‘The quick brown fox jumps over the lazy dog’.

* Depending on the partner system, convert to another
* character set
TRANSLATE RECORD TO CODE PAGE ’0100′.

COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION SEND, RC = ‘, CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / ‘COMMUNICATION DEALLOCATE, RC = ‘, CPIC_RC.
EXIT.
ENDIF.

PROGRAM ZCPICTST.
INCLUDE RSCPICDF.
* The receiving procedure in the relevant partner program follows
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.

COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK AND CPIC_RC NE CM_DEALLOCATED_NORMAL.
EXIT.
ENDIF.
ENDFORM.

———————
ABAPer, mail: abap.community@gmail.com http://www.erpdb.info

Share

If you like this post, you may as well like these too:

  1. ABAP Keywords ABAP Control KeywordsABAP Declarative KeywordsABAP Event KeywordsABAP KeywordsABAP Operational Keywords Contributed by Rajagopalan M~~~~ end of post ~~~~~ ———————ABAPer, mail: abap.community@gmail.com http://www.erpdb.info...
  2. SAP ABAP Keywords Complete List of all SAP ABAP Keywords. Alphabetical Overview of all SAP ABAP Commands or Keywords. A ADD for single fields Adds two single fields. Syntax ADD TO . The...
  3. One Place to Remember when looking for ABAP Keywords? Just bookmark http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/abapindx.htm. This contains almost all the ABAP Keywords you need for reference....
  4. ASSIGN: ABAP Keyword a day ASSIGN Variants:1. ASSIGN f TO .2. ASSIGN (f) TO .3. ASSIGN TABLE FIELD (f) TO .4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .5. ASSIGN COMPONENT idx OF...
  5. FORM: ABAP Keyword a day FORM: Defines a subroutine. Syntax FORM [USING ... [VALUE(][)] [TYPE |LIKE ]„. ] [CHANGING... [VALUE(][)] [TYPE |LIKE ]„. ]. Introduces a subroutine. The USING and CHANGING additions define the subroutine’s...
  6. FETCH : ABAP Keyword a day FETCH Basic form FETCH NEXT CURSOR c target. Effect Uses the cursor c to read the next line or lines from the dataset of a database table determined by OPEN...
  7. EXPORT : ABAP Keyword a day EXPORT 1 2 3 4 *Export data - EXPORT obj1 ... objn TO MEMORY. - EXPORT obj1 ... objn TO DATABASE dbtab(ar) ID key. - EXPORT obj1 ... objn TO...
  8. DESCRIBE : ABAP Keyword a day DESCRIBE Return attributes of a field - DESCRIBE FIELD f. Return attributes of an internal table - DESCRIBE TABLE itab. Determine distance between two fields - DESCRIBE DISTANCE BETWEEN f1...
  9. DATA : ABAP Keyword a day DATA Variants1. DATA f.2. DATA f(len).3. DATA: BEGIN OF rec,…END OF rec.4. DATA: BEGIN OF itab OCCURS n,…END OF itab.5. DATA: BEGIN OF COMMON PART c,…END OF COMMON PART.EffectDefines global...
  10. CONTINUE: ABAP Keyword a day CONTINUE Basic formCONTINUE.EffectWithin loop structures like * DO … ENDDO* WHILE … ENDWHILE* LOOP … ENDLOOP* SELECT … ENDSELECTCONTINUE terminates the current loop pass, returns the processing to the beginning...
  11. CONCATENATE : ABAP Keyword a day CONCATENATE Basic form CONCATENATE f1 … fn INTO g. Addition … SEPARATED BY h Effect Places the fields f1 to fn after g . With the fields fi (1 <=...
  12. COMPUTE: ABAP Keyword a day COMPUTEBasic formCOMPUTE n = arithexp.EffectEvaluates the arithmetic expression arithexp and places the result in the field n .Allows use of the four basic calculation types + , – , *...
  13. CNT : ABAP Keyword a day CNT Basic form… CNT(h) …EffectCNT(h) is not a statement, but a field which is automatically created and filled by the system if f is a sub-field of an extract dataset...
  14. CASE: ABAP Keyword a day CASE Basic formCASE f. Effect Case distinction.Depending on the current contents of a field, this statement executes one of several alternative processing branches. The field whose contents determine how the...
  15. GET PARAMETER: ABAP Keyword a day GET PARAMETER Gets an SPA/GPA parameters. Syntax GET PARAMETER ID <pid> FIELD <field_name>. Writes the value of the SPA/GPA parameter <pid> from the user-specific SAP memory into the variable <f>....



Leave a Reply