This section describes how to create a function module which is identified by the report RSNASTED (form routine NEW_DYN_PERFORM) via a new process code. This function module enters application data in the new basic type. RSNASTED can be found in table TNAPR as an EDI processing program. Message Control reads this table and can then call RSNASTED.
Use the Function Builder to create a new function module.
Create the segments as global data in your function group. The function module must transfer the application data from the application tables to the corresponding segments.
Activate the function module. On the initial screen of the Function Builder choose .
In the example, the new function module is called IDOC_OUTPUT_TESTER. The function module uses the new interface (from Release 3.0 onwards), that is, the application data is stored in an internal table. In addition, the path without the ALE layer (that is, without filters) is selected.
The function module is called from Purchasing (create purchase order) in the same way as IDOC_OUTPUT_ORDERS (IDoc type ORDERS01). The function module therefore fills the segments of your new IDoc type from the purchasing tables, that is, EKKO and EKPO (purchasing document header and item). Note that the intention here is not to simulate a realistic purchase order, but to describe how data reaches an IDoc table from application tables via segment structures. In this case, you should pay particular attention to the form routines HEADER_E1HEAD_FILL or POSITION_E1ITEM_FILL.
Application abbreviation |
M (Materials Management) |
Processing type |
Normal, start immediately |
Formal parameter |
Reference structure |
Explanation |
Import parameter |
||
OBJECT |
MC |
Current Message Control record |
CONTROL_RECORD_IN |
EDIDC |
Contains recipient information |
Export parameters |
||
OBJECT_TYPE |
WFAS1-ASGTP |
Object type for the application object in the Business Object Repository (BOR) |
CONTROL_RECORD_OUT |
EDIDC |
Contains the sender information as well as the date and time at which the IDoc table was filled. |
Table |
||
INT_EDIDD |
EDIDD |
Internal table of IDoc data records |
FUNCTION IDOC_OUTPUT_TESTER. *"------------------------------------------------------------------ *"*"Globale Schnittstelle: *" IMPORTING *" VALUE(OBJECT) LIKE NAST STRUCTURE NAST *" VALUE(CONTROL_RECORD_IN) LIKE EDIDC STRUCTURE EDIDC *" EXPORTING *" VALUE(OBJECT_TYPE) LIKE WFAS1-ASGTP *" VALUE(CONTROL_RECORD_OUT) LIKE EDIDC STRUCTURE EDIDC *" TABLES *" INT_EDIDD STRUCTURE EDIDD *" EXCEPTIONS *" ERROR_MESSAGE_RECEIVED *"------------------------------------------------------------------- CLEAR CONTROL_RECORD_OUT. * fill help fields H_KAPPL = OBJECT-KAPPL. H_EBELN = OBJECT-OBJKY. H_PARVW = OBJECT-PARVW. * fill control record MOVE CONTROL_RECORD_IN TO CONTROL_RECORD_OUT. CONTROL_RECORD_OUT-DIRECT = '1'. CONTROL_RECORD_OUT-SERIAL = SY-DATUM. CONTROL_RECORD_OUT-SERIAL+8 = SY-UZEIT. * read orders PERFORM ORDERS_READ. * fill idoc table PERFORM IDOC_TABLE_FILL. * provide object type OBJECT_TYPE = 'BUS2012'. ENDFUNCTION. FORM ORDERS_READ. SELECT SINGLE * FROM T000 WHERE MANDT EQ SY-MANDT. * read header data SELECT SINGLE * FROM EKKO WHERE EBELN EQ H_EBELN. IF SY-SUBRC NE 0. MESSAGE E751 WITH H_EBELN. ENDIF. EDIDC-SNDPRT = 'MM'. EDIDC-SNDPRN = EKKO-EKORG. * read data of supplier (book keeping view) SELECT SINGLE * FROM LFB1 WHERE LIFNR = EKKO-LIFNR AND BUKRS = EKKO-BUKRS. * fill purchasing organization IF LFB1-EIKTO EQ SPACE. LFB1-EIKTO = EKKO-EKORG. ENDIF. * read position data SELECT * FROM EKPO WHERE EBELN = EKKO-EBELN. MOVE-CORRESPONDING EKPO TO XEKPO. APPEND XEKPO. ENDSELECT. * read schedule lines SELECT * FROM EKET WHERE EBELN = EKKO-EBELN. ENDSELECT. ENDFORM. " ORDERS_READ FORM IDOC_TABLE_FILL. * header data PERFORM HEADER_E1HEAD_FILL. * data in position PERFORM POSITION_E1ITEM_FILL. ENDFORM. " IDOC_TABLE_FILL FORM HEADER_E1HEAD_FILL. CLEAR INT_EDIDD. CLEAR E1HEAD. INT_EDIDD-SEGNAM = 'E1HEAD'. * fill fields * document number E1HEAD-BELNR = EKKO-EBELN. * Die folgenden Konstanten (Zuordnung Kunde/Lieferant zur * Verkaufsorganisation) werden nur in die Segmente geschrieben, damit * im Fallbeispiel die nachfolgende Eingangsverarbeitung im SD * funktioniert. Beim "reellen" Terminauftrag im SD Eingang pflegt man * hierzu Customizing-Tabellen, oder die Zuordnung wird vom * EDI-Subsystem übernommen. * sales organization (not supplied -> constant) E1HEAD-VKORG = '1000'. * distribution channel (not supplied -> constant) E1HEAD-VTWEG = '10'. * division (not supplied -> constant) E1HEAD-SPART = '00'. ENDSELECT. * order type E1HEAD-AUART = 'NB'. * date of delivery IF EKET-EINDT NE 0. E1HEAD-WLDAT = EKET-EINDT. ELSE. E1HEAD-WLDAT = SY-DATUM + 21. ENDIF. CONDENSE E1HEAD-WLDAT. * ordering party / sold to party (AG) E1HEAD-AUGEB = LFB1-EIKTO. * supplier E1HEAD-LIEF = EKKO-LIFNR. * order date E1HEAD-BSTDK = EKKO-BEDAT. CONDENSE E1HEAD-BSTDK. * order time E1HEAD-BELUZT = SY-UZEIT. * move data to segment area of data record MOVE E1HEAD TO INT_EDIDD-SDATA. * append data record to internal table APPEND INT_EDIDD. * customer function in order to change header segment CALL CUSTOMER-FUNCTION '001' EXPORTING PI_EKKO = EKKO IMPORTING PE_EKKO = EKKO TABLES PT_IDOC_DATA_RECORDS = INT_EDIDD. ENDFORM. " HEADER_E1HEAD_FILL FORM POSITION_E1ITEM_FILL. * loop at positions LOOP AT XEKPO. CLEAR INT_EDIDD. CLEAR E1ITEM. INT_EDIDD-SEGNAM = 'E1ITEM'. MOVE XEKPO TO EKPO. * fill fields * position number E1ITEM-POSEX = EKPO-EBELP. CONDENSE E1ITEM-POSEX. * material number IF EKPO-MATNR NE SPACE. E1ITEM-MATNR = EKPO-MATNR. ENDIF. * amount E1ITEM-MENGE = EKPO-MENGE. CONDENSE E1ITEM-MENGE. * unit PERFORM ISO_CODE_UNIT USING EKPO-MEINS. E1ITEM-BMEINH = EKPO-MEINS. * material number of supplier IF EKPO-IDNLF NE SPACE. E1ITEM-LMATNR = EKPO-IDNLF. ENDIF. * move data to segment area of data record MOVE E1ITEM TO INT_EDIDD-SDATA. * append data record to internal table APPEND INT_EDIDD. * customer function for position segment CALL CUSTOMER-FUNCTION '002' EXPORTING PI_EKPO = EKPO IMPORTING PE_EKPO = EKPO TABLES PT_IDOC_DATA_RECORDS = INT_EDIDD. ENDFORM. " HEADER_E1HEAD_FILL ENDLOOP. ENDFORM. " POSITION_E1ITEM_FILL FORM ISO_CODE_UNIT USING ICU_UNIT. CHECK ICU_UNIT NE SPACE. CALL FUNCTION 'UNIT_OF_MEASURE_SAP_TO_ISO' EXPORTING SAP_CODE = ICU_UNIT IMPORTING ISO_CODE = ISO_UNIT EXCEPTIONS NOT_FOUND = 01 NO_ISO_CODE = 02. IF SY-SUBRC NE 0. MESSAGE I764 WITH EKPO-EBELP ICU_UNIT. ENDIF. MOVE ISO_UNIT TO ICU_UNIT. ENDFORM. " ISO_CODE_UNIT
The HLEVEL field (hierarchy level of segment) in the administration section is not filled. This is carried out by the IDoc interface, which receives this value from the definition of the IDoc type TESTER01.
You should also note that the segment in the INT_EDIDD-SEGNAM field must be written in upper case letters. Otherwise, the IDoc interface will return a syntax error.
Global Data from IDOC_OUTPUT_TESTER
*- Tabellen ------------------------------------------------------* TABLES: EKPO, EKET, LFB1, EDIDC, E1HEAD, E1ITEM, T000, EDSDC. * help fields DATA: H_EBELN LIKE EKKO-EBELN, H_KAPPL LIKE NAST-KAPPL, H_PARVW LIKE EKPA-PARVW. * iso codes DATA: ISO_UNIT LIKE T006-ISOCODE. TYPE-POOLS ISOC. *- Direktwerte für Return_variables --------------------------------- DATA: EID LIKE BDWFRETVAR-WF_PARAM VALUE 'Error_IDOCs', PID LIKE BDWFRETVAR-WF_PARAM VALUE 'Processed_IDOCs', APO LIKE BDWFRETVAR-WF_PARAM VALUE 'Appl_Objects', APE LIKE BDWFRETVAR-WF_PARAM VALUE 'Appl_Object'. *- Hilfsfelder für Änderungsbeleg ----------------------------------* INCLUDE FM06ECDT. *- Common-Part für Änderungsbeleg ----------------------------------* INCLUDE FM06LCCD. *- Direktwerte -----------------------------------------------------* INCLUDE FMMEXDIR.