‎2014 Oct 30 7:47 AM
Dear Experts,
I've made a coding by calling BAPI for goods movement with reference to the production order. The result of the program should be executed with the 101 movement type provided with the document no which i'm not able to generate the process.
Piece of coding is as below. Need help .
REPORT ZPP_MAT_EXT.
TABLES : EKKO.
TYPES : BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
END OF TY_EKKO.
TYPES : BEGIN OF TY_EKPO,
EBELN TYPE EBELN,
EBELP TYPE EBELP,
MATNR TYPE MATNR,
WERKS TYPE EWERK,
LGORT TYPE LGORT_D,
MENGE TYPE BSTMG,
MEINS TYPE BSTME,
END OF TY_EKPO.
TYPES : BEGIN OF TY_OUTPUT,
EBELN TYPE EBELN,
MBLNR TYPE MBLNR,
MJAHR TYPE MJAHR,
END OF TY_OUTPUT.
TYPES : BEGIN OF TY_FINAL,
EBELN TYPE EBELN,
EBELP TYPE EBELP,
MATNR TYPE MATNR,
WERKS TYPE EWERK,
LGORT TYPE LGORT_D,
MENGE TYPE BSTMG,
MEINS TYPE BSTME,
END OF TY_FINAL.
DATA : GT_EKKO TYPE TABLE OF TY_EKKO,
GS_EKKO TYPE TY_EKKO.
DATA : GT_EKPO TYPE TABLE OF TY_EKPO,
GS_EKPO TYPE TY_EKPO.
DATA : GT_FINAL TYPE TABLE OF TY_FINAL,
GS_FINAL TYPE TY_FINAL.
DATA : GT_OUTPUT TYPE TABLE OF TY_OUTPUT,
GS_OUTPUT TYPE TY_OUTPUT.
START-OF-SELECTION.
SELECT-OPTIONS : S_EBELN FOR EKKO-EBELN.
PERFORM GET_EKKO_DATA.
PERFORM GET_EKPO_DATA.
PERFORM POPULATE_DATA.
PERFORM CALL_BAPI.
"BAPI_GOODSMVT_CREATE
DATA : GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
GOODSMVT_CODE TYPE BAPI2017_GM_CODE.
DATA : GOODSMVT_HEADRET TYPE BAPI2017_GM_HEAD_RET.
DATA : GT_GOODSMVMT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
GS_GOODSMVMT_ITEM TYPE BAPI2017_GM_ITEM_CREATE.
DATA : GT_RETURN TYPE TABLE OF BAPIRET2,
GS_RETURN TYPE BAPIRET2.
*&---------------------------------------------------------------------*
*& Form GET_EKKO_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_EKKO_DATA .
SELECT
EBELN
FROM EKKO INTO TABLE GT_EKKO WHERE EBELN IN S_EBELN.
ENDFORM. " GET_EKKO_DATA
*&---------------------------------------------------------------------*
*& Form GET_EKPO_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_EKPO_DATA .
IF NOT GT_EKKO IS INITIAL.
SELECT
EBELN
EBELP
MATNR
WERKS
LGORT
MENGE
MEINS
FROM EKPO INTO TABLE GT_EKPO FOR ALL ENTRIES IN GT_EKKO WHERE EBELN = GT_EKKO-EBELN.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form POPULATE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM POPULATE_DATA .
LOOP AT GT_EKPO INTO GS_EKPO.
GS_FINAL-EBELN = GS_EKPO-EBELN.
GS_FINAL-EBELP = GS_EKPO-EBELP.
GS_FINAL-MATNR = GS_EKPO-MATNR.
GS_FINAL-WERKS = GS_EKPO-WERKS.
GS_FINAL-LGORT = GS_EKPO-LGORT.
GS_FINAL-MENGE = GS_EKPO-MENGE.
GS_FINAL-MEINS = GS_EKPO-MEINS.
" BAPI HEADER STRUCTURE
GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
GOODSMVT_HEADER-DOC_DATE = SY-DATUM.
GOODSMVT_HEADER-PR_UNAME = SY-UNAME.
GOODSMVT_HEADER-REF_DOC_NO_LONG = GS_EKPO-EBELN.
" BAPI ITEM STRUCTURE
GS_GOODSMVMT_ITEM-MATERIAL = GS_EKPO-MATNR.
GS_GOODSMVMT_ITEM-PLANT = GS_EKPO-WERKS.
GS_GOODSMVMT_ITEM-STGE_LOC = GS_EKPO-LGORT.
GS_GOODSMVMT_ITEM-MOVE_TYPE = '101'.
GS_GOODSMVMT_ITEM-PO_NUMBER = GS_EKPO-EBELN.
GS_GOODSMVMT_ITEM-PO_ITEM = GS_EKPO-EBELP.
GS_GOODSMVMT_ITEM-ENTRY_QNT = GS_EKPO-MENGE.
GS_GOODSMVMT_ITEM-ENTRY_UOM = GS_EKPO-MEINS.
GS_GOODSMVMT_ITEM-NO_MORE_GR = 'X'.
GS_GOODSMVMT_ITEM-REF_DOC = GS_EKPO-EBELN.
GS_GOODSMVMT_ITEM-PROD_DATE = SY-DATUM.
GS_GOODSMVMT_ITEM-MVT_IND = 'B'.
APPEND GS_GOODSMVMT_ITEM TO GT_GOODSMVMT_ITEM.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CALL_BAPI
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_BAPI .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER
GOODSMVT_CODE = '01'
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
GOODSMVT_HEADRET = GOODSMVT_HEADRET
* MATERIALDOCUMENT =
* MATDOCUMENTYEAR =
TABLES
GOODSMVT_ITEM = GT_GOODSMVMT_ITEM
* GOODSMVT_SERIALNUMBER =
RETURN = GT_RETURN.
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
* AFS_GOODSMVT_SKU =
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
* IMPORTING
* RETURN =
ENDIF.
WRITE:1(15)'PO document', 18(20)'Material Documant', 40(5)'Year'.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
WRITE:/1(15) GS_OUTPUT-EBELN,
18(20) GS_OUTPUT-MBLNR,
40(5) GS_OUTPUT-MJAHR.
ENDLOOP.
ENDFORM. " CALL_BAPI
‎2014 Oct 31 10:16 AM
Hi Vn srikanth,
Declaration :
Data : mat_doc_no TYPE BAPI2017_GM_HEAD_RET-MAT_DOC, "Material doc number
Doc_year type BAPI2017_GM_HEAD_RET-DOC_YEAR "Document Year
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER
GOODSMVT_CODE = '01'
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
GOODSMVT_HEADRET = GOODSMVT_HEADRET
MATERIALDOCUMENT = Mat_doc_no " Material Document
MATDOCUMENTYEAR = Doc_year " Material Document Year
TABLES
GOODSMVT_ITEM = GT_GOODSMVMT_ITEM
* GOODSMVT_SERIALNUMBER =
RETURN = GT_RETURN.
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
* AFS_GOODSMVT_SKU =
IF Mat_doc_no is not initial and doc_year is not initial.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
* IMPORTING
* RETURN =
ENDIF.
'BAPI_GOODSMVT_CREATE it returns a Material document number and Document year.
Kindly check MKPF table after commit the BAPI.
‎2014 Oct 30 10:20 AM
Hi vn,
With reference to a production order
GS_GOODSMVMT_ITEM-MVT_IND = 'F'.
Regards.
JCD
‎2014 Oct 30 10:45 AM
Dear JCD,
The above coding is done with reference to the purchase order - 'B'. Sorry it was wrongly typed as production order. Request your help on the same as it's quite urgent
Best rgds/thnks,
Srikanth.
‎2014 Oct 30 11:00 AM
Hi vn
Check BAPI_GOODSMVT_CREATE documentation, have tou checked messages in table GT_RETURN
Regards.
JCD
‎2014 Oct 30 11:01 AM
Hi Srikanth,
Any idea what's the content of gt_return table??
Thanks,
Nabarko
‎2014 Oct 30 11:14 AM
‎2014 Oct 30 11:19 AM
‎2014 Oct 30 1:20 PM
Hi Srikanth,
Are you able to do a test run in the BAPI??
TESTRUN = 'X' in the BAPI and check what's the gt_return table content.
Thanks,
Nabarko
‎2014 Oct 30 11:52 AM
Hi,
Please pass the movement code as 02 instead of 01:
Hope this helps!
Regards,
Gayatri
‎2014 Oct 30 12:11 PM
Dear Gayathri,
The above coding is done for the good reciept for the purchase order only. Sorry it was typo mistake , wrongly typed as production order.
Best rgds/thnks,
Srikanth.
‎2014 Oct 30 12:38 PM
Hi Srikanth,
Can you kindly elaborate your problem a little more?
Are you saying the document is getting posted but the movement type is different than you have specified?
Regards,
Gayatri
‎2014 Oct 30 12:47 PM
Dear Gayathri,
Selection parameter : Purchase order
So, with reference to the purchase order i was trying to goods receipt by calling BAPI , i can't able to generate the result by posting goods reciept by 101 movement type.
Output should be :
Purchase order
Material document
Movement type
‎2014 Oct 30 12:57 PM
Hi Vn,
Please put break point where you are checking sy-subrc. Well it is not necessary to check sy-subrc before bapi transaction commit.
I think you can get some error in BAPIRETURN. Place break point here...
--> IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
* IMPORTING
* RETURN =
ENDIF.
Rg,
Deeps
‎2014 Oct 30 1:51 PM
Between
RETURN = GT_RETURN.And
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'You MUST loop in GT-RETURN table for error messages (type 'A' or 'E') and if found don't commit but rollback and add error to some log.
Also
Regards,
Raymond
‎2014 Oct 31 3:38 AM
Hi Srikanth,
LOOP AT GT_EKPO INTO GS_EKPO.
GS_FINAL-EBELN = GS_EKPO-EBELN.
GS_FINAL-EBELP = GS_EKPO-EBELP.
GS_FINAL-MATNR = GS_EKPO-MATNR.
GS_FINAL-WERKS = GS_EKPO-WERKS.
GS_FINAL-LGORT = GS_EKPO-LGORT.
GS_FINAL-MENGE = GS_EKPO-MENGE.
GS_FINAL-MEINS = GS_EKPO-MEINS.
" BAPI HEADER STRUCTURE
GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
GOODSMVT_HEADER-DOC_DATE = SY-DATUM.
GOODSMVT_HEADER-PR_UNAME = SY-UNAME.
GOODSMVT_HEADER-REF_DOC_NO_LONG = GS_EKPO-EBELN.
1. Please use: goodsmvt_header-REF_DOC_NO = GS_EKPO-EBELN
...
APPEND GS_GOODSMVMT_ITEM TO GT_GOODSMVMT_ITEM.
ENDLOOP.
Also,
2. Note that the header structure is not a table but a work area.
Hence, when you are putting it in a loop, the last document number data from the loop will be the final reference document going to the BAPI along with the item details table.
Hence it wont work since there is a mismatch between item details document and reference document.
Could you please try it once?
Regards,
Gayatri.
‎2014 Oct 31 4:58 AM
Dear Gayathri,
I've tried the above said , but the same result is generated..
Pls see the below result displaying without any 101 posting..
Changes made as per the advise
Best rgds/thnks,
Srikanth.
‎2014 Oct 31 10:16 AM
Hi Vn srikanth,
Declaration :
Data : mat_doc_no TYPE BAPI2017_GM_HEAD_RET-MAT_DOC, "Material doc number
Doc_year type BAPI2017_GM_HEAD_RET-DOC_YEAR "Document Year
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER
GOODSMVT_CODE = '01'
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
GOODSMVT_HEADRET = GOODSMVT_HEADRET
MATERIALDOCUMENT = Mat_doc_no " Material Document
MATDOCUMENTYEAR = Doc_year " Material Document Year
TABLES
GOODSMVT_ITEM = GT_GOODSMVMT_ITEM
* GOODSMVT_SERIALNUMBER =
RETURN = GT_RETURN.
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
* AFS_GOODSMVT_SKU =
IF Mat_doc_no is not initial and doc_year is not initial.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
* IMPORTING
* RETURN =
ENDIF.
'BAPI_GOODSMVT_CREATE it returns a Material document number and Document year.
Kindly check MKPF table after commit the BAPI.
‎2014 Oct 31 11:26 AM
Dear Rohit,
After doing the above said, the below output had generated , but not posted with 101 mvmt document.
Output Display - Nil
Best rgds/thnks,
Srikanth.
‎2014 Oct 31 11:37 AM
Hi Vn srikanth,
WRITE:1(15)'PO document', 18(20)'Material Documant', 40(5)'Year'.
LOOP AT GT_GOODSMVMT_ITEM INTO GS_GOODSMVMT_ITEM.
WRITE:/1(15) GS_GOODSMVMT_ITEM-PO_NUMBER,
18(20) Mat_doc_no ,
40(5) Doc_year.
ENDLOOP.
Regards,
Rohit
‎2014 Oct 31 11:49 AM
Dear Rohit,
Only PO number is displayed and not posted with the 101 mvmt
Best rgds/thnks,
Srikanth.
‎2014 Oct 31 12:02 PM
Hi Vn srikant,
Kindly debug program and check return internal table (GT_RETURN) .
Regards
Rohit
‎2014 Oct 31 12:07 PM
Dear Rohit,
No messages in the return internal table
Best rgds/thnks,
Srikanth.