Powered By

Free XML Skins for Blogger

Powered by Blogger

Saturday, October 18, 2008

SAP Developing an Outbound IDoc Function

This is an individual coding part where you need to retrieve the information from the database and prepare it in the form the recipient of the IDoc will expect the data.

Read data to send :

The first step is reading the data from the database, the one you want to send.

FUNCTION Y_AXX_COOKBOOK_TEXT_IDOC_OUTB.

*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:

*" IMPORTING

*" VALUE(I_TDOBJECT) LIKE THEAD-TDOBJECT DEFAULT 'TEXT'
*" VALUE(I_TDID) LIKE THEAD-TDID DEFAULT 'ST'
*" VALUE(I_TDNAME) LIKE THEAD-TDNAME
*" VALUE(I_TDSPRAS) LIKE THEAD-TDSPRAS DEFAULT SY-LANGU

*" EXPORTING

*" VALUE(E_THEAD) LIKE THEAD STRUCTURE THEAD

*" TABLES

*" IDOC_DATA STRUCTURE EDIDD OPTIONAL
*" IDOC_CONTRL STRUCTURE EDIDC OPTIONAL
*" TLINES STRUCTURE TLINE OPTIONAL
*" EXCEPTIONS
*" FUNCTION_NOT_EXIST
*" VERSION_NOT_FOUND
*"----------------------------------------------------------------------
CALL FUNCTION 'READ_TEXT'

EXPORTING

ID = ID
LANGUAGE = LANGUAGE
NAME = NAME
OBJECT = OBJECT
TABLES
LINES = LINES.

* now stuff the data into the Idoc record format
PERFORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' E_THEAD.
LOOP AT LINES.
PERFORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' LINES.
ENDLOOP.
ENDFUNCTION.

Converting Data into IDoc Segment Format :

The physical format of the IDocs records is always the same. Therefore, the application data must be converted into a 1000 character string.

Fill the data segments which make up the IDoc :

An IDoc is a file with a rigid formal structure. This allows the correspondents to
correctly interpret the IDoc information. Were it for data exchange between SAPsystems only, the IDoc segments could be simply structured like the correspondent
DDIC structure of the tables whose data is sent.

However, IDocs are usually transported to a variety of legacy systems which do not
run SAP. Both correspondents therefore would agree on an IDoc structure which is
known to the sending and the receiving processes.

Transfer the whole IDoc to an internal table, having the structure of EDIDD :

All data needs to be compiled in an internal table with the structure of the standard
SAP table EDIDD. The records for EDIDD are principally made up of a header
string describing the segment and a variable length character field (called SDATA)
which will contain the actual segment data.

FORM PACK_LINE TABLES IDOC_DATA USING 'THEAD' E_THEAD.
TABLES: THEAD.
MOVE-CORRESPONDING E:THEAD to Z1THEAD.
MOVE ‚Z1THEAD’ TO IDOC_DATA-SEGNAM.
MOVE Z1THEAD TO IDOC_DATA-SDATA.
APPEND IDOC_DATA.
ENDFORM.“

Fill control record :

Finally, the control record has to be filled with meaningful data, especially telling
the IDoc type and message type.

IF IDOC_CONTRL-SNDPRN IS INITIAL.
SELECT SINGLE * FROM T000 WHERE MANDT EQ SY-MANDT.
MOVE T000-LOGSYS TO IDOC_CONTRL-SNDPRN.
ENDIF.

IDOC_CONTRL-SNDPRT = 'LS'.

* Trans we20 -> Outbound Controls muss entsprechend gesetzt werden.
* 2 = Transfer IDoc immediately
* 4 = Collect IDocs
IDOC_CONTRL-OUTMOD = '2'. "1=imediately, subsystem
CLEAR IDOC_CONTRL.
IDOC_CONTRL-IDOCTP = 'YAXX_TEXT'.
APPEND IDOC_CONTRL.

Archives