Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom IDOC

Former Member
0 Kudos

Hi Experts,

while creating custom IDOC we need to create a FM i.e., (Posting program) which is used to fetch the data from IDOC and post the data into DB.

there we need to call 3 FM's

'EDI_DOCUMENT_OPEN_FOR_EDIT'

'EDI_CHANGE_DATA_SEGMENTS'

'EDI_DOCUMENT_CLOSE_EDIT'

plz explain why these FM are required and wht each does????

pts will b rewarded for correct answers

Regards

Faisal.

1 ACCEPTED SOLUTION

ak_upadhyay
Contributor
0 Kudos

Hi,

EDI_DOCUMENT_OPEN_FOR_EDIT (unlocks the idoc for editing)

EDI_CHANGE_DATA_SEGMENT (writes any changes to the idoc segment)

EDI_DOCUMENT_CLOSE_EDIT (closes the idoc to editing)


Updating IDoc data in segments 
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.


Reward points if useful....

Regards

AK

3 REPLIES 3

Former Member
0 Kudos

Hi,

1.For the writing of code .

STEP 1 - Open document to edit with the function 'EDI_DOCUMENT_OPEN_FOR_EDIT' .

STEP2 - Change data segments with the function 'EDI_CHANGE_DATA_SEGMENTS' .

STEP 3 - Change control record with the function 'EDI_CHANGE_CONTROL_RECORD' .

STEP 4 - Close Idoc with the function

'EDI_DOCUMENT_CLOSE_EDIT' .

Regards,

If helpful reward with points(Don't forget).

ak_upadhyay
Contributor
0 Kudos

Hi,

EDI_DOCUMENT_OPEN_FOR_EDIT (unlocks the idoc for editing)

EDI_CHANGE_DATA_SEGMENT (writes any changes to the idoc segment)

EDI_DOCUMENT_CLOSE_EDIT (closes the idoc to editing)


Updating IDoc data in segments 
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.


Reward points if useful....

Regards

AK

Former Member
0 Kudos

Hi,

read the IDOC data using the FM IDOC_READ_COMPLETELY, and find the errors

then now modify the IDoc using

EDI_DOCUMENT_OPEN_FOR_EDIT "open idoc

EDI_CHANGE_DATA_SEGMENTS "change the data

EDI_DOCUMENT_CLOSE_EDIT "close the IDOC

now change the status of the IDoc

The example codes can be found in website

http://www.sapgenie.com/sapedi/idoc_abap.htm

Regards

Kiran Sure