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