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: 

Goods Receipts for Purchase Order using BAPI_GOODSMVT_CREAT

Former Member
0 Kudos

Hi experts,

I am working on the a program where am generating Goods Receipts for Purchase Order. the BAPI_GOODSMVT_CREAT returns an error saying "Material 6003022 not maintained in plant 1001"

Can any one assist? is there a field I may be missing?

Here is a sample code.

DATA: gm_header TYPE bapi2017_gm_head_01.

DATA: gm_code TYPE bapi2017_gm_code.

DATA: gm_headret TYPE bapi2017_gm_head_ret.

DATA: gm_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.

DATA: gm_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: gm_retmtd TYPE bapi2017_gm_head_ret-mat_doc.

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 = '02'.

" MB1A * Write 971 movement to table CLEAR GM_ITEM.

MOVE '101' TO gm_item-move_type .

" MOVE 'Q' TO GM_ITEM-SPEC_STOCK.

MOVE '6003022' TO gm_item-material.

MOVE '10' TO gm_item-entry_qnt.

MOVE 'EA' TO gm_item-entry_uom.

MOVE '1001' TO gm_item-plant.

MOVE '' TO gm_item-stge_loc.

MOVE '0901' TO gm_item-move_reas.

" MOVE '4500006877' TO GM_ITEM-WBS_ELEM.

" MOVE '0020' TO GM_ITEM-VAL_WBS_ELEM.

MOVE '0020' TO gm_item-deliv_numb.

MOVE '4500006881' TO gm_item-po_number.

MOVE '0010' TO gm_item-po_item.

APPEND 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.

IF NOT gm_retmtd IS INITIAL.

COMMIT WORK AND WAIT.

CALL FUNCTION 'DEQUEUE_ALL'.

ELSE.

COMMIT WORK AND WAIT.

CALL FUNCTION 'DEQUEUE_ALL'.

ENDIF.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

>

> Hi experts,

> I am working on the a program where am generating Goods Receipts for Purchase Order. the BAPI_GOODSMVT_CREAT returns an error saying "Material 6003022 not maintained in plant 1001"

> Can any one assist? is there a field I may be missing?

>

> Here is a sample code.

>

> DATA: gm_header TYPE bapi2017_gm_head_01.

> DATA: gm_code TYPE bapi2017_gm_code.

> DATA: gm_headret TYPE bapi2017_gm_head_ret.

> DATA: gm_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.

> DATA: gm_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

> DATA: gm_retmtd TYPE bapi2017_gm_head_ret-mat_doc.

> 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 = '02'.

>

>

> " MB1A * Write 971 movement to table CLEAR GM_ITEM.

> MOVE '101' TO gm_item-move_type .

> " MOVE 'Q' TO GM_ITEM-SPEC_STOCK.

> MOVE '6003022' TO gm_item-material.

> MOVE '10' TO gm_item-entry_qnt.

> MOVE 'EA' TO gm_item-entry_uom.

> MOVE '1001' TO gm_item-plant.

> MOVE '' TO gm_item-stge_loc.

> MOVE '0901' TO gm_item-move_reas.

> " MOVE '4500006877' TO GM_ITEM-WBS_ELEM.

> " MOVE '0020' TO GM_ITEM-VAL_WBS_ELEM.

> MOVE '0020' TO gm_item-deliv_numb.

> MOVE '4500006881' TO gm_item-po_number.

> MOVE '0010' TO gm_item-po_item.

> APPEND 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.

>

> IF NOT gm_retmtd IS INITIAL.

>

> COMMIT WORK AND WAIT.

> CALL FUNCTION 'DEQUEUE_ALL'.

> ELSE.

> COMMIT WORK AND WAIT.

>

> CALL FUNCTION 'DEQUEUE_ALL'.

> ENDIF.

My guess, is that this material is not really maintained in the Plant '1001', to be on the safer side, get the exact values from EKPO itself, also check if this material exists in the table MARC for the plant and storage location.

MOVE '1001' TO gm_item-plant.   "<< Hard coded
MOVE '' TO gm_item-stge_loc.

Replace the above hardcodes to something like this to get the actual value from EKPO.

select werks lgort into (gm_item-plant, gm_item-stge_loc) from ekpo
   where ebeln = gm_item-po_number
        and ebelp = gm_item-po_item.

4 REPLIES 4

Former Member
0 Kudos

>

> Hi experts,

> I am working on the a program where am generating Goods Receipts for Purchase Order. the BAPI_GOODSMVT_CREAT returns an error saying "Material 6003022 not maintained in plant 1001"

> Can any one assist? is there a field I may be missing?

>

> Here is a sample code.

>

> DATA: gm_header TYPE bapi2017_gm_head_01.

> DATA: gm_code TYPE bapi2017_gm_code.

> DATA: gm_headret TYPE bapi2017_gm_head_ret.

> DATA: gm_item TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE.

> DATA: gm_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE.

> DATA: gm_retmtd TYPE bapi2017_gm_head_ret-mat_doc.

> 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 = '02'.

>

>

> " MB1A * Write 971 movement to table CLEAR GM_ITEM.

> MOVE '101' TO gm_item-move_type .

> " MOVE 'Q' TO GM_ITEM-SPEC_STOCK.

> MOVE '6003022' TO gm_item-material.

> MOVE '10' TO gm_item-entry_qnt.

> MOVE 'EA' TO gm_item-entry_uom.

> MOVE '1001' TO gm_item-plant.

> MOVE '' TO gm_item-stge_loc.

> MOVE '0901' TO gm_item-move_reas.

> " MOVE '4500006877' TO GM_ITEM-WBS_ELEM.

> " MOVE '0020' TO GM_ITEM-VAL_WBS_ELEM.

> MOVE '0020' TO gm_item-deliv_numb.

> MOVE '4500006881' TO gm_item-po_number.

> MOVE '0010' TO gm_item-po_item.

> APPEND 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.

>

> IF NOT gm_retmtd IS INITIAL.

>

> COMMIT WORK AND WAIT.

> CALL FUNCTION 'DEQUEUE_ALL'.

> ELSE.

> COMMIT WORK AND WAIT.

>

> CALL FUNCTION 'DEQUEUE_ALL'.

> ENDIF.

My guess, is that this material is not really maintained in the Plant '1001', to be on the safer side, get the exact values from EKPO itself, also check if this material exists in the table MARC for the plant and storage location.

MOVE '1001' TO gm_item-plant.   "<< Hard coded
MOVE '' TO gm_item-stge_loc.

Replace the above hardcodes to something like this to get the actual value from EKPO.

select werks lgort into (gm_item-plant, gm_item-stge_loc) from ekpo
   where ebeln = gm_item-po_number
        and ebelp = gm_item-po_item.

0 Kudos

Hi Ramesh,

ERROR

Update control of movement type is incorrect (entry 101 X X _ L)

This error message I get When this code executes:

SELECT ebeln ebelp bednr lgort werks matnr menge

INTO CORRESPONDING FIELDS OF TABLE i_tab

FROM ekpo

WHERE ebeln EQ 4500006881.

LOOP AT i_tab.

  • SELECT * FROM lips INTO lips

  • WHERE vbeln = p_vbeln.

***<<<<<<<<<<<BAPI Communication Structure: Material Document Header Data>>>>>>>

gt_goodsmvt_item-material = i_tab-matnr.

gt_goodsmvt_item-plant = i_tab-werks.

gt_goodsmvt_item-stge_loc = i_tab-lgort.

  • gt_goodsmvt_item-deliv_numb_to_search = lips-vbeln.

  • gt_goodsmvt_item-deliv_item_to_search = lips-posnr.

gt_goodsmvt_item-move_type = '101'.

gt_goodsmvt_item-entry_qnt = i_tab-menge.

gt_goodsmvt_item-entry_uom = 'EA'."lips-vrkme.

gt_goodsmvt_item-mvt_ind = 'L'.

gt_goodsmvt_item-po_number = i_tab-ebeln .

gt_goodsmvt_item-po_item = '0010'.

gt_goodsmvt_item-no_more_gr = 'X'.

APPEND gt_goodsmvt_item.

  • ENDSELECT.

goodsmvt_code_tmp = '01'. "Assign code to transaction for BAPI goods movement

****<<<<<<<Post goods movements with MB_CREATE_GOODS_MOVEMENT>>>>>>>>>>>>>>>>>>>

EXIT.

ENDLOOP.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

goodsmvt_header = gt_goodsmvt_header

goodsmvt_code = goodsmvt_code_tmp

  • testrun = testrun

IMPORTING

goodsmvt_headret = gt_goodsmvt_headret

TABLES

goodsmvt_item = gt_goodsmvt_item

  • GOODSMVT_SERIALNUMBER =

return = gt_return.

I Hard coded the PO num is the select to create a goods receipt for this specific PO.

What does the error mean?

0 Kudos
gt_goodsmvt_item-mvt_ind = 'L'.

The movement indicator is not maintained for 101. You can refer the table T156T to get the right one or ask someone from the function team to give you the correct customizing values.

0 Kudos

Hi Ramesh,

The value for that field ''gt_goodsmvt_item-mvt_ind'' is 'B'

A goods receipt is create even if it takes a while on the development system...