Wednesday, January 11, 2017

IDOC

IDOC – ALE – EDI
  1. What is IDOC, ALE and EDI?
  1. IDOC
IDOC (stands for Intermediate Document) is a SAP standard format for transferring data between systems. Each IDOC exists as a self-contained text file that can be transmitted directly to the requesting workstation without a central database.

An IDOC structure includes three parts:
  • One Record Control: contains administrative information such as the IDOC’s functional category (Message Type/Basic IDOC Type), as well as its origin (Sender) and destination (Receiver) as in conventional EDI.
  • One or Many Data Record: Includes application data in the segments and describes the hierarchy of these segments in the IDOC. An IDOC always contains a header segments consisting of 6 fields:
    • SEGNAM – Segment
    • MANDT – Client
    • DOCNUM – IDOC Number
    • SEGNUM – Segment Number
    • PSGNUM – Number of the Parent Segment
    • HLEVEL – Hierarchy Level
  • One or Many Status Record: contains all previous processing status as well as messages…
  1. ALE and EDI
IDOC uses ALE (Application Link Enabling) and EDI (Electronic Data Interchange) to deliver the data to the receiving systems. When the data needs to be transferred between two SAP systems, then IDOC uses the ALE Technology. For the exchange data between a SAP system and a non-SAP system, IDOC uses EDI to convert and deliver the data.
The data exchange process comprises of two distinct processes: Outbound process and Inbound Process.
An application function module creates a master IDoc in outbound processing, the so-called master IDoc.
The following steps are carried out in the ALE layer:
  • Receiver determination, if this has not already been done by the application.
  • Data selection
  • Segment filtering
  • Field conversion
  • Version change
  • Dispatch control
The formatted IDoc is passed to the communication layer and from here sent to the system that was called (server) via a transactional remote function call (RFC) or via file interfaces (for example, EDI).
If an error occurs in the ALE layer, the IDoc containing the error is saved and a workflow task is created. The ALE administrator can use this workflow to correct the error.
  1. Outbound process
The data exchange process occurs between two following SAP systems:

SENDER
RECEIVER
Server
54.169.86.172
54.179.161.35
Client
800
050
TABLE
ZIDOCTEST
ZIDOCTEST
Step 1: Create ZIDOCTEST table on Sender systems and put some records:

Step 2: Use T-Code SALE for Creating Logical Systems and Assign to Clients
Assign Logical System to Clients


Step 3: Use T-Code SM59 for creating RFC connections with valid logon information:

Step 4: Use T-Code WE21 for creating Transactional RFC Port:

Step 5: Use T-Code WE31 to create Data Segment structure, have same fields as ZIDOCTEST table but not the MANDT field.

Step 6: Use T-Code WE30 to create Basic IDOC Type and assign Data Segment:
Step 7: Use T-Code WE81 to create Message Type:

Step 8: Use T-Code WE82 to assign Message Type to Basic IDOC Type:

Step 9: Use T-Code BD64 to create Model View and Distributing and Generating Partner profile:
Select the new Model View, click on menu Edit -> Add Message Type:
Generate Partner Profile by click on menu Environment -> Generate Partner Profiles, then click on Execute button

Back to Model View Screen, Distribute the Model View by clicking on menu Edit -> Model View -> Distribute, and select the Receiver System:
Step 10: Check again the Partner Profiles in T-Code WE20:
Now create a Report Program in SE38 to create IDOC control records from ZIDOCTEST table and transfer it to receiver system.

REPORT ZIDOCTEST.

DATA: IT_ZIDOCTEST TYPE STANDARD TABLE OF ZIDOCTEST WITH HEADER LINE,
     IT_COMM TYPE STANDARD TABLE OF EDIDC WITH HEADER LINE,
     IT_EDIDD TYPE STANDARD TABLE OF EDIDD WITH HEADER LINE,

     GW_HEADER  LIKE EDIDC,
     GW_ZIDOCSEGTEST  LIKE ZIDOCSEGTEST.

START-OF-SELECTION.
 SELECT *
   FROM ZIDOCTEST
   INTO TABLE IT_ZIDOCTEST.

 IF SY-SUBRC = 0.
   LOOP AT IT_ZIDOCTEST.
     MOVE-CORRESPONDING IT_ZIDOCTEST TO GW_ZIDOCSEGTEST.
     IT_EDIDD-SEGNAM = 'ZIDOCSEGTEST'.
     IT_EDIDD-SDATA = GW_ZIDOCSEGTEST.

     APPEND IT_EDIDD.
     CLEAR IT_EDIDD.
   ENDLOOP.

   GW_HEADER-RCVPOR = 'PORTIS1050'.
   GW_HEADER-MESTYP = 'ZMESTYP_TEST'.
   GW_HEADER-IDOCTP = 'ZIDOCTYPTEST'.
   GW_HEADER-RCVPRT = 'LS'.
   GW_HEADER-RCVPRN = 'IS1CLNT050'.
   GW_HEADER-SNDPRT = 'LS'.
   GW_HEADER-SNDPRN = 'IDSCLNT800'.

   CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
     EXPORTING
       MASTER_IDOC_CONTROL            = GW_HEADER
     TABLES
       COMMUNICATION_IDOC_CONTROL     = IT_COMM
       MASTER_IDOC_DATA               = IT_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 SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ELSE.
     COMMIT WORK.
     LOOP AT IT_COMM.
       WRITE:/ 'IDoc Generated - ', IT_COMM-DOCNUM.
     ENDLOOP.
   ENDIF.

 ENDIF.

  1. Inbound process
Step 1: Create ZIDOCTEST table same as Sender System without any data:
Step 2: Use T-Code SALE for Creating Logical Systems and Assign to Clients

Assign Logical System to Clients

Step 3: Use T-Code SM59 for create RFC connections with valid logon information:

Step 4: Use T-Code WE21 for creating Transactional RFC Port:

Step 5: Use T-Code WE31 to create Data Segment structure, have same fields as ZIDOCTEST
table but not the MANDT field.

Step 6: Use T-Code WE30 to create Basic IDOC Type and assign Data Segment:
Step 7: Use T-Code WE81 to create Message Type:

 Step 8: Use T-Code WE82 to assign Message Type to Basic IDOC Type:

Step 9: Create a Function Module for triggering IDOC coming to Receiver System:

FUNCTION ZFM_IDOC_TEST.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(INPUT_METHOD) LIKE  BDWFAP_PAR-INPUTMETHD
*"     REFERENCE(MASS_PROCESSING) LIKE  BDWFAP_PAR-MASS_PROC
*"  EXPORTING
*"     REFERENCE(WORKFLOW_RESULT) LIKE  BDWF_PARAM-RESULT
*"     REFERENCE(APPLICATION_VARIABLE) LIKE  BDWF_PARAM-APPL_VAR
*"     REFERENCE(IN_UPDATE_TASK) LIKE  BDWFAP_PAR-UPDATETASK
*"     REFERENCE(CALL_TRANSACTION_DO) LIKE  BDWFAP_PAR-CALLTRANS
*"  TABLES
*"      IDOC_CONTRL STRUCTURE  EDIDC
*"      IDOC_DATA STRUCTURE  EDIDD
*"      IDOC_STATUS STRUCTURE  BDIDOCSTAT
*"      RETURN_VARIABLES STRUCTURE  BDWFRETVAR
*"      SERIALIZATION_INFO STRUCTURE  BDI_SER
*"  EXCEPTIONS
*"      WRONG_FUNCTION_CALLED
*"----------------------------------------------------------------------

 INCLUDE MBDCONWF.

 TABLES: ZIDOCTEST.

 DATA: LW_ZIDOCSEGTEST TYPE ZIDOCSEGTEST,
       LT_ZIDOCTEST LIKE ZIDOCTEST OCCURS 0 WITH HEADER LINE.

 WORKFLOW_RESULT = C_WF_RESULT_OK.

 LOOP AT IDOC_CONTRL.
   IF IDOC_CONTRL-MESTYP NE 'ZMESTYP_TEST'.
     RAISE WRONG_FUNCTION_CALLED.
   ENDIF.

   LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL-DOCNUM.
     LW_ZIDOCSEGTEST = IDOC_DATA-SDATA.
     MOVE-CORRESPONDING LW_ZIDOCSEGTEST TO LT_ZIDOCTEST.
     INSERT INTO ZIDOCTEST VALUES LT_ZIDOCTEST.

     APPEND LT_ZIDOCTEST.
   ENDLOOP.

   UPDATE ZIDOCTEST FROM LT_ZIDOCTEST.

   IF SY-SUBRC = 0.
     IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
     IDOC_STATUS-STATUS = '53'.
     IDOC_STATUS-MSGTY  = 'I'.
     IDOC_STATUS-MSGID  = 'YM'.
     IDOC_STATUS-MSGNO  = '004'.
     IDOC_STATUS-MSGV1  = LT_ZIDOCTEST-DOC_ID.

     APPEND IDOC_STATUS.
     CLEAR IDOC_STATUS.
   ELSE.
     IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
     IDOC_STATUS-STATUS = '51'.
     IDOC_STATUS-MSGTY  = 'E'.
     IDOC_STATUS-MSGID  = 'YM'.
     IDOC_STATUS-MSGNO  = '005'.
     IDOC_STATUS-MSGV1  = LT_ZIDOCTEST-DOC_ID.

     APPEND IDOC_STATUS.
     CLEAR IDOC_STATUS.

     WORKFLOW_RESULT = C_WF_RESULT_ERROR.
     RETURN_VARIABLES-WF_PARAM = 'Error IDOCs'.
     RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.

     APPEND RETURN_VARIABLES.
     CLEAR RETURN_VARIABLES.
   ENDIF.
 ENDLOOP.
ENDFUNCTION.

Step 10: Use T-Code WE57 to assign FM to Logical Message
Step 11: Use T-Code BD51 to Define Input Method for Inbound Function Module:

Step 12: Use T-Code WE42 to create Process Code:


Add Logical Messages to Process Code:
Step 13: Use T-Code BD64 to Generate Partner Profiles:

Step 14: Check again the Partner Profiles in T-Code WE20:
  1. Test transferring Data:
In Sender Systems, execute test program to send data to Receiver System.
Check IDOC Status in T-Code WE02:
The current status is ‘30’ (processing), then process manually in T-Code SE38, program RSEOUT00. Then check the IDOC status again.
Check Data on Receiver System:
Implement the following "triple" into your program that creates the idocs:
 CALL FUNCTION 'DB_COMMIT'.
 CALL FUNCTION 'DEQUEUE_ALL'.
 COMMIT WORK.
Please note: Function module DEQUEUE_ALL dequeues all locks. In case you need to delete the lock of your single IDoc only, please use function
module EDI_DOCUMENT_DEQUEUE_LATER. This function module dequeues the IDoc with the imported IDoc number only.

No comments:

Post a Comment

SAP giới thiệu mã hỗ trợ AI trong ngôn ngữ ABAP riêng của mình

SAP đã ra mắt một loạt tính năng mã hỗ trợ AI trong môi trường phát triển ứng dụng dựa trên đám mây của mình, đồng thời tham gia vào danh sá...