You are on page 1of 27

2019-10-10

INSTOCK TO IPAS
USING EDI WITH IDOC

CHENG ZHANG
INOSSEM CANADA INC.
SUITE 1620, 2075 ROBERT-BOURASSA BLVD., MONTREAL, CANADA
目录
1. Custom IDoc Development Workflow ....................................................................................... 2

2 Develop IDOC....................................................................................................................................... 3

2.1 TCODE: SE11 Creating Custom Table .................................................................................. 3

2.2 TCODE: WE31 Creating the Segments................................................................................. 6

2.3 TCODE: WE30 Building an IDoc Basic Type ....................................................................... 8

2.4 TCODE: WE81 Create a Custom Message Type ............................................................. 11

2.5 TCODE: WE82 Link Message to Basic Type ..................................................................... 12

3 Code IDoc Function ......................................................................................................................... 13

3.1 TCODE: SE37/SE80 Create a new function group ......................................................... 13

3.2 TCODE: SE37/SE80 Create a new function module ...................................................... 14

3.2.1 For an Inbound IDoc ........................................................................................................ 14

4 Configure Interfaces ........................................................................................................................ 19

4.1 TCODE: WE57 Link the Function to Message and Basic Type .................................. 19

4.2 TCODE: BD51 Set Attributes for the Function................................................................ 20

4.3 TCODE: WE42 Create a Custom Process Code ............................................................... 20

4.5 TCODE: WE20 Define the Partner Profile ......................................................................... 22

5 Testing the EDI System in SAP .................................................................................................... 24

5.1 IDoc Test Tools .......................................................................................................................... 24

5.2 The Main IDoc Test Tool: Transaction WE19 .................................................................. 25


1. Custom IDoc Development Workflow

Figure 1.1 outlines the three steps for building a custom IDoc: develop the IDoc, code
the IDoc function, and configure the interface.

Figure 1.1
2 Develop IDOC
2.1 TCODE: SE11 Creating Custom Table
First, we create the custom table ZSEWM_DELIV. The IDoc will post its data to this table
and it is a mandatory part of the development cycle.

1. Run Transaction SE11 and enter table name ZSEWM_DELIV into the Database table field.
2. Click Create to open the Dictionary:

a. Change Table screen in the Delivery and Maintenance tab.

b. Enter a table description in the Short Description field


c. Enter Select Delivery Class A for application data (master and transaction data).
3. In the Fields tab, enter the field values see in Figure 2.1.

Figure 2.1

Figure 2.1.1
4. In the Currency/Quantity Fields tab a link must be made between the quantity field MENGE
and a corresponding unit of measure field in an existing table.
5. Save the table and assign it to a transport.
6. Click Technical Settings and set Data Class to APPLI (Transaction Data, Transparent Tables)
and Size Category to 0 (Data records expected: 0 to 4,300).

7. Save and click Revised <-> Activate.


8. Return to the Fields tab and click Activate (Ctrl+F3) in the toolbar above the table name
field.
2.2 TCODE: WE31 Creating the Segments
We'll begin by creating the segments. We need to create two segments, which are
ZDELISTATUS and ZDELILIST.

Figure 2.2 lists the structure of the segment ZDELISTATUS.

Figure 2.2

1. We'll first create ZDELISTATUS in the segment editor. Go to Transaction WE31, enter
“ZDELISTATUS” into the Segment type field, and click Create.
2. Create the following fields:
a. Enter “ZTYPE” in Field Name and “ZE_INT_TYPE” in Data element.
b. Enter “ZERNAM” in Field Name and “UNAME” in Data element.
c. The rest of field names are use same way to fill out.
3. Click Save. Assign the segment to a package and a change request.
4. Press (F3) to back out to the segment editor’s opening screen. Release the segment by
selecting menu option Edit • Set Release. Once released, the initial screen will look like
Figure 2.2.1.

Figure 2.2.1

5. Follow the same steps to create and release details segment ZDELILIST.
2.3 TCODE: WE30 Building an IDoc Basic Type
We'll create our custom IDoc basic type with Transaction WE30.

1. Enter "ZINSDELI" into the Obj. name field, select Basic type, and click Create. The Create
Basic Type dialog opens after the system informs you that the name is longer than eight
characters. The following are radio buttons under New basic IDoc type: (Figure 2.3)

Figure 2.3

a. Create new builds a new custom IDoc type.


b. Create as copy copies an existing IDoc type that we can change.
c. Create successor creates a new release version of an existing custom IDoc type.

Figure 2.3.1
2. Select Create new and click OK to open the IDoc type editor. We'll assemble our basic
type from segments in this screen. To add segments, put the cursor on the IDoc type root
name and click Create segment, press (Shift)+(F6), or follow the menu path Edit •->Create
Segment.

Figure 2.3.2

3. The Maintain Attributes dialog opens, as in Figure 8.13. To add header segment ZIVPRH,
do the following:
a. Enter "ZDELISTATUS" in the Segment type field.
b. Select the Mandatory seg. checkbox.
c. Enter "1" in Minimum number and "1" in Maximum number.

Figure 2.3.3
4. Click OK. "ZDELISTATUS" is inserted as a child of the basic type root. Select
"ZDELISTATUS" and click Create segment to add the details segment.

Figure 2.3.4

5. The Segment Hierarchy dialog opens. Select Add segment type as child.
6. Click OK to open the Maintain Attributes dialog. Do the following for the next segment:
a. Enter “ZDELILIST” in the Segment type field.
b. Select the Mandatory seg. checkbox.
c. Enter "1" in Minimum number and "999999" in Maximum number.

Figure 2.3.5
7. ZDELILIST is added as a child segment to ZDELISTATUS, as shown in the basic type editor
in Figure 2.3.6.

Figure 2.3.6

8. Double-click ZDELILIST to view the Maintain Attributes dialog. The parent segment is
ZDELISTATUS, and the hierarchy level is 2.

Figure 2.3.7

9. Save the basic type and assign it to a package and a change request. Back out of the edit
window. Release the IDoc basic type by selecting menu option Edit • Set Release.

2.4 TCODE: WE81 Create a Custom Message Type


Next, we create the logical message.

1. Use Transaction WE81 and click Display Change (menu option Table View • Display ->
Change).
2. Click New Entries (menu option Edit • New Entries) to open the Overview of Added Entries
screen.
3. Enter " ZINS10 " in Message type and a description of the message in the Short text field,
as shown in Figure 2.4.

Figure 2.4

4. Save the message type and assign it to a customizing request.

2.5 TCODE: WE82 Link Message to Basic Type


Now we link the logical message to the basic type with Transaction WE82.

1. Click Display Change (menu option Table View • Display -> Change)
2. Then click New Entries (menu option Edit • New Entries) to open the Overview of Added
Entries screen.
3. Enter the following values into the table control, as illustrated in Figure 8.16:
a. Enter “ZINS10” in the Message type field.
b. Enter “ZINSDELI” in the Basic type field.
c. Enter version "740" (your current SAP system release) in the Release field.
4. Save the entry and assign it to a customizing request.

3 Code IDoc Function


3.1 TCODE: SE37/SE80 Create a new function group
We'll create the function group in the object navigator.

1. Run Transaction SE80 and click Edit Object at the top of the Object Navigator window. 2.
Select the Function group tab, enter "ZWM_INSTOCK_IPAS" in the Group name field, and
click Create.

Figure 3.1

2. The Create Function Group dialog opens. Enter a short description in the Short text field
and click Save.
3. Assign the function group to a package and a change request.

Function group ZWM_INSTOCK_IPAS is now ready for coding.

3.2 TCODE: SE37/SE80 Create a new function module


3.2.1 For an Inbound IDoc
We're still in the object navigator:

1. Right Click Function Group, select create, click function module, enter the function name
"ZMW_IPAS_10".

2. Click Save. The Create Function Module dialog opens.

Figure 3.2
3. The Import parameters screen of the Function Builder opens. We'll use standard import
parameters that will be passed to the function by the IDoc interface at runtime.
4. Enter the following values illustrated in Figure 3.2.1.

Figure 3.2.1

5. Export parameters return workflow and other information to the IDoc interface at
runtime. You can also return document numbers and other application data for reporting.
Click the Export tab and enter the values illustrated in Figure 3.2.2.

Figure 3.2.2

6. Click the Tables tab and enter the values for the internal tables listed in Figure 3.2.3. The
tables will pass data in and out of the function. We’re most interested in the IDoc
control, data, and status records. We won't add any exceptions for this example.
Figure 3.2.3

7. Click the Source code tab and enter the function's code.

function zwm_ipas_10.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" VALUE(MBLNR) TYPE MKPF-MBLNR
*" VALUE(MJAHR) TYPE MKPF-MJAHR
*" VALUE(VBELN) TYPE LIKP-VBELN
*" VALUE(RETURN) TYPE BAPIRET2
*" 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
*"----------------------------------------------------------------------

data: gs_zstatus type zdelistatus,


gs_list type zdelilist.

data: gt_deliv1 type standard table of ZSEWM_DELIV with header line,


gs_import type zstr_001.
data: gv_type type c length 2,
gv_vbeln type vbeln,
gv_bldat type datum.
loop at idoc_contrl.
refresh gt_deliv1. clear gt_deliv1.

loop at idoc_data where docnum = idoc_contrl-docnum.


case idoc_data-segnam.
*process header record
when 'ZDELISTATUS'.
gs_zstatus = idoc_data-sdata.
gs_import-ztype = gs_zstatus-ztype.
gs_import-zernam = gs_zstatus-zernam.
gs_import-zdate = gs_zstatus-zdate.
gs_import-ztime = gs_zstatus-ztime.
gs_import-zdjbh = gs_zstatus-zdjbh.
gv_vbeln = gs_zstatus-iv_vbeln.
gv_bldat = gs_zstatus-iv_date.
gv_type = gs_zstatus-iv_type.

*process detail record


when 'ZDELILIST'.
gs_list = idoc_data-sdata.

gt_deliv1-vbeln = gs_list-vbeln.
gt_deliv1-posnr = gs_list-posnr.
gt_deliv1-matnr = gs_list-matnr.
gt_deliv1-charg = gs_list-charg.
gt_deliv1-lgort = gs_list-lgort.
gt_deliv1-dlv_qty = gs_list-dlv_qty.
gt_deliv1-dlv_qty_imunit = gs_list-dlv_qty_imunit.
gt_deliv1-fact_unit_nom = gs_list-fact_unit_nom.
gt_deliv1-fact_unit_denom = gs_list-fact_unit_denom.
gt_deliv1-base_uom = gs_list-base_uom.
gt_deliv1-base_uom_iso = gs_list-base_uom_iso.
gt_deliv1-zdjbh = gs_list-zdjbh.
gt_deliv1-zdjxm = gs_list-zdjxm.
gt_deliv1-posnv = gs_list-posnv.
gt_deliv1-extra1 = gs_list-extra1.
gt_deliv1-extra2 = gs_list-extra2.
gt_deliv1-extra3 = gs_list-extra3.
gt_deliv1-extra4 = gs_list-extra4.
gt_deliv1-extra5 = gs_list-extra5.
gt_deliv1-extra6 = gs_list-extra6.
gt_deliv1-extra7 = gs_list-extra7.
gt_deliv1-extra8 = gs_list-extra8.
gt_deliv1-extra9 = gs_list-extra9.
gt_deliv1-extra10 = gs_list-extra10.
append gt_deliv1.
clear gt_deliv1.

endcase.
endloop.
*-------------------------------------------------------------------

if sy-subrc = 0.
*success message to status record
clear idoc_status.
idoc_status-docnum = idoc_contrl-docnum.
idoc_status-msgty = 's'.
idoc_status-msgid = 'ZEDI01'.
idoc_status-msgno = '001'.
idoc_status-status = '53'.
idoc_status-msgv1 = ls_data-message.
append idoc_status.
else.
*verify record count and total before updating.
clear idoc_status.
idoc_status-docnum = idoc_contrl-docnum.
idoc_status-msgty = 'e'.
idoc_status-msgid = 'ZEDI01'.
idoc_status-msgno = '002'.
idoc_status-status = '51'.
idoc_status-msgv1 = ls_data-message.
append idoc_status.
endif.

endloop.
ENDFUNCTION.

This code is stripped down to its essentials. The control and data records are imported into the
function at runtime through the IDOC_CNTRL and IDOC_DATA internal tables. The program logic
follows:

1. Loops through IDOC_CNTRL.


2. Loops through IDOC_DATA at the current IDoc number.
3. Evaluates the SEGNAM field for the current segment name.
4. Moves the SDATA field in the data record to a string structured by the segment type.
5. Moves data from the structured string to an internal table structured by our target
database table ZSEWM_DELIV.
6. When the loops on IDOC_DATA and IDOC_CNTRL are done and internal table
ZSEWM_DELIV is fully populated with all IDoc data, then database table ZSEWM_DELIV is
updated from the internal table.
7. If the update succeeds, the status record is updated with status 53, and a success
message pulled from custom message class ZEDI01.
8. If the update fails, the status record is updated with status 51, and an error message
pulled from custom message class ZEDI01.
9. Status and message values are passed to internal table IDOC_STATUS and returned to the
calling IDoc interface function IDOC_INPUT, which passes them to routines that update
the status records in the database.

4 Configure Interfaces
4.1 TCODE: WE57 Link the Function to Message and Basic Type
First up is to link the custom function to our logical message and basic type.

1. Go to Transaction WE57, and click Display -> Change (menu path Table View • Display ->
Change)
2. Click New Entries (or press F5) to open the Details of Added Entries screen and enter the
following values into it:
a. Enter "ZWM_IPAS_10" into the Function Module field.
b. Select Function module from the Function Type dropdown.
c. Enter "ZINSDELI" in the Basic type field.
d. Enter "ZINS10" in the Message Type field.
e. Select Inbound from Direction dropdown.

Figure 4.1

3. Click Save and assign the changes to a customizing request. The screen should look like
Figure 4.1 after you're done.
4.2 TCODE: BD51 Set Attributes for the Function
To set attributes for the function, follow these steps:

1. Go to Transaction BD51 and click New Entries.


2. Enter "ZWM_IPAS_10" in the Function module (inbound) field and “0” in Input t. column
for direct input. The function directly inserts IDoc data into the custom table.

Figure 4.2

3. Save and assign the attributes to a transport. The screen should look like Figure 4.2.

4.3 TCODE: WE42 Create a Custom Process Code


The process code ties all the processing pieces together.

1. Go to Transaction WE42, and switch to change mode.


2. Click New Entries to open the Details of Added Entries screen, and do the following:
a. Enter “ZINSDELI” in the Process code field.
b. Enter a text description in the Description field. Begin the description with the
message name.
c. Set Processing type as the function module.

3. Save the entry and assign it to a transport.


4. A more detailed view of the Added Entries screen opens. Select the function
"ZWM_IPAS_10" from the Function Module dropdown list.
5. Save and add to a transport. After the function has been assigned, back out via F3 to the
added entries screen. The function name will be linked to the process code.
6. Double-click the Logical message folder in the Dialog Structure navigation display to
open the Logical message overview screen. Click New Entries and enter "ZINS10" into the
Message type field.

Don't forget to save. This completes the link between the process code, the logical
message, and the custom function module. All these objects are now ready to be used in
a partner profile.

4.5 TCODE: WE20 Define the Partner Profile


All that's left is the inbound partner profile. The inventory report is coming from the
supplier Disc Services International, entered in Acme's SAP vendor master as DISK01.

So, we'll create a partner profile with partner type LI for vendor.

1. Run Transaction WE20, select the Partner Type LI folder, and create a vendor partner
profile header for DSI with partner number DISK01.
2. Save the general view and create inbound parameters to add message type ZINS10. Enter
the following values into the Inbound parameters screen:
a. Enter "LS" in the Partner Role field.
b. Enter "ZINS10" in the Message type field.
c. Enter "ZINSDELI" in the Process code field.
d. Set Trigger Immediately as the processing mode. This is a simple table insert that
comes in once a day and doesn’t involve a lot of processing, so we won't
schedule a background job.
Figure 4.5

3. Save the partner profile. The finished product should look like the inbound partner profile
in Figure 4.5.

5 Testing the EDI System in SAP


5.1 IDoc Test Tools
EDI is a prime example of the old saying, “The more things change, the more they stay
the same.” These test tools largely reflect an earlier era in SAP when it was still assumed
that business documents would be exchanged through file-based interfaces.

However, many businesses continue to do EDI through file-based batch processing


exchanges of standard messages. It is highly unlikely that this will change anytime soon.
SAP's IDoc test tools can be used in several ways:

1. Proof of concept
Confirm use of a message type to post against an SAP document or data record
2. Posting requirements
Confirm data required to post an IDoc to an SAP document or record
3. Configuration
Confirm IDoc configuration settings such as message control, partner profiles, and
ports
4. Development
Debug IDoc functions and user exits

5.2 The Main IDoc Test Tool: Transaction WE19


Transaction WE19 supports all types of unit testing. It is especially useful for inbound
testing because it supports stepping through the code of an IDoc function in the ABAP
debugger, invaluable for working with custom IDocs and functions and a wonderful way
to learn how IDoc functions work.

Inbound IDocs can create a business document through Transaction WE19, making it
the place to go to identify the message type and data requirements for posting to a
particular SAP document or transaction.

The Transaction WE19 selection screen offers several options for processing IDocs; these
are shown in Figure 20.1. For inbound testing, we use BasicTyp or Via message type.
Enter the message type "ZINS10", we'll see the structure of the idoc.

Double click each segment to fill out all the mandatory fields.

Then click Standard inbound button on the menu. we will get the generated idoc
number.

Now go to Tcode BD87, enter the idoc number you just got, and see the status of this
idoc whether it shows error message or passed.

You might also like