销售订单批导
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 |
FUNCTION zsdfu006. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_AUART) TYPE AUART *" VALUE(I_VKORG) TYPE VKORG *" VALUE(I_VTWEG) TYPE VTWEG *" VALUE(I_SPART) TYPE SPART *" VALUE(I_VKBUR) TYPE VKBUR OPTIONAL *" VALUE(I_VKGRP) TYPE VKGRP OPTIONAL *" VALUE(I_KUNAG) TYPE KUNAG *" VALUE(I_AUGRU) TYPE AUGRU OPTIONAL *" VALUE(I_LPRIO) TYPE LPRIO OPTIONAL *" VALUE(I_BSTKD) TYPE BSTKD OPTIONAL *" VALUE(I_KUNNR_KP) TYPE KUNNR OPTIONAL *" VALUE(I_KUNNR_YW) TYPE KUNNR OPTIONAL *" VALUE(I_BUDAT) TYPE BUDAT DEFAULT SY-DATUM *" VALUE(I_WLFY_Z001) TYPE KWERT OPTIONAL *" VALUE(I_WLFY_Z002) TYPE KWERT OPTIONAL *" VALUE(I_BY) TYPE ZRFC001 OPTIONAL *" EXPORTING *" VALUE(E_CODE) TYPE MSGTY *" VALUE(E_MSG) TYPE MSGTXT *" VALUE(E_VBELN) TYPE VBELN *" VALUE(E_BY) TYPE ZRFC002 *" TABLES *" IT_ITEM STRUCTURE ZSDS0006 OPTIONAL *" IT_TX STRUCTURE ZSDS0006_1 OPTIONAL *" IT_WL STRUCTURE ZSDT002 OPTIONAL *"---------------------------------------------------------------------- IF 1 = 1. ENDIF. INCLUDE zfunc_top. "RFC日志管理-定义抬头文件 INCLUDE zfunc_begin. "RFC日志管理-记录接收数据 "数据补充 PERFORM conv_alpha CHANGING i_kunag. PERFORM conv_alpha CHANGING i_kunnr_kp. PERFORM conv_alpha CHANGING i_kunnr_yw. LOOP AT it_item. PERFORM conv_matnr CHANGING it_item-matnr. MODIFY it_item. ENDLOOP. "判断数据 LOOP AT it_item WHERE posnr IS INITIAL. ENDLOOP. IF sy-subrc = 0. e_code = 'E'. e_msg = 'IT_ITEM表存在行项目号码为空'. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 EXIT. ENDIF. LOOP AT it_item WHERE zzztdd IS NOT INITIAL. SELECT SINGLE * INTO @DATA(l_zvbap) FROM zvbap WHERE zzztdd = @it_item-zzztdd AND zzztdd_posnr = @it_item-zzztdd_posnr. IF sy-subrc = 0. e_code = 'E'. EXIT. ENDIF. ENDLOOP. IF e_code = 'E'.. CONCATENATE '中台订单' it_item-zzztdd '行项目' it_item-zzztdd_posnr '存在SAP销售订单' l_zvbap-vbeln ',不允许重复创建' INTO e_msg. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 EXIT. ENDIF. LOOP AT it_tx WHERE posnr IS INITIAL. ENDLOOP. IF sy-subrc = 0. e_code = 'E'. e_msg = 'IT_TX表存在行项目号码为空'. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 EXIT. ENDIF. LOOP AT it_wl WHERE posnr IS INITIAL. ENDLOOP. IF sy-subrc = 0. e_code = 'E'. e_msg = 'IT_WL表存在行项目号码为空'. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 EXIT. ENDIF. DATA: lv_matnr TYPE matnr. DATA: it_in TYPE TABLE OF zpps0020, ls_in TYPE zpps0020. "----判断物料是否存在,不存在则根据 CL30N 获取物料。 "---------------------------------------------------------- "---------------------------------------------------------- DATA: lv_flag TYPE c. CLEAR lv_flag. LOOP AT it_item. IF it_item-matnr IS INITIAL. LOOP AT it_tx WHERE posnr = it_item-posnr AND ( atnam = 'ZC_FM_LK' OR atnam = 'ZC_JB_KB' OR atnam = 'ZC_CPLX' ). MOVE-CORRESPONDING it_tx TO ls_in. APPEND ls_in TO it_in. CLEAR: it_tx,ls_in. ENDLOOP. CALL FUNCTION 'ZPPFU022' EXPORTING i_class = 'Z_CB' i_classtype = '300' IMPORTING e_code = e_code e_msg = e_msg e_matnr = lv_matnr TABLES it_in = it_in. IF e_code = 'E'. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 lv_flag = 'X'."如果有错误直接返回 CONTINUE.. ELSE. it_item-matnr = lv_matnr. ENDIF. MODIFY it_item. ENDIF. CLEAR it_item. ENDLOOP. IF lv_flag = 'X'. RETURN. ENDIF. "---------------------------------------------------------- "---------------------------------------------------------- "交货日期给默认值 LOOP AT it_item. IF it_item-etdat IS INITIAL. it_item-etdat = sy-datum. ENDIF. MODIFY it_item. ENDLOOP. "提交BAPI DATA: ls_order_header_in TYPE bapisdhd1, ls_order_header_inx TYPE bapisdhd1x. DATA: lv_vbeln TYPE bapivbeln-vbeln, ls_return TYPE bapiret2, lt_return LIKE TABLE OF ls_return, lv_posnr TYPE posnr. DATA: ls_vc_ref TYPE bapicucfg, lt_vc_ref TYPE TABLE OF bapicucfg, ls_vc_inst TYPE bapicuins, lt_vc_inst TYPE TABLE OF bapicuins, ls_vc_value TYPE bapicuval, lt_vc_value TYPE TABLE OF bapicuval, ls_vc_vk TYPE bapicuvk, lt_vc_vk TYPE TABLE OF bapicuvk. DATA: lt_order_items_in LIKE TABLE OF bapisditm, ls_order_items_in LIKE LINE OF lt_order_items_in. DATA: lt_order_items_inx LIKE TABLE OF bapisditmx, ls_order_items_inx LIKE LINE OF lt_order_items_inx. DATA: lt_order_partners LIKE TABLE OF bapiparnr, ls_order_partners TYPE bapiparnr. DATA: lt_order_schedules_in LIKE TABLE OF bapischdl, ls_order_schedules_in LIKE LINE OF lt_order_schedules_in. DATA: lt_order_schedules_inx LIKE TABLE OF bapischdlx, ls_order_schedules_inx LIKE LINE OF lt_order_schedules_inx. DATA: lt_order_conditions_in LIKE TABLE OF bapicond, ls_order_conditions_in LIKE LINE OF lt_order_conditions_in. DATA: lt_order_conditions_inx LIKE TABLE OF bapicondx, ls_order_conditions_inx LIKE LINE OF lt_order_conditions_inx. DATA : ls_bapiparex TYPE bapiparex, lt_bapiparex TYPE TABLE OF bapiparex, logic_switch TYPE bapisdls. DATA : lt_bapisdtext TYPE TABLE OF bapisdtext, ls_bapisdtext TYPE bapisdtext. REFRESH lt_bapisdtext . DATA : lv_msg TYPE string, lv_error. DATA:lv_bddat TYPE bddat. DATA : lv_ebeln TYPE ekko-ebeln . DATA lv_pstyv TYPE pstyv . DATA ls_taxm1 TYPE mlan-taxm1. REFRESH : lt_order_items_in ,lt_order_items_inx ,lt_order_partners ,lt_order_schedules_in , lt_order_schedules_inx ,lt_order_conditions_in ,lt_order_conditions_inx ,lt_return . CLEAR: lt_vc_ref[], lt_vc_inst[], lt_vc_value[], lt_vc_vk[]. CLEAR : lv_error . CLEAR lv_posnr . REFRESH:lt_bapisdtext , lt_bapiparex. "销售订单创建 ************抬头************ CLEAR :ls_order_header_inx ,ls_order_header_in. ls_order_header_in-doc_type = i_auart. "销售凭证类型 ls_order_header_inx-doc_type = 'X' . ls_order_header_in-doc_date = i_budat. ls_order_header_inx-doc_date = 'X'. ls_order_header_in-req_date_h = i_budat. ls_order_header_inx-req_date_h = 'X'. ls_order_header_in-price_date = i_budat. ls_order_header_inx-price_date = 'X'. * ls_order_header_in-compl_dlv = 'X'. * ls_order_header_inx-compl_dlv = 'X'. ls_order_header_in-purch_no_c = i_bstkd. "客户采购订单编号 IF i_bstkd IS INITIAL. ls_order_header_in-purch_no_c = sy-datum. ENDIF. ls_order_header_inx-purch_no_c = 'X' . ls_order_header_in-sales_org = i_vkorg ."销售组织 ls_order_header_inx-sales_org = 'X' . ls_order_header_in-distr_chan = i_vtweg ."分销渠道 ls_order_header_inx-distr_chan = 'X' . ls_order_header_in-division = i_spart ."产品组 ls_order_header_inx-division = 'X' . ls_order_header_in-sales_off = i_vkbur ."销售办公室 ls_order_header_inx-sales_off = 'X' . ls_order_header_in-sales_grp = i_vkgrp ."销售组 ls_order_header_inx-sales_grp = 'X' . ls_order_header_in-ord_reason = i_augru . "订单原因 ls_order_header_inx-ord_reason = 'X' . * logic_switch-pricing = 'K'. * "*******文本********** * clear ls_bapisdtext . ** LS_BAPISDTEXT-ITM_NUMBER = LV_POSNR . * ls_bapisdtext-text_id = '0001' . * ls_bapisdtext-langu = '1' . * ls_bapisdtext-langu_iso = 'ZH' . * ls_bapisdtext-format_col = '*'. * ls_bapisdtext-text_line = i_header-ltext . * append ls_bapisdtext to lt_bapisdtext . ************合作伙伴************ CLEAR :lt_order_partners[] , ls_order_partners . "售达方\"收票方\ "付款方\"送达方 DATA: ls_knvp TYPE knvp, lt_knvp TYPE TABLE OF knvp. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_knvp FROM knvp WHERE kunnr = i_kunag AND vkorg = i_vkorg AND vtweg IN ('10','80') AND spart = '99'"i_spart AND parvw IN ('AG','RE','RG','WE'). LOOP AT lt_knvp INTO ls_knvp. CLEAR ls_order_partners . ls_order_partners-partn_numb = ls_knvp-kunn2. ls_order_partners-partn_role = ls_knvp-parvw. ls_order_partners-country = 'CN'. APPEND ls_order_partners TO lt_order_partners. ENDLOOP. IF i_kunnr_kp IS NOT INITIAL. CLEAR ls_order_partners . ls_order_partners-partn_numb = i_kunnr_kp. ls_order_partners-partn_role = 'Z2'. ls_order_partners-country = 'CN'. APPEND ls_order_partners TO lt_order_partners. ENDIF. IF i_kunnr_yw IS NOT INITIAL. CLEAR ls_order_partners . ls_order_partners-partn_numb = i_kunnr_yw. ls_order_partners-partn_role = 'VE'. ls_order_partners-country = 'CN'. APPEND ls_order_partners TO lt_order_partners. ENDIF. "物流费用 IF i_wlfy_z001 IS NOT INITIAL. CLEAR: ls_order_conditions_in. ls_order_conditions_in-itm_number = '000000'. * ls_order_conditions_in-cond_st_no = 1. "步骤编号 ls_order_conditions_in-cond_type = 'Z001'. ls_order_conditions_in-cond_value = i_wlfy_z001 / 10. "价格 ls_order_conditions_in-cond_p_unt = 1. ls_order_conditions_in-cond_updat = 'X'. APPEND ls_order_conditions_in TO lt_order_conditions_in. ENDIF. IF i_wlfy_z002 IS NOT INITIAL. CLEAR: ls_order_conditions_in. ls_order_conditions_in-itm_number = '000000'. * ls_order_conditions_in-cond_st_no = 2. ls_order_conditions_in-cond_type = 'Z002'. ls_order_conditions_in-cond_value = i_wlfy_z002 / 10. "价格-保价 ls_order_conditions_in-cond_p_unt = 1. ls_order_conditions_in-cond_updat = 'X'. APPEND ls_order_conditions_in TO lt_order_conditions_in. ENDIF. ******************************行项目************************* LOOP AT it_item. CLEAR ls_order_items_in. ls_order_items_in-itm_number = it_item-posnr. "行项目 ls_order_items_in-po_itm_no = it_item-posnr. "行项目 ls_order_items_in-material = it_item-matnr. "物料 ls_order_items_in-mat_entrd = it_item-matnr . ls_order_items_in-plant = it_item-werks . CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' EXPORTING input = it_item-vrkme language = sy-langu IMPORTING output = ls_order_items_in-sales_unit EXCEPTIONS unit_not_found = 1 OTHERS = 2. CLEAR ls_order_items_inx . IF it_item-kwmeng < 0. it_item-kwmeng = 0 - it_item-kwmeng. ENDIF. ls_order_items_in-target_qty = it_item-kwmeng. "销售数量 ls_order_items_inx-itm_number = it_item-posnr . "行项目 ls_order_items_inx-po_itm_no = 'X' . "行项目 ls_order_items_inx-mat_entrd = 'X' . ls_order_items_inx-material = 'X'. "物料 IF ls_order_items_in-sales_unit IS NOT INITIAL. ls_order_items_inx-sales_unit = 'X'. "销售单位 ENDIF. ls_order_items_inx-target_qty = 'X'. "销售数量 ls_order_items_inx-updateflag = 'X' . "更新标识 IF ls_order_items_in-plant IS NOT INITIAL. ls_order_items_inx-plant = 'X' . "工厂 ENDIF. IF ls_order_items_in-store_loc IS NOT INITIAL. ls_order_items_inx-store_loc = 'X' . "库存地 ENDIF. IF ls_order_items_in-batch IS NOT INITIAL. ls_order_items_inx-batch = 'X'. ENDIF. IF i_lprio IS NOT INITIAL. ls_order_items_in-dlv_prio = i_lprio. ls_order_items_inx-dlv_prio = 'X'. ENDIF. IF i_auart NE 'ZCR' AND i_auart NE 'ZDR' AND i_auart NE 'ZOR2'. IF it_item-dj_pr01 IS INITIAL. "行项目类别 "免费 SELECT COUNT(*) FROM mvke WHERE matnr = it_item-matnr AND vkorg = i_vkorg AND vtweg = '10' AND mtpos = '0002'. IF sy-subrc = 0. ls_order_items_in-item_categ = 'Z001'. ls_order_items_inx-item_categ = 'X'. ENDIF. SELECT COUNT(*) FROM mvke WHERE matnr = it_item-matnr AND vkorg = i_vkorg AND vtweg = '10' AND mtpos = 'NORM'. IF sy-subrc = 0. ls_order_items_in-item_categ = 'TANN'. ls_order_items_inx-item_categ = 'X'. ENDIF. ELSE. "收费 SELECT COUNT(*) FROM mvke WHERE matnr = it_item-matnr AND vkorg = i_vkorg AND vtweg = '10' AND mtpos = '0002'. IF sy-subrc = 0. ls_order_items_in-item_categ = 'TAC'. ls_order_items_inx-item_categ = 'X'. ENDIF. SELECT COUNT(*) FROM mvke WHERE matnr = it_item-matnr AND vkorg = i_vkorg AND vtweg = '10' AND mtpos = 'NORM'. IF sy-subrc = 0. ls_order_items_in-item_categ = 'TAN'. ls_order_items_inx-item_categ = 'X'. ENDIF. ENDIF. ELSEIF i_auart = 'ZOR2'. IF it_item-dj_pr01 IS INITIAL. "行项目类别 "免费 SELECT COUNT(*) FROM mvke WHERE matnr = it_item-matnr AND vkorg = i_vkorg AND vtweg = '10' AND mtpos = '0002'. IF sy-subrc = 0. ls_order_items_in-item_categ = 'Z005'. ls_order_items_inx-item_categ = 'X'. ENDIF. ENDIF. ENDIF. APPEND ls_order_items_inx TO lt_order_items_inx . APPEND ls_order_items_in TO lt_order_items_in. "*************计划行************ IF i_auart NE 'ZCR' AND i_auart NE 'ZDR'. CLEAR ls_order_schedules_in . ls_order_schedules_in-itm_number = it_item-posnr . "行项目号 ls_order_schedules_in-sched_line = '0001' . "行项目号 ls_order_schedules_in-req_date = it_item-etdat . "计划行日期 ls_order_schedules_in-req_qty = it_item-kwmeng . "数量 ls_order_schedules_in-date_type = 1 . "日期类型 APPEND ls_order_schedules_in TO lt_order_schedules_in . CLEAR ls_order_schedules_inx . ls_order_schedules_inx-itm_number = it_item-posnr . "行项目号 ls_order_schedules_inx-sched_line = '0001' . "行项目号 ls_order_schedules_inx-req_date = 'X' . "计划行日期 ls_order_schedules_inx-req_qty = 'X' . "数量 ls_order_schedules_inx-updateflag = 'X' . "更新标识 ls_order_schedules_inx-date_type = 'X' . "日期类型 APPEND ls_order_schedules_inx TO lt_order_schedules_inx . ENDIF. "价格 DEFINE add_price. IF it_item-&1 IS NOT INITIAL. CLEAR: ls_order_conditions_in. ls_order_conditions_in-itm_number = it_item-posnr . ls_order_conditions_in-cond_type = &2. SELECT COUNT(*) FROM t685a WHERE kappl = 'V' AND kschl = &2 AND krech = 'A' . IF sy-subrc = 0. ls_order_conditions_in-cond_value = it_item-&1. "百分比 ELSE. ls_order_conditions_in-cond_value = it_item-&1 / 10. "价格 ENDIF. ls_order_conditions_in-cond_p_unt = &3. ls_order_conditions_in-cond_updat = 'X'. APPEND ls_order_conditions_in TO lt_order_conditions_in. ENDIF. END-OF-DEFINITION. IF it_item-dj_pr01_kpein = 0. it_item-dj_pr01_kpein = 1. ENDIF. add_price dj_pr01 'PR01' it_item-dj_pr01_kpein. add_price dj_zk01 'ZK01' '1'. add_price dj_zk02 'ZK02' '1'. IF i_vkorg+0(1) = '1'. add_price dj_zjs1 'ZJS1' '1'. ENDIF. IF it_item-dj_zpur > 0. it_item-dj_zpur = it_item-dj_zpur * 1000. SELECT SINGLE taxm1 INTO ls_taxm1 FROM mlan WHERE matnr = it_item-matnr AND aland = 'CN'. CASE ls_taxm1. WHEN 0. add_price dj_zpur 'ZPUR' '1000'. WHEN 1. add_price dj_zpur 'ZPUR' '1170'. WHEN 2. add_price dj_zpur 'ZPUR' '1160'. WHEN 3. add_price dj_zpur 'ZPUR' '1130'. WHEN 4. add_price dj_zpur 'ZPUR' '1110'. WHEN 5. add_price dj_zpur 'ZPUR' '1100'. WHEN 6. add_price dj_zpur 'ZPUR' '1060'. WHEN 7. add_price dj_zpur 'ZPUR' '1050'. WHEN 8. add_price dj_zpur 'ZPUR' '1030'. ENDCASE. ENDIF. add_price dj_zmy 'ZMY' '1'. * "*******文本********** CLEAR ls_bapisdtext . ls_bapisdtext-doc_number = '' . ls_bapisdtext-itm_number = it_item-posnr . ls_bapisdtext-text_id = '0001' . ls_bapisdtext-langu = '1' . ls_bapisdtext-langu_iso = 'ZH' . ls_bapisdtext-format_col = '*'. ls_bapisdtext-text_line = it_item-remarks . APPEND ls_bapisdtext TO lt_bapisdtext . MODIFY it_item. ENDLOOP. DATA: BEGIN OF ls_vc_posnr, posnr TYPE posnr, END OF ls_vc_posnr, lt_vc_posnr LIKE TABLE OF ls_vc_posnr. lt_vc_posnr[] = CORRESPONDING #( it_tx[] ). SORT lt_vc_posnr[]. DELETE ADJACENT DUPLICATES FROM lt_vc_posnr. LOOP AT lt_vc_posnr INTO ls_vc_posnr. ls_vc_ref-posex = ls_vc_posnr-posnr. ls_vc_ref-config_id = ls_vc_posnr-posnr. ls_vc_ref-root_id = ls_vc_posnr-posnr. ls_vc_ref-complete = 'T'. ls_vc_ref-consistent = 'T'. APPEND ls_vc_ref TO lt_vc_ref. ls_vc_inst-config_id = ls_vc_posnr-posnr. ls_vc_inst-inst_id = ls_vc_posnr-posnr. ls_vc_inst-obj_type = 'MARA'. ls_vc_inst-class_type = 'KL'. * ls_vc_inst-quantity_unit = '300'. APPEND ls_vc_inst TO lt_vc_inst. ENDLOOP. LOOP AT it_tx. ls_vc_value-config_id = it_tx-posnr. ls_vc_value-inst_id = it_tx-posnr. ls_vc_value-charc = it_tx-atnam. ls_vc_value-value = it_tx-atwrt. APPEND ls_vc_value TO lt_vc_value. ls_vc_vk-config_id = it_tx-posnr. ls_vc_vk-inst_id = it_tx-posnr. ls_vc_vk-vkey = it_tx-atnam. APPEND ls_vc_vk TO lt_vc_vk. ENDLOOP. sy-batch = 'X'. CLEAR:e_vbeln, lv_vbeln . IF i_auart CS 'ZOR' OR i_auart = 'ZCR' OR i_auart = 'ZDR'. CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' EXPORTING order_header_in = ls_order_header_in order_header_inx = ls_order_header_inx logic_switch = logic_switch IMPORTING salesdocument = lv_vbeln TABLES return = lt_return order_items_in = lt_order_items_in order_items_inx = lt_order_items_inx order_partners = lt_order_partners order_schedules_in = lt_order_schedules_in order_schedules_inx = lt_order_schedules_inx order_conditions_in = lt_order_conditions_in order_conditions_inx = lt_order_conditions_inx order_cfgs_ref = lt_vc_ref order_cfgs_inst = lt_vc_inst order_cfgs_value = lt_vc_value order_cfgs_vk = lt_vc_vk order_text = lt_bapisdtext EXCEPTIONS error_message = 4. ELSE. CALL FUNCTION 'BAPI_CUSTOMERRETURN_CREATE' "退货订单 EXPORTING * SALESDOCUMENTIN = return_header_in = ls_order_header_in return_header_inx = ls_order_header_inx * SENDER = * BINARY_RELATIONSHIPTYPE = * INT_NUMBER_ASSIGNMENT = * BEHAVE_WHEN_ERROR = logic_switch = logic_switch * TESTRUN = * CONVERT = ' ' IMPORTING salesdocument = lv_vbeln TABLES return = lt_return return_items_in = lt_order_items_in return_items_inx = lt_order_items_inx return_partners = lt_order_partners return_schedules_in = lt_order_schedules_in return_schedules_inx = lt_order_schedules_inx return_conditions_in = lt_order_conditions_in return_cfgs_ref = lt_vc_ref return_cfgs_inst = lt_vc_inst * RETURN_CFGS_PART_OF = return_cfgs_value = lt_vc_value * RETURN_CFGS_BLOB = return_cfgs_vk = lt_vc_vk * RETURN_CFGS_REFINST = return_text = lt_bapisdtext * RETURN_KEYS = * EXTENSIONIN = * PARTNERADDRESSES = EXCEPTIONS error_message = 4. . ENDIF. IF lv_vbeln IS NOT INITIAL. e_vbeln = lv_vbeln . PERFORM conv_alpha_out CHANGING e_vbeln. e_code = 'S'. e_msg = '销售订单:' && lv_vbeln && '创建成功!'. "销售订单号赋值 DATA: ls_zvbap TYPE zvbap, lt_zvbap TYPE TABLE OF zvbap. lt_zvbap[] = CORRESPONDING #( it_item[] ). LOOP AT lt_zvbap INTO ls_zvbap. ls_zvbap-vbeln = lv_vbeln. MODIFY lt_zvbap FROM ls_zvbap. ENDLOOP. LOOP AT it_wl. it_wl-vbeln = lv_vbeln. MODIFY it_wl. ENDLOOP. "调用更新函数 CALL FUNCTION 'ZSDFU006_UPDATE_TASK' IN UPDATE TASK TABLES it_zvbap = lt_zvbap it_wl = it_wl. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 "----------------------------------------------------- "----------------------------------------------------- "记录表,并执行后续函数 DATA: lt_save TYPE TABLE OF zppt035, ls_save TYPE zppt035. TYPES: BEGIN OF ty_bjlx, atkla TYPE atkla. INCLUDE STRUCTURE zsds0006_1. TYPES: END OF ty_bjlx. "--部件类型汇总表 DATA: lt_bjlx TYPE TABLE OF ty_bjlx, ls_bjlx TYPE ty_bjlx. "---更加特征获取部件类型 DATA: lt_bjlx_1 TYPE TABLE OF ty_bjlx, ls_bjlx_1 TYPE ty_bjlx. DATA: lt_dd03l TYPE TABLE OF dd03l, ls_dd03l TYPE dd03l. DATA: lt_zppt034 TYPE TABLE OF zppt034, ls_zppt034 TYPE zppt034. FIELD-SYMBOLS <ls_zppt034>. DATA: lv_name TYPE char140, lv_flag_1 TYPE c. FIELD-SYMBOLS: <fs>. "限定订单类型,创建订单BOM,工艺,生产订单 IF i_auart = 'ZOR1' OR i_auart = 'ZOR3' OR i_auart = 'ZOR4' OR i_auart = 'ZOR6'. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_dd03l FROM dd03l WHERE tabname = 'ZPPT034'. "---所有特性加特征组 LOOP AT it_tx. MOVE-CORRESPONDING it_tx TO ls_bjlx_1. SELECT SINGLE atkla INTO ls_bjlx_1-atkla FROM cabn WHERE atnam = it_tx-atnam. APPEND ls_bjlx_1 TO lt_bjlx_1. CLEAR: it_tx, ls_bjlx_1. ENDLOOP. "赋值 REFRESH lt_save. CLEAR ls_save. LOOP AT it_item. CLEAR ls_save. REFRESH lt_save[]. ls_save-vbeln = lv_vbeln. ls_save-posnr = it_item-posnr. ls_save-matnr = it_item-matnr. ls_save-zdrrq = sy-datum."导入日期 ls_save-zdrsj = sy-uzeit."导入时间 ls_save-werks = it_item-werks." "当特性ZC_JB_SFTS = “0000”时,“维护状态”字段为“2”(未维护),其余情况均默认为“1”(已维护)。 READ TABLE it_tx WITH KEY posnr = it_item-posnr atnam = 'ZC_JB_TSMC'. IF sy-subrc = 0. IF it_tx-atwrt IS NOT INITIAL. ls_save-zwhzt = '2'. ELSE. ls_save-zwhzt = '1'. ENDIF. ELSE. ls_save-zwhzt = '1'. ENDIF. "---判断评审类型 "工厂包含2000/2010/2020,物料CUCO- STLKD字段为“X”, 维护状态为“1”的销售订单和行项目。 IF ( it_item-werks = '2000' OR it_item-werks = '2010' OR it_item-werks = '2020' OR it_item-werks = '3000' OR it_item-werks = '3010' OR it_item-werks = '3020' ) AND ls_save-zwhzt = '1'. SELECT COUNT(*) FROM cuco WHERE obtab = 'MARA' AND objek = it_item-matnr AND stlkd = 'X'. IF sy-subrc = 0. "---汇总部件类型,要处理的部件类型有哪些 REFRESH lt_bjlx[]. LOOP AT it_tx WHERE posnr = it_item-posnr AND atnam = 'ZC_BJLX'. ls_bjlx-atkla = it_tx-atwrt. MOVE-CORRESPONDING it_tx TO ls_bjlx. COLLECT ls_bjlx INTO lt_bjlx. CLEAR:it_tx ,ls_bjlx. ENDLOOP. "---根据物料和特征组获取规则,多条 IF lt_bjlx[] IS NOT INITIAL. REFRESH lt_zppt034. SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_zppt034 FROM zppt034 FOR ALL ENTRIES IN lt_bjlx WHERE matnr = it_item-matnr AND atkla = lt_bjlx-atkla. ENDIF. "根据特性部件类型ZC_BJLX,在自定义表ZPPT*(标准评审规则)判断是否有对应的评审规则(如果自定义表的特性值为空,则表示允许所有值), "判断评审规则时,按部件类型进行判断,如果所有部件都存在评审规则,则更新评审状态为“3”(已评审),评审类型为“1”(自动评审) ",更新评审状态时更新对应的评审日期和评审时间字段。 CLEAR lv_flag_1. IF lt_zppt034[] IS NOT INITIAL. LOOP AT lt_zppt034 INTO ls_zppt034."多条规则判断 LOOP AT lt_dd03l INTO ls_dd03l."每个特征判断 lv_name = 'LS_ZPPT034-' && ls_dd03l-fieldname. ASSIGN (lv_name) TO <fs>. IF <fs> IS NOT INITIAL. READ TABLE lt_bjlx_1 INTO ls_bjlx_1 WITH KEY atkla = ls_zppt034-atkla posnr = it_item-posnr atnam = ls_dd03l-fieldname. IF sy-subrc = 0. IF ls_bjlx_1-atwrt <> <fs>. lv_flag_1 = 'X'. EXIT. ENDIF. ELSE. lv_flag_1 = 'X'. EXIT. ENDIF. ENDIF. CLEAR: ls_dd03l,lv_name,ls_bjlx_1. ENDLOOP. CLEAR: ls_zppt034. ENDLOOP. IF lv_flag_1 = ''. ls_save-zpslx = '1'."评审类型 ls_save-zpszt = '3'."评审状态 ls_save-zpsrq = sy-datum."评审日期 ls_save-zpssj = sy-uzeit."评审时间 ENDIF. ENDIF. ENDIF. ENDIF. APPEND ls_save TO lt_save. CALL METHOD zcl_rfc=>save_table EXPORTING i_zrfcid = 'V003' CHANGING t_table1 = lt_save * t_table2 = * t_table3 = RECEIVING e_id = DATA(lv_rfc_log_id). "执行 CALL METHOD zcl_rfc=>exec_asyn * CALL METHOD zcl_rfc=>exec EXPORTING i_id = lv_rfc_log_id. ENDLOOP. ENDIF. "----------------------------------------------------- "----------------------------------------------------- ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' . LOOP AT lt_return INTO ls_return WHERE type = 'A' OR type = 'E' . e_code = 'E'. CONCATENATE e_msg ls_return-message INTO e_msg SEPARATED BY '/' . ENDLOOP. " 有些情况是报错的时候不是E ,但是销售订单没有生成,这里补充该项逻辑 IF e_code IS INITIAL . e_code = 'E'. LOOP AT lt_return INTO ls_return . CONCATENATE e_msg ls_return-message INTO e_msg SEPARATED BY '/' . ENDLOOP. ENDIF. PERFORM update_status IN PROGRAM zfunc USING lv_zz_log_id e_code e_msg. "lv_zz_log_id固定,e_code,e_msg按照实际情况返回。 INCLUDE zfunc_end. "RFC日志管理-记录返回数据 ENDIF. ENDFUNCTION. |