IDOCPort definition for all examples
Salesorder IDOC
Creating a G/L posting IDOC manually
Creating a G/L posting IDOC using an ABAP program
Transaction codes
Developing IDOCs
Usefull programs
Port definitionsThis port definition is used in all the examples.
Use transaction code WE21 to create a new port.
The port should be created as type FILE
General data and outbound file
NOTE: Remember to leave Outbound file blank
Inbound file
undefined
undefinedMore...
undefined[Close]
undefined[Close]
undefined
Salesorder IDOCIn this example a purchase is created, using the SAP standard functionallity for creating salesorders. When the salesorder is saved, and IDOC is automatically generated. Then we use the IDOC test tool to create an order confirmation from the salesorder IDOC.
Create Vendor
Create customer
Create partner profiles
Create purchase order
Create the order confirmation IDOC
Create vendor
Create vendor using transaction code MK01. You can also use an existing vendor.
Vendor: T-BILHFN
Purch. org. : 001
Purchase organization may vary from system to system.
Create Customer
Create a customer using transaction VD01. You could also use an existing customer.
In the follwing example the vendor 3471 is used.
Create partner profiles
Create vendor partner profile
General data
Outbound parameters
Inbound parameters
Create customer partner profile
General data
Outbound parameters
Imbound parameters
Create purchase order
Use transaction ME21 to create the purchase order.
To send an IDOC when the document is finished, go to Header -> Messages and change the output medium to EDI.
Then select Further Data and change Dispatch Time to Send immediately. This will create the IDOC as soon as the purchase order is saved.
Save the document.
Use transaction WE02 to check that the IDOC has been created without errors
Create the order confirmation IDOC
As the system has not been configured to handle the IDOC flow, the IDOC test tool is used to simulate the flow. The Order IDOC is used as a template to create the order confirmation IDOC.
Transaction code: WE19
Type the number of the Order IDOC in on the start screen and select menu IDOC -> Create to create the template.
Change the control record
Note that the name of the port SAPTST may vary from system to system. The name can be seen in the Sender port of the IDOC
Create new E1DK02 segment
The E1DK02 Document header reference data segment includes references to other documents.
The new E1DK02 segment should be created as a copy of the existing E1DK02, and at the same level.
Change the following fields of the record:
Qualifier: 002Document item: 10
Qualifier = IDOC qualifier reference document = 002 = Vendor orderDocument item =: Item number, see the item number on the purchasing document
Create E1EDP02 segment
The E1EDP02 Document Item Reference data includes references to other documents.
Create E1EDP02 as subelement of E1EDP01 Document item General Data
Qualifier: 001 Document: 4500010757 Document item: 10
Qualifier : IDOC qualifier reference document 001 = Customer purchase orderDocument : Document number – The number of the purchase order Document item : Item number, see the item number on the purchasing document
Changing the ACTION field at header or item level
If you are working without a confirmation control key, the IDoc must have a processable action code at either header or item level:
At header level, the segment field ACTION of segment E1EDK01 must be filled with the value '000' if the complete purchase order is to be confirmed.
At item level, the segment field ACTION of segment E1EDP01 must be filled with the value '000' or '004' if the PO item is to be confirmed.
Test IDOC
After the changes have been made, press the Standard Inbound button to generate the IDOC.
If no errors occurs go to transaction WE02 to check if the IDOC has been processed without errors.
If the IDOC has been processed without errors, then display the Purchase order (Transaction ME23). display the item data and double-click on the item line. If all went well, you will now se that the field Acknowl. no. has been filled out.
undefined
undefinedMore...
[Close]
Find Old
Friends
Creating a G/L posting IDOC manually In this example we try to create a FI posting IDOC manually using the IDOC test toll WE19.
Creating a partnerThe first step is to create a partner
General settings
Outbound
Inbound
Notes:
1. As message control is not used, the message control parameters should not be filled out
2. Remember to set the Post permitted agent to your own user (Typ: US – Agent: <your userid> )
Creating the IDOCUse transaction WE19 to create a test IDOC from basic type ACC_GL_POSTING01.
Control record
E1BPACHE08 Posting in Accounting: General Posting
OBJ_TYPE
Object type. Choose an object type from table TTYP
Selected value: BKPFI - Acctg doc.f.initial.
OBJ_KEY
The object key consists of a reference document number and a reference organizational unit.
I don’t quite understand this field, but it seems that typing in a random number will do.
Selected value (E.g.): 127387347
OBJ_SYS
Logical system of source document. Choose a system from table TBDLS
Selected value: APOCLNT800
USERNAME
Selected value: WMHEFRN
HEADER_TXT
Document header text
Selected value: My first header text
COMP_CODE
Company code.
Selected value: 1000
FISC_YEAR
Fiscal year
Selected value: 2001
DOC_DATE
Document date
Selected value: 20010617
PSTNG_DATE
Posting date.
Selected value: 20010617
TRANS_DATE
Transaction date.
Selected value: 20010617
FIS_PERIOD
Fiscal period
Selected value: 06
DOC_TYPE
Document type
Selected value: SA
E1BPACGL08 Posting in Accounting: General Posting
Contains general data for one line item. There most be created a segment for each line item.
Some of the segment fields are the same as in the E1BPACHE08 segment (Company code, date..), and seems that it is not necessary to fill them out if they are filled out in segment E1BPACHE08.
ITEMNO_ACC
Line number in the document.
Selected value debit segement: 10Selected value credit segement 20
GL_ACCOUNT
G/L account number
Selected value debit segement: 0000046000Selected value credit segement 0000046020
NOTE: Remember to to fill in leading zeros !
ITEM_TEXT
Write some text of your own choice
E1BPACCR08 Posting in Accounting: Billing Doc. (Currency Fields, Item)
Currency fields for line items.
ITEMNO_ACC
Line number in the document. Use the corresponding number from segment E1BPACGL08.
Selected value debit segement: 10Selected value credit segement 20
CURR_TYPE
Code for currency type e.g. Document currency and Company code currency. The most important types are:
'00' Document currency '10' Company code currency '11' Company code currency, group valuation
See the IDOC documentation for further types. Seems like a new segment has to be created for each type you want to use.
The currency type is required to be able to transfer amounts between different components of the R/3 System such as Financial Accounting and Controlling (using interfaces).
Selected value debit segement: 00Selected value credit segement 00
CURRENCY
Selected value debit segement: EURSelected value credit segement EUR
AMT_DOCCUR
Amount in document currency. In the last line item, you can specify a '*'. The system will then enter the balance of the line items entered prior to the last item as the amount for the last item. Note: Seems not to work.
NOTE: The IDOC has no posting key segment field. Instead use negative amounts for credit amounts.
Selected value debit segement: 1000Selected value credit segement -1000
Test the IDOCTest the IDOC using the Standard Inbound button in WE19
undefined
undefinedMore...
[Close]
[Close]
Find Old Friends
Creating a G/L posting IDOC using an ABAP program Here we create an ABAP program to extract FI postings from SAP and create an outbound IDOC. When the outbound IDOC has been created, the outbound IDOC is processed using program RSEOUT00. Next transaction WE12 is used to create an inbound IDOC and program RBDAPP01 is used to process it.
Preparations
The ABAP program
Process outbound IDOCs
Create inbound IDOCs
Process inbound IDOCs
Preparations
Use the partner profile created in Creating a G/L posting IDOC manually or create a similar partner profile.
The ABAP Program
This program is developed as a standalone program (No use of message control or change pointers). The program flow is:
Extract data from BKPF and BSEG Build the IDOC control record using structure EDIDC. Build and internal table of structure EDIDD with IDOC segments. EDIDD contains some keyfields, but
the data segment field is simply one string, as EDIDD is used for all type of IDOC’s. To simplify the process of building this string, use the SAP datastructures with the same name as the segment. E.g for segment E1BPACHE08 use structure E1BPACHE08.
Use function module MASTER_IDOC_DISTRIBUTE to create the IDOC’s. Remember to commit.
After the program has been executed, the iDOCs can be viewed using transaction WE02. The IDOCs should habve status code 30 IDOC ready for dispacth.
Important: This program can not handle multiple documents, so all postings must have the same key (Company code, currency code, posting date, document date) so that they can be posted in the same document. If the program should handle multiple documents, data should be split according to the key, and an IDOC created for each document.
The selection screen
The code
REPORT zhefrn_idoc_extract_fi LINE-SIZE 160.*------------------------------------------------------* Purpose* -------* This program extracts FI postings and create IDOCs** Description* -----------* An IDOC of type ACC_GL_POSTING01 is created from the extracted* FI-data.**- Extract data from BKPF and BSEG**- Build the IDOC control record. Use structure EDIDC.**- Build and internal table of structure EDIDD with IDOC segments.* EDIDD contains some keyfields, but the data segment field is simply* one string, as EDIDD is used for all type of IDOC’s. To simplify the* process of building this string, use the SAP datastructures with the* same name as the segment. E.g for segment E1BPACHE08 use structure* E1BPACHE08.**- Use function module MASTER_IDOC_DISTRIBUTE to create the IDOC’s.* Remember to commit.** Important: This program can not handle multiple documents, so all* postings must have the same key (Company code, currency code,* postingdate, document date) so that they can be posted in the same* document. *If the program should handle multiple documents, data* should be split *according to the key, and an IDOC created for each* document.
**------------------------------------------------------* Standard types*------------------------------------------------------TABLES: bkpf, "Accounting Document header bseg. "Accounting Document Segment* TEDS1. "IDoc status values
*------------------------------------------------------* Standard types*------------------------------------------------------TYPES: BEGIN OF st_bkpf, bukrs LIKE bkpf-bukrs, belnr LIKE bkpf-belnr, gjahr LIKE bkpf-gjahr, blart LIKE bkpf-blart, bldat LIKE bkpf-bldat, budat LIKE bkpf-budat, monat LIKE bkpf-monat, waers LIKE bkpf-waers, END OF st_bkpf,
BEGIN OF st_extract, bukrs LIKE bkpf-bukrs, belnr LIKE bkpf-belnr, gjahr LIKE bkpf-gjahr, blart LIKE bkpf-blart, bldat LIKE bkpf-bldat, budat LIKE bkpf-budat, monat LIKE bkpf-monat, waers LIKE bkpf-waers, hkont LIKE bseg-hkont, bschl LIKE bseg-bschl, shkzg LIKE bseg-shkzg, "Debit/credit indicator dmbtr LIKE bseg-dmbtr, wrbtr LIKE bseg-wrbtr, dmbe2 LIKE bseg-dmbe2, END OF st_extract.
*------------------------------------------------------* Table types*------------------------------------------------------
TYPES: tt_bkpf TYPE STANDARD TABLE OF st_bkpf, tt_extract TYPE STANDARD TABLE OF st_extract, tt_edidd TYPE STANDARD TABLE OF edidd, tt_edidc TYPE STANDARD TABLE OF edidc.
*------------------------------------------------------* Internal tables*------------------------------------------------------DATA:* G/L Doc header gi_bkpf TYPE tt_bkpf,* G/L extracted data gi_extract TYPE tt_extract,* IDOC segment data
gi_edidd TYPE tt_edidd,* Return table gi_communication_idoc_control TYPE tt_edidc.
*------------------------------------------------------* Global variables*------------------------------------------------------DATA:* WA for internal tables g_bkpf TYPE st_bkpf, g_extract TYPE st_extract, g_edidd LIKE edidd,
*-- IDOC structures:* IDOC control record g_idoc_control_record LIKE edidc,* G/L document header g_e1bpache08 LIKE e1bpache08,* G/L Account Line Items g_e1bpacgl08 LIKE e1bpacgl08,* Line Item Currency Fields g_e1bpaccr08 LIKE e1bpaccr08,* Return table from MASTER_IDOC_DISTRIBUTE g_communication_idoc_control LIKE edidc.
*------------------------------------------------------* Selection screen*------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME.SELECT-OPTIONS: a_bukrs FOR bkpf-bukrs, a_budat FOR bkpf-budat, a_hkont FOR bseg-hkont, a_usnam FOR bkpf-usnam DEFAULT 'WMHEFRN'.PARAMETERS: p_create AS CHECKBOX.SELECTION-SCREEN END OF BLOCK 1.
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME.* IDOC control record - ReceiverPARAMETERS: p_rcvpor LIKE edidc-rcvpor DEFAULT 'PORT-HFN', "Rec. Port p_rcvprn LIKE edidc-rcvprn DEFAULT 'WMHEFRN', "Rec. Partn. number p_rcvprt LIKE edidc-rcvprt DEFAULT 'US', "Rec. Partn. type. p_rcvpfc LIKE edidc-sndpfc DEFAULT '§§'. "Partner functionSELECTION-SCREEN END OF BLOCK 2.
SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME.* IDOC control record - SenderPARAMETERS: p_sndpor LIKE edidc-sndpor DEFAULT 'SAPC46', "Send. Port p_sndprn LIKE edidc-sndprn DEFAULT 'WMHEFRN', "Send. Partn.number p_sndprt LIKE edidc-sndprt DEFAULT 'US'. "Send. Partn. type.* p_sndpfc LIKE edidc-sndpfc DEFAULT '§P'. "Send. Partn. funct.SELECTION-SCREEN END OF BLOCK 3.
*------------------------------------------------------* Start of selection
*------------------------------------------------------START-OF-SELECTION. PERFORM initialize. PERFORM extract_data. PERFORM build_idoc_control_record. PERFORM build_idoc_segments. IF p_create = 'X'. PERFORM create_idocs. ENDIF. PERFORM write_report.
*&---------------------------------------------------------------------**& Form INITIALIZE*&---------------------------------------------------------------------*FORM initialize. REFRESH: gi_bkpf, gi_extract, gi_edidd.
CLEAR: g_idoc_control_record.
ENDFORM. " INITIALIZE
*&---------------------------------------------------------------------**& Form EXTRACT_DATA*&---------------------------------------------------------------------** Extract FI postings to internal table gi_extract*----------------------------------------------------------------------FORM extract_data.
* Read BKPF SELECT bukrs belnr gjahr blart bldat budat monat waers FROM bkpf APPENDING CORRESPONDING FIELDS OF TABLE gi_bkpf WHERE bukrs IN a_bukrs AND budat IN a_budat AND usnam IN a_usnam.
LOOP AT gi_bkpf INTO g_bkpf. SELECT hkont bschl shkzg dmbtr wrbtr dmbe2 FROM bseg INTO CORRESPONDING FIELDS OF g_extract WHERE bukrs = g_bkpf-bukrs AND belnr = g_bkpf-belnr AND gjahr = g_bkpf-gjahr.
MOVE-CORRESPONDING g_bkpf TO g_extract.
APPEND g_extract TO gi_extract. CLEAR g_extract. ENDSELECT.
ENDLOOP.
SORT gi_extract BY belnr.
ENDFORM. " EXTRACT_DATA
*&---------------------------------------------------------------------**& Form WRITE_REPORT*&---------------------------------------------------------------------** Writes a report showing the selected data, and generated IDOCs* and errors*----------------------------------------------------------------------*FORM write_report.
WRITE: / 'Extracted data' COLOR COL_GROUP INTENSIFIED ON. LOOP AT gi_extract INTO g_extract. AT NEW belnr. SKIP 1. FORMAT COLOR COL_GROUP INTENSIFIED ON. WRITE: 'Document', g_extract-belnr. FORMAT RESET. NEW-LINE. ENDAT.
WRITE: / g_extract-bukrs, g_extract-belnr, g_extract-gjahr, g_extract-blart, g_extract-bldat, g_extract-budat, g_extract-monat, g_extract-waers, g_extract-hkont, g_extract-bschl, g_extract-shkzg, g_extract-dmbtr, g_extract-wrbtr, g_extract-dmbe2. ENDLOOP.
* Write generated IDOCS ULINE. SKIP 2. WRITE: / 'Generated IDOCs' COLOR COL_GROUP INTENSIFIED ON. WRITE: / g_idoc_control_record. LOOP AT gi_edidd INTO g_edidd. WRITE: / g_edidd-segnam(10) COLOR COL_KEY, g_edidd-sdata(140). ENDLOOP.
* Write staus codes returned from function module MASTER_IDOC_DISTRIBUTE IF p_create = 'X'. ULINE. SKIP 2. WRITE: / 'Returncoides from function module MASTER_IDOC_DISTRIBUTE'
COLOR COL_GROUP INTENSIFIED ON. LOOP AT gi_communication_idoc_control INTO g_communication_idoc_control.* Find error message* select single* from TEDS1
WRITE: / g_communication_idoc_control-docnum, g_communication_idoc_control-status.
ENDLOOP. ENDIF.
ENDFORM. " WRITE_REPORT
*&---------------------------------------------------------------------**& Form BUILD_IDOC_CONTROL_RECORD*&---------------------------------------------------------------------*** The IDOC control record contains message type, port and* partnerinformation*----------------------------------------------------------------------
FORM build_idoc_control_record. g_idoc_control_record-mestyp = 'ACC_GL_POSTING'. "Message type g_idoc_control_record-idoctp = 'ACC_GL_POSTING01'. "IDOC type
* Receiver g_idoc_control_record-rcvpor = p_rcvpor. "Port g_idoc_control_record-rcvprn = p_rcvprn. "Partner number g_idoc_control_record-rcvprt = p_rcvprt. "Partner type g_idoc_control_record-rcvpfc = p_rcvpfc. "Partner function
* Sender g_idoc_control_record-sndpor = p_sndpor. "Port g_idoc_control_record-sndprn = p_sndprn. "Partner number g_idoc_control_record-sndprt = p_sndprt. "Partner type* g_idoc_control_record-sndpfc = p_sndpfc. "Partner function
ENDFORM. " BUILD_IDOC_CONTROL_RECORD
*&---------------------------------------------------------------------**& Form BUILD_IDOC_SEGMENTS*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* <-- p2 text*----------------------------------------------------------------------*FORM build_idoc_segments. DATA: l_transdate(8) TYPE c, l_itemnr TYPE i.
CLEAR l_itemnr.
LOOP AT gi_extract INTO g_extract.
* Build data - The structures from the underlying BAPI are used to* simplify thje work of building the data part of the IDOC
*-- Document header segment E1BPACHE08*-- The document header should only be generated in the first loop CLEAR g_edidd.
IF sy-tabix = 1. CLEAR g_e1bpache08. g_edidd-segnam = 'E1BPACHE08'. g_edidd-segnum = 1. g_e1bpache08-obj_type = 'BKPFI'. g_e1bpache08-obj_key = '127387347'. g_e1bpache08-obj_sys = 'APOCLNT800'. g_e1bpache08-username = 'WMHEFRN'. g_e1bpache08-header_txt = 'Humle er godt'. g_e1bpache08-comp_code = g_extract-bukrs. g_e1bpache08-fisc_year = g_extract-gjahr. g_e1bpache08-doc_date = g_extract-budat. g_e1bpache08-pstng_date = g_extract-bldat. g_e1bpache08-trans_date = sy-datum. g_e1bpache08-fis_period = g_extract-monat. g_e1bpache08-doc_type = 'SA'. MOVE g_e1bpache08 TO g_edidd-sdata. APPEND g_edidd TO gi_edidd. ENDIF.
*-- Line item segment E1BPACGL08 CLEAR g_e1bpacgl08. CLEAR g_edidd. l_itemnr = l_itemnr + 1. g_edidd-segnam = 'E1BPACGL08'. g_edidd-segnum = 2. g_e1bpacgl08-itemno_acc = l_itemnr. g_e1bpacgl08-gl_account = g_extract-hkont. g_e1bpacgl08-pstng_date = g_extract-bldat. g_e1bpacgl08-item_text = 'Halli Hallo'. MOVE g_e1bpacgl08 TO g_edidd-sdata. APPEND g_edidd TO gi_edidd.
*-- Line Item Currency Fields segment E1BPACCR08
CLEAR g_e1bpaccr08. CLEAR g_edidd. g_edidd-segnam = 'E1BPACCR08'. g_edidd-segnum = 3. g_e1bpaccr08-itemno_acc = l_itemnr. g_e1bpaccr08-curr_type = '00'. g_e1bpaccr08-currency = g_extract-waers.
IF g_extract-shkzg = 'H'. g_extract-dmbtr = g_extract-dmbtr * -1. ENDIF.
CALL FUNCTION 'CURRENCY_AMOUNT_IDOC_TO_SAP' EXPORTING currency = g_extract-waers idoc_amount = g_extract-dmbtr IMPORTING sap_amount = g_e1bpaccr08-amt_doccur.
MOVE g_e1bpaccr08 TO g_edidd-sdata.
APPEND g_edidd TO gi_edidd. ENDLOOP.
SORT gi_edidd BY segnum. LOOP AT gi_edidd INTO g_edidd. g_edidd-segnum = sy-tabix. MODIFY gi_edidd FROM g_edidd. ENDLOOP. SORT gi_edidd BY segnum.
ENDFORM. " BUILD_IDOC_SEGMENTS
*&---------------------------------------------------------------------**& Form CREATE_IDOCS*&---------------------------------------------------------------------** Create IDOCS*----------------------------------------------------------------------*FORM create_idocs.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING master_idoc_control = g_idoc_control_record TABLES communication_idoc_control = gi_communication_idoc_control master_idoc_data = gi_edidd EXCEPTIONS error_in_idoc_control = 1 error_writing_idoc_status = 2 error_in_idoc_data = 3 sending_logical_system_unknown = 4 OTHERS = 5 . IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE.* Remember to commit ! COMMIT WORK. ENDIF.
ENDFORM. " CREATE_IDOCS
Process outbound IDOCs
Process the outbound IDOCs using program RSEOUT00. The program can be executed from SE38. The IDOC should now have status code 03 Data passed to port OK.
Create inbound IDOCs
The inbound IDOC can be created from the outbound IDOC using transaction WE12 Modification of Outbound file Triggering inbound Procg. The name of the target file is not important, but it must not have the same name as the source file.
Note that the program returns an error, but an inpund IDOC is created.
Source and Sender
The source file must have the same name and path as the outbound file in the partner profile. In this example it is created in the TMP directory which seem to exist in the root directory.
Recipient
Process inbound IDOCs
The inbound IDOC should now have staus code 64. Use program RBDAPP01 to process the inbound IDOC.
Transaction codes
WE02 Display IDOCWE12 Modification of outbound file – Triggering inbound ProcgWE19 Test toolWE20 Partner profilesWE21 Port definitionWE30 IDOC type editorWE31 Segment editorWE60 Display Idoc Types
NACE Conditions for output control
Utility transactions:
MM01 Create materialME21 Create purchase orderMK01 Create vendor - purchasingAL11 View directory onj UnixMK01 Create vendor
Tables:
EDIDC Control record (IDoc)EDID4 IDoc Data Records from 4.0 onwards
Developing IDOCsIf you want to use an existing IDOC og segemnt as template, you can seach for existing IDOCs and segmenst using transaction WE32.
Developing IDOC segments
WE31 Developing IDOC segments. Custom developed segmensts must start with Z. Do not use underscores !
After the segment definition has been created, go 1 screen back and release it Menu Edit-> Set release. From this screen you can also check the segment menu Segment -> Check
Creating basic IDOC type
Transaction WE30
Usefull programsRSEOUT00 Processes outbound IDOCs with status code 30
RBDAPP01 Process inbound IDOCs
RSWWWIDE Deletes work items from the workplace