Application Development and Automation 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: 
Read only

Updating Idoc segment

Former Member
0 Likes
1,154

Hello Experts,

I am being able to update IDOC segments using the following FMs:

  • 'EDI_DOCUMENT_OPEN_FOR_EDIT'
  • 'EDI_CHANGE_DATA_SEGMENT'
  • 'EDI_DOCUMENT_CLOSE_EDIT'

The problem is that two IDOCs are being generated, one for the modified idoc (status 53) and one for the original (status 70).

I want only the modified IDOC being generated, is there any solutions? Below is my code:

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
       EXPORTING
         document_number               = idoc_docnum
      IMPORTING
        idoc_control                   = ls_edidc
       TABLES
         idoc_data                     = lt_idoc_data
      EXCEPTIONS
        document_foreign_lock          = 1
        document_not_exist             = 2
        document_not_open              = 3
        status_is_unable_for_changing  = 4
        OTHERS                         = 5              .


     IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.

     READ TABLE lt_idoc_data ASSIGNING <fs_data>
                             WITH KEY docnum = idoc_docnum
                                      segnam = c_e1fikpf
                             BINARY SEARCH.
     IF sy-subrc EQ 0.

       ls_e1fikpf = <fs_data>-sdata.

       IF ls_e1fikpf-bukrs IS INITIAL .
         ls_e1fikpf-bukrs = ls_e1fikpf-xref2_hd(3).
       ENDIF.

       <fs_data>-sdata = ls_e1fikpf.

       CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENT'
         EXPORTING
           idoc_changed_data_record = <fs_data>
         EXCEPTIONS
           idoc_not_open              = 1
           data_record_not_exist   = 2
           OTHERS                      = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.


       CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
         EXPORTING
          document_number        = idoc_docnum
          do_commit              = 'X'
        EXCEPTIONS
          idoc_not_open          = 1
          db_error               = 2
          OTHERS                 = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.

Hello Experts,

I am being able to update IDOC segments using the following FMs:

  • 'EDI_DOCUMENT_OPEN_FOR_EDIT'
  • 'EDI_CHANGE_DATA_SEGMENT'
  • 'EDI_DOCUMENT_CLOSE_EDIT'

The problem is that two IDOCs are being generated, one for the modified idoc (status 53) and one for the original (status 70).

I want only the modified IDOC being generated, is there any solutions? Below is my code:

CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
       EXPORTING
         document_number               = idoc_docnum
      IMPORTING
        idoc_control                   = ls_edidc
       TABLES
         idoc_data                     = lt_idoc_data
      EXCEPTIONS
        document_foreign_lock          = 1
        document_not_exist             = 2
        document_not_open              = 3
        status_is_unable_for_changing  = 4
        OTHERS                         = 5              .


     IF sy-subrc <> 0.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
     ENDIF.

     READ TABLE lt_idoc_data ASSIGNING <fs_data>
                             WITH KEY docnum = idoc_docnum
                                      segnam = c_e1fikpf
                             BINARY SEARCH.
     IF sy-subrc EQ 0.

       ls_e1fikpf = <fs_data>-sdata.

       IF ls_e1fikpf-bukrs IS INITIAL .
         ls_e1fikpf-bukrs = ls_e1fikpf-xref2_hd(3).
       ENDIF.

       <fs_data>-sdata = ls_e1fikpf.

       CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENT'
         EXPORTING
           idoc_changed_data_record = <fs_data>
         EXCEPTIONS
           idoc_not_open              = 1
           data_record_not_exist   = 2
           OTHERS                      = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.


       CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
         EXPORTING
          document_number        = idoc_docnum
          do_commit              = 'X'
        EXCEPTIONS
          idoc_not_open          = 1
          db_error               = 2
          OTHERS                 = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.

2 REPLIES 2
Read only

ThomasZloch
Active Contributor
0 Likes
862

This is standard behaviour, that you cannot - or at least should not - change. As you noted, the IDoc in status 70 contains the original data before modification, and this is supposed to be saved e.g. for auditing purposes.

Thomas

Read only