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: 

BAPI_GOODSMVT_CREATE error - Duplicate Transfer Posting

Former Member

Hello,

I'm using BAPI_GOODSMVT_CREATE for transfer posting with GM Code 04 and Movement Type 311.

But the posted material document is incorrect. Instead of 2 lines only, the line items becomes 4.

Could anyone please help me?

Thanks in advance!

5 REPLIES 5

sjeevan
Active Contributor
0 Kudos

What did you expect?

MB03 (table MSEG) will have 2X the number of lines.

One line for issuing storage location with - sign.

One line for receiving storage location with + sign.

Former Member
0 Kudos

Thanks Jeevan!

Former Member
0 Kudos

Hi Gold Yap,

I have done the Transfer posting by using BAPI_GOODSMVT_CREATE.

Below i added my sample code. Please go through.

Report XYZ.

TABLES : mslb , mchb .

DATA : BEGIN OF i_stock OCCURS 0 ,

matnr LIKE mslb-matnr ,

werks LIKE mslb-werks ,

charg LIKE mslb-charg ,

sobkz LIKE mslb-sobkz,

lifnr LIKE mslb-lifnr ,

lblab LIKE mslb-lblab ,

END OF i_stock .

DATA : BEGIN OF i_batch OCCURS 0 ,

matnr LIKE mchb-matnr ,

werks LIKE mchb-werks ,

lgort LIKE mchb-lgort ,

charg LIKE mchb-charg ,

clabs LIKE mchb-clabs ,

END OF i_batch .

DATA: BEGIN OF it_mess OCCURS 10,

charg LIKE mslb-charg ,

lgort LIKE mchb-lgort,

lifnr LIKE mslb-lifnr,

err LIKE bapiret2-message,

flag,

END OF it_mess.

DATA match.

DATA : header LIKE bapi2017_gm_head_01 . "OCCURS 0 WITH HEADER LINE .

DATA : code LIKE bapi2017_gm_code . " OCCURS 0 WITH HEADER LINE .

DATA : item LIKE bapi2017_gm_item_create OCCURS 0 WITH HEADER LINE.

DATA : i_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE .

DATA : matdoc LIKE bapi2017_gm_head_ret .

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME .

SELECT-OPTIONS : s_matnr FOR mslb-matnr .

PARAMETERS : p_werks LIKE mslb-werks DEFAULT 'TPFB' .

SELECTION-SCREEN END OF BLOCK b1 .

AT SELECTION-SCREEN OUTPUT .

LOOP AT SCREEN .

IF screen-name = 'P_WERKS' .

screen-input = '0' .

MODIFY SCREEN .

CLEAR screen .

ENDIF.

ENDLOOP .

START-OF-SELECTION .

CLEAR: i_stock[],i_stock.

CLEAR: it_mess[],it_mess.

CLEAR: i_batch[],i_batch.

SELECT matnr werks charg sobkz lifnr lblab

FROM mslb INTO TABLE i_stock

WHERE matnr IN s_matnr

AND werks = p_werks.

DELETE i_stock WHERE sobkz <> 'O'.

DELETE i_stock WHERE lblab <= '0.000'.

IF i_stock[] IS INITIAL .

MESSAGE 'NO Data Available In MSLB Table' TYPE 'S' .

ELSE.

DELETE i_stock WHERE charg = 'COMMON' .

IF i_stock[] IS INITIAL .

MESSAGE 'Already Transfer Posting to Common Batch' TYPE 'S' .

ENDIF.

ENDIF .

SELECT matnr werks lgort charg clabs

FROM mchb

INTO TABLE i_batch

WHERE matnr IN s_matnr

AND werks = p_werks .

DELETE i_batch WHERE clabs <= '0.000'.

IF i_batch[] IS INITIAL .

MESSAGE 'NO Data Available In MCHB Table' TYPE 'S' .

ELSE .

DELETE i_batch WHERE charg = 'COMMON' .

IF i_batch[] IS INITIAL .

MESSAGE 'Already Transfer Posting to Common Batch' TYPE 'S' .

ENDIF.

ENDIF .

CLEAR : header,code,matdoc .

header-pstng_date = sy-datum.

header-doc_date = sy-datum.

header-pr_uname = sy-uname.

header-header_txt = 'Transfer Posting'.

code-gm_code = '04'.

SORT i_batch BY matnr werks charg.

LOOP AT i_batch.

CLEAR: item[],item.

item-material = i_batch-matnr.

item-plant = i_batch-werks.

item-batch = i_batch-charg.

item-entry_qnt = i_batch-clabs .

item-stge_loc = i_batch-lgort .

item-move_type = '309'.

item-move_batch = 'COMMON'.

APPEND item .

CLEAR item .

match = 'X'.

PERFORM bapi_run USING match.

ENDLOOP.

LOOP AT i_stock .

CLEAR: item[],item.

item-material = i_stock-matnr.

item-plant = i_stock-werks.

item-batch = i_stock-charg.

item-vendor = i_stock-lifnr .

item-entry_qnt = i_stock-lblab .

item-move_type = '309'.

item-spec_stock = 'O'.

item-move_batch = 'COMMON'.

APPEND item .

CLEAR item .

match = 'Y'.

PERFORM bapi_run USING match.

ENDLOOP.

IF i_stock[] IS NOT INITIAL OR i_batch[] IS NOT INITIAL .

IF it_mess[] IS INITIAL.

MESSAGE 'Transfer Posted Successfully' TYPE 'S' .

ELSE.

SORT it_mess BY charg err.

WRITE:/2 'Batch',11'Location',20'Vendor'.

LOOP AT it_mess.

AT NEW charg.

SKIP.

ENDAT.

IF it_mess-flag = 'X'.

WRITE: /2 it_mess-charg COLOR 6, it_mess-lgort COLOR 3

INTENSIFIED OFF,it_mess-lifnr COLOR 2 INTENSIFIED OFF.

ENDIF.

WRITE: /10 it_mess-err.

ENDLOOP.

ENDIF.

ENDIF .

&----


*& Form bapi_run

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM bapi_run USING match .

CLEAR: i_return[],i_return.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

goodsmvt_header = header

goodsmvt_code = code

TABLES

goodsmvt_item = item

return = i_return.

IF i_return[] IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSEIF i_return[] IS NOT INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

LOOP AT i_return WHERE type = 'E'.

it_mess-charg = i_stock-charg.

IF match = 'X'.

it_mess-lgort = i_batch-lgort.

ELSEIF match = 'Y'.

it_mess-lifnr = i_stock-lifnr.

ENDIF.

it_mess-err = i_return-message.

IF sy-tabix = 1.

it_mess-flag = 'X'.

ENDIF.

APPEND it_mess.

CLEAR it_mess.

ENDLOOP.

ENDIF.

ENDFORM. " bapi_run

Regards,

S.C.K

Former Member
0 Kudos

Hi Miss Goldiebells,

Please see this link:

GR Posting for each line item of Purchase order using a BAPI

viva_kd
Explorer
0 Kudos

if anyboday got solution to the problem raised.. plz send me answer.. we are facing same.

First we r doing 301 Posting then 412 Posting. so for 301 its posting with 4 Item.