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 for MB31

Noorie
Active Participant
0 Likes
2,083

Hi,

can any1 plz tel me the bapi for T.code MB31.

what i have to do is:

MB31 --->give movt. type (101), order, plant, stor. location, and press enter

selct item > press Adopt+ details, then click on Adopt->Goto  Details from items

then Goto --> Classify Batch --> gives values and save.

Plz let me what bapi to be used and that are the field need to be export to BAPI function module

Thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,314

chk this wiki for BAPI_GOODSMVT_CREATE(To Post Goods Movement) sample code

http://wiki.sdn.sap.com/wiki/display/Snippets/BAPI_GOODSMVT_CREATE-ABAP

4 REPLIES 4
Read only

prince_isaac
Active Participant
0 Likes
1,314

Hie

To create Goods Receipt you can use the BAPI below:


BAPI_GOODSMVT_CREATE

see the sample code also:

*------------------------------------------------------------------------
*   Populate the header data
*------------------------------------------------------------------------
*   Convert date to internal format recognizable by BAPI
      CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
        EXPORTING
          datum = xheader-pstng_date
          dtype = 'DATS'
        IMPORTING
          idate = xgd_header-pstng_date.
*   Convert date to internal format recognizable by BAPI
      CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
        EXPORTING
          datum = xheader-doc_date
          dtype = 'DATS'
        IMPORTING
          idate = xgd_header-doc_date.
      xgd_header-pr_uname       = xheader-pr_uname.
      xgd_header-ref_doc_no     = xheader-works_order.
      xgd_header-header_txt     = xheader-header_txt.
*--------------------------------------------------------------------------
*Populate the trailer items
*--------------------------------------------------------------------------
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = xtrailer-material
        IMPORTING
          output = xgoodsmvt_item-material.
      xgoodsmvt_item-plant      = xtrailer-plant.
      xgoodsmvt_item-stge_loc   = xtrailer-stge_loc.
      xgoodsmvt_item-move_type  = xtrailer-move_type.
      xgoodsmvt_item-vendor     = xtrailer-vendor.
      xgoodsmvt_item-item_text  = xtrailer-item_text.
      xgoodsmvt_item-entry_qnt  = xtrailer-quantity.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = xtrailer-costcenter
        IMPORTING
          output = xgoodsmvt_item-costcenter.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = xtrailer-gl_account
        IMPORTING
          output = xgoodsmvt_item-gl_account.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = xtrailer-gl_account
        IMPORTING
          output = xgoodsmvt_item-gl_account.
*-----------------------------------------------------------------------
*Meaning of the GM Code
*-----------------------------------------------------------------------
* GM_Code 01: Goods receipt for purchase order
* GM_Code 02: Goods receipt for production order
* GM_Code 03: Goods issue
* GM_Code 04: Transfer posting
* GM_Code 05: Other goods receipt
* GM_Code 06: Reversal of goods movements
* GM_Code 07: Subsequent adjustment with regard to a subcontract order
*------------------------------------------------------------------------
      xgd_code-gm_code = '01'.
*-------------------------------------------------------------------------
*Append the data records to the BAPI transfer structures
*-------------------------------------------------------------------------
      APPEND xgoodsmvt_item.
*-------------------------------------------------------------------------
    ENDLOOP.
*-------------------------------------------------------------------------
*Append detail to header structure outside of line items loop
*-------------------------------------------------------------------------
    APPEND xgd_header.
*-------------------------------------------------------------------------
*Create the goods receipt
    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        goodsmvt_header  = xgd_header
        goodsmvt_code    = '01'                           "xgd_code
      IMPORTING
        materialdocument = xmat_doc
        matdocumentyear  = xmat_doc_yr
      TABLES
        goodsmvt_item    = xgoodsmvt_item
        return           = xreturn.

    read table xreturn.
    if sy-tfill <> 0.
      LOOP AT xreturn.

        CLEAR xf_return.
        MOVE-CORRESPONDING xreturn TO xf_return.
        IF xreturn-type = 'A' OR xreturn-type = 'E'.
          xf_return-error_flag = 'X'.
          error_flag = 'X'.
        ENDIF.
        APPEND xf_return.
      endloop.
    else.

    IF error_flag = 'X'.
      ROLLBACK WORK.
    ELSE.
      COMMIT WORK.
      xfinal-works_order  = xheader-works_order.
      xfinal-mat_doc      = xmat_doc.
      xfinal-mat_doc_yr   = xmat_doc_yr.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,314

BAPI_GOODSMVT_CREATE

Check the function module documentation ... Its very clear.

Read only

Former Member
0 Likes
1,315

chk this wiki for BAPI_GOODSMVT_CREATE(To Post Goods Movement) sample code

http://wiki.sdn.sap.com/wiki/display/Snippets/BAPI_GOODSMVT_CREATE-ABAP

Read only

0 Likes
1,314

Hi,

Thanks all of you for your kind reply.

My main concern is i have to give some valuse in classfy batch.

MB31 --->give movt. type (101), order, plant, stor. location, and press enter

selct item > press Adopt+ details, then click on Adopt->Goto  Details from items

then Goto --> Classify Batch --> gives values and save.

wher and how to export this data to BAPI.

we have header for header data and item table for item data etc... for for this classify batch-- i have to give some characterstics.

Kindly let me know

Thanks n regards