Vous êtes sur la page 1sur 78

FINAL REPORT CPEG 598 A

ELECTRONIC DATA INTERCHANGE (EDI)

INSTRUCTOR : PROF. AUSIF MAHMOOD

SUBMITTED BY: ANANTH GOWRI SANKAR PATURU

STUDENT ID NO. 573097.

EDI: It is the electronic exchange of documents between the computer systems of partners, using a standard format over a communication network. BENEFITS OF THE EDI PROCESS: The implementation of EDI benefits both the sender and the receiver. The following things can be minimized with this process: Reduced data entry errors: EDI does not involve data entry at multiple points. In a regular process, a sender creates an document on the system, prints the document, and then faxes or mails it to the receiver. The receiver then re keys the same information on their computer. With this procedure, data goes directly from one computer to the another without any involvement. Reduced process cycle time : The biggest advantage is the reduced processing time of the complete cycle. As soon as documents are entered into the system, they can be processed on the receiving side in seconds. There is a considerable savings in the processing time of document transfer. Availability of data in electronic form. Data from EDI is a electronic form, which makes it easy to share across the organization. For example, a purchasing department can use the data to evaluate vendors, or a marketing department can use the data to analyze the trends and demands of customers.

Reduced cost : The initial cost of an EDI setup is certainly higher compared to the paper process, but over a long period it is very cost effective. In the long term, the overall cost of exchanging business documents in paper form can cost less per transaction. Standard means of communication : Because EDI enforces standards on the contents of data, uniform naming standards and field sizes have emerged. Such consistency leads to clearer communication and less ambiguity.

IMPLEMENTATION: EDI can be implemented in two process: 1. Outbound Process. 2. Inbound process. Outbound process : In this process, we create the document, and the document is transmitted to the Operating system layer and it is transmitted over a TCP/IP network. The outbound process has some specifications and standards which has to be done before transmitting the document. The outbound process uses 1. IDOC types 2. selection programs. 3. Message control. 4. Partner profiles. 5. Port Definitions 6. Service Programs. 7. Tables to generate an IDOC. 1. IDOC types: The EDI document to be generated has an equivalent message type defined in the SAP system. The message type is based on an IDOC structure. As an example, if an EDI transaction of 850, which is a purchase order, is to be generated, the message type ORDERS is assigned to it. This message is based on

IDOC type ORDERS01 and ORDERS02. The IDOC type is the most important component in the EDI process. 2. Selection programs: These are typically implemented as function modules, which are designed to extract application data and create an IDOC. A selection program exists for each message type. The programs are generally named with the following naming convention: IDOC_OUTPUT_<message type> In my project, the selection program for message type ORDERS is IDOC_OUTPUT_ORDERS. A four character process code, ME10, has been assigned to this function module. The list of outbound process codes and their corresponding function modules can find with the transaction : T-code : WE41. 3. Message control: It is used in pricing, account determination, material determination, and output determination. The message control component enables to encapsulate business rules without having to write programs. In the EDI process, Message control determines and processes the various outputs associated with an application document. 4. Port Definition : A port is used in the outbound process to determine the name of the EDI subsystem program, the directory path where the IDOC file will be created at the operating system level, the IDOC file names, and the RFC destination. 5. Partner profiles: The partner profiles specifies the various components used in the outbound process, the mode in which it communicates with the subsystem and the person to be notified in case of errors. 6. Service programs and Configuration tables: The asynchronous outbound process can be seen as a sequence of several processes that work together. In this service programs and configuration tables are used to link the process. The process flow for the outbound process describes the role played by each service program and configuration table.

INBOUND PROCESS: The inbound process uses the following components to post and application document from the IDOC: 1. IDOC type. 2. Port Definition. 3. Posting programs 4. Service programs. 5. configuration tables. All the things described above are the same except for the posting programs. Posting programs: These are implemented in the system as function modules. A posting program exists for each message type. The posting programs are named with the following naming convention. IDOC_INPUT<message type> In my project, the posting program for the message type ORDERS I have taken is IDOC_INPUT_ORDERS. A four- character process code, ORDE, has been assigned to this function module. The list of inbound process codes and their corresponding function modules by executing the following transaction. T-CODE : WE42.

With the above specifications, I have configured the following things before actually start working on the interchange process : 1. Configuration of Port Definition. 2. Configuration of Partner Profiles. 3. Assigning number range and selection of IDOC. 4. Assigning organization and user. 5. Setting up RFC destination. 6. Creation of Purchasing document. 7. Creation of receiving fields information.

1.Configuration of Port Definition: In this section, we provide the complete details about the subsystem, the outbund file and the function module we are using, the status file, which tells about the status of the IDOC. Transaction Code: WE21.

For EDI process, the port that is used is the FILE port. Transaction RFCs are used for ALE applications. Internet port is used for internet applications. XML port is used for XML applications. This is a very important step in the whole process, because all the outbound, inbound and status files are stored in the port definitions. Configuration of Partner Profiles:

It is important to maintain the profiles of each partner in the business scenario with whom we exchange our business documents. TRANSACTION : WE20. There are three views of a partner profile in which different parameters can be entered as a partner : General Parameters view : These values are stored in table EDPP1. In this view, it contains very basic information about the partner, such as partner number, partner type, and default individual to notify in case an error occurs. These partner attributes appear at the top of the main partner profiles screen and under the post

processing : permitted agent and classification tabs.

Partner number : In EDI, the partner number is a customer number or bank ID. In this case, I have taken my student number(573097) as my partner number. Partner type : The partner type represents the type of our business partner. In this case, I have taken type as customer(KU).

Assigning number range and selection of IDOC: This is done by the following transaction. This is very important in every EDI applications because it will be a big problem if two IDOCs are assigned a same value. T- Code : WE46.

Setting up RFC destination : Every transaction that is transmitted over a network must know the destination point before it is transmitted. This is done by using the Remote Function Call called as RFC. The program called SERVER_EXEC is selected for TCP/IP connections. The transaction code used for this process is : SM59. This program starts an application on the server and establishes a network between the two systems.

Creation of application document: T-code : ME11. In my project, I have taken a purchasing order as the application document and created all the required fields in the document and saved. As soon as the application document is saved, it fills all the details in the database tables.

The yellow state in the output screen tells that the document is saved without any errors. Creation of receiving fields information: For every transaction, the receiver information must be entered for every transaction. This can be done with the following transaction. T-code : XD02.

The receiver fields are the most critical in the EDI transaction. If there is something wrong in the information, the application document is transmitted and the acknowledge is given to the sender. But before the transmission, the receiver is notified that the information is available and waits for the permission whether it is ready to share. In this way, all the fields in the receiver section should be filled before actually sending the document. THE FOLLOWING STEPS ARE DONE FOR THE SUCCESSFUL TRANSMISSION OF EDI DOCUMENT: STEP 1: DEFINING THE GLOBAL PARAMETERS FOR IDOC: Transaction Code: WE47. In order an Idoc to be transmitted, it should be first assigned so that all application components can identify the type of Idoc.

This can be done by giving the administrator name and its type. CONFIGURING THE PARTNER PROFILES: Transaction code : WE20. I have created a partner profiles with Partner number : 123 (ANANTH GOWRI SANKAR PATURU) Partner type : Customer. OUTBOUND PARAMETERS: Message type : ORDRSP. Receiver port : SUBSYSTEM (because all my transactions are residing in my R/3). Idoc type : ORDERS05 Application : EF (which is the message type supported for this application ). Process code : SD10 ( Every transaction of this message type for outbound process needs a process code SD10). INBOUND PARAMETERS: Message type : ORDERS. Receiver port : SUBSYSTEM (because all my transactions are residing in my R/3). Idoc type : ORDERS05 Application : EF (which is the message type supported for this application ). Process code : ORDE ( Every transaction of this message type for inbound transaction needs a process code ORDE). In the same way for the receiving end, Partner number : 3030 (AIR PARTS) Partner type : vendor. OUTBOUND PARAMETERS: Message type : ORDRSP. Receiver port : SUBSYSTEM (because all my transactions are residing in my R/3). Idoc type : ORDERS05 Application : EF (which is the message type supported for this application ). Process code : ME10 ( Every transaction of this message type for outbound process needs a process code ME10).

INBOUND PARAMETERS: Message type : ORDRSP. Receiver port : SUBSYSTEM (because all my transactions are residing in my R/3). Idoc type : ORDERS05 Application : EF (which is the message type supported for this application ). Process code : ORDR ( Every transaction of this message type for inbound transaction needs a process code ORDE). CONFIGURING THE RFC DESTINATION : Transaction Code : SM59. In the settings of the RFC destination being used in the process, I have taken the destination type as SERVER_EXEC because it is the only one that supports the R/3 system for the version. CONFIGURING THE PORT DEFINITION : Transaction Code : WE21. In the port definition I have taken FILE as the port because it is the only port that supports this EDI transaction. In the port definition, all the outbound process and inbound process are stored in a specific location. CREATION OF APPLICATION DOCUMENT: Transaction Code : MK01. This is the most typical part in the program : I have created an application document with the above profiles of the sending and the receiver information. The details are as follows: Vendor : 3030 (Air parts) Purchasing organization : 3000. (IDES USA) Customer : 123 (Ananth gowri sankar paturu). Material Description : R300. As soon as the document is saved the Idoc is generated from the NAST table by storing the application document. CONFIRMATION NUMBER FOR THE APPLICATION DOCUMENT : 4500008604.

CHECKING FOR THE SUCCESSFUL CREATION OF APPLICATION DOCUMENT: Transaction Code : MK23. By giving the confirmation number of the application document, the purchase order transaction can be confirmed. CONFIRMING THE APPLICATION DOUMENT ENTRIES IN THE DATABASE: Transaction Code : SE16. By typing the table name NAST in the table entry we can view all the details of the application document. WRITING A PROGRAM FOR THE VALIDITY OF SENDING AND RECEIVING PROFILES AND GENERATION OF Idoc FOR THE DATA THAT IS SAVED IN THE APPLICATION DOCUMENT : Transaction Code : SE38. Program Name : Database Tables I have used in my program : edpp1, edkp1, eddp1,edk12, edk13, edk21,tede1, tede2, edmat, edmsg, edimsg. Outbound Parameters Tables : EDPP1 Inbound Parameters Tables : EDP12,EDP13,EDP21. By retrieving the data from the above tables which are storing the values of the application document and receiving , sending profiles by using SELECT statements, SUBROUTINES , FUNCTION MODUELES , the following things are executed. 1. VALIDITY OF THE PARTNER PROFILES. 2. GENERATION OF IDOC. 3. CORRECT PORT ASSIGNMENT. 4. GIVING A PROPER ERROR MESSAGE. VERIFICATION OF IDOC: Transaction Code : WE02.

VERIFICATION OF STATUS: Transaction Code : WE05. INBOUND PROCESS: UNPACKING THE IDOC: Transaction Code : WE19. I have selected the same idoc which I have used for the outbound process and created a text file called in123.dat and saved the idoc in the current file. Next, by selecting the function module IDOC_INPUT_MATMAS01, the inbound process flow is started and an incoming Idoc is created in the system. VERIFICATION OF POSTING OF APPLICATION DOCUMENTS: Transaction Code: BD87. With this transaction , the application document is restored. The final application document is viewed from the current location of the purchase order. After all the settings are done, the successful posting of an EDI document in the outbound process is done by getting all the details from the data stored in the tables. Program that I have written to get the details of the partner profiles, port definitions, is ZEFSKFLSDJ.

The flow chart for the complete execution of the process is shown below:

B BEGIN
T-CODE : OYSN SELECTING NUMBER RANGE: S SELECT EDIDOC S

T-CODE: WE46 ASSIGNING ORGANISATIO N AND USER NAME N

INTERNAL TABLES DATA IS EXTRACTED AND SERVER_EXEC IS STARTED. T-CODE: WE41 ASSINGING PROCESSCODE IN THIS TRANSACTION ME10. M M

T-CODE : SM59 SETTING UP RFC DESTINATION BY CHOOSING SERVER_EXEC FROM THE TCP/IP LAYER. IT STARTS rfcexec PROGRAM ON THE T SERVER

T-CODE : WE21. ASSIGNING PORT THROUGH WHICH BOTH INCOMING AND OUTGOING MESSAGES ARE EXCHANGED. IN EDI, IT IS FILE. E

T-CODE : SE11. DATABASE TABLES: THE ABOVE TRANSACTIONS ARE STORED IN THE FOLLOWING TABLES: EDPP1, EDP13. EDP12. EDP21. NACE. ZMRPDTLLOAD.

T-CODE: ME11. CREATION OF PURCHASE DOCUMENT D

T-CODE : XD02 RECEIVER FIELDS INFORMATION .

APPLICATINDOC T-CODE: ME21. MAT:100-100. CAST IRON. ORDER NO: 4500008606 4

T-CODE : WE20. OUTBUND PARAME SENDER: COMPANY CODE:3030 NAME: AIR PARTS MESSAGE: ORDERSP,NEU,EF. O

NAST ENTRIES. T-CODE : SE38. T-CODE : SE11. PROGRAM NAME : ZEFSKFLSDJ. DATABASE TABLES: PARTNER CHECKING FOR CONSTITENCIES OF PARTNER THE ABOVE TRANSACTIONS PROFILES PROFILES. ARE STORED IN OUTPUT THE IF THERE ARE NO ERRORS IN THE EVENT LINKAGEPROCESS OF ALL THE COMPONENTS.SUCHA MODE: FOLLOWING TABLES: PROGRAM, AS BASIC TYPE OF INTERMEDIATE DOCUMENT, STATUS EDPP1, CODE(ME10) T-CODE : SE11. IF YES, T-CODE : WE02. ENTRIES FOR OUTBOUND PROCESS, ENTRIES FOR EDP13. PROCESSED. P SELECTION SCREEN : DATABASE TABLES: EXECUTE THIS TRANSACTION IN SM59. INBOUND PROCESS,ENTRIES FOR HEADER TABLE. EDP12. VENDOR PARTNER3030. NAME : NAST: CHECK THE START THE CORRECT RFCEXEC PROGRAM IF THE PROGRAM RUNS WITHOUT ERRORSCONTROL DATA: AND DATA RECORD: ISEDP21. THETYPE APPLICATIONDO ALL THE VALUES OF THE T-CODE: WE05 STATUS RECORD: STATUS OF AND THE IDOC IS : LI. PROFILES,APPLICATION DOCUMENT WITHOUT WARNINGS, THAT MEANS THE DETAILS IT CONTAINS THE NACE. IS THE ANY IDOC SENT CUMENT CORRESPONDING FILEDS OF DETAILS,PROCESS CODE AND IF NO, IDOC . IF SE;ECTTHE IDOC THE IT CONTAINS THEARE TRANSFERRED TO IF DATA IDOC SUBSYSTEM E ZMRPDTLLOAD. Z THAT IS BY Z AND EXECUTE BY CHECK FOR THE OF THE DOCUMENT YES, PROPER AND BASIC RECORDS. E ERRORS? ONCE OR PARTNER PROFILES,PORT IF RECEIVING PRESSING F8, . YES, CORRECT PORT DEFINITION ARE IF NO, IDOC IS STATUS IS THESTATUS OF THE THE SYSTEM SENT THE OUTPUT S SYNTACTICALLYGO TO S ONE CORRECT NEXT PORT THE DATA DETAILS. IS OUTSIDE COLLECT THE DEFINITIONS,PURCHASE ORDER THE AND BY EXECUTING THE CHECK FOR CHECK THEIN THE NEXT SENT IT SAVED IN THEN INBOX IDOC AT EVERY GREEN, CONNECTING WITH EITHER GIVEN RADIOBUTTONIN AVAILABLE AND IS SHOWN STORED AS A THE SENDER BEGINNINGNO SYSTEM ITS I OR WITH OUTBOX FOR THE PARTNERANDR/3 PROGRAM AND IDOC ISB ONE. PFOFILES,COLLECT THETHERE ARE MILESTONE IN THE TCP/IP SELECTION A ARE STORED IN THE NAST TABLE. SCREEN.R/3 BY S THE IDOC IS SERIES OF TYPE,THE OF THE CORRECT PORT G GENERATED. IDOCS G O I C DATABASE. D E ORDERS SUBSYSTEM. S ERRORS. CONNECTIVITY. SENT. S FORMAT. RECEIVER TYPE F R D DEFINITION P PROGRAM

The following program reads the values of the tables,edpp1, edkp1, eddp1,edk12, edk13, edk21,tede1, tede2, edmat, edmsg, edimsg, where the details of the application document, partner profiles, port definitions, sender and receiver fields and integrates them as a process. By executing the program, we can tell whether all the fields are correct and any incorrect values should be corrected before executing the next step. The program is shown as follows:

REPORT zefskflsdj. * database tables and structures tables: edpp1, edkp1, eddp1,edk12, edk13, edk21,tede1, tede2, edmat, edmsg, edimsg. * internal tables and data data: i_edpp1 like edpp1 occurs 30 with header line, i_edp12 like edp12 occurs 50 with header line, i_edp13 like edp13 occurs 50 with header line, i_edp21 like edp21 occurs 50 with header line. * This is the idoc structure data: pt_protocol like protstru occurs 30 with header line. DATA: BEGIN OF EDP12_KEY, RCVPRN LIKE EDP12-RCVPRN, S2 VALUE '/', RCVPRT LIKE EDP12-RCVPRT, S3 VALUE '/', RCVPFC LIKE EDP12-RCVPFC, S4 VALUE '/', KAPPL LIKE EDP12-KAPPL, S5 VALUE '/', KSCHL LIKE EDP12-KSCHL, S6 VALUE '/', AENDE LIKE EDP12-AENDE. DATA: END OF EDP12_KEY. DATA: BEGIN OF EDP13_KEY, RCVPRN LIKE EDP13-RCVPRN, S2 VALUE '/', RCVPRT LIKE EDP13-RCVPRT, S3 VALUE '/', RCVPFC LIKE EDP13-RCVPFC, S4 VALUE '/', MESTYP LIKE EDP13-MESTYP, S5 VALUE '/', MESCOD LIKE EDP13-MESCOD, S6 VALUE '/', MESFCT LIKE EDP13-MESFCT, S7 VALUE '/', TEST LIKE EDP13-TEST. DATA: END OF EDP13_KEY. DATA: BEGIN OF EDP21_KEY, SNDPRN LIKE EDP21-SNDPRN, S2 VALUE '/', SNDPRT LIKE EDP21-SNDPRT, S3 VALUE '/', SNDPFC LIKE EDP21-SNDPFC, S4 VALUE '/', MESTYP LIKE EDP21-MESTYP, S5 VALUE '/', MESCOD LIKE EDP21-MESCOD, S6 VALUE '/', MESFCT LIKE EDP21-MESFCT, S7 VALUE '/', TEST LIKE EDP21-TEST. DATA: END OF EDP21_KEY. DATA: BEGIN OF EDPP1_KEY, PARNUM LIKE EDPP1-PARNUM, S2 VALUE '/',

PARTYP LIKE EDPP1-PARTYP. DATA: END OF EDPP1_KEY. data: percentage type i, last_percentage type i, lines type i, rc like sy-subrc, g_name like sprwr-name. constants: p_error like protstru-msgty value 'E', p_warning like protstru-msgty value 'W', p_success like protstru-msgty value 'S', c_message_id like protstru-msgid value 'E1', C_TYPE_SEPARATOR LIKE PROTSTRU-LINETYPE VALUE 'N', C_TYPE_MESSAGE LIKE PROTSTRU-LINETYPE VALUE 'M'. DEFINE ADD_SEPARATOR. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_SEPARATOR. APPEND PT_PROTOCOL. END-OF-DEFINITION. * no variables DEFINE ADD_MESSAGE_0. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_MESSAGE. PT_PROTOCOL-MSGID = C_MESSAGE_ID. PT_PROTOCOL-MSGTY = &1. PT_PROTOCOL-MSGNO = &2. APPEND PT_PROTOCOL. END-OF-DEFINITION. * one variable DEFINE ADD_MESSAGE_1. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_MESSAGE. PT_PROTOCOL-MSGID = C_MESSAGE_ID. PT_PROTOCOL-MSGTY = &1. PT_PROTOCOL-MSGNO = &2. PT_PROTOCOL-MSGV1 = &3. APPEND PT_PROTOCOL. END-OF-DEFINITION. * two variables DEFINE ADD_MESSAGE_2. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_MESSAGE. PT_PROTOCOL-MSGID = C_MESSAGE_ID. PT_PROTOCOL-MSGTY = &1. PT_PROTOCOL-MSGNO = &2. PT_PROTOCOL-MSGV1 = &3. PT_PROTOCOL-MSGV2 = &4. APPEND PT_PROTOCOL. END-OF-DEFINITION. * three variables DEFINE ADD_MESSAGE_3. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_MESSAGE. PT_PROTOCOL-MSGID = C_MESSAGE_ID. PT_PROTOCOL-MSGTY = &1. PT_PROTOCOL-MSGNO = &2. PT_PROTOCOL-MSGV1 = &3. PT_PROTOCOL-MSGV2 = &4. PT_PROTOCOL-MSGV3 = &5.

APPEND PT_PROTOCOL. END-OF-DEFINITION. * four variables DEFINE ADD_MESSAGE_4. CLEAR PT_PROTOCOL. PT_PROTOCOL-LINETYPE = C_TYPE_MESSAGE. PT_PROTOCOL-MSGID = C_MESSAGE_ID. PT_PROTOCOL-MSGTY = &1. PT_PROTOCOL-MSGNO = &2. PT_PROTOCOL-MSGV1 = &3. PT_PROTOCOL-MSGV2 = &4. PT_PROTOCOL-MSGV3 = &5. PT_PROTOCOL-MSGV4 = &6. APPEND PT_PROTOCOL. END-OF-DEFINITION. select-options: s_parnum for edpp1-parnum, s_partyp for edpp1-partyp. parameters: p_mode(1) type c no-display.

* collect all relevant entries from EDPP1 in table I_EDPP1 case p_mode. when 'L'. * select from EDPP1 for every single combination of PARNUM/PARTYP loop at s_parnum. read table s_partyp index sy-tabix. check sy-subrc eq 0. select * from edpp1 appending table i_edpp1 where parnum eq s_parnum-low and partyp eq s_partyp-low. endloop. when others. * use standard logic to select partners select * from edpp1 into table i_edpp1 where parnum in s_parnum and partyp in s_partyp. endcase. if i_edpp1[] is initial. * no entries found for these select criteria perform no_entries. else. describe table i_edpp1 lines lines. loop at i_edpp1. percentage = 100 * sy-tabix / lines. if last_percentage ne percentage. perform progress using percentage. last_percentage = percentage. endif. refresh: i_edp12, i_edp13, i_edp21. move-corresponding i_edpp1 to edkp1. * get all entries for the current partner CALL FUNCTION 'EDI_PARTNER_READ_COMPLETE' EXPORTING REC_EDKP1 = edkp1 IMPORTING

REC_EDDP1 = eddp1 TABLES TAB_EDP12 = i_edp12 TAB_EDP13 = i_edp13 TAB_EDP21 = i_edp21 EXCEPTIONS DB_ERROR = 01 ENTRY_NOT_EXIST = 02. check sy-subrc eq 0. add_separator. move-corresponding i_edpp1 to edpp1_key. add_message_1 P_SUCCESS '105' edpp1_key. add_separator. * test EDPP1 perform test_edpp1. add_separator. * test EDP12 perform test_edp12. add_separator. * test EDP13 perform test_edp13. add_separator. * test EDP21 perform test_edp21. add_separator. endloop. endif. g_name = sy-uzeit. CALL FUNCTION 'DISPLAY_PROTOCOL' EXPORTING NAME = g_name TABLES IN = pt_protocol. * Form NO_ENTRIES *no entries found FORM NO_ENTRIES. add_separator. add_message_0 p_error '101'. add_separator. ENDFORM. *Form TEST_EDPP1 *test data in EDDP1 * PARNUM partner number * PARTYP partner type FORM TEST_EDPP1. add_message_0 P_SUCCESS '106'. * execute test routine for number and type " NO_ENTRIES

DATA: L_TEDSTSTRUC LIKE TEDSTSTRUC, L_RC LIKE SY-SUBRC, L_REPID LIKE TEDST-REPID, L_FORM LIKE TEDST-ROUTIDREAD. * get access routine from table TEDST SELECT SINGLE REPID ROUTIDREAD FROM TEDST INTO (L_REPID, L_FORM) WHERE RCVPRT EQ edkp1-partyp. IF SY-SUBRC EQ 0. * use external perform to validate PARNUM * form-routine and report-id are found in TEDST CLEAR L_TEDSTSTRUC. L_TEDSTSTRUC-PARNUM = EDkP1-PARNUM. PERFORM (L_FORM) IN PROGRAM (L_REPID) USING L_TEDSTSTRUC L_RC. IF L_RC EQ 8. * PARNUM not found add_message_2 p_error '137' edkp1-parnum edkp1-partyp. ENDIF. ENDIF. * test EDMAT entry (EDPP1-MATLVL) select single * from edmat where matlvl eq eddp1-matlvl and langua eq sy-langu. if sy-subrc eq 0. add_message_0 P_SUCCESS '109'. else. add_message_1 P_ERROR '110' eddp1-matlvl. endif. * test receiver of notifications perform test_receiver using eddp1-usrtyp eddp1-usrkey rc. if rc eq 0. add_message_0 P_SUCCESS '107'. else. add_message_2 P_ERROR '108' eddp1-usrtyp eddp1-usrkey. endif. ENDFORM. *Form TEST_RECEIVER * USRTYP type of receiver * USRKEY receiver's ID * RC returncode FORM TEST_RECEIVER using usrtyp like edpp1-usrtyp usrkey like edpp1-usrkey rc like sy-subrc. data: rhobject like rhobjects-object. move usrtyp to rhobject. move usrkey to rhobject+2. CALL FUNCTION 'RH_CHECK_ORG_OBJECT_EXISTS' EXPORTING ACT_OBJECT_EXT = rhobject AUTHORITY_CHECK ='' " TEST_EDPP1

EXCEPTIONS NO_ACTIVE_PLVAR = 01 NO_ORG_OBJECT = 02 ORG_OBJECT_NOT_FOUND = 03. rc = sy-subrc. ENDFORM. *Form TEST_EDP12 * PARNUM partner number * PARTYP partner type FORM TEST_EDP12. if not i_edp12[] is initial. add_message_0 p_success '112'. endif. loop at i_edp12. move-corresponding i_edp12 to edk12. move-corresponding i_edp12 to edp12_key. add_separator. add_message_1 p_success '111' edp12_key. * test if an EDP13 entry exists for the current EDP12 entry loop at i_edp13 where rcvprn eq i_edp12-rcvprn and rcvprt eq i_edp12-rcvprt and rcvpfc eq i_edp12-rcvpfc and mestyp eq i_edp12-mestyp and mescod eq i_edp12-mescod and mesfct eq i_edp12-mesfct and test eq i_edp12-test. endloop. if sy-subrc eq 0. add_message_0 p_success '132'. else. add_message_0 p_error '133'. endif. * test message type select single * from edmsg where msgtyp eq i_edp12-mestyp. if sy-subrc eq 0. add_message_0 p_success '113'. else. add_message_1 p_error '114' i_edp12-mestyp. endif. * test outgoing process code select single * from tede1 where evcode eq i_edp12-evcoda. if sy-subrc eq 0. add_message_0 p_success '115'. else. add_message_1 p_error '116' i_edp12-evcoda. endif. endloop. ENDFORM. " TEST_EDP12 " TEST_RECEIVER

*Form TEST_EDP13 * PARNUM partner number * PARTYP partner type FORM TEST_EDP13. data: port_type like edipo-porttyp. if not i_edp13[] is initial. add_message_0 p_success '117'. endif. loop at i_edp13. move-corresponding i_edp13 to edk13. move-corresponding i_edp13 to edp13_key. add_separator. add_message_1 p_success '111' edp13_key. * test if an EDP12 entry exists for the current EDP13 entry loop at i_edp12 where rcvprn eq i_edp13-rcvprn and rcvprt eq i_edp13-rcvprt and rcvpfc eq i_edp13-rcvpfc and mestyp eq i_edp13-mestyp and mescod eq i_edp13-mescod and mesfct eq i_edp13-mesfct and test eq i_edp13-test. endloop. if sy-subrc eq 0. add_message_0 p_success '134'. else. add_message_0 p_warning '135'. endif. * test port CALL FUNCTION 'EDI_PORT_READ' EXPORTING PORTNAME = i_edp13-rcvpor IMPORTING TYP = port_type EXCEPTIONS PORT_NOT_EXIST = 1 OTHERS = 2. if sy-subrc eq 0. add_message_0 p_success '118'. else. * no port found clear port_type. add_message_1 p_error '119' i_edp13-rcvpor. endif. * test package size for the current port if port_type eq '1' and i_edp13-pcksiz le 0. if i_edp13-pcksiz is initial. add_message_1 p_error '120' '0'. else. add_message_1 p_error '120' i_edp13-pcksiz. endif. endif. * test OUTMOD for the current entry (if port_type = 1 (aRFC))

if port_type eq '1' and ( i_edp13-outmod eq 1 or i_edp13-outmod eq 3 ). add_message_1 p_error '121' i_edp13-outmod. endif. * test basis type CALL FUNCTION 'IDOCTYPE_EXISTENCE_CHECK' EXPORTING PI_IDOCTYP = i_edp13-idoctyp * IMPORTING * PE_ATTRIBUTES = EXCEPTIONS OBJECT_NOT_FOUND = 1 DB_ERROR =2 OTHERS = 3. if sy-subrc eq 0. add_message_0 p_success '122'. else. add_message_1 p_error '123' i_edp13-idoctyp. endif. * test extension if i_edp13-cimtyp ne space. CALL FUNCTION 'EXTTYPE_EXISTENCE_CHECK' EXPORTING PI_CIMTYP = i_edp13-cimtyp * IMPORTING * PE_ATTRIBUTES = EXCEPTIONS OBJECT_NOT_FOUND = 1 DB_ERROR =2 OTHERS = 3. if sy-subrc eq 0. add_message_0 p_success '124'. else. add_message_1 p_error '125' i_edp13-cimtyp. endif. * if there is an extension: test their combination CALL FUNCTION 'CHECK_STRUCTURES_MATCH' EXPORTING PI_IDOCTYP = i_edp13-idoctyp PI_CIMTYP = i_edp13-cimtyp TABLES PT_IDOCSYN = PT_CIMSYN = EXCEPTIONS SEGMENT_IN_BOTH_STRUCTURES = 1 NO_REFERENCE_SEGMENT_FOUND = 2 COMPONENT_NOT_FOUND =3 OTHERS = 4. if sy-subrc eq 0. add_message_0 p_success '150'. else. add_message_2 p_error '151' i_edp13-idoctyp i_edp13-cimtyp. endif. endif.

* * *

* test assignment between message type and IDoc select single * from edimsg where idoctyp eq i_edp13-idoctyp and cimtyp eq i_edp13-cimtyp and mestyp eq i_edp13-mestyp. if sy-subrc eq 0. add_message_0 p_success '126'. else. add_message_0 p_error '127'. endif. * test view (if applicable) if i_edp13-ediview ne space. perform test_ediview using i_edp13-idoctyp i_edp13-cimtyp i_edp13-mestyp i_edp13-ediview rc. if rc eq 0. add_message_0 p_success '136'. else. add_message_4 p_error '201' i_edp13-ediview i_edp13-idoctyp i_edp13-cimtyp i_edp13-mestyp. endif. endif. * test if receiver of notifications exists if i_edp13-usrtyp ne space or i_edp13-usrkey ne space. perform test_receiver using i_edp13-usrtyp i_edp13-usrkey rc. if rc eq 0. add_message_0 p_success '107'. else. add_message_2 p_error '108' i_edp13-usrtyp i_edp13-usrkey. endif. endif. endloop. ENDFORM. *Form TEST_EDP21 * PARNUM partner number * PARTYP partner type FORM TEST_EDP21. if not i_edp21[] is initial. add_message_0 p_success '128'. endif. loop at i_edp21. move-corresponding i_edp21 to edk21. move-corresponding i_edp21 to edp21_key. add_separator. add_message_1 p_success '111' edp21_key. * test incoming process code " TEST_EDP13

select single * from tede2 where evcode eq i_edp21-evcode. if sy-subrc eq 0. add_message_0 p_success '129'. else. add_message_1 p_error '130' i_edp21-evcode. endif. * test if receiver of notifications exists if i_edp21-usrtyp ne space or i_edp21-usrkey ne space. perform test_receiver using i_edp21-usrtyp i_edp21-usrkey rc. if rc eq 0. add_message_0 p_success '107'. else. add_message_2 p_error '108' i_edp21-usrtyp i_edp21-usrkey. endif. endif. endloop. ENDFORM. " TEST_EDP21

*FORM progress form progress using percentage type i. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING PERCENTAGE = percentage EXCEPTIONS OTHERS = 1. endform. FORM test_ediview USING PI_iDOCTYP like edp13-idoctyp PI_CIMTYP like edp13-cimtyp PI_MESTYP like edp13-mestyp PI_EDIVIEW like edp13-ediview Pe_RC. CALL FUNCTION 'EDI_CHECK_PARTNER_EDIVIEW' EXPORTING PI_IDOCTYP = pi_idoctyp PI_CIMTYP = pi_cimtyp PI_MESTYP = pi_mestyp PI_EDIVIEW = pi_ediview EXCEPTIONS OTHERS = 2. pe_rc = sy-subrc. ENDFORM. " test_ediview

The output of the above program is shown below:

After executing this program, the program for the generation of intermediate document(IDOC) is executed. This Idoc contains all the details about the application document, RFC applications in the form of three layers. 1. control record. 2. data record. 3. status record. 1. Control record: This contains the details of the sender and the receiver, the mode of the process, the document type . 2. Data record : This contains the details of the document in the form of separate segments. 3. Status record: This contains the status of the IDOC at all intermediate levels.

By executing the following program, an IDOC is generated and it is saved. The saved IDOC is ready for transmission. The program for the generation of IDOC is below:
PROGRAM RSNAST00 MESSAGE-ID VN. TABLES: NAST, nase, T681B. TABLES: ALARC_PAR1, ARC_PARAMS, TOA_DARA, NAST00. TABLES: TNAPR, *TNAPR, T681Z, T685B.

"#EC NEEDED "#EC NEEDED

INCLUDE RSEF4HLP. CONSTANTS: KVEWE_NAST LIKE T681Z-KVEWE ON(1) TYPE C VALUE 'X'. FIELD-GROUPS: HEADER, STATUS.

VALUE 'B',

SELECTION-SCREEN BEGIN OF BLOCK BLK_SEL WITH FRAME TITLE TEXT-001. SELECT-OPTIONS: S_KAPPL FOR nase-KAPPL, S_OBJKY FOR NAST-OBJKY, S_KSCHL FOR nase-KSCHL, S_NACHA FOR NAST-NACHA. SELECTION-SCREEN SKIP 1. PARAMETERS: P_AGAIN LIKE NAST00-REPEAT, P_SORT LIKE NAST00-SORT. SELECTION-SCREEN END OF BLOCK BLK_SEL. SELECTION-SCREEN BEGIN OF BLOCK BLK_PAR WITH FRAME TITLE TEXT-002. PARAMETERS: P_PRINT LIKE NAST-LDEST, P_SUFF2 LIKE NAST-DSUF2. SELECTION-SCREEN END OF BLOCK BLK_PAR. DATA: RETURNCODE LIKE SY-SUBRC, "Returncode aus Druckprogramm RETCODE LIKE SY-SUBRC, "Returncode COUNT LIKE SY-INDEX, "Counter: verarbeitete Belege COUNT_1 LIKE SY-INDEX, "Counter: erfolgreich verarbeitet COUNT_2 LIKE SY-INDEX, "Counter: fehlerhaft verarbeitet XSCREEN(1) TYPE C. DATA: BEGIN OF PARTNER, ROLLE LIKE NAST-PARVW, NUMMER LIKE NAST-PARNR, END OF PARTNER. DATA: P_VSTAT LIKE NAST-VSTAT. INSERT NAST INTO STATUS. CASE P_SORT. WHEN '01'. INSERT NAST-PARNR NAST-KAPPL NAST-KSCHL NAST-OBJKY INTO HEADER. WHEN '02'. INSERT NAST-KAPPL NAST-OBJKY INTO HEADER. WHEN '03'. INSERT NAST-KSCHL NAST-PARNR INTO HEADER. WHEN '10'. INSERT NAST-SORT1 NAST-SORT2 NAST-SORT3 INTO HEADER.

WHEN '11'. INSERT NAST-KAPPL NAST-SORT1 NAST-SORT2 NAST-SORT3 INTO HEADER. WHEN '12'. INSERT NAST-KSCHL NAST-SORT1 NAST-SORT2 NAST-SORT3 INTO HEADER. INCLUDE RSNASTZZ. WHEN OTHERS. INSERT NAST-PARNR NAST-KAPPL NAST-KSCHL NAST-OBJKY INTO HEADER. ENDCASE. IF P_AGAIN EQ ON. " MOVE '1' TO P_VSTAT. MOVE '0' TO P_VSTAT. ELSE. ENDIF.

SELECT * FROM NAST WHERE VSTAT EQ P_VSTAT AND KAPPL IN S_KAPPL AND VSZTP BETWEEN 1 AND 2 AND OBJKY IN S_OBJKY AND KSCHL IN S_KSCHL AND NACHA IN S_NACHA AND AKTIV EQ SPACE. PERFORM CHECK_KAPPLS_NOT_TO_PROCESS USING NAST-KAPPL RETURNCODE. CHECK RETURNCODE EQ 0. PERFORM CHECK_NAST_VSZTP USING NAST RETURNCODE. CHECK RETURNCODE EQ 0. EXTRACT STATUS. ENDSELECT. CLEAR COUNT. SORT. LOOP. AT STATUS. PERFORM OBJEKT_SPERREN USING RETCODE ' '. CHECK RETCODE = 0. PERFORM CHECK_STATUS_ON_DB USING RETCODE. IF RETCODE NE 0. PERFORM OBJEKT_ENTSPERREN. ENDIF. CHECK RETCODE = 0. ADD 1 TO COUNT. IF SY-BATCH NE SPACE. PARTNER-ROLLE = NAST-PARVW. PARTNER-NUMMER = NAST-PARNR. MESSAGE I035 WITH NAST-OBJKY NAST-KSCHL PARTNER. ENDIF. perform T685B_LESEN using nast-kappl nast-kschl. if t685b-nbear eq space. IF P_PRINT NE SPACE. NAST-LDEST = P_PRINT. ENDIF. IF P_SUFF2 NE SPACE. NAST-DSUF2 = P_SUFF2. ENDIF. endif. PERFORM TNAPR_LESEN USING NAST-KSCHL NAST-NACHA

NAST-KAPPL. CLEAR XSCREEN. PERFORM OPTISCHE_ARCHIVIERUNG. PERFORM PROGRAMM_AUFRUFEN USING XSCREEN. PERFORM SET_COUNTERS USING RETURNCODE. IF SY-BATCH NE SPACE. PARTNER-ROLLE = NAST-PARVW. PARTNER-NUMMER = NAST-PARNR. MESSAGE I034 WITH NAST-OBJKY NAST-KSCHL PARTNER RETURNCODE. ENDIF. IF P_AGAIN NE 'X'. PERFORM PROTOCOL_STORE USING NAST-KAPPL NAST-KSCHL CHANGING NAST-CMFPNR. PERFORM NAST_UPDATE USING RETCODE. IF RETCODE NE 0. MESSAGE A013 WITH NAST-KAPPL NAST-OBJKY. ENDIF. ENDIF. COMMIT WORK. PERFORM OBJEKT_ENTSPERREN. ENDAT. IF SY-BATCH = SPACE. IF P_AGAIN EQ ON. perform t685b_lesen using nast-kappl nast-kschl. check t685b-noprotocol eq space. CALL FUNCTION 'WFMC_PROTOCOL_GET_UNSTORED' EXCEPTIONS OTHERS = 0. ELSE. CALL FUNCTION 'WFMC_PROTOCOL_LOAD' EXPORTING CPS_NAST = NAST. ENDIF. ENDIF. ENDLOOP. IF SY-BATCH = SPACE. CALL FUNCTION 'WFMC_PROTOCOL_SHOW' EXPORTING CPS_KALSM = SPACE CPS_NAST = NAST NO_HEADER = 'X'. ENDIF. MESSAGE I033 WITH COUNT COUNT_1 COUNT_2. FORM EINZELNACHRICHT USING US_SUBRC LIKE SY-SUBRC. DATA: L_SUBRC LIKE SY-SUBRC. PERFORM TNAPR_LESEN USING NAST-KSCHL NAST-NACHA NAST-KAPPL. CLEAR XSCREEN. PERFORM OPTISCHE_ARCHIVIERUNG. PERFORM PROGRAMM_AUFRUFEN USING XSCREEN. US_SUBRC = RETURNCODE. PERFORM PROTOCOL_STORE USING NAST-KAPPL NAST-KSCHL CHANGING NAST-CMFPNR. PERFORM NAST_UPDATE USING L_SUBRC. IF L_SUBRC NE 0. MESSAGE A013 WITH NAST-KAPPL NAST-OBJKY. ENDIF. ENDFORM.

FORM EINZELNACHRICHT_DIALOG USING US_SUBRC LIKE SY-SUBRC. PERFORM TNAPR_LESEN USING NAST-KSCHL NAST-NACHA NAST-KAPPL. CLEAR XSCREEN. PERFORM OPTISCHE_ARCHIVIERUNG. PERFORM PROGRAMM_AUFRUFEN USING XSCREEN. US_SUBRC = RETURNCODE. DATA TMP_SUBRC LIKE SY-SUBRC. PERFORM CHECK_KAPPLS_NOT_TO_PROCESS USING NAST-KAPPL "excluded records TMP_SUBRC. IF TMP_SUBRC EQ 0. CASE RETURNCODE. WHEN '0'. "erfolgreich versandt NAST-VSTAT = '1'. WHEN '1'. "fehlerhaft NAST-VSTAT = '2'. WHEN '2'. "uebersetzt (EDI) NAST-VSTAT = '1'. WHEN '3'. "Beleg noch unvollstndig WHEN OTHERS. "fehlerhaft NAST-VSTAT = '2'. ENDCASE. NAST-DATVR = SY-DATUM. NAST-UHRVR = SY-UZEIT. ENDIF. PERFORM PROTOCOL_STORE USING NAST-KAPPL NAST-KSCHL CHANGING NAST-CMFPNR. CALL FUNCTION 'RV_MESSAGE_UPDATE_SINGLE' IN UPDATE TASK EXPORTING MSG_NAST = NAST. ENDFORM. FORM EINZELNACHRICHT_SCREEN USING US_SUBRC LIKE SY-SUBRC. PERFORM TNAPR_LESEN USING NAST-KSCHL NAST-NACHA NAST-KAPPL. XSCREEN = 'X'. PERFORM PROGRAMM_AUFRUFEN USING XSCREEN. US_SUBRC = RETURNCODE. ENDFORM. FORM EINZELNACHRICHT_OHNE_UPDATE USING US_SUBRC LIKE SY-SUBRC. PERFORM TNAPR_LESEN USING NAST-KSCHL NAST-NACHA NAST-KAPPL. CLEAR XSCREEN. PERFORM PROGRAMM_AUFRUFEN USING XSCREEN. US_SUBRC = RETURNCODE. ENDFORM. FORM NAST_UPDATE USING NAST_SUBRC LIKE SY-SUBRC.

PERFORM CHECK_KAPPLS_NOT_TO_PROCESS USING NAST-KAPPL "excluded records NAST_SUBRC. check nast-snddr eq space. IF NAST_SUBRC EQ 0. CASE RETURNCODE. WHEN '0'. WHEN '1'. NAST-VSTAT = '2'. WHEN '3'. WHEN OTHERS. NAST-VSTAT = '2'. ENDCASE. ELSE. RETURNCODE = 0. ENDIF. IF RETURNCODE NE 3. IF NAST_SUBRC EQ 0. NAST-DATVR = SY-DATUM. NAST-UHRVR = SY-UZEIT. ENDIF. UPDATE NAST. IF SY-SUBRC NE 0. INSERT NAST. IF SY-SUBRC NE 0. NAST_SUBRC = SY-SUBRC. ENDIF. ENDIF. ENDIF. ENDFORM. FORM OBJEKT_ENTSPERREN. DATA: BELNR LIKE VBAK-VBELN. DATA: EBELN LIKE EKKO-EBELN. DATA: TKNUM LIKE VTTK-TKNUM. DATA: PABNUM LIKE PABIT-PABNUM. DATA: L_KNUMA TYPE KNUMA. DATA: L_WBELN TYPE WBELN_AG. CASE NAST-KAPPL. WHEN 'V1'. BELNR = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVVBAKE' EXPORTING VBELN = BELNR. WHEN 'V2'. EXPORTING VBELN = BELNR. WHEN 'V3'. BELNR = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVVBRKE' EXPORTING VBELN = BELNR. WHEN 'V4'. BELNR = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVVBLKE' EXPORTING VBELN = BELNR. WHEN 'V6'. WHEN 'V7'. TKNUM = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVVTTKE'

NAST-VSTAT = '1'.

EXPORTING MANDT = SY-MANDT TKNUM = TKNUM. WHEN 'K1'. BELNR = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVVBKAE' EXPORTING VBELN = BELNR. WHEN 'EF' OR 'EA' OR 'EV' OR 'ES' OR 'EL'. EBELN = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EMEKKOE' EXPORTING EBELN = EBELN EXCEPTIONS OTHERS = 0. WHEN 'NF'. DATA: NFNUM_INT LIKE J_1BNFDOC-DOCNUM. NFNUM_INT = NAST-OBJKY. CALL FUNCTION 'J_1B_NF_DOCUMENT_UNLOCK' EXPORTING DOC_NUMBER = NFNUM_INT LOCK_MODE = 'E' EXCEPTIONS OTHERS = 0. WHEN 'PA'. PABNUM = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_E_PABIT_E' EXPORTING PABNUM = PABNUM X_PABPOS = ON EXCEPTIONS OTHERS = 0. WHEN 'WN'. L_KNUMA = NAST-OBJKY+10(10). CALL FUNCTION 'DEQUEUE_EVKONAE' EXPORTING KNUMA = L_KNUMA. WHEN 'WR'. L_WBELN = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EMWBRKE' EXPORTING WBELN = L_WBELN. WHEN 'WS'. L_KNUMA = NAST-OBJKY. CALL FUNCTION 'DEQUEUE_EVKONAE' EXPORTING KNUMA = L_KNUMA. ENDCASE. ENDFORM. FORM OBJEKT_SPERREN USING US_SUBRC LIKE SY-SUBRC US_NOMSG TYPE C. DATA: BELNR LIKE VBAK-VBELN. DATA: EBELN LIKE EKKO-EBELN. DATA: TKNUM LIKE VTTK-TKNUM. DATA: PABNUM LIKE PABIT-PABNUM. DATA: L_KNUMA TYPE KNUMA. DATA: L_WBELN TYPE WBELN_AG. CLEAR US_SUBRC. CASE NAST-KAPPL.

WHEN 'V1'. BELNR = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVBAKE' EXPORTING VBELN = BELNR EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'V2'. BELNR = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVBLKE' EXPORTING VBELN = BELNR EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'V3'. BELNR = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVBRKE' EXPORTING VBELN = BELNR EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'V4'. BELNR = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVBLKE' EXPORTING VBELN = BELNR EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'V6' WHEN 'V7'. TKNUM = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVTTKE' EXPORTING TKNUM = TKNUM EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'K1'. BELNR = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVVBKAE' EXPORTING VBELN = BELNR EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3. WHEN 'EF' OR 'EA' OR 'EV' OR 'ES' OR 'EL'. EBELN = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EMEKKOE' EXPORTING EBELN = EBELN EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN 'NF'. DATA: NFNUM_INT LIKE J_1BNFDOC-DOCNUM. NFNUM_INT = NAST-OBJKY. CALL FUNCTION 'J_1B_NF_DOCUMENT_LOCK' EXPORTING DOC_NUMBER = NFNUM_INT LOCK_MODE = 'E'

EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN 'PA'. PABNUM = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_E_PABIT_E' EXPORTING PABNUM = PABNUM X_PABPOS = ON EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN 'WN'. L_KNUMA = NAST-OBJKY+10(20). CALL FUNCTION 'ENQUEUE_EVKONAE' EXPORTING KNUMA = L_KNUMA EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN 'WR'. L_WBELN = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EMWBRKE' EXPORTING WBELN = L_WBELN EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN 'WS'. L_KNUMA = NAST-OBJKY. CALL FUNCTION 'ENQUEUE_EVKONAE' EXPORTING KNUMA = L_KNUMA EXCEPTIONS FOREIGN_LOCK = 2 SYSTEM_FAILURE = 3 OTHERS = 3. WHEN OTHERS. SY-SUBRC = 0. ENDCASE. US_SUBRC = SY-SUBRC. IF US_NOMSG IS INITIAL. CASE SY-SUBRC. WHEN 2. MESSAGE I036 WITH NAST-OBJKY NAST-KAPPL NAST-KSCHL. WHEN 3. MESSAGE A600(MC). ENDCASE. ENDIF. ENDFORM.

FORM OPTISCHE_ARCHIVIERUNG. DATA: BEGIN OF XOBJID, OBJKY LIKE NAST-OBJKY, ARCNR LIKE NAST-OPTARCNR, END OF XOBJID. DATA: XOJ_NAME LIKE TOA_DARA-SAP_OBJECT. DATA: XOBJKY LIKE NAST-OBJKY. CHECK NAST-TDARMOD = '2' OR NAST-TDARMOD = '3'. XOBJKY = NAST-OBJKY. CALL FUNCTION 'WFMC_GET_ARCHIVE_OBJECT_TYPE' EXPORTING PI_KAPPL = NAST-KAPPL IMPORTING PE_OBJECT_TYPE = XOJ_NAME CHANGING PC_OBJKY = XOBJKY. IF XOJ_NAME = SPACE. MESSAGE A049 WITH NAST-KAPPL. ENDIF. PERFORM T685B_LESEN USING NAST-KAPPL NAST-KSCHL. CALL FUNCTION 'NUMBER_GET_NEXT' EXPORTING NR_RANGE_NR = '01' OBJECT = 'NA_OPT_ARC' IMPORTING NUMBER = NAST-OPTARCNR. XOBJID-OBJKY = XOBJKY. XOBJID-ARCNR = NAST-OPTARCNR. TOA_DARA-MANDANT = NAST-MANDT. TOA_DARA-SAP_OBJECT = XOJ_NAME. TOA_DARA-AR_OBJECT = T685B-ARCOBJART. TOA_DARA-OBJECT_ID = XOBJID. ARC_PARAMS-SAP_OBJECT = XOJ_NAME. ARC_PARAMS-AR_OBJECT = T685B-ARCOBJART. ARC_PARAMS-MANDANT = NAST-MANDT. IF NAST-TDRECEIVER NE SPACE. ARC_PARAMS-ARCUSER = NAST-TDRECEIVER. ELSE. ARC_PARAMS-ARCUSER = NAST-USNAM. ENDIF. ARC_PARAMS-PRINTER = NAST-LDEST. ALARC_PAR1-SAP_OBJECT = XOJ_NAME. ALARC_PAR1-AR_OBJECT = T685B-ARCOBJART. ALARC_PAR1-MANDANT = NAST-MANDT. ALARC_PAR1-ARCUSER = NAST-USNAM. ALARC_PAR1-PRINTER = NAST-LDEST. ENDFORM. FORM PROGRAMM_AUFRUFEN USING US_SCREEN TYPE C. DATA: RONAM LIKE TNAPR-RONAM, FONAM LIKE TNAPR-FONAM, PGNAM LIKE TNAPR-PGNAM, TEMP_NAST LIKE NAST. DATA US_SUBRC LIKE SY-SUBRC. PERFORM CHECK_KAPPLS_NOT_TO_PROCESS USING NAST-KAPPL "excluded records

US_SUBRC. CHECK US_SUBRC EQ 0. if us_screen ne on. check nast-snddr eq space. endif. IF NAST-NACHA = '1' AND NAST-TDRECEIVER IS INITIAL. NAST-TDRECEIVER = NAST-USNAM. ENDIF. CALL FUNCTION 'NAST_PROTOCOL_INITIALIZE'. *TNAPR = TNAPR. DO 5 TIMES VARYING RONAM FROM *TNAPR-RONAM NEXT *TNAPR-RONAM2 VARYING FONAM FROM *TNAPR-FONAM NEXT *TNAPR-FONAM2 VARYING PGNAM FROM *TNAPR-PGNAM NEXT *TNAPR-PGNAM2. CHECK PGNAM NE SPACE. TNAPR-RONAM = RONAM. TNAPR-FONAM = FONAM. TNAPR-PGNAM = PGNAM. IF TNAPR-RONAM NE SPACE OR TNAPR-PGNAM NE SPACE. SY-MSGID = 'VN'. SY-MSGNO = '056'. SY-MSGTY = 'I'. SY-MSGV1 = TNAPR-PGNAM. CONDENSE SY-MSGV1 NO-GAPS. SY-MSGV2 = TNAPR-RONAM. CONDENSE SY-MSGV2 NO-GAPS. CALL FUNCTION 'NAST_PROTOCOL_UPDATE' EXPORTING MSG_ARBGB = SY-MSGID MSG_NR = SY-MSGNO MSG_TY = SY-MSGTY MSG_V1 = SY-MSGV1 MSG_V2 = SY-MSGV2 EXCEPTIONS OTHERS = 0. ENDIF. IF NAST-NACHA EQ '1'. IF NAST-PFLD5 NE SPACE. TNAPR-FUNCNAME = NAST-PFLD5. ENDIF. ENDIF. IF NAST-NACHA EQ '1' OR NAST-NACHA EQ '2'. IF NAST-PFLD4 NE SPACE. TNAPR-FONAM = NAST-PFLD4. ENDIF. ENDIF. RETURNCODE = 999. TEMP_NAST = NAST. PERFORM (TNAPR-RONAM) IN PROGRAM (TNAPR-PGNAM) USING RETURNCODE US_SCREEN IF FOUND. NAST = TEMP_NAST. IF RETURNCODE = 999. SYST-MSGID = 'VN'. SYST-MSGNO = 068. SYST-MSGTY = 'E'. SYST-MSGV1 = TNAPR-RONAM. SYST-MSGV2 = TNAPR-PGNAM. CALL FUNCTION 'NAST_PROTOCOL_UPDATE' EXPORTING

MSG_ARBGB = SYST-MSGID MSG_NR = SYST-MSGNO MSG_TY = SYST-MSGTY MSG_V1 = SYST-MSGV1 MSG_V2 = SYST-MSGV2 EXCEPTIONS OTHERS = 0. ENDIF. IF RETURNCODE NE 0. EXIT. ENDIF. ENDDO. TNAPR = *TNAPR. ENDFORM.

FORM PROTOCOL_STORE USING VALUE(PI_KAPPL) LIKE NAST-KAPPL VALUE(PI_KSCHL) LIKE NAST-KSCHL CHANGING P_CMFPNR LIKE NAST-CMFPNR. DATA: L_NAST_CMFPNR LIKE NAST-CMFPNR. PERFORM T685B_LESEN USING PI_KAPPL PI_KSCHL. IF T685B-NOPROTOCOL EQ SPACE. CALL FUNCTION 'NAST_PROTOCOL_STORE' IMPORTING MSG_CMFPNR = L_NAST_CMFPNR EXCEPTIONS NO_PROTOCOL_UPDATE = 01. IF SY-SUBRC EQ 0. P_CMFPNR = L_NAST_CMFPNR. ENDIF. ELSE. CLEAR P_CMFPNR. ENDIF. ENDFORM. FORM TNAPR_LESEN USING VALUE(P_KSCHL) LIKE NAST-KSCHL VALUE(P_NACHA) LIKE NAST-NACHA VALUE(P_KAPPL) LIKE NAST-KAPPL. CHECK TNAPR-KSCHL NE P_KSCHL OR TNAPR-NACHA NE P_NACHA OR TNAPR-KAPPL NE P_KAPPL. SELECT SINGLE * FROM TNAPR WHERE KSCHL = P_KSCHL AND NACHA = P_NACHA AND KAPPL = P_KAPPL. IF SY-SUBRC NE 0. MESSAGE A020 WITH P_KSCHL P_NACHA P_KAPPL. ENDIF. ENDFORM.

FORM T685B_LESEN USING VALUE(US_KAPPL) LIKE T685B-KAPPL VALUE(US_KSCHL) LIKE T685B-KSCHL. CHECK T685B-KAPPL NE US_KAPPL OR T685B-KSCHL NE US_KSCHL.

SELECT SINGLE * FROM T685B WHERE KAPPL = US_KAPPL AND KSCHL = US_KSCHL. IF SY-SUBRC NE 0. MESSAGE A047 WITH US_KAPPL US_KSCHL. ENDIF. ENDFORM. FORM CHECK_NAST_VSZTP USING P_NAST STRUCTURE NAST P_SUBRC LIKE SY-SUBRC. P_SUBRC = 4. CHECK P_NAST-VSZTP NE '3'. IF P_NAST-VSZTP = '2'. IF P_NAST-VSDAT CN '0'. CHECK P_NAST-VSDAT LE SY-DATUM. ENDIF. IF P_NAST-VSURB IS INITIAL. CHECK P_NAST-VSURA LE SY-UZEIT. ELSE. CHECK P_NAST-VSURA LE SY-UZEIT AND P_NAST-VSURB GE SY-UZEIT. ENDIF. ENDIF. P_SUBRC = 0. ENDFORM. FORM CHECK_KAPPLS_NOT_TO_PROCESS USING VALUE(P_KAPPL) LIKE NAST-KAPPL P_SUBRC LIKE SY-SUBRC. CASE P_KAPPL. WHEN 'WA'. P_SUBRC = 4. WHEN OTHERS. P_SUBRC = 0. ENDCASE. ENDFORM. " CHECK_KAPPLS_NOT_TO_PROCESS FORM CHECK_STATUS_ON_DB USING RC LIKE SY-SUBRC. DATA: ST_NAST LIKE NAST. RC = 0. IF NAST-VSTAT = '0'. SELECT SINGLE * FROM NAST INTO ST_NAST WHERE KAPPL = NAST-KAPPL AND OBJKY = NAST-OBJKY AND KSCHL = NAST-KSCHL AND SPRAS = NAST-SPRAS AND PARNR = NAST-PARNR AND PARVW = NAST-PARVW AND ERDAT = NAST-ERDAT AND ERUHR = NAST-ERUHR. IF SY-SUBRC <> 0 OR ST_NAST-VSTAT <> '0'. RC = 8. ENDIF. ENDIF. ENDFORM. " CHECK_STATUS_ON_DB FORM SET_COUNTERS USING L_SUBRC LIKE SY-SUBRC. CASE L_SUBRC. WHEN '0'. ADD 1 TO COUNT_1. WHEN '1'. ADD 1 TO COUNT_2. "successfully processed "processing failure

* WHEN '2'. * ADD 1 TO count_1. WHEN '3'. WHEN OTHERS. ADD 1 TO COUNT_2. ENDCASE. ENDFORM.

"translated (EDI) "application document incomplete "processing failure

The output is shown as follows:

The green state indicates that the transmission is done without any errors. The typical format of an IDOC is shown below:

The IDOC control record, data records, status records are shown above. Once the idoc is in the system, there are lot of status records for the IDOC depending on the situation of the IDOC. This is the complete process of the outbound process. Inbound process: The inbound process acts as the same as the outbound process. Because I have been working on the same computer, the IDOC that I have used for the outbound process is used as the same for the inbound process.

The flowchart for this process is shown below:

B BEGIN

E EDI

SUB SYSTEM

S START IDOC_INBOUND_MODULE

T-CODE:SMOD THIS IS USED ONLY ONCE O INBOUND TYPE: IDOC ORDER TYPE: ORDE CHECK THE IDOC TRIGEER IMMEDIATELY .PARTNER FUNCTION IS CHOOSEN AS BP WHICH IS VALIDATED. V

T-CODE: WE20. NO: 123. RECEIVING INFO I

PROCES CODE: TCODE:WE42 C

FUNCTION MODULE: IS INVOKED. IDOC_INBOUND I

T-CODE : SE38. REPORT : ZINBOUND. THIS REPORT SHOULD BE SAVED AND CHECK FOR ANY INCONSTITENCIES AND SHOULD BE B ACTIVATED.

PROCESS CODE IS TAKEN FROM THE PARTNER PROFILES P

T-CODE : WE19. IN THE EXISTING IDOC BOX, ENTERTHE EXISTING OUTBOUND IDOC TO CONVERT INTO INBOUND RECORD. I

WHEN CREATED, COPY THE NECESSARY SEGMENTS AND SAVED AS NAME.TXT N T-CODE : BD87. EXECUTE THE SAVED INBOUND FILE TO POST THE APPLICATION DOCUMENT. IF THERE ARE T-CODE : RBDAPP01 AND EXECUTE THENO ERRORS, REPORT MM02. IDOC APPLICATION MAKE SUREIS END NO DATA IS BEING THAT THE FUNCTION MODULE CREATED IN THE ISINVOKEDFLATFILE DOCUMENT SUBSYSTEM.O SIELECTED. S ISFORMED. SHOULD BE R ELSE START POSTED. P SYSTEM. WORKFLOW. WS

In the inbound process, the incoming IDOC is read and all the details are entered in the database tables, which is the reversal of the outbound process for the creation of the application document. The following programs reads the details of the IDOC as soon as the program is checked, activated, the details of the data record, control record, are entered in the tables. The tables that are used in the program are : edidc, edids, edid4, edid2, edidd, edidd_old, teds2, tbd55, serial, tbd54, bdfields.
REPORT ZINBOUND . INCLUDE mbdconst. TABLES: edidc, edids, edid4, edid2, edidd, edidd_old, teds2, tbd55, serial, tbd54, bdfields. DATA: BEGIN OF t_idoc_control_r OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_r. DATA: BEGIN OF t_idoc_control_n OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_n. DATA: BEGIN OF t_idoc_control_s OCCURS 0. INCLUDE STRUCTURE edidc. INCLUDE STRUCTURE serial. DATA: END OF t_idoc_control_s. DATA: BEGIN OF t_idoc_control_tmp OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_tmp. DATA: BEGIN OF t_packet OCCURS 0. INCLUDE STRUCTURE edp21. DATA: END OF t_packet. DATA: BEGIN OF t_teds2 OCCURS 0. INCLUDE STRUCTURE teds2. DATA: END OF t_teds2. DATA: BEGIN OF t_update OCCURS 0, docnum LIKE edidc-docnum, upddat LIKE edidc-upddat, updtim LIKE edidc-updtim. DATA: END OF t_update. DATA: i_tbd55 LIKE tbd55 OCCURS 0 WITH HEADER LINE. * Only needed for interface to APPLICATION_IDOC_POST DATA: BEGIN OF t_idoc_data OCCURS 0. INCLUDE STRUCTURE edidd. DATA: END OF t_idoc_data. SELECT-OPTIONS: docnum FOR edidc-docnum. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: credat FOR edidc-credat. SELECT-OPTIONS: cretim FOR edidc-cretim DEFAULT '000000' TO '235959'.

SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: status FOR edidc-status. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: mestyp FOR bdfields-mestyp. SELECT-OPTIONS: mescod FOR edidc-mescod. SELECT-OPTIONS: mesfct FOR edidc-mesfct. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: sndprt FOR edidc-sndprt. SELECT-OPTIONS: sndprn FOR edidc-sndprn. SELECT-OPTIONS: sndpfc FOR edidc-sndpfc. SELECTION-SCREEN SKIP 1. PARAMETERS: p_pcksiz LIKE edp13-pcksiz DEFAULT 1. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: test FOR edidc-test NO-EXTENSION. SELECTION-SCREEN SKIP 1. SELECTION-SCREEN BEGIN OF BLOCK block WITH FRAME TITLE text-tit. PARAMETERS: p_parall LIKE bdfields-parallel DEFAULT ' '. PARAMETERS: p_rfcgr LIKE bdfields-rfcgr DEFAULT ' '. SELECTION-SCREEN END OF BLOCK block. SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-ti2. SELECT-OPTIONS: obj_type FOR tbd55-obj_type. SELECTION-SCREEN END OF BLOCK block2. DATA: ext_prot VALUE ' ', err_msgs VALUE ' '. DATA: DATA: DATA: DATA: output_text(80). output_counter(7). output_total(7). output_trigger LIKE sy-tabix.

DATA: help_counter LIKE sy-tabix, end_of_packet TYPE c, status_text LIKE teds2-descrp. * Read IDOC control records with status output_text = 'Daten werden gerade selektiert'(o02). CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING text = output_text. SELECT * FROM edidc INTO TABLE t_idoc_control_r WHERE ( status = c_status_in_ready_post OR status = c_idoc_status_postponed ) AND status IN status AND docnum IN docnum AND mestyp IN mestyp AND mescod IN mescod AND mesfct IN mesfct AND sndprt IN sndprt AND sndprn IN sndprn AND sndpfc IN sndpfc AND credat IN credat AND cretim IN cretim AND test IN test. IF sy-subrc NE 0. MESSAGE i083(b1). "keine Daten selektiert

EXIT. ENDIF. * all authorization AUTHORITY-CHECK OBJECT 'S_IDOCMONI' ID 'ACTVT' FIELD c_display ID 'EDI_DIR' FIELD '*'

ID 'EDI_MES' FIELD '*' ID 'EDI_PRN' FIELD '*' ID 'EDI_PRT' FIELD '*' ID 'EDI_TCD' DUMMY. IF sy-subrc NE 0. "no auth. for all test each LOOP AT t_idoc_control_r. AUTHORITY-CHECK OBJECT 'S_IDOCMONI' ID 'ACTVT' FIELD c_display ID 'EDI_DIR' FIELD t_idoc_control_r-direct ID 'EDI_MES' FIELD t_idoc_control_r-mestyp ID 'EDI_PRN' FIELD t_idoc_control_r-sndprn ID 'EDI_PRT' FIELD t_idoc_control_r-sndprt ID 'EDI_TCD' DUMMY. IF sy-subrc NE 0. "no auth. MESSAGE i285(b1) WITH t_idoc_control_r-docnum. DELETE t_idoc_control_r. ENDIF. ENDLOOP. ENDIF. SORT t_idoc_control_r BY sndprn sndprt sndpfc mestyp mescod mesfct test serial. PERFORM divi_idocs . LOOP AT t_idoc_control_r. t_update-docnum = t_idoc_control_r-docnum. t_update-upddat = t_idoc_control_r-upddat. t_update-updtim = t_idoc_control_r-updtim. APPEND t_update. ENDLOOP. * Copy packet-fields to t_packet. * A packet will only be processed as such if table EDP21's key fields * are identical for all IDOCs in the packet. LOOP AT t_idoc_control_n. MOVE-CORRESPONDING t_idoc_control_n TO t_packet. APPEND t_packet. ENDLOOP. IF p_parall = c_true AND p_rfcgr <> space. CALL FUNCTION 'SPBT_INITIALIZE' EXPORTING group_name = p_rfcgr EXCEPTIONS invalid_group_name =1 internal_error =2 pbt_env_already_initialized = 3 currently_no_resources_avail = 4 no_pbt_resources_found =5 OTHERS = 6. IF sy-subrc = 1 OR sy-subrc = 2 OR sy-subrc = 5 OR sy-subrc = 6. MESSAGE i286(b1) WITH p_rfcgr. p_rfcgr = space. ENDIF. ENDIF. output_counter = 0. DESCRIBE TABLE t_idoc_control_r LINES output_total. help_counter = 0. output_trigger = 0. end_of_packet = c_false. REFRESH t_idoc_control_tmp.

LOOP AT t_packet. AT END OF test. end_of_packet = c_true. ENDAT. READ TABLE t_idoc_control_n INDEX sy-tabix. help_counter = help_counter + 1. output_trigger = output_trigger + 1. IF ( output_trigger >= 10 ) OR ( output_total <= 100 ). "#EC PORTABLE output_trigger = 0. ENDIF. PERFORM out_progress. t_idoc_control_tmp = t_idoc_control_n. APPEND t_idoc_control_tmp. IF help_counter >= p_pcksiz OR end_of_packet = c_true. * Need to refresh t_idoc_data because APPLICATION_IDOC_POST fills it. REFRESH t_idoc_data. PERFORM idoc_data_read TABLES t_idoc_control_tmp t_idoc_data. IF p_parall = c_true. IF p_rfcgr <> space. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc <> 0. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ELSE. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING 'X' "parallel flag ext_prot. ENDIF.

* *

* *

* *

ELSE. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' STARTING NEW TASK 'ALE' DESTINATION IN GROUP DEFAULT exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc <> 0. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot.

* *

ELSE. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING 'X' "parallel flag ext_prot. ENDIF. ENDIF. ELSE. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' * exporting * post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ENDIF. COMMIT WORK. CALL FUNCTION 'DEQUEUE_ALL'. help_counter = 0. end_of_packet = c_false. REFRESH t_idoc_control_tmp. ENDIF. ENDLOOP. "End of LOOP AT T_PACKET. IF help_counter <> 0.

REFRESH t_idoc_data. PERFORM idoc_data_read TABLES t_idoc_control_tmp t_idoc_data. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ENDIF. * * PERFORM obj_serial_proc. * Output result ULINE. WRITE: / SKIP 1. WRITE: /(16) 'IDoc'(002), '|', (30) 'NachrichtenTyp'(003), '|', (20) 'Serialinfo'(016), '|', 'St'(004), '|', 'Beschreibung'(005). ULINE. * Exit here if there were no IDocs processed (this is because select READ TABLE t_update INDEX 1. CHECK sy-subrc = 0. * Get text for status values SELECT * FROM teds2 INTO TABLE t_teds2 WHERE langua = sy-langu. * Read the IDoc's status after processing SELECT * FROM edidc INTO TABLE t_idoc_control_tmp FOR ALL ENTRIES IN t_update WHERE docnum = t_update-docnum. LOOP AT t_update. READ TABLE t_idoc_control_tmp INDEX sy-tabix. IF t_idoc_control_tmp-upddat = t_update-upddat AND t_idoc_control_tmp-updtim = t_update-updtim. * IDoc is still being processed, since control record unchanged. FORMAT COLOR 3. status_text = 'Das IDoc wird noch verarbeitet'(006). ELSE. * IDoc has been processed, since control record changed. READ TABLE t_teds2 WITH KEY status = t_idoc_control_tmp-status. status_text = t_teds2-descrp. IF t_idoc_control_tmp-status = c_status_in_idoc_posted. * ok status FORMAT COLOR 1.

ELSE. error status FORMAT COLOR 6. ENDIF. ENDIF. WRITE: / t_idoc_control_tmp-docnum, '|', t_idoc_control_tmp-mestyp, '|', t_idoc_control_tmp-serial, '|', t_idoc_control_tmp-status, '|', status_text. HIDE: t_idoc_control_tmp, status_text. CLEAR: t_idoc_control_tmp, status_text.

ENDLOOP. IF err_msgs = 'X'. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. MESSAGE i066(b1). ENDIF. AT LINE-SELECTION. IF NOT t_idoc_control_tmp IS INITIAL OR NOT status_text IS INITIAL. CALL FUNCTION 'EDI_DOCUMENT_STATUS_DISPLAY' EXPORTING docnum = t_idoc_control_tmp-docnum * ACTIONS =' ' * STATUS_KEY =' ' * CALL_ASYN ='' * TREE_DISPLAY = 'Y' * IMPORTING * ACTION = EXCEPTIONS no_status_record_found = 1 OTHERS = 2. CLEAR: t_idoc_control_tmp, status_text. ENDIF. *T_IDOC_CONTROL IDOC control records *T_IDOC_DATA IDOC data records FORM idoc_data_read TABLES t_idoc_control STRUCTURE edidc t_idoc_data STRUCTURE edidd. "Export

"Import

CALL FUNCTION 'ALE_FTCH_DATA_SEGMENTS_OF_IDOC' TABLES t_idoc_control = t_idoc_control t_idoc_data = t_idoc_data. ENDFORM. *FORM OUT_PROGRESS FORM out_progress. * status output (if <=100, show all; otherwise show only all tenth) output_counter = output_counter + 1. IF output_trigger = 0. output_text =

'(& von &) IDoc & wird gerade abgearbeitet'(o01). REPLACE '&' WITH output_counter INTO output_text. REPLACE '&' WITH output_total INTO output_text. REPLACE '&' WITH t_idoc_control_n-docnum INTO output_text. CONDENSE output_text. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING text = output_text. ENDIF. ENDFORM. *Form DIVI_IDOCS FORM divi_idocs. DATA: lines LIKE sy-index. DESCRIBE TABLE obj_type LINES lines. * Fetch Customizing table SELECT * FROM tbd55 INTO TABLE i_tbd55. SORT i_tbd55. LOOP AT t_idoc_control_r. serial = t_idoc_control_r-serial. READ TABLE i_tbd55 WITH KEY mandt = sy-mandt sndprn = t_idoc_control_r-sndprn sndprt = t_idoc_control_r-sndprt sndpfc = t_idoc_control_r-sndpfc obj_type = serial-obj_type. IF sy-subrc EQ 4. "nicht da -> standard MOVE t_idoc_control_r TO t_idoc_control_n. IF lines EQ 0. "bei ges. obj_type wird KEIN anderes IDoc verarb. APPEND t_idoc_control_n. ELSE. DELETE t_idoc_control_r. ENDIF. ELSE. "da -> serial MOVE t_idoc_control_r-serial TO serial. MOVE-CORRESPONDING: t_idoc_control_r TO t_idoc_control_s, serial TO t_idoc_control_s. IF serial-obj_type IN obj_type. "filter acc. to sel-options APPEND t_idoc_control_s. ELSE. DELETE t_idoc_control_r. ENDIF. ENDIF. ENDLOOP. ENDFORM. " DIVI_IDOCS FORM obj_serial_proc. DATA: act_okey LIKE bdserinstr, old_okey LIKE bdserinstr, lines LIKE sy-index, count_id TYPE p. DATA: t_idoc_proc LIKE t_idoc_control_s OCCURS 0 WITH HEADER LINE. DESCRIBE TABLE t_idoc_control_s LINES lines. IF lines EQ 0. EXIT. ENDIF. * Serial packet process: Sort SORT t_idoc_control_s BY sndprt sndprn obj_type chnum chcou.

CLEAR: act_okey, old_okey, count_id. REFRESH t_idoc_proc. LOOP AT t_idoc_control_s. t_idoc_control_n-docnum = t_idoc_control_s-docnum. "Show act. IDoc PERFORM out_progress. MOVE-CORRESPONDING t_idoc_control_s TO act_okey. IF act_okey NE old_okey AND old_okey-obj_type NE ''. * Process all data together IF p_parall EQ 'X' AND p_rfcgr NE ''. IF count_id GE p_pcksiz. "Counter must be ge otherwise "collect more (than one Object per packet) "start new task CALL FUNCTION 'ALE_SERIAL_PROCESS' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc NE 0. "error try local CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. REFRESH t_idoc_proc. CLEAR count_id. ELSE. PERFORM out_protocoll TABLES t_idoc_proc "extended protocoll USING 'X' "parallel flag ext_prot. REFRESH t_idoc_proc. CLEAR count_id. ENDIF. ENDIF. ELSE. "take my workprocess CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc. REFRESH t_idoc_proc. CLEAR count_id. ENDIF. * WRITE: / ' end of object bundle', old_okey(20). ENDIF. old_okey = act_okey. * WRITE: / t_idoc_cntrl-docnum, t_idoc_cntrl-mestyp,

t_idoc_cntrl-serial. MOVE t_idoc_control_s TO t_idoc_proc. APPEND t_idoc_proc. ADD 1 TO count_id. ENDLOOP. IF p_parall EQ 'X' AND p_rfcgr NE ''."start new task CALL FUNCTION 'ALE_SERIAL_PROCESS' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc NE 0. "error try local CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. ELSE. PERFORM out_protocoll TABLES t_idoc_proc "extended protocoll USING 'X'"parallel flag ext_prot. ENDIF. ELSE. CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc. ENDIF.

* WRITE: / ' end of object bundle', old_okey(20). ENDFORM. " OBJ_SERIAL_PROC

FORM out_protocoll TABLES p_t_idoc_control STRUCTURE edidc USING p_parfl p_ext_prot. CALL FUNCTION 'ALE_SER_PROTOCOLL' EXPORTING p_parfl = p_parfl p_ext_prot = p_ext_prot TABLES p_t_idoc_control = p_t_idoc_control. ENDFORM. " OUT_PROTOCOLL

Unpacking the IDOC: The IDOC is now unpacked for the creation of application document.

The transaction code used in the process is : WE19.

The existing IDOC(outbound) is copied into the system and executed. An appropriate file name is given for the inbound process and it is saved.

As soon as the document is saved , the inbound function module is invoked. The function module I have taken in this process is shown below.

The incoming IDOC is now unpacked, the details of which are entered in the database tables, a flat file format is created. Final Step: The unpacked IDOC is now entered in the application, the following program reads the saved incoming IDOC details, the database tables, where the partner profiles,port definitions are given valid. By executing the program the final application document is created. The program name is ZINBOUND.

REPORT rbdapp01 NO STANDARD PAGE HEADING LINE-SIZE 152. * xlp 100398 Serialization * Include constants INCLUDE mbdconst. TABLES: TABLES: TABLES: TABLES: edidc. edids. edid4, edid2, edidd, edidd_old. teds2, tbd55, serial, tbd54, bdfields.

DATA: BEGIN OF t_idoc_control_r OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_r. DATA: BEGIN OF t_idoc_control_n OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_n. DATA: BEGIN OF t_idoc_control_s OCCURS 0. INCLUDE STRUCTURE edidc. INCLUDE STRUCTURE serial. DATA: END OF t_idoc_control_s. DATA: BEGIN OF t_idoc_control_tmp OCCURS 0. INCLUDE STRUCTURE edidc. DATA: END OF t_idoc_control_tmp. DATA: BEGIN OF t_packet OCCURS 0. INCLUDE STRUCTURE edp21. DATA: END OF t_packet. DATA: BEGIN OF t_teds2 OCCURS 0. INCLUDE STRUCTURE teds2. DATA: END OF t_teds2. DATA: BEGIN OF t_update OCCURS 0, docnum LIKE edidc-docnum, upddat LIKE edidc-upddat, updtim LIKE edidc-updtim. DATA: END OF t_update. DATA: i_tbd55 LIKE tbd55 OCCURS 0 WITH HEADER LINE. * Only needed for interface to APPLICATION_IDOC_POST DATA: BEGIN OF t_idoc_data OCCURS 0. INCLUDE STRUCTURE edidd. DATA: END OF t_idoc_data. SELECT-OPTIONS: docnum FOR edidc-docnum. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: credat FOR edidc-credat. SELECT-OPTIONS: cretim FOR edidc-cretim DEFAULT '000000' TO '235959'. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: status FOR edidc-status. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: mestyp FOR bdfields-mestyp. SELECT-OPTIONS: mescod FOR edidc-mescod. SELECT-OPTIONS: mesfct FOR edidc-mesfct. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: sndprt FOR edidc-sndprt. SELECT-OPTIONS: sndprn FOR edidc-sndprn. SELECT-OPTIONS: sndpfc FOR edidc-sndpfc. SELECTION-SCREEN SKIP 1.

PARAMETERS: p_pcksiz LIKE edp13-pcksiz DEFAULT 1. SELECTION-SCREEN SKIP 1. SELECT-OPTIONS: test FOR edidc-test NO-EXTENSION. SELECTION-SCREEN SKIP 1. SELECTION-SCREEN BEGIN OF BLOCK block WITH FRAME TITLE text-tit. PARAMETERS: p_parall LIKE bdfields-parallel DEFAULT ' '. PARAMETERS: p_rfcgr LIKE bdfields-rfcgr DEFAULT ' '. SELECTION-SCREEN END OF BLOCK block. SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME TITLE text-ti2. SELECT-OPTIONS: obj_type FOR tbd55-obj_type. SELECTION-SCREEN END OF BLOCK block2. DATA: ext_prot VALUE ' ', err_msgs VALUE ' '. DATA: DATA: DATA: DATA: output_text(80). output_counter(7). output_total(7). output_trigger LIKE sy-tabix.

DATA: help_counter LIKE sy-tabix, end_of_packet TYPE c, status_text LIKE teds2-descrp. * Read IDOC control records with status 64 or 66 output_text = 'Daten werden gerade selektiert'(o02). CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING text = output_text. SELECT * FROM edidc INTO TABLE t_idoc_control_r WHERE ( status = c_status_in_ready_post OR status = c_idoc_status_postponed ) AND status IN status AND docnum IN docnum AND mestyp IN mestyp AND mescod IN mescod AND mesfct IN mesfct AND sndprt IN sndprt AND sndprn IN sndprn AND sndpfc IN sndpfc AND credat IN credat AND cretim IN cretim AND test IN test. IF sy-subrc NE 0. "keine Daten selektiert MESSAGE i083(b1). * Es konnten keine Daten selektiert werden. EXIT. ENDIF. * all authorization ?? AUTHORITY-CHECK OBJECT 'S_IDOCMONI' ID 'ACTVT' FIELD c_display ID 'EDI_DIR' FIELD '*' ID 'EDI_MES' FIELD '*' ID 'EDI_PRN' FIELD '*' ID 'EDI_PRT' FIELD '*' ID 'EDI_TCD' DUMMY. IF sy-subrc NE 0. "no auth. for all test each LOOP AT t_idoc_control_r. AUTHORITY-CHECK OBJECT 'S_IDOCMONI' ID 'ACTVT' FIELD c_display ID 'EDI_DIR' FIELD t_idoc_control_r-direct ID 'EDI_MES' FIELD t_idoc_control_r-mestyp ID 'EDI_PRN' FIELD t_idoc_control_r-sndprn

ID 'EDI_PRT' FIELD t_idoc_control_r-sndprt ID 'EDI_TCD' DUMMY. IF sy-subrc NE 0. "no auth. MESSAGE i285(b1) WITH t_idoc_control_r-docnum. DELETE t_idoc_control_r. ENDIF. ENDLOOP. ENDIF. SORT t_idoc_control_r BY sndprn sndprt sndpfc mestyp mescod mesfct test serial. * Find out, if IDocs are to serialize via object channel PERFORM divi_idocs . LOOP AT t_idoc_control_r. t_update-docnum = t_idoc_control_r-docnum. t_update-upddat = t_idoc_control_r-upddat. t_update-updtim = t_idoc_control_r-updtim. APPEND t_update. ENDLOOP. * Copy packet-fields to t_packet. * A packet will only be processed as such if table EDP21's key fields * are identical for all IDOCs in the packet. LOOP AT t_idoc_control_n. MOVE-CORRESPONDING t_idoc_control_n TO t_packet. APPEND t_packet. ENDLOOP. IF p_parall = c_true AND p_rfcgr <> space. CALL FUNCTION 'SPBT_INITIALIZE' EXPORTING group_name = p_rfcgr EXCEPTIONS invalid_group_name =1 internal_error =2 pbt_env_already_initialized = 3 currently_no_resources_avail = 4 no_pbt_resources_found =5 OTHERS = 6. IF sy-subrc = 1 OR sy-subrc = 2 OR sy-subrc = 5 OR sy-subrc = 6. MESSAGE i286(b1) WITH p_rfcgr. * Servergruppe & konnte nicht initialisiert werden; GROUP DEFAULT wird p_rfcgr = space. ENDIF. ENDIF. * Loop through IDOCs and call APPLICATION_IDOC_POST once per packet. output_counter = 0. DESCRIBE TABLE t_idoc_control_r LINES output_total. help_counter = 0. output_trigger = 0. end_of_packet = c_false. REFRESH t_idoc_control_tmp. LOOP AT t_packet. AT END OF test. end_of_packet = c_true. ENDAT. READ TABLE t_idoc_control_n INDEX sy-tabix. help_counter = help_counter + 1.

output_trigger = output_trigger + 1. IF ( output_trigger >= 10 ) OR ( output_total <= 100 ). "#EC PORTABLE output_trigger = 0. ENDIF. PERFORM out_progress. t_idoc_control_tmp = t_idoc_control_n. APPEND t_idoc_control_tmp. IF help_counter >= p_pcksiz OR end_of_packet = c_true. * Need to refresh t_idoc_data because APPLICATION_IDOC_POST fills it. REFRESH t_idoc_data. PERFORM idoc_data_read TABLES t_idoc_control_tmp t_idoc_data. IF p_parall = c_true. IF p_rfcgr <> space. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc <> 0. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ELSE. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING 'X' "parallel flag ext_prot. ENDIF. ELSE. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' STARTING NEW TASK 'ALE' DESTINATION IN GROUP DEFAULT exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS

* *

* *

* *

RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc <> 0. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot.

* *

ELSE. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING 'X' "parallel flag ext_prot. ENDIF. ENDIF. ELSE. CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' * exporting * post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ENDIF. COMMIT WORK. CALL FUNCTION 'DEQUEUE_ALL'. help_counter = 0. end_of_packet = c_false. REFRESH t_idoc_control_tmp. ENDIF. ENDLOOP. "End of LOOP AT T_PACKET. IF help_counter <> 0. REFRESH t_idoc_data. PERFORM idoc_data_read TABLES t_idoc_control_tmp t_idoc_data. * * CALL FUNCTION 'APPLICATION_IDOC_POST_IMMEDIAT' exporting post_immediately = c_true TABLES idoc_control = t_idoc_control_tmp

idoc_data = t_idoc_data EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. PERFORM out_protocoll TABLES t_idoc_control_tmp "extended protocoll USING ' ' "parallel flag ext_prot. ENDIF. PERFORM obj_serial_proc. * Output result ULINE. WRITE: / 'Folgende IDocs wurden an die Anwendung bergeben:'(001). SKIP 1. WRITE: /(16) 'IDoc'(002), '|', (30) 'NachrichtenTyp'(003), '|', (20) 'Serialinfo'(016), '|', 'St'(004), '|', 'Beschreibung'(005). ULINE. * Exit here if there were no IDocs processed (this is because select * with 'for all entries' takes ages when the entries table is empty). READ TABLE t_update INDEX 1. CHECK sy-subrc = 0. * Get text for status values SELECT * FROM teds2 INTO TABLE t_teds2 WHERE langua = sy-langu. * Read the IDoc's status after processing SELECT * FROM edidc INTO TABLE t_idoc_control_tmp FOR ALL ENTRIES IN t_update WHERE docnum = t_update-docnum. LOOP AT t_update. READ TABLE t_idoc_control_tmp INDEX sy-tabix. IF t_idoc_control_tmp-upddat = t_update-upddat AND t_idoc_control_tmp-updtim = t_update-updtim. * IDoc is still being processed, since control record unchanged. FORMAT COLOR 3. status_text = 'Das IDoc wird noch verarbeitet'(006). ELSE. * IDoc has been processed, since control record changed. READ TABLE t_teds2 WITH KEY status = t_idoc_control_tmp-status. status_text = t_teds2-descrp. IF t_idoc_control_tmp-status = c_status_in_idoc_posted. * ok status FORMAT COLOR 1. ELSE. * error status FORMAT COLOR 6. ENDIF. ENDIF. * End of if t_idoc_control_tmp-upddat = t_update-upddat * and t_idoc_control_tmp-updtim = t_update-updtim. WRITE: / t_idoc_control_tmp-docnum,

'|', t_idoc_control_tmp-mestyp, '|', t_idoc_control_tmp-serial, '|', t_idoc_control_tmp-status, '|', status_text. HIDE: t_idoc_control_tmp, status_text. CLEAR: t_idoc_control_tmp, status_text. ENDLOOP. IF err_msgs = 'X'. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. MESSAGE i066(b1). * Es sind Meldungen bei der Verarbeitung aufgetreten. ENDIF. ************************************************************************ AT LINE-SELECTION. IF NOT t_idoc_control_tmp IS INITIAL OR NOT status_text IS INITIAL. CALL FUNCTION 'EDI_DOCUMENT_STATUS_DISPLAY' EXPORTING docnum = t_idoc_control_tmp-docnum * ACTIONS =' ' * STATUS_KEY =' ' * CALL_ASYN ='' * TREE_DISPLAY = 'Y' * IMPORTING * ACTION = EXCEPTIONS no_status_record_found = 1 OTHERS = 2. CLEAR: t_idoc_control_tmp, status_text. ENDIF. *---------------------------------------------------------------------* * FORM IDOC_DATA_READ * *---------------------------------------------------------------------* * This routine reads the IDOC's data records from the database. * *---------------------------------------------------------------------* * --> T_IDOC_CONTROL IDOC control records * * <-- T_IDOC_DATA IDOC data records * *---------------------------------------------------------------------* FORM idoc_data_read TABLES t_idoc_control STRUCTURE edidc "Import t_idoc_data STRUCTURE edidd. "Export CALL FUNCTION 'ALE_FTCH_DATA_SEGMENTS_OF_IDOC' TABLES t_idoc_control = t_idoc_control t_idoc_data = t_idoc_data. ENDFORM. *---------------------------------------------------------------------* * FORM OUT_PROGRESS * *---------------------------------------------------------------------* FORM out_progress. * status output (if <=100, show all; otherwise show only all tenth)

output_counter = output_counter + 1. IF output_trigger = 0. output_text = '(& von &) IDoc & wird gerade abgearbeitet'(o01). REPLACE '&' WITH output_counter INTO output_text. REPLACE '&' WITH output_total INTO output_text. REPLACE '&' WITH t_idoc_control_n-docnum INTO output_text. CONDENSE output_text. CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR' EXPORTING text = output_text. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form DIVI_IDOCS *&---------------------------------------------------------------------* * Make 2 bundels of IDocs (standard and to serialize ones) *----------------------------------------------------------------------* FORM divi_idocs. DATA: lines LIKE sy-index. DESCRIBE TABLE obj_type LINES lines. * Fetch Customizing table SELECT * FROM tbd55 INTO TABLE i_tbd55. SORT i_tbd55. LOOP AT t_idoc_control_r. serial = t_idoc_control_r-serial. READ TABLE i_tbd55 WITH KEY mandt = sy-mandt sndprn = t_idoc_control_r-sndprn sndprt = t_idoc_control_r-sndprt sndpfc = t_idoc_control_r-sndpfc obj_type = serial-obj_type. IF sy-subrc EQ 4. "nicht da -> standard MOVE t_idoc_control_r TO t_idoc_control_n. IF lines EQ 0. "bei ges. obj_type wird KEIN anderes IDoc verarb. APPEND t_idoc_control_n. ELSE. DELETE t_idoc_control_r. ENDIF. ELSE. "da -> serial MOVE t_idoc_control_r-serial TO serial. MOVE-CORRESPONDING: t_idoc_control_r TO t_idoc_control_s, serial TO t_idoc_control_s. IF serial-obj_type IN obj_type. "filter acc. to sel-options APPEND t_idoc_control_s. ELSE. DELETE t_idoc_control_r. ENDIF. ENDIF. ENDLOOP. ENDFORM. " DIVI_IDOCS *&---------------------------------------------------------------------* *& Form OBJ_SERIAL_PROC *&---------------------------------------------------------------------* * Make bundels by Object channels *----------------------------------------------------------------------* FORM obj_serial_proc. DATA: act_okey LIKE bdserinstr, old_okey LIKE bdserinstr, lines LIKE sy-index, count_id TYPE p.

DATA: t_idoc_proc LIKE t_idoc_control_s OCCURS 0 WITH HEADER LINE. DESCRIBE TABLE t_idoc_control_s LINES lines. IF lines EQ 0. EXIT. ENDIF. * Serial packet process: Sort SORT t_idoc_control_s BY sndprt sndprn obj_type chnum chcou. * Serial packet process: Make bundles by objectchannels CLEAR: act_okey, old_okey, count_id. REFRESH t_idoc_proc. LOOP AT t_idoc_control_s. t_idoc_control_n-docnum = t_idoc_control_s-docnum. "Show act. IDoc PERFORM out_progress. MOVE-CORRESPONDING t_idoc_control_s TO act_okey. IF act_okey NE old_okey AND old_okey-obj_type NE ''. * Process all data in bundle now * Parallel ? IF p_parall EQ 'X' AND p_rfcgr NE ''. IF count_id GE p_pcksiz. "Counter must be ge otherwise "collect more (than one Object per packet) "start new task CALL FUNCTION 'ALE_SERIAL_PROCESS' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc NE 0. "error try local CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. REFRESH t_idoc_proc. CLEAR count_id. ELSE. PERFORM out_protocoll TABLES t_idoc_proc "extended protocoll USING 'X' "parallel flag ext_prot. REFRESH t_idoc_proc. CLEAR count_id. ENDIF. ENDIF. ELSE. "take my workprocess CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING

ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc. REFRESH t_idoc_proc. CLEAR count_id. ENDIF. * WRITE: / ' --> end of object bundle', old_okey(20). ENDIF. old_okey = act_okey. * WRITE: / t_idoc_cntrl-docnum, t_idoc_cntrl-mestyp, * t_idoc_cntrl-serial. MOVE t_idoc_control_s TO t_idoc_proc. APPEND t_idoc_proc. ADD 1 TO count_id. ENDLOOP. * Process last bundle * Parallel ? IF p_parall EQ 'X' AND p_rfcgr NE ''."start new task CALL FUNCTION 'ALE_SERIAL_PROCESS' STARTING NEW TASK 'ALE' DESTINATION IN GROUP p_rfcgr EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS RESOURCE_FAILURE =1 system_failure =2 communication_failure =3 OTHERS = 4. IF sy-subrc NE 0. "error try local CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc EXCEPTIONS error_message = 1. IF sy-subrc NE 0. err_msgs = 'X'. ENDIF. ELSE. PERFORM out_protocoll TABLES t_idoc_proc "extended protocoll USING 'X'"parallel flag ext_prot. ENDIF. ELSE. "take my workprocess CALL FUNCTION 'ALE_SERIAL_PROCESS' EXPORTING ext_prot = ext_prot TABLES t_idoc_cntrl = t_idoc_proc. ENDIF. * WRITE: / ' --> end of object bundle', old_okey(20). ENDFORM. " OBJ_SERIAL_PROC FORM out_protocoll TABLES p_t_idoc_control STRUCTURE edidc USING p_parfl p_ext_prot. CALL FUNCTION 'ALE_SER_PROTOCOLL' EXPORTING

p_parfl = p_parfl p_ext_prot = p_ext_prot TABLES p_t_idoc_control = p_t_idoc_control. ENDFORM. " OUT_PROTOCOLL

With the execution of this program, the IDOC is now should be saved as the application document. But in my project, as I am same port and the same server, the document is only saved in the form of a flat format. Because in real time situations, all the IDOCs are transferred to a different computer. Though all my programs are free of syntax errors and free of logic errors, as I have used the same port for both the inbound and outbound process, it couldn't validate against the sender and receiver fields. But the successful transmission of the document is shown by looking at the inbound flat file which I have saved as ananth.txt. The text file is shown as follows:

With this, the EDI transmission is done correctly by checking the following scenarios: 1. When this file is compared to the application document for which I have created in the outbound process, it tells the same results. 2. The data in the database tables is validated for both the outbound and the inbound process.

3. The status records in every milestone are correct which implies for the successful transmission of EDI document.

REFERENCE: 1. ALE, EDI, & IDOC Technologies for SAP 2nd Edition by Arvind Nagpal with John Pitlak.

2.SAMS Teach Yourself ABAP/4 for programming. 3.Introduction to ABAP/4 Programming by Gareth M. de. Bruyn and Robert Lyfareff. Online Help CD: ALE related information is available under the version 4.6 R/3 Library, Basis Components, Middleware, Application Link Enabling (BC-MID-ALE). IDOC related information is available under R/3 Library, Basis Components, Basis Services/ Communication Interfaces(BC-SRV), The IDOC Interface. Message Control - information is available under R/3 Library, Logistics, Sales and Distribution (SD), Output Determination (SD BF OC) and Logistics, Materials Management(MM), Purchasing (MM-PUR), Entering Text, Printing, and Transmitting Documents, Messages. For Questions and Solutions: 1. www.ittoolbox.com 2. www.sapfans.com 3. www.sap.com

Vous aimerez peut-être aussi