首页 > 其他分享 >ABAP-CS02BOM批量修改

ABAP-CS02BOM批量修改

时间:2023-07-19 13:22:20浏览次数:36  
标签:sy stb 批量 CS02BOM stpo lv ABAP ls TYPE

  1 FUNCTION zfm_pp_0009.
  2 *"----------------------------------------------------------------------
  3 *"*"本地接口:
  4 *"  EXPORTING
  5 *"     VALUE(EV_TYPE) TYPE  CHAR1
  6 *"     VALUE(EV_MESSAGE) TYPE  CHAR255
  7 *"     VALUE(EV_BOMNO) TYPE  STNUM
  8 *"  TABLES
  9 *"      TI_INPUT STRUCTURE  ZSPP_0007 OPTIONAL
 10 *"----------------------------------------------------------------------
 11 
 12   DATA:lv_material    TYPE csap_mbom-matnr,
 13        lv_bom_usage   TYPE csap_mbom-stlan,
 14        lv_plant       TYPE csap_mbom-werks,
 15        lv_alternative TYPE csap_mbom-stlal,
 16        ls_stko        TYPE stko_api01,
 17        ls_stpo        TYPE stpo_api03,
 18        lt_stpo        TYPE TABLE OF stpo_api03,
 19        lv_date        TYPE datuv_bi,
 20        lt_stb         TYPE TABLE OF stpox,
 21        ls_stb         TYPE stpox,
 22        ls_topmat      TYPE cstmat.
 23 
 24   CLEAR lv_material .
 25   CLEAR lv_bom_usage .
 26   CLEAR lv_plant .
 27   CLEAR ls_stko .
 28   CLEAR ls_stpo .
 29   REFRESH lt_stpo .
 30   CLEAR lv_date .
 31   REFRESH lt_stb .
 32   CLEAR ls_stb .
 33   CLEAR ls_topmat .
 34 
 35   CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
 36     EXPORTING
 37       date_internal            = sy-datum
 38     IMPORTING
 39       date_external            = lv_date
 40     EXCEPTIONS
 41       date_internal_is_invalid = 1
 42       OTHERS                   = 2.
 43 
 44   LOOP AT ti_input ASSIGNING FIELD-SYMBOL(<fs_input>) .
 45 
 46     CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
 47       EXPORTING
 48         input        = <fs_input>-matnr
 49       IMPORTING
 50         output       = <fs_input>-matnr
 51       EXCEPTIONS
 52         length_error = 1
 53         OTHERS       = 2.
 54 
 55     CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
 56       EXPORTING
 57         input        = <fs_input>-idnrk
 58       IMPORTING
 59         output       = <fs_input>-idnrk
 60       EXCEPTIONS
 61         length_error = 1
 62         OTHERS       = 2.
 63 
 64   ENDLOOP .
 65 
 66   IF ti_input[] IS NOT INITIAL .
 67 
 68     READ TABLE ti_input INTO DATA(ls_input) INDEX 1 .
 69 
 70     CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
 71       EXPORTING
 72 *       FTREL                 = ' '
 73 *       ALEKZ                 = ' '
 74 *       ALTVO                 = ' '
 75 *       AUFSW                 = ' '
 76         aumgb                 = 'X'
 77 *       AUMNG                 = 0
 78 *       AUSKZ                 = ' '
 79 *       AMIND                 = ' '
 80 *       BAGRP                 = ' '
 81 *       BEIKZ                 = ' '
 82 *       BESSL                 = ' '
 83 *       BGIXO                 = ' '
 84 *       BREMS                 = ' '
 85         capid                 = 'PP01'
 86 *       CHLST                 = ' '
 87 *       COSPR                 = ' '
 88 *       CUOBJ                 = 000000000000000
 89 *       CUOVS                 = 0
 90 *       CUOLS                 = ' '
 91         datuv                 = sy-datum
 92 *       DELNL                 = ' '
 93 *       DRLDT                 = ' '
 94         ehndl                 = '1'
 95 *       EMENG                 = 0
 96 *       ERSKZ                 = ' '
 97 *       ERSSL                 = ' '
 98 *       FBSTP                 = ' '
 99 *       KNFBA                 = ' '
100 *       KSBVO                 = ' '
101 *       MBWLS                 = ' '
102         mktls                 = 'X'
103         mdmps                 = 'X'
104 *       MEHRS                 = ' '
105 *       MKMAT                 = ' '
106 *       MMAPS                 = ' '
107 *       SALWW                 = ' '
108 *       SPLWW                 = ' '
109 *       MMORY                 = ' '
110         mtnrv                 = ls_input-matnr
111 *       NLINK                 = ' '
112 *       POSTP                 = ' '
113 *       RNDKZ                 = ' '
114 *       RVREL                 = ' '
115 *       SANFR                 = ' '
116 *       SANIN                 = ' '
117 *       SANKA                 = ' '
118 *       SANKO                 = ' '
119 *       SANVS                 = ' '
120 *       SCHGT                 = ' '
121 *       STKKZ                 = ' '
122         stlal                 = ls_input-stlal
123         stlan                 = ls_input-stlan
124         stpst                 = '0'
125         svwvo                 = 'X'
126         werks                 = ls_input-werks
127 *       NORVL                 = ' '
128 *       MDNOT                 = ' '
129 *       PANOT                 = ' '
130 *       QVERW                 = ' '
131 *       VERID                 = ' '
132         vrsvo                 = 'X'
133 *       SGT_SCAT              =
134 *       SGT_REL               =
135 *       CALLER_APP            =
136 *       BOM_VERSN             =
137       IMPORTING
138         topmat                = ls_topmat
139 *       DSTST                 =
140       TABLES
141         stb                   = lt_stb
142 *       MATCAT                =
143       EXCEPTIONS
144         alt_not_found         = 1
145         call_invalid          = 2
146         material_not_found    = 3
147         missing_authorization = 4
148         no_bom_found          = 5
149         no_plant_data         = 6
150         no_suitable_bom_found = 7
151         conversion_error      = 8
152         OTHERS                = 9.
153 
154   ENDIF .
155 
156   LOOP AT ti_input ASSIGNING <fs_input> .
157 
158     AT FIRST .
159 
160       lv_material = <fs_input>-matnr .
161       lv_plant = <fs_input>-werks .
162       lv_bom_usage = <fs_input>-stlan .
163       lv_alternative = <fs_input>-stlal .
164 
165       ls_stko-base_quan = <fs_input>-bmeng .
166       ls_stko-alt_text = <fs_input>-stktx .
167       ls_stko-bom_status = <fs_input>-stlst .
168       ls_stko-base_unit = <fs_input>-bmein .
169 
170     ENDAT .
171 
172     CLEAR ls_stpo .
173 
174     IF <fs_input>-flag = 'N' .
175 
176     ELSEIF <fs_input>-flag = 'C' .
177 
178       READ TABLE lt_stb INTO ls_stb WITH KEY posnr = <fs_input>-posnr
179       idnrk = <fs_input>-idnrk  .
180       IF sy-subrc = 0 .
181         ls_stpo-item_node = ls_stb-stlkn .
182         ls_stpo-item_count = ls_stb-stpoz .
183       ENDIF .
184 
185     ELSEIF <fs_input>-flag = 'D' .
186 
187       ls_stpo-fldelete = 'X' .
188       READ TABLE lt_stb INTO ls_stb WITH KEY posnr = <fs_input>-posnr
189       idnrk = <fs_input>-idnrk .
190       IF sy-subrc = 0 .
191         ls_stpo-item_node = ls_stb-stlkn .
192         ls_stpo-item_count = ls_stb-stpoz .
193       ENDIF .
194 
195     ENDIF .
196 
197     IF <fs_input>-flag IS NOT INITIAL .
198 
199       ls_stpo-item_no = <fs_input>-posnr .
200       ls_stpo-item_categ = <fs_input>-postp .
201       ls_stpo-component = <fs_input>-idnrk .
202       ls_stpo-comp_qty = <fs_input>-menge .
203       ls_stpo-comp_unit = <fs_input>-meins .
204       ls_stpo-comp_scrap = <fs_input>-ausch .
205       ls_stpo-issue_loc = <fs_input>-lgort .
206       ls_stpo-co_product = <fs_input>-kzkup .
207       ls_stpo-ai_group = <fs_input>-alpgr .
208       ls_stpo-ai_prio = <fs_input>-alprf .
209       ls_stpo-usage_prob = <fs_input>-ewahr .
210       ls_stpo-ai_strateg = <fs_input>-alpst .
211       ls_stpo-rel_cost = <fs_input>-sanka .
212       ls_stpo-bulk_mat = <fs_input>-schgt .
213       ls_stpo-sortstring = <fs_input>-sortf .
214       ls_stpo-valid_from = <fs_input>-datuv .
215       ls_stpo-fixed_qty = <fs_input>-fmeng .
216       ls_stpo-item_text1 = <fs_input>-potx1 .
217       ls_stpo-item_text2 = <fs_input>-potx2 .
218       ls_stpo-op_scrap = <fs_input>-avoau .
219       ls_stpo-op_net_ind = <fs_input>-netau .
220 
221       APPEND ls_stpo TO lt_stpo .
222 
223     ENDIF .
224 
225   ENDLOOP .
226 
227   CALL FUNCTION 'CSAP_MAT_BOM_MAINTAIN'
228     EXPORTING
229       material    = lv_material
230       plant       = lv_plant
231       bom_usage   = lv_bom_usage
232       alternative = lv_alternative
233       valid_from  = lv_date
234 *     CHANGE_NO   =
235 *     REVISION_LEVEL            =
236       i_stko      = ls_stko
237 *     FL_NO_CHANGE_DOC          = ' '
238 *     FL_COMMIT_AND_WAIT        = 'X'
239 *     FL_CAD      = ' '
240 *     FL_BOM_CREATE             = ' '
241 *     FL_NEW_ITEM = ' '
242 *     FL_COMPLETE = ' '
243 *     FL_DEFAULT_VALUES         = 'X'
244 *     FL_IDENTIFY_BY_GUID       = ' '
245 *     FL_RECURSIVE              = ' '
246 * IMPORTING
247 *     FL_WARNING  =
248 *     O_STKO      =
249     TABLES
250       t_stpo      = lt_stpo
251 *     T_DEP_DATA  =
252 *     T_DEP_DESCR =
253 *     T_DEP_ORDER =
254 *     T_DEP_SOURCE              =
255 *     T_DEP_DOC   =
256 *     T_DOC_LINK  =
257 *     T_DMU_TMX   =
258 *     T_LTX_LINE  =
259 *     T_STPU      =
260 *     T_FSH_BOMD  =
261 *     T_SGT_BOMC  =
262     EXCEPTIONS
263       error       = 1
264       OTHERS      = 2.
265   IF sy-subrc <> 0.
266 
267     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
268     CALL FUNCTION 'MESSAGE_TEXT_BUILD'
269       EXPORTING
270         msgid               = sy-msgid
271         msgnr               = sy-msgno
272         msgv1               = sy-msgv1
273         msgv2               = sy-msgv2
274         msgv3               = sy-msgv3
275         msgv4               = sy-msgv4
276       IMPORTING
277         message_text_output = ev_message.
278     ev_type = 'E' .
279 
280   ELSE .
281 
282     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
283       EXPORTING
284         wait = 'X'.
285     ev_type = 'S' .
286     ev_message = '修改成功' .
287     ev_bomno = ls_topmat-stlnr .
288 
289   ENDIF.
290 
291 ENDFUNCTION.

标签:sy,stb,批量,CS02BOM,stpo,lv,ABAP,ls,TYPE
From: https://www.cnblogs.com/TigerMan/p/17565314.html

相关文章

  • ABAP文件夹搜索帮助
      DATA:  lv_folder   TYPE string.     CALL METHOD cl_gui_frontend_services=>directory_browse      EXPORTING        WINDOW_TITLE  = '请选择要下载路径文件夹'      CHANGING        selected_folder = lv_folder   ......
  • access 批量设置条件格式
    PrivateSubForm_Load()ForEachtempInMe.ControlsIfNotTypeOftempIsLabelThentemp.OnClick="=GetVal()"NextAddConditionalFormattingToFieldsEndSubFunctionGetVal()Me.Tag=Nz(Me.单据编号,"")'设......
  • django 批量使用 同一个表的字段做转换
    使用结束减去开始时间ExamRecord.objects.filter(over_time__lt=datetime.datetime.now(),submit=1).update(submit=3,use_time=ExpressionWrapper(Extract(F('over_time')-F('start_time'),'epoch')......
  • centos7 批量杀进程(批量kill -9)
    命令为ps-ef|grep进程名|grep-vgrep|awk'{print"kill-9"$2}'|bash例如:后台启动了n个java程序,想要一下子都杀掉,启动时候执行该命令启动的javacn.edu.ruc.cmd.BootStrap则批量杀进程命令为ps-ef|grepcn.edu.ruc.cmd.BootStrap|grep-vgrep|awk'{print"......
  • 使用ME批量转码
    导出媒体导出到ME后PR可以继续工作AE也是同理用Me批量修改格式新建预设导入文件注意边上的格式......
  • 【补充】批量插入
    【1】准备数据classBook(models.Model):title=models.CharField(max_length=32)【2】一条一条插入后端defab_many(request):#(1)先给Book表插入一万条数据foriinrange(1000):models.Book.objects.create(title=f'第{i}本书')#(2)将所有......
  • linux 批量生成文件 随机数据
    seq20|xargs-iddif=/dev/urandomof=$(date+"%Y%m%d_%H%M%S"){}.databs=102400count=1#随机生成20个100K数据文件,文件名字为“日期时间_序号.data”nohupseq100000|xargs-iddif=/dev/zeroof={}.databs=102400count=1>>/dev/null2>&1&#加上后台运......
  • ABAP-库龄分析报表开发心得
    1.CLAER结构语句最好写在LOOP循环语句内的第一行因为写在LOOP循环语句内的最后一行,如果中间有CONTINUE语句,则结构不会被清空。当下个循环的结构某些字段是空值,则上一个结构里面有值的字段不会被更新为空值,也就是说INTO只会把不为空的值往结构的对应字段里面填充。LOOPATlt_ko......
  • 七牛云批量删除文件 (mac端)
    1.下载qshell工具https://developer.qiniu.com/kodo/1302/qshell选择mac下载2.执行账号绑定AK、SK在秘钥中心查看./qshell AKSK自定义名称3.执行导出空间文件名列表./qshelllistbucket2空间名--start2018-01-01-00-00-00--end2023-01-01-00-00-00-olist.txt4.......
  • 如何把 SAP ABAP 字符串变量的值下载成本地文件,以及文件路径 F4 Value Help 的实现方
    笔者这篇文章使用ABAP事物码SM59创建Destination来读取外网的数据,有朋友留言:请问,当前获取到的百度首页数据的类型是string保存在lv_html变量中,而在GUI_DOWNLOAD调用中,接收的入参数据类型是tableofx255,那么需要如何做转换处理呢?谢谢本文就专门来解答这个问题。我们的......