IDoc Step by Step (EXT)

Source: Internet
Author: User

http://blog.csdn.net/liangziyisheng/article/details/7402239

Create IDoc:

First step: WE31 Create the fields that the IDoc contains.

Step Two: WE30 create IDoc to assign segment to IDoc

Step Three: WE81 Create information types

Fourth step: WE82 the IDoc type corresponds to the information type.

Fifth step: WE57 Assign Message & Idoc Type to a Function Module for Data Process

Sixth step: SM59 Define a RFC connection for Idoc transfer

Seventh Step: WE21 Define a Port (Assign a RFC destination which created in SM59)

Eighth step: we41/42 creat Process Code

Nineth Step: WE20 Define a Partner Profiles (Also creat a Outbound parameters with Port, or Inbound parameters with Process code)

Management IDOC:WE02 Display IDoc, can find idoc based on time, IDoc type, view success, error message.

WE46 IDoc Management (out/in)

WE60 IDoc Type document (you can view the IDOC structure, and the description of each field.)

WE19 according to the IDOC number IDoc processing, can modify the IDoc value for replacement action, processing is divided into inward and outward.

Message configuration: WE20 Configure partner message in and out IDoc types

WE21 configuration Partners.

----------------------instance------------------------------------------------

Outbound idoc-

In short, IDOC is an integrated tool for XML-like SAP systems and other systems. Assuming that I04 and I02 are SAP systems for two different subsidiaries under the same group, I04 need to send their purchase order information to I02 in a timely manner. The following is a brief introduction to the setup steps of IDoc, in order to avoid confusion, my name is more special.

1, set IDoc Type.

(1) WE31, creating segment, similar to creating XML nodes and Node attributes. Here first enter Ypohead, click Create, in the next screen, input Ebeln, Bukrs, Bedat and other fields and their corresponding data element; Then create Ypoitem, enter Ebeln, Ebelp, Matnr, Menge, Meins fields and their corresponding data element. After saving with SE12 view you will find that the system automatically adds the Ypohead and Ypoitem two structures, each of which is a char type, and the length is the EXPORT LENG in WE31.

(2) WE30, create IDoc Type, define the mutual logical relationship between nodes. Enter Ypoidoc First, then click Create, and follow the button to enter new. In the main interface, first click the Create button, add Ypohead, set mandatory seg tick, min = 1, max = 1, each of US IDoc contains only one purchase order. Then add Ypoitem under Ypohead, the same mandatory seg tick, min = 1, max = 99999.

2, create the message Type.

(1) WE81, create the message Type. First switch to edit state, then click New Entries, enter Ypo.

(2) WE82, associated with message type and IDOC type.

3. Create a port to I02. First make sure that the R/3 Connection (SM59) is already in the system to I02, and if not, first create a name of I02001. Then WE21 creates the port, the type transactional RFC, and the I02001 is filled in with the name I02PORT,RFC destination.

4,sale, create the logical System. Define logical systems, a new logical system named I02ls, is added as a partner for the next step. To define a logical system I04LS for the Systems (I04), under define logical systems, there is assign client to logical system, and my definition of client 001 is I04LS.

5,WE20, define our partner profile. Under Partner type for logical system, create a Patner no for i02ls partner,type fill in LS. The following permitted agent, fill us (user), Agent for your own user name or a basis person user name. Then, click the plus sign below outbound to create a outbound parameter. Message type Ypo,receiver port for i02port,output mode Select transfer idoc immed.,basic type to fill in the Ypoidoc, save it.

6, Programming send IDoc set up so much, really tired ah, finally can write program, is not very happy? The idea of the program is to add each IDoc node as a string, and the order of the strings will naturally reflect the logical relationship between the IDOC nodes. The code is as follows:

Data:ls_poheadTYPE Ypohead,

Ls_poitemTYPE Ypoitem,
Ls_edidcTYPE EDIDC,
Lt_edidcTYPETABLEof EDIDC,
Lt_ediddTYPETABLEof EdiddWithHEADER line.
CLEAR LS_EDIDC.
* The system can be associated with the WE20 setting according to the following 4 lines
Ls_edidc-mestyp =' YPO '.The Message Type
LS_EDIDC-IDOCTP =' Ypoidoc '."IDOC Type
LS_EDIDC-RCVPRN =' I02ls '."Partner Number of Recipient
LS_EDIDC-RCVPRT =' LS '."Partner Type of Receiver
* Add IDOC nodes.
CLEAR Lt_edidd.
Lt_edidd-segnam =' Ypohead '.The node name
Lt_edidd-dtint2 =0.
CLEAR Ls_pohead.
Ls_pohead-ebeln =' 4001122334 '.
Ls_pohead-bukrs =' 0400 '.
Ls_pohead-bedat =' 20090630 '.
Lt_edidd-sdata = Ls_pohead."Node content
APPEND Lt_edidd.
CLEAR Lt_edidd.
Lt_edidd-segnam =' Ypoitem '.
Lt_edidd-dtint2 =0.
CLEAR Ls_poitem.
Ls_poitem-ebeln =' 4001122334 '.
Ls_poitem-ebelp =' 0001 '.
LS_POITEM-MATNR =' 000000000000004527 '.
Ls_poitem-menge =' 3 '.
Ls_poitem-meins =' ST '.
Lt_edidd-sdata = Ls_poitem.
APPEND Lt_edidd.
CLEAR Lt_edidd.
Lt_edidd-segnam =' Ypoitem '.
Lt_edidd-dtint2 =0.
CLEAR Ls_poitem.
Ls_poitem-ebeln =' 4001122334 '.
Ls_poitem-ebelp =' 0002 '.
LS_POITEM-MATNR =' 000000000000009289 '.
Ls_poitem-menge =' 5 '.
Ls_poitem-meins =' M '.
Lt_edidd-sdata = Ls_poitem.
APPEND Lt_edidd.
PagerFUNCTION' Master_idoc_distribute '
Exporting
Master_idoc_control = LS_EDIDCThe Export
TABLES
Communication_idoc_control = LT_EDIDCThe Import
Master_idoc_data = Lt_ediddThe Export
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.
MESSAGEID Sy-msgidtype sy-msgty number sy-msgno
     with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
  commit work.
  write:  ' idoc sent: '.
  loop at lt_edidc INTO &NBSP;LS_EDIDC.
    new-line.
    write:  ' Idoc number is ',  ls_edidc-docnum,
                           endloop.
ENDIF.

7, view IDoc. WE05 can see the idoc we just sent, BD87 can also do some processing for idoc.

----------------------instance------------------------------------------------

Inbound Idoc

1, create the IDoc type and message type. Exactly the same as the first two steps in the previous outbound IDoc.

2, create a function:y_idoc_po_process. When the IDOC is set, SAP can automatically call the Funtion module to process the IDoc. So the interface of this function is normative.

The following steps will be introduced in the TCODE:BD51 can query to many inbound Function, such as Idoc_input_bbp_iv, can be referenced to create our interface. You can then write our code to create the corresponding sales order based on the IDoc content.

To simplify, here we just save it in the database table, first create two tables Y02_pohead and Y02_poitem, the fields refer to Ypohead and Ypoitem in WE31.

Then write the following code:

Data:lv_subrcLike SY-SUBRC,
Ls_cheadTYPE Ypohead,
Ls_citemTYPE Ypoitem,
Ls_poheadTYPE Y02_pohead,
Lt_poitemTYPETABLEof Y02_poitemWithHEADER line.
CLEAR Idoc_contrl.
READTABLE Idoc_contrlINDEX1.
IF Idoc_contrl-mestyp <>' YPO '.
RAISE wrong_function_called.
ENDIF.
LOOPAt Idoc_contrl.
Clear:ls_pohead, lt_poitem[].
LOOPAt Idoc_dataWHERE DocNum = Idoc_contrl-docnum.
Case Idoc_data-segnam.
When' Ypohead '.
Clear:ls_chead, Ls_pohead.
Ls_chead = Idoc_data-sdata.
Move-corresponding Ls_cheadTo Ls_pohead.
When' Ypoitem '.
Clear:ls_citem, Lt_poitem.
Ls_citem = Idoc_data-sdata.
Move-corresponding Ls_citemTo Lt_poitem.
APPEND Lt_poitem.
When OTHERS.
Endcase.
Endloop.
LV_SUBRC =0.
INSERT Y02_poheadFrom Ls_pohead.
IF SY-SUBRC =0.
INSERT Y02_poitemFromTABLE Lt_poitem.
LV_SUBRC = SY-SUBRC.
ELSE."The order number already exists
LV_SUBRC = SY-SUBRC.
ENDIF.
IF LV_SUBRC =0.
COMMIT work.
CLEAR Idoc_status.
Idoc_status-docnum = Idoc_contrl-docnum.
Idoc_status-status = "         else.
    rollback work.
    clear idoc_status.
    idoc_status-docnum = idoc_contrl-docnum.
    idoc_status-status =    "IDoc unsuccessful
    idoc_status-msgty =  ' E ' .      idoc_status-msgid =  ' YMSG '.
    idoc_status-msgno =  ' 001 '.
    append idoc_status.
  endif.
Endloop.

3, register our function Module in BD51. In the edit state, click New Entries, fill in the function name Y_idoc_po_process,input type=1.

4, in WE57, associate the Function module with the IDOC type/message type by clicking the new entries,function module input y_idoc_po_process, the type below it is filled in f;idoc Type under Basic type fill in Ypoidoc;message type ypo;direction fill in 2 (Inbound).

5,we42, create inbound Process Code. Note This step must be followed by BD51 and WE57, or an error message will appear. Create a new entry, Process code input YPC_PO, select the processing with ALE service under the option ALE, and select the function module under Processing type. After saving, in the subsequent window, enter the inbound module as y_idoc_po_process.

6,WE20, maintain partner Profiles. First make sure that the Logical System that corresponds to the sender is maintained in the sale, assuming the name is I04LS. (WE05 See your inbound IDOC, you can see its partner name, that's all we need.) This step is similar to the WE20 in the previous article, and the difference is that this is the maintenance of Inbound Parameters coming from I04ls. Message type Enter ypo,process type input YPC_PO, and then select "Trigger immediately".

7, at this point, our setup is complete. When the system receives the IDOC from I04, it is processed immediately. At the same time, you have done practice for the last friend, the system should leave a few in the wrong state of IDoc it? You can use BD87, after the main interface to select the Ypo node, click the Process button, one-time processing. Before processing, you can debug by opening y_idoc_po_process in SE37 and setting a few breakpoints.

Add: (1) If the status code is 56, then it should be your WE20 not set well;

(2) Since the above code controls cannot insert the same purchase number, so only one Inbound IDoc will handle the success (status Code 53), the rest will fail (status code 51). As long as the newly sent IDoc assigned to a different purchase number can be avoided.

(3) The status code of the Outbound is 0-50, 03 means the Ok;inbound status code is 50-99, and 53 means OK.

IDoc Step by Step (EXT)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.