ABAP-MIGO561期初库存批导BAPI

  1 DATA:BEGIN OF gt_data OCCURS 0,
  2        bldat       TYPE bldat,
  3        budat       TYPE budat,
  4        bktxt       TYPE kbtxt,
  5        bwart       TYPE mseg-bwart,
  6        matnr       TYPE mseg-matnr,
  7        werks       TYPE mseg-werks,
  8        lgort       TYPE mseg-lgort,
  9        charg       TYPE mseg-charg,
 10        erfmg       TYPE mseg-erfmg,
 11        erfme       TYPE mseg-erfme,
 12        exbwr       TYPE mseg-exbwr,
 13        sobkz       TYPE mseg-sobkz,
 14        lifnr       TYPE mseg-lifnr,
 15        kdauf       TYPE mseg-kdauf,
 16        kdpos       TYPE mseg-kdpos,
 17        ablad       TYPE mseg-ablad,
 18        wempf       TYPE mseg-wempf,
 19        sgtxt       TYPE mseg-sgtxt,
 20 
 21        mblnr       TYPE mseg-mblnr,
 22        mjahr       TYPE mseg-mjahr,
 23        zeile       TYPE mseg-zeile,
 24        zstatus     TYPE c,
 25        zmesg(30),
 26        checkbox(1),
 27      END OF gt_data.
 28 
 29 DATA:gs_header TYPE bapi2017_gm_head_01,
 30      gs_code   TYPE bapi2017_gm_code,
 31      gt_item   TYPE TABLE OF bapi2017_gm_item_create,
 32      gs_item   TYPE bapi2017_gm_item_create,
 33      gt_return TYPE TABLE OF bapiret2,
 34      gs_return TYPE bapiret2.
 35 
 36 LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<fs_add>) WHERE checkbox = 'X' AND zstatus <>  'S'.
 37 
 38   CLEAR gs_header .
 39   CLEAR gs_item .
 40   REFRESH gt_item .
 41   REFRESH gt_return .
 42 
 43   gs_code-gm_code = '05' .
 44 
 45   gs_header-pstng_date = <fs_add>-budat .
 46   gs_header-doc_date = <fs_add>-bldat .
 47   gs_header-header_txt = <fs_add>-bktxt .
 48 
 49   gs_item-move_type = <fs_add>-bwart .
 50   gs_item-material = <fs_add>-matnr .
 51   gs_item-plant = <fs_add>-werks .
 52   gs_item-stge_loc = <fs_add>-lgort .
 53   gs_item-batch = <fs_add>-charg .
 54   gs_item-entry_qnt = <fs_add>-erfmg .
 55   gs_item-entry_uom = <fs_add>-erfme .
 56   gs_item-amount_lc = <fs_add>-exbwr .
 57   gs_item-spec_stock = <fs_add>-sobkz .
 58   gs_item-vendor = <fs_add>-lifnr .
 59   gs_item-unload_pt = <fs_add>-ablad .
 60   gs_item-val_sales_ord = <fs_add>-kdauf .
 61   gs_item-val_s_ord_item = <fs_add>-kdpos .
 62   gs_item-gr_rcpt = <fs_add>-wempf .
 63   gs_item-item_text = <fs_add>-sgtxt .
 64   APPEND gs_item TO gt_item .
 65 
 66   CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
 67     EXPORTING
 68       goodsmvt_header  = gs_header
 69       goodsmvt_code    = gs_code
 70 *     TESTRUN          = ' '
 71 *     GOODSMVT_REF_EWM =
 72 *     GOODSMVT_PRINT_CTRL           =
 73     IMPORTING
 74 *     goodsmvt_headret =
 75       materialdocument = <fs_add>-mblnr
 76       matdocumentyear  = <fs_add>-mjahr
 77     TABLES
 78       goodsmvt_item    = gt_item
 79 *     GOODSMVT_SERIALNUMBER         =
 80       return           = gt_return
 81 *     GOODSMVT_SERV_PART_DATA       =
 82 *     EXTENSIONIN      =
 83 *     GOODSMVT_ITEM_CWM             =
 84     .
 85 
 86   IF gt_return[] IS NOT INITIAL .
 87     READ TABLE gt_return INTO gs_return WITH KEY type = 'E'.
 88     IF sy-subrc = 0 .
 89       CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
 90       <fs_add>-zstatus = 'E'.
 91       <fs_add>-zmesg = gs_return-message.
 92       <fs_add>-checkbox = ''.
 93     ENDIF.
 94   ELSE.
 95     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
 96       EXPORTING
 97         wait = 'X'.
 98     <fs_add>-zstatus = 'S'.
 99     <fs_add>-zmesg = '成功'.
100     <fs_add>-checkbox = ''.
101     SELECT SINGLE zeile
102       INTO <fs_add>-zeile
103       FROM mseg
104       WHERE mblnr = <fs_add>-mblnr
105       AND mjahr = <fs_add>-mjahr
106       AND matnr = <fs_add>-matnr.
107   ENDIF.
108 
109 ENDLOOP.
posted @ 2022-06-20 15:58  TigerMan  阅读(216)  评论(0编辑  收藏  举报