Updating IDoc data in segments (By Kevin Wilson) STEP 1 - Open document to edit CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT' EXPORTING document_number = t_docnum IMPORTING idoc_control = itab_edidc TABLES idoc_data = itab_edidd EXCEPTIONS document_foreign_lock = 1 document_not_exist = 2 document_not_open = 3 status_is_unable_for_changing = 4 OTHERS = 5. STEP 2 - Loop at itab_edidd and change data LOOP AT itab_edidd WHERE segnam = 'E1EDKA1'. e1edka1 = itab_edidd-sdata. IF e1edka1-parvw = 'LF'. e1edka1-partn = t_eikto. itab_edidd-sdata = e1edka1. MODIFY itab_edidd. EXIT. ENDIF. ENDLOOP. STEP 3 - Change data segments CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS' TABLES idoc_changed_data_range = itab_edidd EXCEPTIONS idoc_not_open = 1 data_record_not_exist = 2 OTHERS = 3. STEP 3a - Change control record CALL FUNCTION 'EDI_CHANGE_CONTROL_RECORD' EXPORTING idoc_changed_control = itab_edidc EXCEPTIONS idoc_not_open = 1 direction_change_not_allowed = 2 OTHERS = 3. STEP 4 - Close Idoc * Update IDoc status CLEAR t_itab_edids40. t_itab_edids40-docnum = t_docnum. t_itab_edids40-status = '51'. t_itab_edids40-repid = sy-repid. t_itab_edids40-tabnam = 'EDI_DS'. t_itab_edids40-mandt = sy-mandt. t_itab_edids40-stamqu = 'SAP'. t_itab_edids40-stamid = 'B1'. t_itab_edids40-stamno = '999'. t_itab_edids40-stapa1 = 'Sold to changed to '. t_itab_edids40-stapa2 = t_new_kunnr. t_itab_edids40-logdat = sy-datum. t_itab_edids40-logtim = sy-uzeit. APPEND t_itab_edids40. CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT' EXPORTING document_number = t_docnum do_commit = 'X' do_update = 'X' write_all_status = 'X' TABLES status_records = t_itab_edids40 EXCEPTIONS idoc_not_open = 1 db_error = 2 OTHERS = 3. Getting IDocs linked to Application documents (By Kevin Wilson) REFRESH: t_roles. * VBRK = Invoice * LIKP = Delivery * BUS2032 = Sales Order * BUS2035 = Scheduling Agreement * objkey - Application document number appended with line if applicable t_object-objkey = itab_data-objky. t_object-objtype = 'VBRK'. CALL FUNCTION 'SREL_GET_NEXT_RELATIONS' EXPORTING object = t_object TABLES roles = t_roles EXCEPTIONS internal_error = 1 no_logsys = 2 OTHERS = 3.
LOOP AT t_roles WHERE objtype = 'IDOC'. t_idoc_docnum = t_roles-objkey. ENDLOOP. Displaying and IDoc in a reportAT LINE-SELECTION. GET CURSOR FIELD field_name. CASE field_name. WHEN 'ITAB_DATA-DOCNUM'. "IDoc number CALL FUNCTION 'EDI_DOCUMENT_DATA_DISPLAY' EXPORTING docnum = itab_data2-docnum EXCEPTIONS no_data_record_found = 1 OTHERS = 2. Read IDoc from Database (By Kevin Wilson) *** Read the IDoc detail from the database CALL FUNCTION 'IDOC_READ_COMPLETELY' EXPORTING document_number = p_docnum IMPORTING idoc_control = s_edidc TABLES int_edidd = itab_edidd EXCEPTIONS document_not_exist = 1 document_number_invalid = 2 OTHERS = 3. Creating and sending an IDoc (By Kevin Wilson) *** STEP 1 - Create IDoc internal table entries *** STEP 2 - Call the function to distribute the IDoc CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING master_idoc_control = s_edidc obj_type = 'BUS2032' TABLES communication_idoc_control = itab_edidc master_idoc_data = itab_edidd EXCEPTIONS error_in_idoc_control = 1 error_writing_idoc_status = 2 error_in_idoc_data = 3 sending_logical_system_unknown = 4 OTHERS = 5. *** STEP 3 - Update IDoc status - If you wish to send additional status messages through REFRESH: itab_edids. itab_edids-status = c_idoc_status_ok. itab_edids-msgty = c_info_msg. itab_edids-msgid = c_msgid. itab_edids-msgno = c_msgno. itab_edids-msgv1 = itab_edidc-docnum. itab_edids-msgv2 = s_edidc-sndprn. *** Call the function to update the ORDCHG IDoc status CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE' EXPORTING idoc_number = s_edidc-docnum TABLES idoc_status = itab_edids EXCEPTIONS idoc_foreign_lock = 1 idoc_not_found = 2 idoc_status_records_empty = 3 idoc_status_invalid = 4 db_error = 5 OTHERS = 6. ALE Inbound Pre-Processing (By Kevin Wilson) Sometimes it's necessary to change an Idoc before it is processed. One way to achieve this is to call a function module that updates the IDoc tables before calling the appropriate function module. Note that the function module below can be replaced with EDI_DATA_INCOMING if you are using the EDI File Port method to load IDocs to SAP. FUNCTION Z_IDOC_INBOUND_ASYNCHRONOUS. *"---------------------------------------------------------------------- *"*"Local interface: *" TABLES *" IDOC_CONTROL_REC_40 STRUCTURE EDI_DC40 *" IDOC_DATA_REC_40 STRUCTURE EDI_DD40 *"---------------------------------------------------------------------- data e1edp16 type e1edp16. loop at idoc_control_rec_40 where mestyp = 'DELINS'. loop at IDOC_DATA_REC_40 where docnum = idoc_control_rec_40-docnum and segnam = 'E1EDP16'. move IDOC_DATA_REC_40-sdata to e1edp16. IF not E1EDP16-PRGRS CA 'DWMI'. delete IDOC_DATA_REC_40. ENDIF. endloop. endloop. CALL FUNCTION 'IDOC_INBOUND_ASYNCHRONOUS' TABLES idoc_control_rec_40 = IDOC_CONTROL_REC_40 idoc_data_rec_40 = IDOC_DATA_REC_40. ENDFUNCTION. |