1 FUNCTION ZRFC_FICO_MR21_V1. 2 *"---------------------------------------------------------------------- 3 *"*"本地接口: 4 *" IMPORTING 5 *" VALUE(BUDAT) TYPE BUDAT OPTIONAL 6 *" TABLES 7 *" IM_TAB STRUCTURE ZSTRU_MEBW_MR21 OPTIONAL 8 *" EX_MESSAGE STRUCTURE CMFMSG OPTIONAL 9 *"---------------------------------------------------------------------- 10 *" 创建成本价 11 * 传入金额,币种----转换为工厂本位币 12 * 没有使用ROLLBACK 13 *"---------------------------------------------------------------------- 14 15 DATA: BEGIN OF WERK_TAB OCCURS 0, 16 BUKRS TYPE BUKRS, 17 WERKS TYPE WERKS_D, 18 WAERS TYPE WAERS, 19 FACTOR TYPE ISOC_FACTOR, 20 END OF WERK_TAB. 21 22 DATA: LV_TAB LIKE ZSTRU_MEBW_MR21. 23 DATA: LT_TAB TYPE TABLE OF ZSTRU_MEBW_MR21. 24 DATA: LT_RESULT TYPE TABLE OF ZSTRU_MEBW_MR21. 25 DATA: I TYPE I, 26 J TYPE I. 27 28 *---------------------------------------------------------------------- 29 *初始化全局变量 30 *---------------------------------------------------------------------- 31 " 过账日期 32 F_MR21HEAD-BUDAT = BUDAT. 33 IF F_MR21HEAD-BUDAT IS INITIAL. 34 F_MR21HEAD-BUDAT = SY-DATUM. 35 ENDIF. 36 37 * 初始化输出参数 38 REFRESH EX_MESSAGE. 39 40 *---------------------------------------------------------------------- 41 *初始化本地参数 42 *---------------------------------------------------------------------- 43 44 * 汇集公司 工厂 45 SORT IM_TAB BY BUKRS WERKS MATNR. 46 LOOP AT IM_TAB. 47 WERK_TAB-BUKRS = IM_TAB-BUKRS. 48 WERK_TAB-WERKS = IM_TAB-WERKS. 49 WERK_TAB-WAERS = IM_TAB-WAERS. 50 COLLECT WERK_TAB. 51 ENDLOOP. 52 " 循环公司工厂 53 LOOP AT WERK_TAB. 54 55 IF WERK_TAB-WAERS IS INITIAL. 56 SELECT SINGLE WAERS INTO WERK_TAB-WAERS FROM T001 WHERE BUKRS = WERK_TAB-BUKRS. 57 ENDIF. 58 59 WERK_TAB-FACTOR = 1. 60 CALL FUNCTION 'ZGET_CURRENCY_FACTOR' 61 EXPORTING 62 CURRENCY = WERK_TAB-WAERS 63 IMPORTING 64 FACTOR = WERK_TAB-FACTOR. 65 66 67 68 F_MR21HEAD-BUKRS = WERK_TAB-BUKRS. 69 CLEAR LT_TAB[]. 70 71 LOOP AT IM_TAB INTO LV_TAB WHERE BUKRS = WERK_TAB-BUKRS 72 AND WERKS = WERK_TAB-WERKS . 73 APPEND LV_TAB TO LT_TAB. 74 ENDLOOP. 75 76 77 CLEAR I. 78 LOOP AT LT_TAB INTO LV_TAB . 79 I = I + 1. 80 J = I MOD 500. 81 LV_TAB-KBETR = LV_TAB-KBETR / WERK_TAB-FACTOR. 82 APPEND LV_TAB TO LT_RESULT. 83 84 IF J = 0 . " 是倍数,则执行 85 "创建成本价 86 PERFORM CREATE_MR21 TABLES LT_RESULT. 87 IF G_RT = 1. 88 WRITE : '有错误---生成成本价. 公司工厂', 89 WERK_TAB-BUKRS, WERK_TAB-WERKS,/ . 90 ENDIF. 91 92 " 返回消息 93 APPEND LINES OF GT_MSG TO EX_MESSAGE. 94 95 "初始化 96 CLEAR LT_RESULT[]. 97 ENDIF. 98 99 AT LAST. "最后一条不是倍数,则执行 100 IF J <> 0. 101 "创建成本价 102 PERFORM CREATE_MR21 TABLES LT_RESULT. 103 IF G_RT = 1. 104 WRITE : '有错误---生成成本价. 公司工厂', 105 WERK_TAB-BUKRS, WERK_TAB-WERKS,/ . 106 ENDIF. 107 108 " 返回消息 109 APPEND LINES OF GT_MSG TO EX_MESSAGE. 110 111 "初始化 112 CLEAR LT_RESULT[]. 113 114 ENDIF. 115 ENDAT. 116 117 ENDLOOP. 118 119 120 ENDLOOP. 121 122 123 ENDFUNCTION. 124 125 126 FORM CREATE_MR21 TABLES IM_MBEW STRUCTURE ZSTRU_MEBW_MR21. 127 DATA: LT_MSG TYPE STANDARD TABLE OF CMFMSG, 128 LV_MSG TYPE CMFMSG. 129 130 DATA: H_INDEX LIKE SY-TABIX. 131 DATA: H_POPER LIKE CKMLPP-POPER, 132 H_BDATJ LIKE CKMLPP-BDATJ. 133 134 DATA: LV_TAB LIKE ZSTRU_MEBW_MR21. 135 DATA: L_RX LIKE TCURR-UKURS, "汇率 136 L_KBETR LIKE MBEW-STPRS, "成本价 137 L_VPRSV LIKE MBEW-VPRSV. "价格控制指示符 V OR S 138 139 *---------------------------------------------------------------------- 140 *初始化 141 *---------------------------------------------------------------------- 142 CLEAR G_RT. "执行标志初始化 143 CLEAR GT_MSG[]. 144 145 REFRESH: T_MATPR. 146 CLEAR : T_MATPR, F_MATPR, F_MATCR. 147 148 CLEAR LT_MSG[]. 149 CLEAR LV_MSG. 150 *---------------------------------------------------------------------- 151 *查看账期,并检查物料账期是否开启 152 *---------------------------------------------------------------------- 153 *获取过账日期 154 CALL FUNCTION 'FI_PERIOD_DETERMINE' 155 EXPORTING 156 I_BUKRS = F_MR21HEAD-BUKRS 157 I_BUDAT = F_MR21HEAD-BUDAT 158 IMPORTING 159 E_MONAT = POPER 160 E_GJAHR = BDATJ. 161 162 H_BDATJ = BDATJ. 163 H_POPER = POPER. 164 165 CALL FUNCTION 'FI_PERIOD_CHECK' 166 EXPORTING 167 I_BUKRS = F_MR21HEAD-BUKRS 168 I_GJAHR = H_BDATJ 169 I_KOART = '+' 170 I_KONTO = '+' 171 I_MONAT = H_POPER "TH 172 EXCEPTIONS 173 ERROR_PERIOD = 1 174 ERROR_PERIOD_ACC = 2. 175 176 CALL FUNCTION 'MARV_SINGLE_READ' 177 EXPORTING 178 KZRFB = ' ' 179 MAXTZ = '100' 180 BUKRS = F_MR21HEAD-BUKRS 181 IMPORTING 182 WMARV = MARV 183 EXCEPTIONS 184 NOT_FOUND = 1 185 WRONG_CALL = 2 186 OTHERS = 3. 187 188 DATA: XRUEM, 189 XRUEJ. 190 DATA: L_RET TYPE STRING. 191 CLEAR L_RET. 192 PERFORM MARV_CHECK USING XRUEM XRUEJ L_RET . 193 IF L_RET IS NOT INITIAL. 194 CLEAR LV_MSG. 195 LV_MSG-ARBGB = 'CKPRCH'. 196 LV_MSG-MSGTY = 'E'. 197 LV_MSG-MSGNR = '009'. 198 LV_MSG-MSGV1 = L_RET. 199 APPEND LV_MSG TO GT_MSG. 200 RETURN. 201 ENDIF. 202 *---------------------------------------------------------------------- 203 *需求的物料清单 204 *---------------------------------------------------------------------- 205 LOOP AT IM_MBEW INTO LV_TAB. 206 CLEAR F_ONECURR. 207 F_ONECURR-MATNR = LV_TAB-MATNR. "物料号 208 F_ONECURR-BWKEY = LV_TAB-WERKS. "工厂 209 210 CLEAR F_MATPR. 211 READ TABLE T_MATPR INTO F_MATPR 212 WITH KEY PP-MATNR = F_ONECURR-MATNR 213 PP-BWKEY = F_ONECURR-BWKEY 214 PP-BWTAR = F_ONECURR-BWTAR 215 PP-VBELN = F_ONECURR-VBELN 216 PP-POSNR = F_ONECURR-POSNR 217 PP-PSPNR = F_ONECURR-PSPNR. 218 IF SY-SUBRC <> 0. 219 MOVE-CORRESPONDING F_ONECURR TO F_MATPR-PP. 220 F_MATPR-PP-POPER = H_POPER. 221 F_MATPR-PP-BDATJ = H_BDATJ. 222 223 REFRESH F_MATPR-CR. 224 225 APPEND F_MATPR TO T_MATPR. 226 ENDIF. 227 ENDLOOP. 228 229 *---------------------------------------------------------------------- 230 *获取产品成本核算号以及对用币种 231 *---------------------------------------------------------------------- 232 CALL FUNCTION 'CM_F_INITIALIZE' 233 EXPORTING 234 APLID = 'CKML'. 235 "读取物料 236 CALL FUNCTION 'PRICES_PROPOSE' 237 EXPORTING 238 ACTUAL_BDATJ = H_BDATJ 239 ACTUAL_POPER = H_POPER 240 BUKRS = F_MR21HEAD-BUKRS 241 TABLES 242 T_MATPR = T_MATPR 243 EXCEPTIONS 244 DATA_ERROR = 1 245 OTHERS = 2. 246 247 IF SY-SUBRC <> 0. 248 249 G_RT = 1. 250 * MESSAGE e017(ckprch) WITH t_onecurr-matnr. 251 CLEAR LV_MSG. 252 LV_MSG-ARBGB = 'CKPRCH'. 253 LV_MSG-MSGTY = 'E'. 254 LV_MSG-MSGNR = '017'. 255 APPEND LV_MSG TO GT_MSG. 256 ENDIF. 257 258 CALL FUNCTION 'CM_F_MESSAGES_GET' 259 EXPORTING 260 APLID = 'CKML' 261 TABLES 262 E_MSGPROT = LT_MSG. 263 APPEND LINES OF LT_MSG TO GT_MSG. 264 LOOP AT LT_MSG INTO LV_MSG WHERE MSGTY = 'A' OR MSGTY = 'E'. 265 G_RT = 1. 266 EXIT. 267 ENDLOOP. 268 269 * IF g_rt = 1. 270 * RETURN. 271 * ENDIF. 272 *---------------------------------------------------------------------- 273 * 获得新的物料价格--根据币种 274 *---------------------------------------------------------------------- 275 276 DATA: V_FACTOR TYPE ISOC_FACTOR. 277 278 LOOP AT IM_MBEW INTO LV_TAB. 279 CLEAR F_ONECURR. 280 F_ONECURR-MATNR = LV_TAB-MATNR. "物料号 281 F_ONECURR-BWKEY = LV_TAB-WERKS. "工厂 282 283 284 285 286 V_FACTOR = 1. 287 CALL FUNCTION 'ZGET_CURRENCY_FACTOR' 288 EXPORTING 289 CURRENCY = LV_TAB-WAERS 290 IMPORTING 291 FACTOR = V_FACTOR. 292 293 294 295 READ TABLE T_MATPR INTO F_MATPR 296 WITH KEY 297 PP-MATNR = F_ONECURR-MATNR 298 PP-BWKEY = F_ONECURR-BWKEY 299 PP-BWTAR = F_ONECURR-BWTAR 300 PP-VBELN = F_ONECURR-VBELN 301 PP-POSNR = F_ONECURR-POSNR 302 PP-PSPNR = F_ONECURR-PSPNR. 303 IF SY-SUBRC = 0. 304 CLEAR H_INDEX. 305 H_INDEX = SY-TABIX. 306 307 "物料标准价类型 308 CLEAR L_VPRSV. 309 SELECT SINGLE VPRSV INTO L_VPRSV 310 FROM MBEW 311 WHERE MATNR = F_ONECURR-MATNR AND BWKEY = F_ONECURR-BWKEY. 312 313 "设定新价格 314 LOOP AT F_MATPR-CR INTO F_MATCR. 315 F_MATCR-NEWPEINH = LV_TAB-KPEIN. "新价格单位 316 "检查币种,获取汇率 317 CLEAR L_RX. 318 CLEAR L_KBETR. 319 IF F_MATCR-WAERS = LV_TAB-WAERS. 320 L_KBETR = LV_TAB-KBETR. 321 322 323 324 325 326 ELSE. 327 328 CLEAR L_RX. 329 data: L_rate TYPE p LENGTH 15 DECIMALS 7. 330 data: L_TMP type TZNTSTMPL. 331 clear: L_TMP , L_RATE. 332 CALL FUNCTION 'ZRFC_EXCHANGERATE_GETDETAIL' 333 EXPORTING 334 FROM_CURR = LV_TAB-WAERS 335 TO_CURRNCY = F_MATCR-WAERS 336 IMPORTING 337 NEW_RATE = L_TMP. 338 * EXCH_RATE = L_RX. "注释by kasen 20200318 339 Move L_TMP to L_RATE. 340 L_KBETR = LV_TAB-KBETR * L_RATE * V_FACTOR. 341 342 ENDIF. 343 344 "更新价格类型 345 IF L_VPRSV = 'V'. 346 F_MATCR-NEWPVPRS = L_KBETR. "移动平均价 347 IF F_MATCR-NEWPVPRS <> F_MATCR-PVPRS 348 OR F_MATCR-NEWPEINH <> F_MATCR-PEINH. 349 350 F_MATCR-MANPAE_V = 'X'. "价格变更标志 351 ENDIF. 352 ELSE. 353 F_MATCR-NEWSTPRS = L_KBETR. "标准价格 354 IF F_MATCR-NEWSTPRS <> F_MATCR-STPRS 355 OR F_MATCR-NEWPEINH <> F_MATCR-PEINH. 356 357 F_MATCR-MANPAE_S = 'X'. "价格变更标志 358 ENDIF. 359 ENDIF. 360 361 362 MODIFY F_MATPR-CR FROM F_MATCR. 363 364 ENDLOOP. 365 366 MODIFY T_MATPR FROM F_MATPR INDEX H_INDEX. 367 ENDIF. 368 369 ENDLOOP. 370 371 IF T_MATPR[] IS INITIAL. "没有记录 372 G_RT = 1. 373 RETURN. 374 ENDIF. 375 376 *---------------------------------------------------------------------- 377 * 检查变更的物料 并保存更新 378 *---------------------------------------------------------------------- 379 PERFORM KALK_ENRICH CHANGING 380 T_MATPR. 381 382 CALL FUNCTION 'CM_F_INITIALIZE' 383 EXPORTING 384 APLID = 'CKPF'. 385 386 "检查数据 387 CALL FUNCTION 'PRICES_CHANGE' 388 EXPORTING 389 ACTUAL_BDATJ = H_BDATJ 390 ACTUAL_POPER = H_POPER 391 BUKRS = F_MR21HEAD-BUKRS 392 BUDAT = F_MR21HEAD-BUDAT 393 XBLNR = F_MR21HEAD-XBLNR 394 * account_modification = h_komok 395 * subs_dbt = 'X' 396 TABLES 397 T_MATPR = T_MATPR 398 EXCEPTIONS 399 ERROR_MESSAGE = 1 400 INVALID_PERIOD = 2 401 OTHERS = 3. 402 403 404 "没有物料的价格变更 405 READ TABLE T_MATPR WITH KEY PP-XERROR = ' ' 406 TRANSPORTING NO FIELDS. 407 IF SY-SUBRC <> 0. 408 G_RT = 1. 409 * MESSAGE i046(ckprch). 410 CLEAR LV_MSG. 411 LV_MSG-ARBGB = 'CKPRCH'. 412 LV_MSG-MSGTY = 'I'. 413 LV_MSG-MSGNR = '046'. 414 APPEND LV_MSG TO GT_MSG. 415 * Es wurden keine Preisänderungen durchgeführt 416 ELSE. 417 418 * Falls Customizing für variable KOMOKs gepflegt, wird hier der 419 * eingetragene KOMOK an Prices_Post mit dem Belegkopftext übergeben. 420 "更新数据 421 CALL FUNCTION 'PRICES_POST' 422 EXPORTING 423 I_BKTXT = F_MR21HEAD-BKTXT 424 BUKRS = F_MR21HEAD-BUKRS 425 LIS_UPDATE = 'X' 426 TABLES 427 T_MATPR = T_MATPR. 428 429 430 CALL FUNCTION 'CM_F_MESSAGES_GET' 431 EXPORTING 432 APLID = 'CKPF' 433 TABLES 434 E_MSGPROT = LT_MSG. 435 436 APPEND LINES OF LT_MSG TO GT_MSG. 437 * LOOP AT lt_msg INTO lv_msg WHERE MSGTY = 'A' OR MSGTY = 'E'. 438 * g_rt = 1. 439 * EXIT. 440 * ENDLOOP. 441 * IF g_rt = 1. 442 * ROLLBACK WORK. 443 * RETURN. 444 * ELSE. 445 * COMMIT WORK. 446 * ENDIF. 447 448 COMMIT WORK. 449 450 ENDIF. 451 452 453 ENDFORM. 454 455 456 *&---------------------------------------------------------------------* 457 *& Form kalk_enrich 458 *&---------------------------------------------------------------------* 459 * Die Untertabelle CKMLPR aus dem globalen Kontrollblock 460 * GD_MATCB_TBL sowie die Untertabelle KEKO aus dem globalen 461 * Kontrollbrlock GD_KEKOCB_TBL 462 * wird in die Struktur R_MATPR übertragen, falls es 463 * zu dem Material eine Plankalkulation existiert. 464 *----------------------------------------------------------------------* 465 * <--> R_MATPR Liste der Materialien 466 *----------------------------------------------------------------------* 467 FORM KALK_ENRICH CHANGING 468 R_MATPR TYPE CKMPR_MAT_PRICE. 469 470 FIELD-SYMBOLS: 471 <R_MATPR> LIKE LINE OF R_MATPR, 472 <MATCR> TYPE LINE OF CKMPR_CURTP_PRICES. 473 474 DATA: 475 LD_COSTING_TO_RELEASE TYPE BOOLE_D, 476 LD_WA_MATCB LIKE LINE OF GD_MATCB_TBL, 477 LD_WA_KEKOCB LIKE LINE OF GD_KEKOCB_TBL. 478 479 LOOP AT R_MATPR ASSIGNING <R_MATPR>. 480 481 * Existiert zu irgendeiner Währung eine Plankalkulation? 482 CLEAR LD_COSTING_TO_RELEASE. 483 LOOP AT <R_MATPR>-CR ASSIGNING <MATCR>. 484 IF <MATCR>-ERZKALK = Y_X. 485 LD_COSTING_TO_RELEASE = Y_X. 486 ENDIF. 487 ENDLOOP. 488 UNASSIGN <MATCR>. 489 CHECK NOT LD_COSTING_TO_RELEASE IS INITIAL. 490 491 * Übertragen der Tabelle für die zukünftigen Preise 492 * aus dem globalen Kontrollblock in die T_MATPR 493 READ TABLE GD_MATCB_TBL INTO LD_WA_MATCB 494 WITH TABLE KEY KALNR = <R_MATPR>-PP-KALN1. 495 IF SY-SUBRC EQ 0. 496 <R_MATPR>-CKMLPR[] = LD_WA_MATCB-CKMLPR[]. 497 ENDIF. 498 * Übertragen der Tabelle für die Kalkulationsdaten 499 * aus dem globalen Kontrollblock in die T_MATPR 500 READ TABLE GD_KEKOCB_TBL INTO LD_WA_KEKOCB 501 WITH TABLE KEY KALNR = <R_MATPR>-PP-KALN1. 502 IF SY-SUBRC EQ 0. 503 <R_MATPR>-KEKO[] = LD_WA_KEKOCB-KEKO[]. 504 ENDIF. 505 ENDLOOP. 506 UNASSIGN <R_MATPR>. 507 508 ENDFORM. " kalk_enrich 509 510 *&---------------------------------------------------------------------* 511 *& Form MARV_CHECK 512 *&---------------------------------------------------------------------* 513 * text 514 *----------------------------------------------------------------------* 515 * -->P_XRUEM text * 516 * -->P_XRUEJ text * 517 *----------------------------------------------------------------------* 518 FORM MARV_CHECK USING P_XRUEM TYPE XFELD 519 P_XRUEJ TYPE XFELD 520 P_RET TYPE STRING. 521 DATA: MESSAGE_TEXT(60). 522 523 TABLES: CKMLMVADMIN. 524 STATICS: ADMIN_READ TYPE C, 525 ALLOW_BACKPOSTING TYPE C. 526 527 IF ADMIN_READ IS INITIAL. 528 ADMIN_READ = Y_X. 529 SELECT SINGLE * FROM CKMLMVADMIN 530 WHERE KKEY = 'MR21_XRUEM'. 531 IF SY-SUBRC = 0 AND CKMLMVADMIN-KDATA+0(1) = Y_X. 532 ALLOW_BACKPOSTING = Y_X. 533 ENDIF. 534 ENDIF. 535 536 CLEAR: P_XRUEM, 537 P_XRUEJ. 538 539 IF BDATJ NE MARV-LFGJA 540 OR POPER NE MARV-LFMON. 541 IF BDATJ = MARV-VJGJA 542 AND POPER = MARV-VJMON. 543 544 *------- Rueckbuchen Vorjahr -----------------------------------------* 545 P_XRUEJ = 'X'. 546 IF BDATJ = MARV-VMGJA 547 AND POPER = MARV-VMMON. 548 549 *------- Rueckbuchen Vorjahr gleich Vormonat -------------------------* 550 P_XRUEM = 'X'. 551 ELSE. 552 *------- Rueckbuchen Vorjahr ungleich Vormonat------------------------* 553 IF MARV-XRUEM = SPACE AND ALLOW_BACKPOSTING IS INITIAL. 554 CALL FUNCTION 'MB_EDIT_MESSAGE' 555 EXPORTING 556 T1 = MARV-LFMON 557 T2 = MARV-LFGJA 558 IMPORTING 559 MESSAGE = MESSAGE_TEXT. 560 ELSE. 561 CALL FUNCTION 'MB_EDIT_MESSAGE' 562 EXPORTING 563 T1 = MARV-LFMON 564 T2 = MARV-LFGJA 565 T3 = '/' 566 T4 = MARV-VMMON 567 T5 = MARV-VMGJA 568 IMPORTING 569 MESSAGE = MESSAGE_TEXT. 570 ENDIF. 571 "ADD BY LH 20180906 572 * MESSAGE ID 'CKPRCH' TYPE 'E' NUMBER '009' WITH message_text. 573 P_RET = MESSAGE_TEXT. 574 RETURN. 575 576 ENDIF. 577 ELSE. 578 IF BDATJ = MARV-VMGJA 579 AND POPER = MARV-VMMON 580 AND ( MARV-XRUEM NE SPACE OR ALLOW_BACKPOSTING = Y_X ). 581 582 *------- Rueckbuchen Monat -------------------------------------------* 583 P_XRUEM = 'X'. 584 ELSE. 585 586 *------- Periode ungueltig -------------------------------------------* 587 IF MARV-XRUEM = SPACE AND ALLOW_BACKPOSTING IS INITIAL. 588 CALL FUNCTION 'MB_EDIT_MESSAGE' 589 EXPORTING 590 T1 = MARV-LFMON 591 T2 = MARV-LFGJA 592 IMPORTING 593 MESSAGE = MESSAGE_TEXT. 594 ELSE. 595 CALL FUNCTION 'MB_EDIT_MESSAGE' 596 EXPORTING 597 T1 = MARV-LFMON 598 T2 = MARV-LFGJA 599 T3 = '/' 600 T4 = MARV-VMMON 601 T5 = MARV-VMGJA 602 IMPORTING 603 MESSAGE = MESSAGE_TEXT. 604 ENDIF. 605 "ADD BY LH 20180906 606 * MESSAGE ID 'CKPRCH' TYPE 'E' NUMBER '009' WITH message_text. 607 P_RET = MESSAGE_TEXT. 608 RETURN. 609 610 ENDIF. 611 ENDIF. 612 ENDIF. 613 614 ENDFORM. " MARV_CHECK