1, 介绍
下面介绍一个修改订单BOM(Order BOM)的函数CSAP_ORD_BOM_MAINTAIN。通过这个函数不仅能修改订单BOM还能直接创建相关的长文本。
在前台是可以通过CS61 CS62 CS63来创建,修改,显示订单BOM.
其他:如果要创建一个新的订单BOM,可以通过函数CSAP_ORD_BOM_CREATE,参数和CSAP_ORD_BOM_MAINTAIN的差不多。
2, 例子代码
写了一个简单的修改订单BOM的程序,逻辑如下:
1,调用 CS_BOM_EXPL_MAT_V2 展开一个物料BOM,
2,将物料BOM中的class K转换成L,
3,调用CSAP_ORD_BOM_MAINTAIN修改订单BOM和相关长文本
完整代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
REPORT ztest_copy_bom. DATA: lit_stb TYPE TABLE OF stpox, lwa_stb TYPE stpox, lit_matcat TYPE TABLE OF cscmat, lwa_vbap TYPE vbap, lwa_stko TYPE stko_api01, lwa_stpo TYPE stpo_api03, lit_stpo TYPE TABLE OF stpo_api03 WITH HEADER LINE, l_item_no TYPE stpo_api03-item_no. DATA:git_stb TYPE STANDARD TABLE OF stpox, gwa_stb TYPE stpox. DATA:lit_line TYPE STANDARD TABLE OF csltx_line, lwa_line TYPE csltx_line. SELECTION-SCREEN BEGIN OF BLOCK b_kopvor WITH FRAME TITLE text-001. PARAMETERS: p_matnr1 LIKE mast-matnr MEMORY ID mat, p_werks1 LIKE mast-werks OBLIGATORY MEMORY ID wrk, "plant p_stlan1 LIKE mast-stlan DEFAULT '1' MODIF ID mod. "BOM Usage SELECTION-SCREEN END OF BLOCK b_kopvor. SELECTION-SCREEN BEGIN OF BLOCK b_aufstu WITH FRAME TITLE text-002. PARAMETERS: p_vbeln LIKE kdst-vbeln MEMORY ID aun MATCHCODE OBJECT vmva, p_vbpos LIKE kdst-vbpos MEMORY ID aup, p_matnr2 LIKE kdst-matnr MEMORY ID ma2, p_werks2 LIKE mast-werks OBLIGATORY MEMORY ID wrk, "Werk p_stlan2 LIKE mast-stlan DEFAULT '1' MODIF ID mod. SELECTION-SCREEN END OF BLOCK b_aufstu. DATA:l_from TYPE csap_kbom-datuv. * 物料BOM展开 CALL FUNCTION 'CS_BOM_EXPL_MAT_V2' EXPORTING mtnrv = p_matnr1 "'AK47' werks = p_werks1 "'1130' stlan = p_stlan1 "'1' datuv = sy-datum ehndl = '1' mmory = '1' capid = 'PP01' aufsw = ' ' mbwls = ' ' mehrs = ' ' TABLES stb = git_stb EXCEPTIONS alt_not_found = 1 call_invalid = 2 material_not_found = 3 missing_authorization = 4 no_bom_found = 5 no_plant_data = 6 no_suitable_bom_found = 7. LOOP AT git_stb INTO gwa_stb. * BOM Item ADD 10 TO l_item_no. "Fill Bom Item to update CLEAR lwa_stpo. lwa_stpo-item_categ = gwa_stb-postp. CALL FUNCTION 'CONVERSION_EXIT_NUMCV_INPUT' EXPORTING input = l_item_no IMPORTING output = lwa_stpo-item_no. lwa_stpo-component = gwa_stb-idnrk. * 将物料BOM中的class K转换成L,创建订单BOM IF lwa_stpo-item_categ = 'K'. lwa_stpo-item_categ = 'L'. lwa_stpo-component = gwa_stb-ojtxp. ENDIF. " … Fill any fields you need lwa_stpo-comp_qty = gwa_stb-menge. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = gwa_stb-meins language = sy-langu IMPORTING * LONG_TEXT = output = lwa_stpo-comp_unit * SHORT_TEXT = EXCEPTIONS unit_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. lwa_stpo-item_text1 = gwa_stb-potx1. lwa_stpo-item_text2 = gwa_stb-potx2. lwa_stpo-bom_no = gwa_stb-stlnr. lwa_stpo-item_node = gwa_stb-stlkn. lwa_stpo-item_count = gwa_stb-stpoz. lwa_stpo-bom_alt = gwa_stb-stlal. * identifier用来标识长文本是保存在哪个BOM Item上 lwa_stpo-identifier = l_item_no. APPEND lwa_stpo TO lit_stpo. * 长文本 CLEAR:lwa_line. * identifier用来标识长文本是保存在哪个BOM Item上 lwa_line-identifier = l_item_no. lwa_line-tdformat = '*'. lwa_line-tdline = 'line1'. lwa_line-object_id = '2'. "2: STPO, 1:STKP 0:STZU APPEND lwa_line TO lit_line. lwa_line-tdline = 'line12'. APPEND lwa_line TO lit_line. lwa_line-tdline = 'line123'. APPEND lwa_line TO lit_line. lwa_line-tdline = 'line1234'. APPEND lwa_line TO lit_line. ENDLOOP. CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING date_internal = sy-datum IMPORTING date_external = l_from EXCEPTIONS date_internal_is_invalid = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. * 订单BOM维护 CALL FUNCTION 'CSAP_ORD_BOM_MAINTAIN' EXPORTING order = p_vbeln "'06900222222' position = p_vbpos "'200' material = p_matnr2 "'000000000050333339' plant = p_werks2 "'1130' bom_usage = p_stlan2 "'1' valid_from = l_from i_stko = lwa_stko fl_new_item = 'X' fl_commit_and_wait = 'X' TABLES t_stpo = lit_stpo t_ltx_line = lit_line EXCEPTIONS error = 1 OTHERS = 2. |
上面代码上关于长文创建需要特别注意的是OBJECT_ID和IDENTIFIER两个字段:
- identifier 是用来标识长文本是创建在哪个BOM item上的字段,也就是代码中的 lwa_stpo-identifier 和 lwa_line-identifier这两个字段
- object_id是用来标识长文的是创建在抬头上还是行项目上
‘2’:BOM行项目STPO上
‘1’:BOM抬头STKO上
‘0’:STZU上。
3, 代码运行
选择画面输入物料BOM和订单BOM相关条件。
运行后订单BOM就创建完毕了。。。很简陋,,,,也没个弹出消息,,
CS63,输入刚才在选择画面上输入的订单,行项目,物料,工厂和BOM usage,然后回车
双击BOM item号
长文本也创建成功,如下:
发现一个小问题,就是前两行的长文本与代码中的不一致,代码中是line1 line12,如下:
1 2 3 4 5 6 7 8 9 10 11 |
lwa_line-identifier = l_item_no. lwa_line-tdformat = '*'. lwa_line-tdline = 'line1'. lwa_line-object_id = '2'. "2: STPO, 1:STKP 0:STZU APPEND lwa_line TO lit_line. lwa_line-tdline = 'line12'. APPEND lwa_line TO lit_line. lwa_line-tdline = 'line123'. APPEND lwa_line TO lit_line. lwa_line-tdline = 'line1234'. APPEND lwa_line TO lit_line. |
这是由于lit_line中的长文本不能覆盖STPO中的item_text1 和 item_text2,相关代码如下:
1 2 |
lwa_stpo-item_text1 = gwa_stb-potx1. lwa_stpo-item_text2 = gwa_stb-potx2. |
以上。
发表评论