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

BAPI_GOODSMVT_CREATE

VenuAnumayam
Participant
0 Likes
1,623

Hello,

I am using "BAPI_GOODSMVT_CREATE" to post 344 Movement Type. When I am running the program(foreground), sometimes it is running successfully and sometimes it is giving errors saying Material XXXXX is currently blocked. When I run this program in debug mode to see what is happening, it is running successfully. Following is my code. Anybody please let me know if there is an issue.

Thanks Much.

loop at 344_data.

    refresh: i_item, i_return.
    clear: i_header, i_headret, i_item, i_return.

*--- Start Transaction
    CALL FUNCTION 'TRANSACTION_BEGIN'
         IMPORTING
              TRANSACTION_ID = l_tid.

*--- Set up document header data.
    i_header-pstng_date = sy-datum.
    i_header-doc_date   = sy-datum.
    i_header-pr_uname   = sy-uname.

*--- Set up document item data.
    i_item-move_type  = '344'.                 "Movement Type
    i_item-plant      = 344_data-werks.        "Plant
    i_item-material   = 344_data-matnr.        "Material
    i_item-entry_qnt  = 344_data-clabs.        "Quantity
    i_item-batch      = 344_data-charg.        "Batch
    i_item-stge_loc   = 344_data-lgort.        "Storage Location
    append i_item.

*--- Transfer posting.
    call function 'BAPI_GOODSMVT_CREATE'
         EXPORTING
              goodsmvt_header  = i_header
              goodsmvt_code    = '04'          "MB1B Transaction
              testrun          = l_test
         IMPORTING
              goodsmvt_headret = i_headret
         TABLES
              goodsmvt_item    = i_item
              return           = i_return.

*--- End transaction.
    if i_return[] is initial.
      call function 'TRANSACTION_END'
           EXPORTING
                transaction_id = l_tid.

      call function 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
                wait = 'X'.
    else.
      call function 'TRANSACTION_ABORT'
           EXPORTING
                transaction_id = l_tid.

      add 1 to err_344.
      l_subrc = sy-subrc.
      read table i_return index 1.
      l_text = i_return-message.

      continue.

    endif.

    if sy-subrc = 0.
      add 1 to ok_344.
    else.
      add 1 to err_344.
      l_subrc = sy-subrc.
      read table i_return index 1.
      l_text = i_return-message.
    endif.

  endloop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,251

well if someone is changing an material MM02 or MM42 he is blocking this material.

NOONE else can maintain it at the same time, even not the BAPI. Nothing wrong with your code so far.

4 REPLIES 4
Read only

Former Member
0 Likes
1,252

well if someone is changing an material MM02 or MM42 he is blocking this material.

NOONE else can maintain it at the same time, even not the BAPI. Nothing wrong with your code so far.

Read only

0 Likes
1,251

If possible use WAIT statement in your code and try if it works for you.

Read only

0 Likes
1,251

Thanks for the responses. I have added "Commit Work and wait" statement. But I'm still seeing that error. Any idea?

Read only

0 Likes
1,251

I have modified the program to post goods movement at end of material and it worked.