ABAP-CS01BOM批导

  1 TYPES:BEGIN OF ty_data,
  2 
  3         matnr   LIKE  mast-matnr, "父件物料号
  4         zzzcbms TYPE  stko-zzzcbms,
  5         sqz     TYPE  stko_api01-auth_group,
  6         bmeng   TYPE  string, "父件基本数量
  7         posnr   LIKE  stpo-posnr, "子项目编号
  8         idnrk   LIKE  stpo-idnrk, "组件物料号
  9         menge   TYPE  string, "组件数量
 10         sortf   TYPE  stpo-sortf,
 11         alpgr   LIKE  stpo-alpgr, "替代组
 12         ewahr   LIKE  stpo-ewahr, "使用概率
 13         flg     TYPE  icon_d,      "状态灯
 14         message TYPE  c LENGTH 200, "错误信息
 15 
 16       END OF ty_data.
 17 
 18 DATA:gt_itab TYPE TABLE OF ty_data WITH HEADER LINE,
 19      gs_itab TYPE ty_data.
 20 DATA:gv_date  TYPE datuv_bi.
 21 
 22 CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
 23   EXPORTING
 24     date_internal                =  ‘19000101 25   IMPORTING
 26     date_external               = gv_date
 27   EXCEPTIONS
 28     date_internal_is_invalid = 1
 29    OTHERS                        = 2.
 30 
 31 DATA:ls_stko    TYPE stko_api01,
 32      ls_stpo    TYPE stpo_api01,
 33      lt_stpo    TYPE TABLE OF stpo_api01,
 34      lv_bom_no  TYPE stko_api02-bom_no,
 35      lv_warning TYPE capiflag-flwarning,
 36      lt_line    TYPE TABLE OF csltx_line.
 37 
 38 SORT gt_itab BY matnr posnr .
 39 
 40 LOOP AT gt_itab ASSIGNING FIELD-SYMBOL(<fs_itab>) .
 41 
 42   AT NEW matnr .
 43 
 44     CLEAR ls_stko .
 45     CLEAR ls_stpo .
 46     CLEAR lv_bom_no .
 47     REFRESH lt_stpo .
 48 
 49     ls_stko-zzzcbms = <fs_itab>-zzzcbms .
 50     ls_stko-base_quan = <fs_itab>-bmeng .
 51     ls_stko-bom_status = '01' .
 52     ls_stko-base_unit = '' .
 53     ls_stko-auth_group = <fs_itab>-sqz .
 54     ls_stko-zzzcb = '11' .
 55 
 56   ENDAT .
 57 
 58   CLEAR ls_stpo .
 59 
 60   ls_stpo-item_no = <fs_itab>-posnr .
 61   ls_stpo-component = <fs_itab>-idnrk .
 62   ls_stpo-comp_qty = <fs_itab>-menge .
 63   ls_stpo-sortstring = <fs_itab>-sortf .
 64   ls_stpo-ai_group = <fs_itab>-alpgr .
 65   ls_stpo-usage_prob = <fs_itab>-ewahr .
 66 
 67   IF ls_stpo-ai_group IS NOT INITIAL .
 68     ls_stpo-ai_strateg = '1' .
 69   ENDIF .
 70   ls_stpo-rel_cost = 'X' .
 71   ls_stpo-item_categ = 'L' .
 72   ls_stpo-bulk_mat = '' .
 73   ls_stpo-comp_unit = '' .
 74   APPEND ls_stpo TO lt_stpo .
 75 
 76   AT END OF matnr .
 77 
 78     CALL FUNCTION 'CSAP_MAT_BOM_CREATE'
 79       EXPORTING
 80         material    = <fs_itab>-matnr
 81         plant       = p_werks
 82         bom_usage   = p_stlan
 83         alternative = ''
 84         valid_from  = gv_date
 85         change_no   = ''
 86 *       REVISION_LEVEL           =
 87         i_stko      = ls_stko
 88 *       FL_NO_CHANGE_DOC         = ' '
 89 *       FL_COMMIT_AND_WAIT       = ' '
 90 *       FL_CAD      = ' '
 91 *       FL_DEFAULT_VALUES        = 'X'
 92 *       FL_RECURSIVE             = ' '
 93       IMPORTING
 94         fl_warning  = lv_warning
 95         bom_no      = lv_bom_no
 96       TABLES
 97         t_stpo      = lt_stpo
 98 *       T_DEP_DATA  =
 99 *       T_DEP_DESCR =
100 *       T_DEP_ORDER =
101 *       T_DEP_SOURCE             =
102 *       T_DEP_DOC   =
103         t_ltx_line  = lt_line
104 *       T_STPU      =
105 *       T_FSH_BOMD  =
106 *       T_SGT_BOMC  =
107       EXCEPTIONS
108         error       = 1
109         OTHERS      = 2.
110 
111     IF lv_bom_no IS INITIAL .
112 
113       CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
114 
115       CLEAR gs_itab .
116 
117       gs_itab-flg = icon_red_light .
118       MODIFY gt_itab FROM gs_itab TRANSPORTING flg message WHERE matnr  = <fs_itab>-matnr.
119 
120     ELSE .
121 
122       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
123         EXPORTING
124           wait = 'X'.
125 
126       CLEAR gs_itab .
127       gs_itab-flg = icon_green_light .
128       gs_itab-message = '导入成功' .
129       MODIFY gt_itab FROM gs_itab TRANSPORTING flg message WHERE matnr  = <fs_itab>-matnr .
130 
131     ENDIF .
132 
133   ENDAT .
134 
135 ENDLOOP .
posted @ 2022-08-31 15:16  TigerMan  阅读(144)  评论(0编辑  收藏  举报