BAPI_GOODSMVT_CREATE (311) - Transfer Posting SAP Upload Tool.

This sample program can be used for mass transfer posting using BAPI 'BAPI_GOODSMVT_CREATE'. Suppose there is a requirement to move stock from one storage location to another or transfer stock from one batch to another, here is where this program will come handy.

REPORT zmm_311_movement.

TYPESBEGIN OF gty_upload,
         srno       TYPE sy-tabix,
         material   TYPE mseg-matnr,
         plant      TYPE mseg-werks,
         stge_loc   TYPE mseg-lgort,
         move_stloc TYPE mseg-lgort,
         spec_stock TYPE mseg-sobkz,
         entry_qnt  TYPE char16,
         batch      TYPE charg_d,
         move_batch TYPE umcha,
       END OF gty_upload.

TYPES BEGIN OF gty_log,
          srno       TYPE sy-tabix,
          matno      TYPE matnr,
          plant      TYPE werks,
          move_stloc TYPE mseg-lgort,
          stge_loc   TYPE mseg-lgort,
          batch      TYPE charg_d,
          move_batch TYPE umcha,
          matdoc_no  LIKE bapi2017_gm_head_ret,
          type       TYPE bapiret2-type,
          message    TYPE bapiret2-message,
        END OF gty_log.

DATAgt_log  TYPE TABLE OF gty_log,
      gwa_log TYPE gty_log.

DATAgt_upload  TYPE TABLE OF gty_upload,
      gwa_upload TYPE gty_upload.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001.
PARAMETERSp_file TYPE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  PERFORM p_f4_help.

START-OF-SELECTION.
  PERFORM p_upload_file.
  PERFORM p_call_bapi.
  PERFORM p_display.
*&---------------------------------------------------------------------*
*& Form P_F4_HELP
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM p_f4_help .
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  syst-cprog
      dynpro_number syst-dynnr
      field_name    ' '
    IMPORTING
      file_name     p_file.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_UPLOAD_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM p_upload_file .

  DATAgt_raw TYPE truxs_t_text_data.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_field_seperator    'X'
      i_line_header        'X'
      i_tab_raw_data       gt_raw
      i_filename           p_file
    TABLES
      i_tab_converted_data gt_upload
    EXCEPTIONS
      conversion_failed    1
      OTHERS               2.
  IF sy-subrc <> 0.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_CALL_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM p_call_bapi .

  DATAgwa_header TYPE bapi2017_gm_head_01,
        gt_item    TYPE TABLE OF bapi2017_gm_item_create,
        gwa_item   TYPE bapi2017_gm_item_create,
        lv_gmcode  TYPE bapi2017_gm_code,
        lv_doc     LIKE bapi2017_gm_head_ret,
        gt_return  TYPE TABLE OF bapiret2,
        gwa_return TYPE bapiret2.

  lv_gmcode '04'.
  LOOP AT gt_upload INTO gwa_upload.
    gwa_header-pstng_date =  sy-datum.
    gwa_header-doc_date   =  sy-datum.

    gwa_item-move_type '311'.
    gwa_item-spec_stock gwa_upload-spec_stock.
    gwa_item-material =  |{ gwa_upload-material  ALPHA IN }|.
    gwa_item-plant gwa_upload-plant.
    gwa_item-stge_loc gwa_upload-stge_loc.
    gwa_item-move_stloc gwa_upload-move_stloc.
    gwa_item-entry_qnt gwa_upload-entry_qnt.
    gwa_item-batch gwa_upload-batch     .
    gwa_item-move_batch gwa_upload-move_batch.

    APPEND gwa_item TO gt_item.
    CLEARgwa_item.

    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        goodsmvt_header  gwa_header
        goodsmvt_code    lv_gmcode
      IMPORTING
        goodsmvt_headret lv_doc
      TABLES
        goodsmvt_item    gt_item
        return           gt_return.

    IF lv_doc IS NOT INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait abap_true.
    ENDIF.

    gwa_log-srno gwa_upload-srno.
    gwa_log-plant gwa_upload-plant.
    gwa_log-matdoc_no lv_doc.
    gwa_log-matno gwa_upload-material.
    gwa_log-stge_loc   gwa_upload-stge_loc.
    gwa_log-move_stloc gwa_upload-move_stloc.
    gwa_log-batch   gwa_upload-batch.
    gwa_log-move_batch gwa_upload-move_batch.

    IF gt_return IS INITIAL.
      gwa_log-type   'S'.
      gwa_log-message '311 Movement Successful.'.
      APPEND gwa_log TO gt_log.
    ELSE.
      LOOP AT gt_return INTO gwa_return.
        gwa_log-message gwa_return-message.
        gwa_log-type   gwa_return-type.
        APPEND gwa_log TO gt_log.
      ENDLOOP.
    ENDIF.
    CLEARgt_itemgwa_itemgwa_headergt_returngwa_returngwa_loglv_doc.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form P_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM p_display .
  cl_salv_table=>factoryIMPORTING r_salv_table DATA(gr_table)
                          CHANGING t_table gt_log ).

  DATA(columnsgr_table->get_columns).
  columns->set_optimize).

  DATA(functionsgr_table->get_functions).
  functions->set_all).

  gr_table->display).

ENDFORM.


FILE FORMAT



Comments

Also Read...