Enterprise Resource Planning PortalERPGenie.COM Enterprise Resource Planning Portal

   Advertise | Founder BLOG

Web ERPGenie.COM  Other Search Options

Home | Vote for us |

ERPGenie.COM -> EDI -> ABAP related to IDocs

Quicklinks

Table of Contents

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 report

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)

*** 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.

API for IDoc processing

File interface

EDI_DATA_INCOMING

EDI_STATUS_INCOMING

RFC interface

IDOC_INBOUND_SYNCHRONOUS (3.x mode) single IDoc per call

INBOUND_IDOC_PROCESS (3.x mode) standard in tRFC, batch of IDocs allowed/recommended

IDOC_INBOUND_SINGLE (4.x mode) single IDoc per call

IDOC_INBOUND_ASYNCHRONOUS (4.x mode) standard in tRFC, batch of IDocs allowed/recommended

API for IDoc Types and Segment Definitions

A wide range of function modules is available for developing segments and IDoc types automatically. This programming interface (API) is also used by the IDoc type editor and the segment editor.

The API is subdivided into three function groups: the function modules which operate on segments are located in function group EDIJ, while those which operate on basic types and extensions are located in function group EDIM. The third function group contains RFC-compatible function modules which can be used from external developments. One example is the IDoc Class Library (the documentation is only available in English), which is written in C.

Function modules in the EDIJ group (segments)

Function modules in the EDIM group (basic types and extensions)

Function modules in the EDIMEXT group (API for external programs)

See also OSS note #212011.

IDOCTYPES_LIST_WITH_MESSAGES

Returns a list of all Basis types (IDoc types), Extensions (IDoc types) and all messages related with their respective IDoc types.

since release 4.0B, Hotpackage 48

IDOCTYPES_FOR_MESTYPE_READ

Reads all IDoc types assigned to a message type (logical message).

since release 4.0B, Hotpackge 42

IDOCTYPE_READ_COMPLETE

Reads the structure and attributes (segments), as well as the segment attributes (fields and fixed values), for an IDoc type. In this case, the version of the record types and segments must be sent to the function module.

since release 4.0B, Hotpackge 42

SEGMENT_READ_COMPLETE

Reads the structure and attributes for a segment. In this case, the version of the record types and the release for the segments must be sent to the function module.

since release 4.0B, Hotpackge 42

IDOC_RECORD_READ

Reads the structure of the record types for the specified version.

since release 4.0B, Hotpackge 42

 

Contact Us | Polls | Add URL | Contribute | About | Privacy | Terms | Feedback | Help!

Message Board | Discussion Forum | BLOG | Consultants: Post your resume | Companies: Advertise on ERPGenie.COM | Post Job
Genie Press | ERPTopSites | Financials Consultant | Consultant Review | Gallia Consulting | Supply Chain Project | SAP Financials Forum | WorkflowGenie