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_GOODSMVT_CREATE for production order,not update database

Former Member
0 Likes
1,366

hi guru,

i am using BAPI_GOODSMVT_CREATE for production order.When i m testing this BAPI

at se37 it creates one mat doc no and i m not getting any return messages.Now i m

writing code for it at se38. but it does not update the database even though i used

bapi_transaction_commit. here sy-subrc = 0.bt when i m checking MSEG table showing

that mat doc no does not exists.

please help me out asap.

thanks and regurds,

manasi

hi guru,

i am using BAPI_GOODSMVT_CREATE for production order.When i m testing this BAPI

at se37 it creates one mat doc no and i m not getting any return messages.Now i m

writing code for it at se38. but it does not update the database even though i used

bapi_transaction_commit. here sy-subrc = 0.bt when i m checking MSEG table showing

that mat doc no does not exists.

please help me out asap.

thanks and regurds,

manasi

3 REPLIES 3
Read only

0 Likes
968

HI,

when you run the same bapi in SE37 you neet to perfomr the Bapi_transcation_commit other wise the database wouldn`t commit.

please user the below code.

CLEAR: return, return[].

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

EXPORTING

goodsmvt_header = p_goodsmvt_header

goodsmvt_code = p_goodsmvt_code

  • TESTRUN = ' '

IMPORTING

  • GOODSMVT_HEADRET =

materialdocument = p_mat_doc

matdocumentyear = p_mat_docu_year

TABLES

goodsmvt_item = goodsmvt_item

  • GOODSMVT_SERIALNUMBER =

return = return.

IF p_mat_doc NE space AND NOT p_mat_docu_year IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

ELSE.

return = return.

ENDIF.

Thanks,

Nelson

Edited by: Nelson karunakar on Nov 10, 2009 12:50 PM

Read only

Former Member
0 Likes
968

CHECK THIS CODE

REPORT ZBAPI_GOODSMVT_CREATE.

*------------------------------------------------------------------------*
*DECLARING INTERNAL TABLE TO HOLD FILE DATA.
*------------------------------------------------------------------------*

DATA: BEGIN OF itab OCCURS 0,

          text(200),

      END OF itab.

*-------------------------------------------------------------------------*
*DECLARING INTERNAL TABLE TO PASS FILE DATA.
*-------------------------------------------------------------------------*

TYPES: BEGIN OF tw_goodsmvt,
            pstng_date TYPE budat,
            doc_date TYPE bldat,
            material TYPE matnr,
            plant TYPE werks_d,
            stge_loc TYPE lgort_d,
            move_type TYPE bwart,
*            entry_qnt TYPE erfmg,
            costcenter TYPE kostl,
        END OF tw_goodsmvt,
        tt_goodsmvt TYPE STANDARD TABLE OF tw_goodsmvt.

DATA: lt_goodsmvt TYPE tt_goodsmvt,
      lw_goodsmvt TYPE tw_goodsmvt.

*----------------------------------------------------------------------------*
*declaring internal table of bapi structure.
*-----------------------------------------------------------------------------*

DATA:s_goodsmvt_header LIKE  bapi2017_gm_head_01,
     lt_goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
     lt_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.

DATA:str_filename TYPE string,
     gm_code TYPE gm_code,
      v_head_count TYPE i VALUE 0,
      v_prev_count TYPE i VALUE 1,
      v_qnt TYPE string,
      v_dummy.

*--------------------------------------------------------------------------*
*selection screen
*--------------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK bk with frame title text_001.
PARAMETERS:p_docdat TYPE bldat,
           p_pstdat TYPE budat,
           fname LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK bk.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR fname.

*---------------------------------------------------------------------------*
*to provide F4 functionality.
*---------------------------------------------------------------------------*

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name = syst-cprog
    IMPORTING
      file_name    = fname.

*----------------------------------------------------------------------------*
* start of selection
*-----------------------------------------------------------------------------*

START-OF-SELECTION.

  str_filename = fname.
  gm_code = '06'.

*------------------------------------------------------------------------------*
* to upload data
*------------------------------------------------------------------------------*


  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename            = str_filename
      filetype            = 'ASC'
      has_field_separator = 'X'
      read_by_line        = 'X'
    TABLES
      data_tab            = itab.

*-------------------------------------------------------------------------------*
*SPLITING DATA TO INTERNAL TABLES.
*-------------------------------------------------------------------------------*

  LOOP AT itab.
    IF itab+0(1) EQ 'H'.
      v_head_count =  v_head_count + 1.

      IF v_head_count GT v_prev_count.
        PERFORM bapi_upload.
      ENDIF.
      SPLIT itab-text AT ',' INTO v_dummy
                                  lw_goodsmvt-pstng_date
                                  lw_goodsmvt-doc_date.

      s_goodsmvt_header-doc_date   = lw_goodsmvt-doc_date.
      s_goodsmvt_header-pstng_date = lw_goodsmvt-pstng_date.

      v_prev_count = v_head_count.


  ELSEIF itab+0(1) EQ 'L'.

    SPLIT itab-text AT ',' INTO v_dummy
                                lw_goodsmvt-material
                                lw_goodsmvt-plant
                                lw_goodsmvt-stge_loc
                                lw_goodsmvt-move_type
                                v_qnt
                                lw_goodsmvt-costcenter.
*---------------------------------------------------------------------------*
* PASSING DATA TO INTERNAL TABLE TYPE BAPI STRUCTURE.
*---------------------------------------------------------------------------*
    lt_goodsmvt_item-material = lw_goodsmvt-material.
    lt_goodsmvt_item-plant    = lw_goodsmvt-plant.
    lt_goodsmvt_item-stge_loc = lw_goodsmvt-stge_loc.
    lt_goodsmvt_item-move_type = lw_goodsmvt-move_type.
    lt_goodsmvt_item-entry_qnt = v_qnt.
    lt_goodsmvt_item-costcenter = lw_goodsmvt-costcenter.


    APPEND lt_goodsmvt_item.
  ENDIF.
  v_prev_count = v_head_count.
  ENDLOOP.
  PERFORM bapi_upload.

*&---------------------------------------------------------------------*
*&      Form  bapi_upload
*&---------------------------------------------------------------------*

form bapi_upload .

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
  EXPORTING
    goodsmvt_header             = s_goodsmvt_header
    goodsmvt_code               = gm_code
*   TESTRUN                     = ' '
* IMPORTING
*   GOODSMVT_HEADRET            =
*   MATERIALDOCUMENT            =
*   MATDOCUMENTYEAR             =
  tables
    goodsmvt_item               = lt_goodsmvt_item
*   GOODSMVT_SERIALNUMBER       =
    return                      = lt_return.

        PERFORM commit_work TABLES lt_return.

        CLEAR : lw_goodsmvt, s_goodsmvt_header.
        REFRESH: lt_goodsmvt[], lt_goodsmvt_item[].




endform.                    " bapi_upload


*&---------------------------------------------------------------------*
*&      Form  commit_work
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_RETURN  text
*----------------------------------------------------------------------*

form commit_work  tables   p_lt_return structure bapiret2.

  IF NOT lt_return[] IS INITIAL.

*------------------------------------------------------------------------*
*error handling
*------------------------------------------------------------------------*

loop at lt_return.
CALL FUNCTION 'FORMAT_MESSAGE'
 EXPORTING
   ID              = lt_return-id
   LANG            = sy-langu
   NO              = lt_return-NUMBER
   V1              = lt_return-message_v1
   V2              = lt_return-message_v2
   V3              = lt_return-message_v3
   V4              = lt_return-message_v4
 IMPORTING
   MSG             = lt_return-MESSAGE
 EXCEPTIONS
   NOT_FOUND       = 1
   OTHERS          = 2.




WRITE: lt_return-id, lt_return-message, lt_return-message_v1, lt_return-message_v2,
             lt_return-message_v3, lt_return-message_v4.

      CLEAR lt_return.
    ENDLOOP.


  ELSE.

*---------------------------------------------------------------------------*
* commit work
*---------------------------------------------------------------------------*

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*   EXPORTING
*     WAIT          =
   IMPORTING
     RETURN        = lt_return.

WRITE: lt_return-id, lt_return-message, lt_return-message_v1, lt_return-message_v2,
             lt_return-message_v3, lt_return-message_v4.

      CLEAR lt_return.


endif.
endform.                    " commit_work

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
968

Hi,

Follow the simple steps below:-

Step 1 : Go to transaction SE37.

Step 2 : Click the menu Function Module, click option TEST and click TEST SEQUENCES.

Step 3 : Give the first entry as BAPI_GOODSMVT_CREATE and give the second entry as BAPI_TRANSACTION_COMMIT and click execute.

Step 4 : Now Give the details for the bapi BAPI_GOODSMVT_CREATE and press execute, after this automatically the new bapi will come. Give 5 as input (5 seconds) and click execute.

Now check the data in the database.

Hope this helps you.

Regards,

Tarun