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 - Goods mvmt

Former Member
0 Likes
6,649

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
6,564

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.

21 REPLIES 21
Read only

JuanCarlosDelga
Contributor
0 Likes
6,564

Hi vn,

With reference to a production order

GS_GOODSMVMT_ITEM-MVT_IND = 'F'.


Regards.

JCD

Read only

0 Likes
6,564

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.

Read only

0 Likes
6,564


Hi vn

Check BAPI_GOODSMVT_CREATE documentation, have tou checked messages in table GT_RETURN

Regards.

JCD

Read only

0 Likes
6,564

Hi Srikanth,

Any idea what's the content of gt_return table??

Thanks,

Nabarko

Read only

0 Likes
6,564

Dear Nabarko,

No message is displayed at GT_RETURN..

Read only

0 Likes
6,564

Dear JCD,

No message is displayed at GT_RETURN.

Read only

0 Likes
6,564

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

Read only

Former Member
0 Likes
6,564

Hi,

Please pass the movement code as 02 instead of 01:

Hope this helps!

Regards,

Gayatri

Read only

0 Likes
6,564

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.

Read only

0 Likes
6,564

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

Read only

0 Likes
6,564

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  

Read only

0 Likes
6,564

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
6,564

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

Read only

Former Member
0 Likes
6,564

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.


Read only

0 Likes
6,563

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.

Read only

Former Member
0 Likes
6,565

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.

Read only

0 Likes
6,563

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.

Read only

0 Likes
6,563

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

Read only

0 Likes
6,563

Dear Rohit,

Only PO number is displayed and not posted with the 101 mvmt

Best rgds/thnks,
Srikanth.

Read only

0 Likes
6,563

Hi Vn srikant,

Kindly debug program and check return internal table (GT_RETURN) .

Regards

Rohit

Read only

0 Likes
6,563

Dear Rohit,

No messages in the return internal table

Best rgds/thnks,

Srikanth.