Miscellanous Tips part 2

Getting IDocs linked to Application documents
Displaying and IDoc in a report
Read IDoc from Database
Creating and sending an IDoc
ALE Inbound Pre-Processing

 

 

 

Getting IDocs linked to Application documents

By Kevin Wilson - From ErpGenie.com 

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 report

By Kevin Wilson - From ErpGenie.com
AT 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 - From ErpGenie.com
*** 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 - From ErpGenie.com
*** 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 - From ErpGenie.com
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. 
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)