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'

Former Member
0 Likes
920

hi,

how can i get the no. of goods successfully posted. and the no. of failed goods movement.

Even though there are numerous postings on the BAPI itself but I could not find something relevant to this issue.

here is my code.

data: rno type rkpf-rsnum,

itno type rkpf-kdpos.

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module USER_COMMAND_0100 input.

if sy-ucomm = 'F4'.

perform check_screen_0100.

elseif sy-ucomm = 'F2'.

clear rno.

clear itno.

elseif sy-ucomm = 'F3'.

exit.

endif.

endmodule. " USER_COMMAND_0100 INPUT

&----


*& Form check_screen_0100

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form check_screen_0100 .

select rsnum kdpos from rkpf into (rno,itno) where rsnum = rno and

kdpos = itno.

endselect.

if sy-subrc ne 0.

CALL FUNCTION 'CALL_MESSAGE_SCREEN'

EXPORTING

I_MSGID = 'ZDHRUV'

i_lang = 'E'

i_msgno = '001'

  • I_MSGV1 =

  • I_MSGV2 =

  • I_MSGV3 =

  • I_MSGV4 =

  • I_SEPERATE = ' '

  • I_CONDENSE = ' '

  • I_MESSAGE_SCREEN = '0999'

  • I_LINE_SIZE = 0

  • I_LINES = 0

I_NON_LMOB_ENVT = 'X'

  • I_MODPL =

  • IMPORTING

  • O_ANSWER =

  • TABLES

  • T_MSG_TEXT =

  • EXCEPTIONS

  • INVALID_MESSAGE1 = 1

  • OTHERS = 2

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

else.

types: begin of mblb,

rsnum like rkpf-rsnum,

kdpos like rkpf-kdpos,

kdauf like rkpf-kdauf,

end of mblb.

data: it_mblb type standard table of mblb,

wa_mblb type mblb.

move rno to wa_mblb-rsnum.

move itno to wa_mblb-kdpos.

append wa_mblb to it_mblb.

data : goodsmvt_header type bapi2017_gm_head_01 .

data : goodsmvt_code type bapi2017_gm_code .

*data : it_headret type bapi2017_gm_head_ret.

*data : materialdocument type bapi2017_gm_head_ret-mat_doc .

*data : matdocumentyear type bapi2017_gm_head_ret-doc_year .

data : goodsmvt_item type table of bapi2017_gm_item_create .

data : gw_goodsmvt_item type bapi2017_gm_item_create .

data : return type table of bapiret2 .

data : gw_return type bapiret2 .

*Fill Header Data

goodsmvt_header-pstng_date = sy-datum .

goodsmvt_header-doc_date = sy-datum .

*Fill Movement Code This you have to fill as per you requirement

goodsmvt_code = '04' .

loop at it_mblb into wa_mblb.

if wa_mblb-kdauf is not initial.

*select rsnum kdpos from rkpf into table goodsmvt_item.

move wa_mblb-rsnum to gw_goodsmvt_item-reserv_no.

move wa_mblb-kdpos to gw_goodsmvt_item-s_ord_item.

  • CHECK SY-SUBRC EQ 0.

gw_goodsmvt_item-MOVE_TYPE = '311+E'.

gw_goodsmvt_item-mvt_ind = ' '.

append gw_goodsmvt_item to goodsmvt_item.

*endif.

else.

select rsnum kdpos from rkpf into table goodsmvt_item.

CHECK SY-SUBRC EQ 0.

gw_goodsmvt_item-MOVE_TYPE = '311'.

gw_goodsmvt_item-mvt_ind = ' '.

append gw_goodsmvt_item to goodsmvt_item.

endif.

endloop.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = goodsmvt_header

GOODSMVT_CODE = goodsmvt_code

  • TESTRUN = ' '

  • GOODSMVT_REF_EWM =

  • IMPORTING

  • GOODSMVT_HEADRET = it_headret

  • MATERIALDOCUMENT = materialdocument

  • MATDOCUMENTYEAR = matdocumentyear

TABLES

GOODSMVT_ITEM = goodsmvt_item

  • GOODSMVT_SERIALNUMBER =

RETURN = return

  • GOODSMVT_SERV_PART_DATA =

  • EXTENSIONIN =

.

*if sy-subrc = 0.

*CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT = 'X'

  • IMPORTING

  • RETURN =

  • .

*endif.

LOOP AT return into gw_return.

WRITE:/ gw_return-type, gw_return-id, gw_return-number,

gw_return-message.

ENDLOOP.

endif.

endform. " check_screen_0100

5 REPLIES 5
Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
784

hi,

in loop ....endloop set a counter. And find out the number of records in return table by using DESCRIBE

statement.

For Example:

Data : counter type i,
          lin type i,
          gud_rec type i.

Loop at <IT> into <wa>.

counter = counter + 1.

endloop.


describe table return lines lin.

gud_rec = counter - lin.   "-----> these are the no of records which are posted

Thanks & Regards

Read only

Former Member
0 Likes
784

Hello Friend,

Previous answer is correct.

I want to add some points;

RETURN table conatins the no lines which has error.

So when you are counting number of lines for the table which you are passing to 'BAPI_GOODSMVT_CREATE'.

So the subtraction is the numbe of lines which are successful.

Hope it will help you.

Regards

Krishnendu

Read only

Former Member
Read only

Former Member
0 Likes
784

thanks for your suggestions,

in which loop .... endloop we should write counter statement.

Read only

Former Member
0 Likes
784

hi,

i wrote the code, but my problem is when i entered the reservation no. i am not getting

the no. of goodsmovements posted. it simply showing blank.

here is the code. could anyone find the error in it.

data: rno type rkpf-rsnum,

itno type rkpf-kdpos,

matno type string, "no of goodsmovement posted.

counter type i,

lin type i,

gud_rec type i.

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

if sy-ucomm = 'F4'.

perform check_screen_0100.

elseif sy-ucomm = 'F2'.

clear rno.

clear itno.

elseif sy-ucomm = 'F3'.

exit.

endif.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Form check_screen_0100

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM check_screen_0100 .

select rsnum kdpos from rkpf into (rno,itno) where rsnum = rno and

kdpos = itno.

endselect.

if sy-subrc ne 0.

CALL FUNCTION 'CALL_MESSAGE_SCREEN'

EXPORTING

I_MSGID = 'ZDHRUV'

I_LANG ='E'

I_MSGNO = '001'

  • I_MSGV1 =

  • I_MSGV2 =

  • I_MSGV3 =

  • I_MSGV4 =

  • I_SEPERATE = ' '

  • I_CONDENSE = ' '

  • I_MESSAGE_SCREEN = '0999'

  • I_LINE_SIZE = 0

  • I_LINES = 0

  • I_NON_LMOB_ENVT =

  • I_MODPL =

  • IMPORTING

  • O_ANSWER =

  • TABLES

  • T_MSG_TEXT =

  • EXCEPTIONS

  • INVALID_MESSAGE1 = 1

  • OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

else.

types: begin of mblb,

rsnum like rkpf-rsnum,

kdpos like rkpf-kdpos,

kdauf like rkpf-kdauf,

end of mblb.

data: it_mblb type standard table of mblb,

wa_mblb type mblb.

move rno to wa_mblb-rsnum.

move itno to wa_mblb-kdpos.

append wa_mblb to it_mblb.

DATA :

WA_goodsmvt_header TYPE bapi2017_gm_head_01,

wa_goodsmvt_code type bapi2017_gm_code,

it_goodsmvt_item type standard table of bapi2017_gm_item_create,

wa_goodsmvt_item type bapi2017_gm_item_create,

it_return type standard table of bapiret2,

wa_return type bapiret2.

*

  • Fill Header Data

wa_goodsmvt_header-pstng_date = sy-datum.

wa_goodsmvt_header-doc_date = sy-datum.

*Fill Movement Code This you have to fill as per you requirement

wa_goodsmvt_code = '04'.

loop at it_mblb into wa_mblb.

if wa_mblb-kdauf is initial.

move wa_mblb-rsnum to wa_goodsmvt_item-reserv_no.

move wa_mblb-kdpos to wa_goodsmvt_item-s_ord_item.

wa_goodsmvt_item-MOVE_TYPE = '311'.

wa_goodsmvt_item-mvt_ind = ' '.

append wa_goodsmvt_item to it_goodsmvt_item.

endif.

counter = counter + 1.

endloop.

REFRESH: it_return.

CLEAR it_return.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

GOODSMVT_HEADER = wa_goodsmvt_header

GOODSMVT_CODE = wa_goodsmvt_code

  • TESTRUN = ' '

  • GOODSMVT_REF_EWM =

  • IMPORTING

  • GOODSMVT_HEADRET =

  • MATERIALDOCUMENT = matdoc

  • MATDOCUMENTYEAR =

TABLES

GOODSMVT_ITEM = it_goodsmvt_item

  • GOODSMVT_SERIALNUMBER =

RETURN = it_return

  • GOODSMVT_SERV_PART_DATA =

  • EXTENSIONIN =

.

describe table it_return lines lin.

gud_rec = counter - lin. "-----> these are the no of records which are posted

call screen 200.

endif.

ENDFORM. " check_screen_0100

&----


*& Module STATUS_0200 OUTPUT

&----


  • text

----


MODULE STATUS_0200 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

matno = gud_rec.

ENDMODULE. " STATUS_0200 OUTPUT