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: 

how to solve this problem "Document_foreign_lock "

Former Member
0 Kudos

On using this fn. mod. "EDI_DOCUMENT_OPEN_FOR_EDIT" to open the Idoc, I am getting the error like "Document foreign lock"

How to solve this problem ? Please Very Urgent requirement.

Thanks,

Vinayak

3 REPLIES 3

former_member188685
Active Contributor
0 Kudos

Hi,

that means either you are some body else opened the idoc for editing, that function module will lock the idoc when you are editing the idoc. it won't let others to modify the same at a time. i think you might be running the same program in some other window check it.

regards

vijay

0 Kudos
-- Opening the IDoc for Edit
    CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
      EXPORTING
        DOCUMENT_NUMBER               = X_EDIDC-DOCNUM
      TABLES
        IDOC_DATA                     = IT_EDIDD
      EXCEPTIONS
<b>        DOCUMENT_FOREIGN_LOCK         = 1</b>
        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.
*-- Editing the IDoc
    CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'
      TABLES
        IDOC_CHANGED_DATA_RANGE = LT_EDIDD
      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.
*-- Closing the IDoc after Edit
    CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
      EXPORTING
        DOCUMENT_NUMBER  = X_EDIDC-DOCNUM
        DO_COMMIT        = 'X'
        DO_UPDATE        = 'X'
        WRITE_ALL_STATUS = '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.

close the programs if any body is running for the same idoc. and check.

regards

vijay

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Vinayak!

Is this a problem with one IDOC or are you handling a big list and from time to time you run into this error?

In case it's a one time problem: look in SM12 who is locking your IDOC.

In case you are locking yourself: is it a performance issue (only from time to time) or everytime -> your process flow should be re-designed. In case of performance problems, try to set commit work <b>and wait</b> on the actions before opening the IDOC.

Give more input!

Regards,

Christian