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_PRODORDCONF_CREATE_TT problem.

Former Member
0 Likes
2,128

Hi !!

BAPI_PRODORDCONF_CREATE_TT crates goods movements which are triggered in backround. When i use that bapi in loop i very often gets an COGI error - MAterial Plant data is blocked by user (for ingriediens). How to wait for finish of that background goods movemnts process ?? (i have tried erliaer with enque deque logic for it but it doesnt work ).

BR, Jacek.

Message was edited by: Jacek Slowikowski

.

Message was edited by: Jacek Slowikowski

7 REPLIES 7
Read only

Former Member
0 Likes
1,454

You will have to use the BAPI_TRANSACTION_COMMIT with wait set to X after BAPI_PRODORDCONF_CREATE_TT.

One more check you can add in the program is to check whether the object you are trying to update is locked using the function ENQUEUE_READ and introduce a wait if the object is locked.

See the sample code below

CALL FUNCTION 'ENQUEUE_READ'

EXPORTING

gclient = sy-mandt

gname = p_tablename

garg = p_tablekey

IMPORTING

number = p_number

subrc = p_subrc

TABLES

enq = pt_enq

EXCEPTIONS

communication_failure = 1

system_failure = 2

OTHERS = 3.

IF p_number GT 0.

WAIT UP TO 2 SECONDS.

ENDIF.

-Kiran

Please mark useful answers

Message was edited by: Kiran Raorane

Read only

Former Member
0 Likes
1,454

I do it that way. Commit is set with wait. And for all ingrediens i am trying to set enque and then deque...but still i have errors..

BR< Jacek

Read only

0 Likes
1,454

You don't need to set the lock explicitly in your program as the BAPI will take care of it. What I had suggested earlier is to check whether the object (Material in your scenario) is locked before the BAPI is called for processing the 2nd record in the loop.

Function ENQUEUE_READ will return the a value greater then 0 in the parameter NUMBER if the object is locked. If the object is locked you can introduce a WAIT of 2 seconds and then continue processing. You can also consider adding the above logic in a DO 2 TIMES - ENDDO loop.

-Kiran

*Please reward useful answers

Read only

0 Likes
1,454

what i am doing now.

LOOP AT lt_bapi2017_gm_item_create INTO

ls_bapi2017_gm_item_create . "wai until all ingrediens are dequeed.

GET RUN TIME FIELD t_1.

d_t = 0.

sy-subrc = 9.

WHILE d_t <= 600000000 AND sy-subrc <> 0.

CALL FUNCTION 'ENQUEUE_EMMARCE'

EXPORTING

mode_marc = 'E'

mandt = sy-mandt

matnr = ls_bapi2017_gm_item_create-material

werks = ls_bapi2017_gm_item_create-plant

  • X_MATNR = ' '

  • X_WERKS = ' '

_scope = '3'

wait = gcx

  • _COLLECT = ' '

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3

.

GET RUN TIME FIELD t_2.

d_t = t_2 - t_1.

ENDWHILE.

CALL FUNCTION 'DEQUEUE_EMMARCE'

EXPORTING

mode_marc = 'E'

mandt = sy-mandt

matnr = ls_bapi2017_gm_item_create-material

werks = ls_bapi2017_gm_item_create-plant

  • X_MATNR = ' '

  • X_WERKS = ' '

_scope = '3'

synchron = gcx.

  • _COLLECT = ' '

ENDLOOP.

CLEAR lt_bapi_coru_return[].

CALL FUNCTION 'BAPI_PRODORDCONF_CREATE_TT' "create order do material movements.

EXPORTING

post_wrong_entries = lv_post

testrun = lv_testrun

IMPORTING

return = ls_bapiret1

TABLES

timetickets = lt_bapi_pp_timeticket

goodsmovements = lt_bapi2017_gm_item_create

link_conf_goodsmov = lt_bapi_link_conf_goodsmov

detail_return = lt_bapi_coru_return.

IF lv_testrun IS INITIAL.

EXIT.

ELSE.

IF ls_bapiret1 IS INITIAL.

CLEAR lv_testrun.

ENDIF.

ENDIF.

IF ls_bapiret1 IS INITIAL. "commit work.

  • COMMIT WORK AND WAIT.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = gc_x.

  • Setup current confirmation number

READ TABLE lt_bapi_pp_timeticket ASSIGNING <bapi_tickets>

INDEX 1.

IF sy-subrc IS INITIAL.

e_confirmation-rueck_current = <bapi_tickets>-conf_no.

ENDIF.

ELSE.

e_subrc = 1.

ENDIF.

that code is processed in loop. Therericaly my logic of deques an enques should work similiar to enque_read ...

BR, JAcek

Message was edited by: Jacek Slowikowski

Read only

0 Likes
1,454

Hi Jacek,

Try this ..... it should resolve your problem.

Just before calling the BAPI put in this statement.

SET UPDATE TASK LOCAL.

The reason is when a BAPI is called mostly the data is updated in a separate update task. Which takes a few mins before the actuall update happens. Since you need to call the BAPI in a loop using the above statement will solve ur issue.

http://help.sap.com/saphelp_nw2004s/helpdata/en/41/7af4d7a79e11d1950f0000e82de14a/frameset.htm

Cheers

VJ

If it helps dont forget to mark points.

Read only

0 Likes
1,454

i have tried that. Problem is that update of matertial movements is still triggered not locally. so set update task local is no soution.

Message was edited by: Jacek Slowikowski

Read only

0 Likes
1,454

Hi,

The only other option is use the DEQUEUE_ALL

Try DEQUEUEing after the commit. Here is a sample coding.


* 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.
 
if not gm_retmtd is initial.
  commit work and wait.
  call function 'DEQUEUE_ALL'.
  write:/ gm_retmtd.
else.
  commit work and wait.
  call function 'DEQUEUE_ALL'.
endif.

The above works in most of the cases but not a recommended way to do it.

Cheers

VJ