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 and BDC is working in only debug Mode?

Former Member
0 Likes
4,597

Hi Experts,

I am working on one Z report in that am using BDC for MB1B ( call Transaction method) for transferring  unrestricted to block stock  and Bapi (BAPI_GOODSMVT_CREATE) for (Batch to Batch stock transfer )

Both are  working fine in debug mode but while executing the transaction directly it is not working.

Please help me its an urgent requirement.

Thanks and Regards.,

Uma

Hi Experts,

I am working on one Z report in that am using BDC for MB1B ( call Transaction method) for transferring  unrestricted to block stock  and Bapi (BAPI_GOODSMVT_CREATE) for (Batch to Batch stock transfer )

Both are  working fine in debug mode but while executing the transaction directly it is not working.

Please help me its an urgent requirement.

Thanks and Regards.,

Uma

16 REPLIES 16
Read only

VijayaKrishnaG
Active Contributor
0 Likes
3,630

Hi Uma,

Have you used COMMIT WORK statement after BAPI?

If not use Commit work and also try WAIT UP TO 2 SECONDS (2 or 3 seconds) before COMMIT WORK.

Orelse you can also use Function module :: BAPI_TRANSACTION_COMMIT. (Also use Wait statement before calling this FM).

Hope this works,

Thanks & Regards,

- Vijay

Read only

0 Likes
3,630

Hi Vijaykrishna

Ya am using COMMIT WORK and BAPI_TRANSACTION_COMMIT  statement ...

If that is the case it should not work in debug mode also right?

Read only

0 Likes
3,630

Hi Uma,

I have experienced the same issue, that time myself realized that system need some time (maximum 1 or 2 seconds, some times fraction of seconds too) to update all the tables and commit its work. In the debugging obviously system gets time to update or commit by the time we press keys like F5 or F6 etc. So I used WAIT statement, then my issue solved .

You can also use SET UPDATE TASK LOCAL instead of BAPI_TRANSACTION_COMMIT after BAPI.

-Vijay

Read only

venkat_aileni
Contributor
0 Likes
3,630

Hi-

Both are working fine in debug mode means are you able to post material document? if so have you checked that material document in DB table MSEG?

After BAPI call just call this BAPI 'BAPI_TRANSACTION_COMMIT'.

Hope this helps!

-Venkat

Read only

0 Likes
3,630

Yes i can able to see the document which is generated in debug mode

Read only

0 Likes
3,630

Are you using BAPI commit?

Can you place your sample code written for BAPI?

Read only

0 Likes
3,630

Hi-

Try like this...

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

         EXPORTING

           goodsmvt_header  = lwa_goodsmvt_header

           goodsmvt_code    = lwa_goodsmvt_code

         IMPORTING

           goodsmvt_headret = lwa_goodsmvt_headret

           materialdocument = lwa_materialdocument

           matdocumentyear  = lwa_matdocumentyear

         TABLES

           goodsmvt_item    = i_goodsmvt_item

           return           = i_return.

       IF lwa_materialdocument IS NOT INITIAL.

*--BAPI commit

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            WAIT          = 'X'.

       ENDIF.

-Venkat

Read only

0 Likes
3,630

Hi Venakat,

Here is my code for BAPI

  clear: gm_return, gm_retmtd. refresh gm_return.

* Setup BAPI header data.

       gm_header-pstng_date = sy-datum.

       gm_header-doc_date   = sy-datum.

       gm_code-gm_code      = '04'.                                " MB1B

* Write 971 movement to table

       clear gm_item.

       gm_item-material = g_matnr.

       gm_item-plant = w_ztppi-werks.

       gm_item-stge_loc   = 'WP20'.

       gm_item-batch = w_ztppi-rcharg.

       gm_item-move_type  = '309'.

       move w_ztppi-rkwmeng to lv_qty.

       condense lv_qty.

       move lv_qty to gm_item-entry_qnt .

       gm_item-move_mat = g_matnr.

       gm_item-move_plant = w_ztppi-werks.

       gm_item-move_stloc = 'WP20'.

       gm_item-move_batch = w_ztppi-scharg.

       append gm_item to gm_item.

       clear gm_item.

*   Call goods movement BAPI

       call function 'BAPI_GOODSMVT_CREATE'

         exporting

           goodsmvt_header  = gm_header

           goodsmvt_code    = gm_code

         importing

           goodsmvt_headret = gm_headret

           materialdocument = gm_retmtd

         tables

           goodsmvt_item    = gm_item

           return           = gm_return.

       call function 'BAPI_TRANSACTION_COMMIT'

         exporting

           wait = 'X'.

       commit work.

Read only

0 Likes
3,630

May I know the difference between my code ur code?

Bcz am always getting material document no.in debug mode

Read only

0 Likes
3,630

Are you getting any entries in BAPI return table? If so then there might be data missing problem.

Else just check for material document number returned from BAPI.

Say:

lwa_materialdocument is not initial

Then call BAPI commit

-Venkat

Read only

0 Likes
3,630

Can you please put a screen shot of debugger when document number is generated along with contents of LT_RETURN table

Read only

0 Likes
3,630

Hi Madan,

Please check the below screen shot...

HI

Read only

0 Likes
3,630

What does GM_RETURN table has..? When you execute it completely are you able to see the document in MB03..?   Seconldy when you execute directly put a break piint after commit and check what does return have then

Read only

0 Likes
3,630

Hi-

If your BAPI posting was successful you would have got your return table without any entries, in your case return table is not initial hence there is some problem with the data you are passing. Check them.

In below screenshot I have successfully posted material document hence return table is initial.

Hope this helps!

-Venkat

Read only

0 Likes
3,630

Hi

Replace this Code with your existing code after BAPI Call .... ..

IF gm_retmtd IS INITIAL .

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    EXIT.

  ELSE.

  gm_return-TYPE = 'S'.

  gm_return-MESSAGE = gm_retmtd.

    APPEND gm_return .

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

      EXPORTING

        WAIT = 'X'.

  ENDIF.

Replace above code with your below code....

also check below notes:

Note 369518 - Transfer stock not reached if posted with BAPI

Note 520813 - FAQ: BAPIs for goods movements

Note 457499 - No material document generated for BAPI BAPI_GOODSMVT_CREATE

Regard's

Smruti

Read only

Former Member
0 Likes
3,630

Uma ,

WAIT UNTIL sy-subrc eq 0.

   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

     EXPORTING

       WAIT   = 'X'

     IMPORTING

       RETURN = RETURN.