临时
1 # 一、第一次考核 2 3 ## 1、z2107_33160exam1a 4 5 ![](C:\liuliu\typora\图片\z2107_33160exam1a要求.png) 6 7 ```ABAP 8 *&---------------------------------------------------------------------* 9 *& Report Z2107_33160EXAM1A 10 *&---------------------------------------------------------------------* 11 *& 12 *&---------------------------------------------------------------------* 13 REPORT z2107_33160exam1a. 14 15 TABLES: likp,makt,lips,t001w. 16 17 *TYPE-POOLS:slis. ”定义Tables的时候,一般会加上TYPE-POOLS SLIS。 slis应该是个Package.声明了它后就可以用它包括的函数、类、消息等。 18 19 TYPES: BEGIN OF aa, 20 vbeln TYPE likp-vbeln, 21 erdat TYPE likp-erdat, 22 vkorg TYPE likp-vkorg, 23 lfart TYPE likp-lfart, 24 posnr TYPE lips-posnr, 25 matnr TYPE lips-matnr, 26 maktx type makt-maktx, 27 matwa TYPE lips-matwa, 28 matkl TYPE lips-matkl, 29 werks TYPE lips-werks, 30 name1 type t001w-name1, 31 lgort TYPE lips-lgort, 32 lfimg TYPE lips-lfimg, 33 meins TYPE lips-meins, 34 id TYPE icon-id, 35 chk, 36 END OF aa. 37 38 TYPES: BEGIN OF bb, 39 matnr TYPE makt-matnr, 40 maktx TYPE makt-maktx, 41 END OF bb. 42 43 TYPES: BEGIN OF cc, 44 werks TYPE t001w-werks, 45 name1 TYPE t001w-name1, 46 END OF cc. 47 48 DATA: gt_a TYPE TABLE OF aa, 49 gt_b TYPE TABLE OF bb, 50 gt_c TYPE TABLE OF cc, 51 gs_a TYPE aa, 52 gs_b TYPE bb, 53 gs_c TYPE cc. 54 55 DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, 56 gs_fieldcat TYPE slis_fieldcat_alv, 57 gs_layout TYPE slis_layout_alv. 58 59 *PARAMETERS: p_vbeln type likp-vbeln, 60 * p_ernam type likp-ernam. 61 * P_vkorg type likp-vkorg, 62 * p_lfart type likp-lfart, 63 * p_matnr type lips-matnr. 64 SELECT-OPTIONS: s_vbeln FOR likp-vbeln NO INTERVALS, 65 * s_ernam FOR likp-ernam DEFAULT '33160' NO-EXTENSION NO INTERVALS, 66 * s_erdat for likp-erdat DEFAULT '20210101' to '20211231', 67 s_ernam FOR likp-ernam NO-EXTENSION NO INTERVALS, 68 s_erdat for likp-erdat, 69 s_vkorg FOR likp-vkorg NO INTERVALS, 70 s_lfart FOR likp-lfart NO INTERVALS, 71 s_matnr FOR lips-matnr NO INTERVALS. 72 73 CLEAR gs_a. 74 CLEAR gs_b. 75 CLEAR gs_c. 76 77 INITIALIZATION."(初始化) 78 PERFORM frm_init. 79 80 AT SELECTION-SCREEN."(屏幕跳出前) 81 *PERFORM frm_check. 82 83 START-OF-SELECTION."(取数据) 84 PERFORM za. 85 86 END-OF-SELECTION."(展示数据) 87 PERFORM z_li. 88 PERFORM z_output. 89 90 *BREAK-POINT. 91 92 FORM frm_init. 93 s_ernam-sign = 'I'. 94 s_ernam-option = 'EQ'. 95 s_ernam-low = sy-uname. 96 APPEND s_ernam. 97 98 s_erdat-sign = 'I'. 99 s_erdat-option = 'BT'. 100 s_erdat-low+0(4) = sy-datum+0(4). 101 s_erdat-low+4(4) = '0101'. 102 s_erdat-high+0(4) = sy-datum+0(4). 103 s_erdat-high+4(4) = '1231'. 104 APPEND s_erdat. 105 ENDFORM. 106 107 FORM zt. 108 IF gt_a IS INITIAL. 109 MESSAGE '错误' TYPE 'E'. 110 LEAVE LIST-PROCESSING and RETURN TO SCREEN 0. 111 ENDIF. 112 ENDFORM. 113 114 FORM frm_check. 115 IF s_erdat IS INITIAL. 116 MESSAGE '创建日期没有填写' TYPE 'E'. 117 * S成功 E错误(程序终止) W警告 I消息框(弹出消息框) A错误(弹出框) X系统错误 118 ENDIF. 119 ENDFORM. 120 121 FORM za. 122 SELECT 123 likp~vbeln 124 likp~erdat 125 likp~vkorg 126 likp~lfart 127 lips~posnr 128 lips~matnr 129 lips~matwa 130 lips~matkl 131 lips~werks 132 lips~lgort 133 lips~lfimg 134 lips~meins 135 from likp join lips on likp~vbeln = lips~vbeln 136 into CORRESPONDING FIELDS OF TABLE gt_a 137 WHERE likp~vbeln in s_vbeln 138 and likp~erdat in s_erdat and likp~ernam in s_ernam 139 and likp~vkorg in s_vkorg and likp~lfart in s_lfart and lips~matnr in s_matnr. 140 141 IF gt_a IS INITIAL. 142 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. 143 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. 144 ENDIF. 145 146 IF gt_a is NOT INITIAL. 147 SELECT 148 makt~matnr 149 makt~maktx 150 from makt 151 INTO CORRESPONDING FIELDS OF TABLE gt_b 152 FOR ALL ENTRIES IN gt_a 153 WHERE makt~matnr = gt_a-matnr. 154 ENDIF. 155 156 IF gt_a is NOT INITIAL. 157 SELECT 158 t001w~werks 159 t001w~name1 160 from t001w 161 INTO CORRESPONDING FIELDS OF TABLE gt_c 162 FOR ALL ENTRIES IN gt_a 163 WHERE t001w~werks = gt_a-werks. 164 ENDIF. 165 166 LOOP AT gt_a into gs_a. 167 IF gs_a-vbeln > 90001750. 168 gs_a-id = icon_green_light. 169 ENDIF. 170 IF gs_a-vbeln < 90001750. 171 gs_a-id = icon_red_light. 172 ENDIF. 173 * gs_a-vbeln = icon_green_light. 174 READ TABLE gt_b into gs_b WITH KEY matnr = gs_a-matnr. 175 IF sy-subrc = 0. 176 gs_a-maktx = gs_b-maktx. 177 ENDIF. 178 MODIFY gt_a from gs_a. 179 ENDLOOP. 180 181 LOOP AT gt_a into gs_a. 182 READ TABLE gt_c into gs_c WITH KEY werks = gs_a-werks. 183 IF sy-subrc = 0. 184 gs_a-name1 = gs_c-name1. 185 ENDIF. 186 MODIFY gt_a from gs_a. 187 ENDLOOP. 188 189 ENDFORM. 190 191 192 FORM z_li. 193 gs_layout-colwidth_optimize = 'X'. 194 gs_layout-zebra = 'X'. 195 gs_FIELDCAT-fieldname = 'ID'. 196 gs_FIELDCAT-ref_tabname = ''. 197 gs_FIELDCAT-ref_fieldname = ''. 198 append gs_FIELDCAT to gt_FIELDCAT. 199 CLEAR gs_FIELDCAT. 200 201 gs_layout-colwidth_optimize = 'X'. 202 gs_layout-zebra = 'X'. 203 gs_FIELDCAT-fieldname = 'VBELN'. 204 gs_FIELDCAT-ref_tabname = 'LIKP'. 205 gs_FIELDCAT-ref_fieldname = 'VBELN'. 206 append gs_FIELDCAT to gt_FIELDCAT. 207 CLEAR gs_FIELDCAT. 208 209 gs_layout-colwidth_optimize = 'X'. 210 gs_layout-zebra = 'X'. 211 gs_FIELDCAT-fieldname = 'ERDAT'. 212 gs_FIELDCAT-ref_tabname = 'LIKP'. 213 gs_FIELDCAT-ref_fieldname = 'ERDAT'. 214 append gs_FIELDCAT to gt_FIELDCAT. 215 CLEAR gs_FIELDCAT. 216 217 gs_layout-colwidth_optimize = 'X'. 218 gs_layout-zebra = 'X'. 219 gs_FIELDCAT-fieldname = 'VKORG'. 220 gs_FIELDCAT-ref_tabname = 'LIKP'. 221 gs_FIELDCAT-ref_fieldname = 'VKORG'. 222 append gs_FIELDCAT to gt_FIELDCAT. 223 CLEAR gs_FIELDCAT. 224 225 gs_layout-colwidth_optimize = 'X'. 226 gs_layout-zebra = 'X'. 227 gs_FIELDCAT-fieldname = 'LFART'. 228 gs_FIELDCAT-ref_tabname = 'LIKP'. 229 gs_FIELDCAT-ref_fieldname = 'LFART'. 230 append gs_FIELDCAT to gt_FIELDCAT. 231 CLEAR gs_FIELDCAT. 232 233 gs_layout-colwidth_optimize = 'X'. 234 gs_layout-zebra = 'X'. 235 gs_FIELDCAT-fieldname = 'POSNR'. 236 gs_FIELDCAT-ref_tabname = 'LIPS'. 237 gs_FIELDCAT-ref_fieldname = 'POSNR'. 238 append gs_FIELDCAT to gt_FIELDCAT. 239 CLEAR gs_FIELDCAT. 240 241 gs_layout-colwidth_optimize = 'X'. 242 gs_layout-zebra = 'X'. 243 gs_FIELDCAT-fieldname = 'MATNR'. 244 gs_FIELDCAT-ref_tabname = 'LIPS'. 245 gs_FIELDCAT-ref_fieldname = 'MATNR'. 246 append gs_FIELDCAT to gt_FIELDCAT. 247 CLEAR gs_FIELDCAT. 248 249 gs_layout-colwidth_optimize = 'X'. 250 gs_layout-zebra = 'X'. 251 gs_FIELDCAT-fieldname = 'MAKTX'. 252 gs_FIELDCAT-ref_tabname = 'MAKT'. 253 gs_FIELDCAT-ref_fieldname = 'MAKTX'. 254 append gs_FIELDCAT to gt_FIELDCAT. 255 CLEAR gs_FIELDCAT. 256 257 gs_layout-colwidth_optimize = 'X'. 258 gs_layout-zebra = 'X'. 259 gs_FIELDCAT-fieldname = 'MATWA'. 260 gs_FIELDCAT-ref_tabname = 'LIPS'. 261 gs_FIELDCAT-ref_fieldname = 'MATWA'. 262 append gs_FIELDCAT to gt_FIELDCAT. 263 CLEAR gs_FIELDCAT. 264 265 gs_layout-colwidth_optimize = 'X'. 266 gs_layout-zebra = 'X'. 267 gs_FIELDCAT-fieldname = 'MATKL'. 268 gs_FIELDCAT-ref_tabname = 'LIPS'. 269 gs_FIELDCAT-ref_fieldname = 'MATKL'. 270 append gs_FIELDCAT to gt_FIELDCAT. 271 CLEAR gs_FIELDCAT. 272 273 gs_layout-colwidth_optimize = 'X'. 274 gs_layout-zebra = 'X'. 275 gs_FIELDCAT-fieldname = 'WERKS'. 276 gs_FIELDCAT-ref_tabname = 'LIPS'. 277 gs_FIELDCAT-ref_fieldname = 'WERKS'. 278 append gs_FIELDCAT to gt_FIELDCAT. 279 CLEAR gs_FIELDCAT. 280 281 gs_layout-colwidth_optimize = 'X'. 282 gs_layout-zebra = 'X'. 283 gs_FIELDCAT-fieldname = 'NAME1'. 284 gs_FIELDCAT-ref_tabname = 'T001W'. 285 gs_FIELDCAT-ref_fieldname = 'NAME1'. 286 append gs_FIELDCAT to gt_FIELDCAT. 287 CLEAR gs_FIELDCAT. 288 289 gs_layout-colwidth_optimize = 'X'. 290 gs_layout-zebra = 'X'. 291 gs_FIELDCAT-fieldname = 'LGORT'. 292 gs_FIELDCAT-ref_tabname = 'LIPS'. 293 gs_FIELDCAT-ref_fieldname = 'LGORT'. 294 append gs_FIELDCAT to gt_FIELDCAT. 295 CLEAR gs_FIELDCAT. 296 297 gs_layout-colwidth_optimize = 'X'. 298 gs_layout-zebra = 'X'. 299 gs_FIELDCAT-fieldname = 'LFIMG'. 300 gs_FIELDCAT-ref_tabname = 'LIPS'. 301 gs_FIELDCAT-ref_fieldname = 'LFIMG'. 302 append gs_FIELDCAT to gt_FIELDCAT. 303 CLEAR gs_FIELDCAT. 304 305 gs_layout-colwidth_optimize = 'X'. 306 gs_layout-zebra = 'X'. 307 gs_FIELDCAT-fieldname = 'MEINS'. 308 gs_FIELDCAT-ref_tabname = 'LIPS'. 309 gs_FIELDCAT-ref_fieldname = 'MEINS'. 310 append gs_FIELDCAT to gt_FIELDCAT. 311 CLEAR gs_FIELDCAT. 312 ENDFORM. 313 314 315 FORM z_output. 316 gs_layout-box_fieldname = 'CHK'. 317 318 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 319 EXPORTING 320 * I_INTERFACE_CHECK = ' ' 321 * I_BYPASSING_BUFFER = ' ' 322 * I_BUFFER_ACTIVE = ' ' 323 I_CALLBACK_PROGRAM = sy-repid 324 I_CALLBACK_PF_STATUS_SET = 'FRM_SET_PF_STATUS' 325 I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND' 326 * I_CALLBACK_TOP_OF_PAGE = ' ' 327 * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' 328 * I_CALLBACK_HTML_END_OF_LIST = ' ' 329 * I_STRUCTURE_NAME = 330 * I_BACKGROUND_ID = ' ' 331 I_GRID_TITLE = '卡哇伊' 332 * I_GRID_SETTINGS = 333 IS_LAYOUT = gs_layout 334 IT_FIELDCAT = gt_FIELDCAT 335 * IT_EXCLUDING = 336 * IT_SPECIAL_GROUPS = 337 * IT_SORT = 338 * IT_FILTER = 339 * IS_SEL_HIDE = 340 * I_DEFAULT = 'X' 341 * I_SAVE = ' ' 342 * IS_VARIANT = 343 * IT_EVENTS = 344 * IT_EVENT_EXIT = 345 * IS_PRINT = 346 * IS_REPREP_ID = 347 * I_SCREEN_START_COLUMN = 0 348 * I_SCREEN_START_LINE = 0 349 * I_SCREEN_END_COLUMN = 0 350 * I_SCREEN_END_LINE = 0 351 * I_HTML_HEIGHT_TOP = 0 352 * I_HTML_HEIGHT_END = 0 353 * IT_ALV_GRAPHICS = 354 * IT_HYPERLINK = 355 * IT_ADD_FIELDCAT = 356 * IT_EXCEPT_QINFO = 357 * IR_SALV_FULLSCREEN_ADAPTER = 358 * O_PREVIOUS_SRAL_HANDLER = 359 * IMPORTING 360 * E_EXIT_CAUSED_BY_CALLER = 361 * ES_EXIT_CAUSED_BY_USER = 362 TABLES 363 t_outtab = gt_a 364 EXCEPTIONS 365 PROGRAM_ERROR = 1 366 OTHERS = 2 367 . 368 369 ENDFORM. 370 371 * 选中一个格子 双击跳转 调试界面 372 FORM frm_user_command USING r_ucomm LIKE sy-ucomm 373 rs_selfield TYPE slis_selfield. 374 * BREAK-POINT. 375 CASE r_ucomm. 376 WHEN '&IC1'." 控制双击 377 IF rs_selfield-fieldname = 'VBELN'." 控制 鼠标双击列 378 SET PARAMETER ID 'ANR' FIELD rs_selfield-value. 379 CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN. 380 ENDIF. 381 ENDCASE. 382 ENDFORM. 383 384 385 *增加按钮 386 *----------------------------------------------------------------------* 387 *自定义状态 388 *----------------------------------------------------------------------* 389 FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab. 390 *--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 391 392 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' . 393 *--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB 394 * SET TITLEBAR 'TITLE'. 395 ENDFORM. "frm_set_pf_status 396 ``` 397 398 ![](C:\liuliu\typora\图片\z2107_33160exam1a.png) 399 400 401 402 ## 2、z2107_33160exam1b 403 404 ![](C:\liuliu\typora\图片\z2107_33160exam1b要求.png) 405 406 ```ABAP 407 *&---------------------------------------------------------------------* 408 *& Report Z2107_33160EXAM1B 409 *&---------------------------------------------------------------------* 410 *& 411 *&---------------------------------------------------------------------* 412 REPORT z2107_33160exam1b. 413 414 TABLES: vbrk,tvkot,icon,vbrp,makt. 415 416 TYPE-POOLS:slis. 417 418 TYPES: BEGIN OF aa, 419 vbeln TYPE vbrk-vbeln, 420 fkart TYPE vbrk-fkart, 421 fktyp TYPE vbrk-fktyp, 422 vbtyp TYPE vbrk-vbtyp, 423 waerk TYPE vbrk-waerk, 424 vkorg TYPE vbrk-vkorg, 425 vtext TYPE tvkot-vtext, 426 vtweg TYPE vbrk-vtweg, 427 vsbed TYPE vbrk-vsbed, 428 fkdat TYPE vbrk-fkdat, 429 ernam TYPE vbrk-ernam, 430 erzet TYPE vbrk-erzet, 431 erdat TYPE vbrk-erdat, 432 posnr TYPE vbrp-posnr, 433 fkimg TYPE vbrp-fkimg, 434 vrkme TYPE vbrp-vrkme, 435 vgbel TYPE vbrp-vgbel, 436 vgpos TYPE vbrp-vgpos, 437 matnr TYPE vbrp-matnr, 438 maktx TYPE makt-maktx, 439 id TYPE icon-id, 440 chk, 441 END OF aa. 442 443 TYPES: BEGIN OF bb, 444 vkorg TYPE tvkot-vkorg, 445 vtext TYPE tvkot-vtext, 446 END OF bb. 447 448 TYPES: BEGIN OF cc, 449 matnr TYPE makt-matnr, 450 maktx TYPE makt-maktx, 451 END OF cc. 452 453 DATA: gt_a TYPE TABLE OF aa, 454 gt_b TYPE TABLE OF bb, 455 gt_c TYPE TABLE OF cc, 456 gs_a TYPE aa, 457 gs_b TYPE bb, 458 gs_c TYPE cc. 459 460 DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, 461 gs_fieldcat TYPE slis_fieldcat_alv, 462 gs_layout TYPE slis_layout_alv. 463 464 SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln, 465 s_fkart FOR vbrk-fkart, 466 s_vkorg FOR vbrk-vkorg, 467 s_ernam FOR vbrk-ernam NO-EXTENSION NO INTERVALS, 468 s_erdat FOR vbrk-erdat, 469 s_vgbel FOR vbrp-vgbel. 470 471 472 473 474 CLEAR gs_a. 475 CLEAR gs_b. 476 CLEAR gs_c. 477 478 INITIALIZATION."(初始化) 479 PERFORM frm_init. 480 481 AT SELECTION-SCREEN."(屏幕跳出前) 482 *PERFORM frm_check. 483 484 START-OF-SELECTION."(取数据) 485 486 PERFORM za. 487 488 END-OF-SELECTION."(展示数据) 489 *PERFORM z_li. 490 PERFORM z_output. 491 CALL FUNCTION 'ZFM_33160_TEST004' 492 EXPORTING 493 it_zwss = s_vbeln[]. 494 495 * BREAK-POINT. 496 497 498 FORM frm_init. 499 s_ernam-sign = 'I'. 500 s_ernam-option = 'EQ'. 501 s_ernam-low = sy-uname. 502 APPEND s_ernam. 503 504 s_erdat-sign = 'I'. 505 s_erdat-option = 'BT'. 506 s_erdat-low+0(4) = sy-datum+0(4). 507 s_erdat-low+4(4) = '0101'. 508 s_erdat-high+0(4) = sy-datum+0(4). 509 s_erdat-high+4(4) = '1231'. 510 APPEND s_erdat. 511 ENDFORM. 512 513 FORM za. 514 SELECT 515 vbrk~vbeln 516 vbrk~fkart 517 vbrk~fktyp 518 vbrk~vbtyp 519 vbrk~waerk 520 vbrk~vkorg 521 vbrk~vtweg 522 vbrk~vsbed 523 vbrk~fkdat 524 vbrk~ernam 525 vbrk~erzet 526 vbrk~erdat 527 vbrp~posnr 528 vbrp~fkimg 529 vbrp~vrkme 530 vbrp~vgbel 531 vbrp~vgpos 532 vbrp~matnr 533 FROM vbrk JOIN vbrp ON vbrk~vbeln = vbrp~vbeln 534 INTO CORRESPONDING FIELDS OF TABLE gt_a 535 WHERE vbrk~vbeln IN s_vbeln 536 AND vbrk~fkart IN s_fkart 537 AND vbrk~vkorg IN s_vkorg 538 AND vbrk~ernam IN s_ernam 539 AND vbrk~erdat IN s_erdat 540 AND vbrp~vgbel IN s_vgbel. 541 542 IF gt_a IS INITIAL. 543 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. 544 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. 545 ENDIF. 546 547 IF gt_a IS NOT INITIAL. 548 SELECT 549 tvkot~vkorg 550 tvkot~vtext 551 FROM tvkot 552 INTO CORRESPONDING FIELDS OF TABLE gt_b 553 FOR ALL ENTRIES IN gt_a 554 WHERE tvkot~vkorg = gt_a-vkorg. 555 556 SELECT 557 makt~matnr 558 makt~maktx 559 FROM makt 560 INTO CORRESPONDING FIELDS OF TABLE gt_c 561 FOR ALL ENTRIES IN gt_a 562 WHERE makt~matnr = gt_a-matnr. 563 ENDIF. 564 565 LOOP AT gt_a INTO gs_a. 566 IF gs_a-vbeln > 90001750. 567 gs_a-id = icon_green_light. 568 ENDIF. 569 IF gs_a-vbeln < 90001750. 570 gs_a-id = icon_red_light. 571 ENDIF. 572 READ TABLE gt_b INTO gs_b WITH KEY vkorg = gs_a-vkorg. 573 IF sy-subrc = 0. 574 gs_a-vtext = gs_b-vtext. 575 ENDIF. 576 577 READ TABLE gt_c INTO gs_c WITH KEY matnr = gs_a-matnr. 578 IF sy-subrc = 0. 579 gs_a-maktx = gs_c-maktx. 580 ENDIF. 581 MODIFY gt_a FROM gs_a. 582 ENDLOOP. 583 ENDFORM. 584 585 FORM z_output. 586 gs_layout-box_fieldname = 'CHK'. "选择行 587 588 PERFORM frm_build_fieldcat USING: 'ID' '' '', 589 'VBELN' 'VBRK' 'VBELN', 590 'FKART' 'VBRK' 'FKART', 591 'FKTYP' 'VBRK' 'FKTYP', 592 'VBTYP' 'VBRK' 'VBTYP', 593 'WAERK' 'VBRK' 'WAERK', 594 'VKORG' 'VBRK' 'VKORG', 595 'VTEXT' 'TVKOT' 'VTEXT', 596 'VTWEG' 'VBRK' 'VTWEG', 597 'VSBED' 'VBRK' 'VSBED', 598 'FKDAT' 'VBRK' 'FKDAT', 599 'ERNAM' 'VBRK' 'ERNAM', 600 'ERZET' 'VBRK' 'ERZET', 601 'ERDAT' 'VBRK' 'ERDAT', 602 'POSNR' 'VBRP' 'POSNR', 603 'FKIMG' 'VBRP' 'FKIMG', 604 'VRKME' 'VBRP' 'VRKME', 605 'VGBEL' 'VBRP' 'VGBEL', 606 'VGPOS' 'VBRP' 'VGPOS', 607 'MATNR' 'VBRP' 'MATNR', 608 'MAKTX' 'MAKT' 'MAKTX'. 609 610 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 611 EXPORTING 612 * I_INTERFACE_CHECK = ' ' 613 * I_BYPASSING_BUFFER = ' ' 614 * I_BUFFER_ACTIVE = ' ' 615 i_callback_program = sy-repid 616 i_callback_pf_status_set = 'FRM_SET_PF_STATUS' 617 i_callback_user_command = 'FRM_USER_COMMAND' 618 * I_CALLBACK_TOP_OF_PAGE = ' ' 619 * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' 620 * I_CALLBACK_HTML_END_OF_LIST = ' ' 621 * I_STRUCTURE_NAME = 622 * I_BACKGROUND_ID = ' ' 623 i_grid_title = '卡哇伊' 624 * I_GRID_SETTINGS = 625 is_layout = gs_layout 626 it_fieldcat = gt_fieldcat 627 * IT_EXCLUDING = 628 * IT_SPECIAL_GROUPS = 629 * IT_SORT = 630 * IT_FILTER = 631 * IS_SEL_HIDE = 632 * I_DEFAULT = 'X' 633 * I_SAVE = ' ' 634 * IS_VARIANT = 635 * IT_EVENTS = 636 * IT_EVENT_EXIT = 637 * IS_PRINT = 638 * IS_REPREP_ID = 639 * I_SCREEN_START_COLUMN = 0 640 * I_SCREEN_START_LINE = 0 641 * I_SCREEN_END_COLUMN = 0 642 * I_SCREEN_END_LINE = 0 643 * I_HTML_HEIGHT_TOP = 0 644 * I_HTML_HEIGHT_END = 0 645 * IT_ALV_GRAPHICS = 646 * IT_HYPERLINK = 647 * IT_ADD_FIELDCAT = 648 * IT_EXCEPT_QINFO = 649 * IR_SALV_FULLSCREEN_ADAPTER = 650 * O_PREVIOUS_SRAL_HANDLER = 651 * IMPORTING 652 * E_EXIT_CAUSED_BY_CALLER = 653 * ES_EXIT_CAUSED_BY_USER = 654 TABLES 655 t_outtab = gt_a 656 EXCEPTIONS 657 program_error = 1 658 OTHERS = 2. 659 IF sy-subrc <> 0. 660 * Implement suitable error handling here 661 ENDIF. 662 663 ENDFORM. 664 665 FORM frm_build_fieldcat USING fu_fieldname 666 fu_rtabname 667 fu_rfieldname. 668 DATA: ls_fieldcat TYPE slis_fieldcat_alv. 669 gs_layout-colwidth_optimize = 'X'. 670 gs_layout-zebra = 'X'. 671 ls_fieldcat-fieldname = fu_fieldname. 672 ls_fieldcat-ref_tabname = fu_rtabname. 673 ls_fieldcat-ref_fieldname = fu_rfieldname. 674 APPEND ls_fieldcat TO gt_fieldcat. 675 676 ENDFORM. 677 678 FORM frm_check_screen. 679 IF s_erdat IS INITIAL. 680 MESSAGE '创建日期没有填写' TYPE 'E'. 681 ENDIF. 682 ENDFORM. 683 684 * 选中一个格子 双击跳转 调试界面 685 FORM frm_user_command USING r_ucomm LIKE sy-ucomm 686 rs_selfield TYPE slis_selfield. 687 * BREAK-POINT. 688 CASE r_ucomm. 689 WHEN '&IC1'." 控制双击 690 IF rs_selfield-fieldname = 'VBELN'." 控制 鼠标双击列 691 SET PARAMETER ID 'VF' FIELD rs_selfield-value. 692 CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN. 693 ENDIF. 694 ENDCASE. 695 ENDFORM. 696 697 698 *增加按钮 699 *----------------------------------------------------------------------* 700 *自定义状态 701 *----------------------------------------------------------------------* 702 FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab. 703 *--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 704 705 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' . 706 *--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB 707 * SET TITLEBAR 'TITLE'. 708 ENDFORM. 709 ``` 710 711 ![](C:\liuliu\typora\图片\z2107_33160exam1b.png) 712 713 714 715 ## 3、z2107_33160exam1c 716 717 ![](C:\liuliu\typora\图片\z2107_33160exam1c要求.png) 718 719 ```ABAP 720 *&---------------------------------------------------------------------* 721 *& Report Z2107_33160EXAM1C 722 *&---------------------------------------------------------------------* 723 *& 724 *&---------------------------------------------------------------------* 725 REPORT z2107_33160exam1c. 726 727 TABLES: aufk, afko,icon. 728 729 730 TYPES: BEGIN OF aa, 731 matnr TYPE makt-matnr, 732 aufnr TYPE aufk-aufnr, 733 ernam TYPE aufk-ernam, 734 erdat TYPE aufk-erdat, 735 bukrs TYPE aufk-bukrs, 736 werks TYPE aufk-werks, 737 name1 TYPE t001w-name1, 738 plnbez TYPE afko-plnbez, 739 maktx TYPE makt-maktx, 740 gasmg TYPE afko-gasmg, 741 gamng TYPE afko-gamng, 742 gmein TYPE afko-gmein, 743 id TYPE icon-id, 744 chk, 745 END OF aa. 746 747 TYPES: BEGIN OF bb, 748 werks TYPE t001w-werks, 749 name1 TYPE t001w-name1, 750 END OF bb. 751 752 TYPES: BEGIN OF cc, 753 matnr TYPE makt-matnr, 754 maktx TYPE makt-maktx, 755 END OF cc. 756 757 DATA: gt_a TYPE TABLE OF aa, 758 gt_b TYPE TABLE OF bb, 759 gt_c TYPE TABLE OF cc, 760 gs_a TYPE aa, 761 gs_b TYPE bb, 762 gs_c TYPE cc. 763 764 DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, 765 gs_fieldcat TYPE slis_fieldcat_alv, 766 gs_layout TYPE slis_layout_alv. 767 768 data: lt_aufk type ZL33160_002. 769 770 SELECT-OPTIONS: s_ernam FOR aufk-ernam NO-EXTENSION NO INTERVALS, 771 s_aufnr FOR aufk-aufnr, 772 s_erdat FOR aufk-erdat, 773 s_bukrs FOR aufk-bukrs, 774 s_werks FOR aufk-werks, 775 s_plnbez FOR afko-plnbez. 776 777 CLEAR gs_a. 778 CLEAR gs_b. 779 CLEAR gs_c. 780 781 INITIALIZATION."(初始化) 782 PERFORM frm_init. 783 784 AT SELECTION-SCREEN."(屏幕跳出前) 785 *PERFORM frm_check. 786 787 START-OF-SELECTION."(取数据) 788 *CALL FUNCTION 'ZFM_33160_TEST005' 789 * EXPORTING 790 * it_one = s_erdat[] 791 * IMPORTING 792 * ET_ONE = lt_aufk. 793 * 794 PERFORM za. 795 796 END-OF-SELECTION."(展示数据) 797 * PERFORM z_li. 798 PERFORM z_output. 799 800 801 802 803 FORM frm_init. 804 s_ernam-sign = 'I'. 805 s_ernam-option = 'EQ'. 806 s_ernam-low = sy-uname. 807 APPEND s_ernam. 808 809 s_erdat-sign = 'I'. 810 s_erdat-option = 'BT'. 811 s_erdat-low+0(4) = sy-datum+0(4). 812 s_erdat-low+4(4) = '0101'. 813 s_erdat-high+0(4) = sy-datum+0(4). 814 s_erdat-high+4(4) = '1231'. 815 APPEND s_erdat. 816 ENDFORM. 817 818 FORM frm_check. 819 IF s_erdat IS INITIAL. 820 MESSAGE '创建日期没有填写' TYPE 'E'. 821 * S成功 E错误(程序终止) W警告 I消息框(弹出消息框) A错误(弹出框) X系统错误 822 ENDIF. 823 ENDFORM. 824 825 FORM za. 826 SELECT 827 aufk~aufnr 828 aufk~ernam 829 aufk~erdat 830 aufk~bukrs 831 aufk~werks 832 afko~plnbez 833 afko~gasmg 834 afko~gamng 835 afko~gmein 836 FROM aufk JOIN afko ON aufk~aufnr = afko~aufnr 837 INTO CORRESPONDING FIELDS OF TABLE gt_a 838 WHERE aufk~aufnr IN s_aufnr 839 AND aufk~ernam IN s_ernam 840 AND aufk~erdat IN s_erdat 841 AND aufk~bukrs IN s_bukrs 842 AND aufk~werks IN s_werks 843 AND afko~plnbez IN s_plnbez. 844 845 IF gt_a IS INITIAL. 846 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. 847 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. 848 ENDIF. 849 850 IF gt_a IS NOT INITIAL. 851 SELECT werks 852 name1 853 FROM t001w 854 INTO CORRESPONDING FIELDS OF TABLE gt_b 855 FOR ALL ENTRIES IN gt_a 856 WHERE werks = gt_a-werks. 857 858 SELECT matnr 859 maktx 860 FROM makt 861 INTO CORRESPONDING FIELDS OF TABLE gt_c 862 FOR ALL ENTRIES IN gt_a 863 WHERE makt~matnr = gt_a-plnbez. 864 * matnr = gt_a-matnr 865 * AND spras = sy-langu. 866 ENDIF. 867 868 LOOP AT gt_a INTO gs_a. 869 * IF gs_a-ERNAM > 14532. 870 * gs_a-id = icon_green_light. 871 * ENDIF. 872 * IF gs_a-ERNAM < 14532. 873 * gs_a-id = icon_red_light. 874 * ENDIF. 875 gs_a-id = icon_green_light. 876 READ TABLE gt_b INTO gs_b WITH KEY werks = gs_a-werks. 877 IF sy-subrc = 0. 878 gs_a-name1 = gs_b-name1. 879 ENDIF. 880 881 READ TABLE gt_c INTO gs_c WITH KEY matnr = gs_a-plnbez. 882 IF sy-subrc = 0. 883 gs_a-maktx = gs_c-maktx. 884 ENDIF. 885 MODIFY gt_a FROM gs_a. 886 ENDLOOP. 887 ENDFORM. 888 889 FORM z_output. 890 * gs_layout-box_fieldname = 'CHK'. "选择行 891 892 PERFORM frm_build_fieldcat USING: "'ID' '' '', 893 'AUFNR' 'AUFK' 'AUFNR', 894 'ERNAM' 'AUFK' 'ERNAM', 895 'ERDAT' 'VBRK' 'ERDAT', 896 'BUKRS' 'AUFK' 'BUKRS', 897 'WERKS' 'AUFK' 'WERKS', 898 'NAME1' 'T001W' 'NAME1', 899 'PLNBEZ' 'AFKO' 'PLNBEZ', 900 'MAKTX' 'MAKT' 'MAKTX', 901 'GASMG' 'AFKO' 'GASMG', 902 'GAMNG' 'AFKO' 'GAMNG', 903 'GMEIN' 'AFKO' 'GMEIN'. 904 905 906 CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' 907 EXPORTING 908 * I_INTERFACE_CHECK = ' ' 909 * I_BYPASSING_BUFFER = ' ' 910 * I_BUFFER_ACTIVE = ' ' 911 i_callback_program = sy-repid 912 i_callback_pf_status_set = 'FRM_SET_PF_STATUS' 913 i_callback_user_command = 'FRM_USER_COMMAND' 914 * I_CALLBACK_TOP_OF_PAGE = ' ' 915 * I_CALLBACK_HTML_TOP_OF_PAGE = ' ' 916 * I_CALLBACK_HTML_END_OF_LIST = ' ' 917 * I_STRUCTURE_NAME = 918 * I_BACKGROUND_ID = ' ' 919 i_grid_title = '卡哇伊' 920 * I_GRID_SETTINGS = 921 is_layout = gs_layout 922 it_fieldcat = gt_fieldcat 923 * IT_EXCLUDING = 924 * IT_SPECIAL_GROUPS = 925 * IT_SORT = 926 * IT_FILTER = 927 * IS_SEL_HIDE = 928 * I_DEFAULT = 'X' 929 * I_SAVE = ' ' 930 * IS_VARIANT = 931 * IT_EVENTS = 932 * IT_EVENT_EXIT = 933 * IS_PRINT = 934 * IS_REPREP_ID = 935 * I_SCREEN_START_COLUMN = 0 936 * I_SCREEN_START_LINE = 0 937 * I_SCREEN_END_COLUMN = 0 938 * I_SCREEN_END_LINE = 0 939 * I_HTML_HEIGHT_TOP = 0 940 * I_HTML_HEIGHT_END = 0 941 * IT_ALV_GRAPHICS = 942 * IT_HYPERLINK = 943 * IT_ADD_FIELDCAT = 944 * IT_EXCEPT_QINFO = 945 * IR_SALV_FULLSCREEN_ADAPTER = 946 * O_PREVIOUS_SRAL_HANDLER = 947 * IMPORTING 948 * E_EXIT_CAUSED_BY_CALLER = 949 * ES_EXIT_CAUSED_BY_USER = 950 TABLES 951 t_outtab = gt_a"lt_aufk" 952 EXCEPTIONS 953 program_error = 1 954 OTHERS = 2. 955 IF sy-subrc <> 0. 956 * Implement suitable error handling here 957 ENDIF. 958 959 ENDFORM. 960 961 FORM frm_build_fieldcat USING fu_fieldname 962 fu_rtabname 963 fu_rfieldname. 964 DATA: ls_fieldcat TYPE slis_fieldcat_alv. 965 gs_layout-colwidth_optimize = 'X'. 966 gs_layout-zebra = 'X'. 967 ls_fieldcat-fieldname = fu_fieldname. 968 ls_fieldcat-ref_tabname = fu_rtabname. 969 ls_fieldcat-ref_fieldname = fu_rfieldname. 970 APPEND ls_fieldcat TO gt_fieldcat. 971 972 ENDFORM. 973 974 * 选中一个格子 双击跳转 调试界面 975 FORM frm_user_command USING r_ucomm LIKE sy-ucomm 976 rs_selfield TYPE slis_selfield. 977 * BREAK-POINT. 978 CASE r_ucomm. 979 WHEN '&IC1'." 控制双击 980 IF rs_selfield-fieldname = 'AUFNR'." 控制 鼠标双击列 981 SET PARAMETER ID 'ANR' FIELD rs_selfield-value. 982 CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN. 983 ENDIF. 984 ENDCASE. 985 ENDFORM. 986 987 988 *增加按钮 989 *----------------------------------------------------------------------* 990 *自定义状态 991 *----------------------------------------------------------------------* 992 FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab. 993 *--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 994 995 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' . 996 *--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB 997 * SET TITLEBAR 'TITLE'. 998 ENDFORM. "frm_set_pf_status 999 ``` 1000 1001 ![](C:\liuliu\typora\图片\z2107_33160exam1c.png) 1002 1003 1004 1005 # 二、第二次考核 1006 1007 ## 1、Z2107_33160EXAM2B 1008 1009 ![](C:\liuliu\typora\图片\Z2107_33160EXAM2B要求.png) 1010 1011 ```ABAP 1012 *&---------------------------------------------------------------------* 1013 *& Report Z2107_33160EXAM2B 1014 *&---------------------------------------------------------------------* 1015 *& 1016 *&---------------------------------------------------------------------* 1017 REPORT Z2107_33160EXAM2B. 1018 1019 TABLES: vbrk,tvkot,icon,vbrp,makt. 1020 1021 TYPE-POOLS:slis. 1022 1023 TYPES: BEGIN OF aa, 1024 vbeln TYPE vbrk-vbeln, 1025 fkart TYPE vbrk-fkart, 1026 fktyp TYPE vbrk-fktyp, 1027 vbtyp TYPE vbrk-vbtyp, 1028 waerk TYPE vbrk-waerk, 1029 vkorg TYPE vbrk-vkorg, 1030 vtext TYPE tvkot-vtext, 1031 vtweg TYPE vbrk-vtweg, 1032 vsbed TYPE vbrk-vsbed, 1033 fkdat TYPE vbrk-fkdat, 1034 ernam TYPE vbrk-ernam, 1035 erzet TYPE vbrk-erzet, 1036 erdat TYPE vbrk-erdat, 1037 posnr TYPE vbrp-posnr, 1038 fkimg TYPE vbrp-fkimg, 1039 vrkme TYPE vbrp-vrkme, 1040 vgbel TYPE vbrp-vgbel, 1041 vgpos TYPE vbrp-vgpos, 1042 matnr TYPE vbrp-matnr, 1043 maktx TYPE makt-maktx, 1044 chk, 1045 END OF aa. 1046 1047 TYPES: BEGIN OF bb, 1048 vkorg TYPE tvkot-vkorg, 1049 vtext TYPE tvkot-vtext, 1050 END OF bb. 1051 1052 TYPES: BEGIN OF cc, 1053 matnr TYPE makt-matnr, 1054 maktx TYPE makt-maktx, 1055 END OF cc. 1056 1057 DATA: gt_a TYPE TABLE OF aa, 1058 gtt_a TYPE TABLE OF aa, 1059 gt_b TYPE TABLE OF bb, 1060 gt_c TYPE TABLE OF cc, 1061 gs_a TYPE aa, 1062 gs_b TYPE bb, 1063 gs_c TYPE cc. 1064 DATA: lt_a TYPE TABLE OF aa, 1065 ls_a TYPE aa. 1066 1067 DATA: ok_code TYPE sy-ucomm, 1068 save_ok_code TYPE sy-ucomm. 1069 1070 DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, 1071 gs_fieldcat TYPE slis_fieldcat_alv, 1072 gs_layout TYPE slis_layout_alv. 1073 1074 SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln, 1075 s_fkart FOR vbrk-fkart, 1076 s_vkorg FOR vbrk-vkorg, 1077 s_ernam FOR vbrk-ernam NO-EXTENSION NO INTERVALS, 1078 s_erdat FOR vbrk-erdat, 1079 s_vgbel FOR vbrp-vgbel. 1080 1081 1082 CLEAR gs_a. 1083 CLEAR gs_b. 1084 CLEAR gs_c. 1085 1086 INITIALIZATION."(初始化) 1087 PERFORM frm_init. 1088 1089 AT SELECTION-SCREEN."(屏幕跳出前) 1090 *PERFORM frm_check. 1091 1092 START-OF-SELECTION."(取数据) 1093 1094 PERFORM za. 1095 1096 END-OF-SELECTION."(展示数据) 1097 CALL SCREEN 9100. 1098 *PERFORM z_li. 1099 * PERFORM z_output. 1100 1101 1102 FORM frm_init. 1103 s_ernam-sign = 'I'. 1104 s_ernam-option = 'EQ'. 1105 s_ernam-low = sy-uname. 1106 APPEND s_ernam. 1107 1108 s_erdat-sign = 'I'. 1109 s_erdat-option = 'BT'. 1110 s_erdat-low+0(4) = sy-datum+0(4). 1111 s_erdat-low+4(4) = '0101'. 1112 s_erdat-high+0(4) = sy-datum+0(4). 1113 s_erdat-high+4(4) = '1231'. 1114 APPEND s_erdat. 1115 ENDFORM. 1116 1117 1118 1119 FORM za. 1120 SELECT 1121 vbrk~vbeln 1122 vbrk~fkart 1123 vbrk~fktyp 1124 vbrk~vbtyp 1125 vbrk~waerk 1126 vbrk~vkorg 1127 vbrk~vtweg 1128 vbrk~vsbed 1129 vbrk~fkdat 1130 vbrk~ernam 1131 vbrk~erzet 1132 vbrk~erdat 1133 vbrp~posnr 1134 vbrp~fkimg 1135 vbrp~vrkme 1136 vbrp~vgbel 1137 vbrp~vgpos 1138 vbrp~matnr 1139 FROM vbrk JOIN vbrp ON vbrk~vbeln = vbrp~vbeln 1140 INTO CORRESPONDING FIELDS OF TABLE gt_a 1141 WHERE vbrk~vbeln IN s_vbeln 1142 AND vbrk~fkart IN s_fkart 1143 AND vbrk~vkorg IN s_vkorg 1144 AND vbrk~ernam IN s_ernam 1145 AND vbrk~erdat IN s_erdat 1146 AND vbrp~vgbel IN s_vgbel. 1147 1148 IF gt_a IS INITIAL. 1149 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. 1150 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. 1151 ENDIF. 1152 1153 IF gt_a IS NOT INITIAL. 1154 SELECT 1155 tvkot~vkorg 1156 tvkot~vtext 1157 FROM tvkot 1158 INTO CORRESPONDING FIELDS OF TABLE gt_b 1159 FOR ALL ENTRIES IN gt_a 1160 WHERE tvkot~vkorg = gt_a-vkorg. 1161 1162 SELECT 1163 makt~matnr 1164 makt~maktx 1165 FROM makt 1166 INTO CORRESPONDING FIELDS OF TABLE gt_c 1167 FOR ALL ENTRIES IN gt_a 1168 WHERE makt~matnr = gt_a-matnr. 1169 ENDIF. 1170 1171 LOOP AT gt_a INTO gs_a. 1172 * IF gs_a-vbeln > 90001750. 1173 * gs_a-id = icon_green_light. 1174 * ENDIF. 1175 * IF gs_a-vbeln < 90001750. 1176 * gs_a-id = icon_red_light. 1177 * ENDIF. 1178 READ TABLE gt_b INTO gs_b WITH KEY vkorg = gs_a-vkorg. 1179 IF sy-subrc = 0. 1180 gs_a-vtext = gs_b-vtext. 1181 ENDIF. 1182 1183 READ TABLE gt_c INTO gs_c WITH KEY matnr = gs_a-matnr. 1184 IF sy-subrc = 0. 1185 gs_a-maktx = gs_c-maktx. 1186 ENDIF. 1187 MODIFY gt_a FROM gs_a. 1188 ENDLOOP. 1189 ENDFORM. 1190 1191 1192 FORM frm_user_command. "USING r_ucomm LIKE sy-ucomm 1193 "rs_selfield TYPE slis_selfield. 1194 1195 * BREAK-POINT. 1196 * DATA: lt_a TYPE TABLE OF aa, 1197 * ls_a TYPE aa. 1198 CLEAR ls_a. 1199 * CASE r_ucomm. 1200 * 1201 * 1202 * WHEN 'PRINT'. 1203 lt_a = gt_a. 1204 DELETE lt_a WHERE chk IS INITIAL. 1205 SORT lt_a BY vbeln. 1206 DELETE ADJACENT DUPLICATES FROM lt_a COMPARING vbeln."只保留相邻重复行的第一行数据 1207 LOOP AT lt_a INTO ls_a. 1208 * 抬头部分 1209 LOOP AT gt_a INTO gs_a WHERE vbeln = ls_a-vbeln." AND erdat = ls_a-erdat. 1210 * 行项目部分 1211 APPEND gs_a TO gtt_a. 1212 ENDLOOP. 1213 ENDLOOP. 1214 1215 DATA:g_name TYPE rs38l_fnam. "SMARTFORMS 1216 DATA:control TYPE ssfctrlop. 1217 DATA:output_options TYPE ssfcompop, 1218 l_job_output_info TYPE ssfcrescl. 1219 DATA:formname TYPE tdsfname . 1220 1221 1222 *g_name = '/1BCDWB/SF00000297'. 1223 * formname = 'ZBD_33160_001'."测试打印(SMARTFORM名字) 1224 1225 * g_name = '/1BCDWB/SF00000337'. 1226 * formname = 'ZBD_33160_004'."测试打印(SMARTFORM名字) 1227 1228 * g_name = '/1BCDWB/SF00000352'. 1229 * formname = 'ZBD_33160_005'."测试打印(SMARTFORM名字) 1230 1231 g_name = '/1BCDWB/SF00000359'. 1232 formname = 'ZBD_33160_006'."测试打印(SMARTFORM名字) 1233 1234 "开启批量打印 1235 control-no_open = 'X'. 1236 control-no_close = 'X'. 1237 output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面 1238 1239 1240 *打开Smartform 1241 CALL FUNCTION 'SSF_OPEN' 1242 EXPORTING 1243 output_options = output_options 1244 control_parameters = control 1245 * IMPORTING 1246 * JOB_OUTPUT_OPTIONS = 1247 EXCEPTIONS 1248 formatting_error = 1 1249 internal_error = 2 1250 send_error = 3 1251 user_canceled = 4 1252 OTHERS = 5. 1253 IF sy-subrc <> 0. 1254 MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. 1255 EXIT. 1256 ELSE. 1257 1258 CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' 1259 EXPORTING 1260 formname = formname 1261 IMPORTING 1262 fm_name = g_name 1263 EXCEPTIONS 1264 no_form = 1 1265 no_function_module = 2 1266 OTHERS = 3. 1267 IF sy-subrc <> 0. 1268 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 1269 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1270 EXIT. 1271 ENDIF. 1272 1273 1274 1275 CALL FUNCTION g_name 1276 EXPORTING 1277 control_parameters = control 1278 TABLES 1279 gt_item = gtt_a 1280 gt_head = lt_a. 1281 IF sy-subrc <> 0. 1282 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 1283 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1284 EXIT. 1285 ENDIF. 1286 1287 1288 1289 *关闭Smartform,此时会弹出一个选择打印机选项 1290 CLEAR l_job_output_info. 1291 CALL FUNCTION 'SSF_CLOSE' 1292 IMPORTING 1293 job_output_info = l_job_output_info 1294 EXCEPTIONS 1295 formatting_error = 1 1296 internal_error = 2 1297 send_error = 3 1298 OTHERS = 4. 1299 IF sy-subrc <> 0. 1300 MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno 1301 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. 1302 EXIT. 1303 ENDIF. 1304 1305 1306 IF l_job_output_info-outputdone = 'X'."打印成功 1307 1308 MESSAGE '打印成功!' TYPE 'S' . 1309 1310 ELSE. 1311 MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. 1312 ENDIF. 1313 ENDIF. 1314 1315 * ENDCASE. 1316 ENDFORM. 1317 1318 1319 *增加按钮 1320 *----------------------------------------------------------------------* 1321 *自定义状态 1322 *----------------------------------------------------------------------* 1323 FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab. 1324 *--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 1325 1326 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' . 1327 *--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB 1328 * SET TITLEBAR 'TITLE'. 1329 ENDFORM. 1330 *&---------------------------------------------------------------------* 1331 *& Module STATUS_9100 OUTPUT 1332 *&---------------------------------------------------------------------* 1333 *& 1334 *&---------------------------------------------------------------------* 1335 MODULE status_9100 OUTPUT. 1336 SET PF-STATUS 'Z_33160EXAM2'. 1337 SET TITLEBAR 'Z_33160EXAM'. 1338 ENDMODULE. 1339 *&---------------------------------------------------------------------* 1340 *& Module USER_COMMAND_9100 INPUT 1341 *&---------------------------------------------------------------------* 1342 * text 1343 *----------------------------------------------------------------------* 1344 MODULE user_command_9100 INPUT. 1345 save_ok_code = ok_code. 1346 CLEAR ok_code. 1347 CASE save_ok_code. 1348 WHEN 'PRINT'. 1349 PERFORM frm_user_command. 1350 WHEN '&F03' OR '&F12' OR '&F15'. 1351 LEAVE TO SCREEN 0. 1352 * LEAVE PROGRAM. 1353 WHEN OTHERS . 1354 ENDCASE. 1355 ENDMODULE. 1356 1357 *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9100' ITSELF 1358 CONTROLS: TC_9100 TYPE TABLEVIEW USING SCREEN 9100. 1359 1360 *&SPWIZARD: LINES OF TABLECONTROL 'TC_9100' 1361 DATA: G_TC_9100_LINES LIKE SY-LOOPC. 1362 1363 *&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE! 1364 INCLUDE Z2107_33160EXAM2B_PBO . 1365 INCLUDE Z2107_33160EXAM2B_PAI . 1366 INCLUDE Z2107_33160EXAM2B_INC . 1367 *&---------------------------------------------------------------------* 1368 *& Module REFRASH INPUT 1369 *&---------------------------------------------------------------------* 1370 * text 1371 *----------------------------------------------------------------------* 1372 MODULE refrash INPUT. 1373 1374 SELECT 1375 makt~matnr 1376 makt~maktx 1377 FROM makt 1378 INTO CORRESPONDING FIELDS OF ls_a 1379 where makt~matnr = gs_a-matnr. 1380 ENDSELECT. 1381 MODify gt_a 1382 from ls_a 1383 INDEX tc_9100-current_line 1384 TRANSPORTING 1385 matnr 1386 maktx. 1387 ENDMODULE. 1388 ``` 1389 1390 ![](C:\liuliu\typora\图片\Z2107_33160EXAM2B.png) 1391 1392 ```ABAP 1393 PROCESS BEFORE OUTPUT. 1394 *&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TC_9100' 1395 MODULE TC_9100_CHANGE_TC_ATTR. 1396 *&SPWIZARD: MODULE TC_9100_CHANGE_COL_ATTR. 1397 LOOP AT GT_A 1398 INTO GS_A 1399 WITH CONTROL TC_9100 1400 CURSOR TC_9100-CURRENT_LINE. 1401 MODULE TC_9100_GET_LINES. 1402 *&SPWIZARD: MODULE TC_9100_CHANGE_FIELD_ATTR 1403 ENDLOOP. 1404 1405 MODULE STATUS_9100. 1406 * 1407 PROCESS AFTER INPUT. 1408 *&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TC_9100' 1409 LOOP AT GT_A. 1410 CHAIN. 1411 FIELD GS_A-VBELN. 1412 FIELD GS_A-FKART. 1413 FIELD GS_A-FKTYP. 1414 FIELD GS_A-VBTYP. 1415 FIELD GS_A-WAERK. 1416 FIELD GS_A-VKORG. 1417 FIELD GS_A-VTEXT. 1418 FIELD GS_A-VTWEG. 1419 FIELD GS_A-VSBED. 1420 FIELD GS_A-FKDAT. 1421 FIELD GS_A-ERNAM. 1422 FIELD GS_A-ERZET. 1423 FIELD GS_A-ERDAT. 1424 FIELD GS_A-POSNR. 1425 FIELD GS_A-FKIMG. 1426 FIELD GS_A-VRKME. 1427 FIELD GS_A-VGBEL. 1428 FIELD GS_A-VGPOS. 1429 FIELD GS_A-MATNR. 1430 FIELD GS_A-MAKTX. 1431 MODULE TC_9100_MODIFY ON CHAIN-REQUEST. 1432 endchain. 1433 FIELD GS_A-CHK 1434 MODULE TC_9100_MARK ON REQUEST. 1435 CHAIN. 1436 FIELD gs_a-MATNR. 1437 FIELD gs_a-MAKTX. 1438 MODULE refrash ON CHAIN-INPUT. 1439 ENDCHAIN. 1440 ENDLOOP. 1441 MODULE TC_9100_USER_COMMAND. 1442 *&SPWIZARD: MODULE TC_9100_CHANGE_TC_ATTR. 1443 *&SPWIZARD: MODULE TC_9100_CHANGE_COL_ATTR. 1444 1445 MODULE USER_COMMAND_9100. 1446 ``` 1447 1448 1449 1450 ## 2、Z2107_33160EXAM2C 1451 1452 ![](C:\liuliu\typora\图片\Z2107_33160EXAM2C要求.png) 1453 1454 ```ABAP 1455 *&---------------------------------------------------------------------* 1456 *& Report Z2107_33160EXAM2C 1457 *&---------------------------------------------------------------------* 1458 *& 1459 *&---------------------------------------------------------------------* 1460 REPORT z2107_33160exam2c. 1461 1462 TABLES: aufk, afko,t001w,makt. 1463 1464 TYPES : BEGIN OF typ_aufk, 1465 matnr TYPE makt-matnr, 1466 aufnr TYPE aufk-aufnr, 1467 ernam TYPE aufk-ernam, 1468 erdat TYPE aufk-erdat, 1469 bukrs TYPE aufk-bukrs, 1470 werks TYPE aufk-werks, 1471 name1 TYPE t001w-name1, 1472 plnbez TYPE afko-plnbez, 1473 maktx TYPE makt-maktx, 1474 gasmg TYPE afko-gasmg, 1475 gamng TYPE afko-gamng, 1476 gmein TYPE afko-gmein, 1477 chk, 1478 END OF typ_aufk. 1479 1480 TYPES: BEGIN OF typ_t001w, 1481 werks TYPE t001w-werks, 1482 name1 TYPE t001w-name1, 1483 END OF typ_t001w. 1484 1485 TYPES : BEGIN OF typ_makt, 1486 matnr TYPE makt-matnr, 1487 maktx TYPE makt-maktx, 1488 END OF typ_makt. 1489 . 1490 SELECT-OPTIONS:s_ernam FOR aufk-ernam NO-EXTENSION NO INTERVALS , 1491 s_aufnr FOR aufk-aufnr, 1492 s_erdat FOR aufk-erdat, 1493 s_bukrs FOR aufk-bukrs, 1494 s_werks FOR aufk-werks, 1495 s_plnbez FOR afko-plnbez. 1496 1497 DATA: gt_afko_aufk TYPE TABLE OF zl33160_yt008, 1498 gt_t001w TYPE TABLE OF typ_t001w, 1499 gt_makt TYPE TABLE OF typ_makt, 1500 gs_afko_aufk TYPE zl33160_yt008, 1501 gs_t001w TYPE typ_t001w, 1502 gs_makt TYPE typ_makt, 1503 ls_aufk TYPE zl33160_yt008, 1504 it_aufk TYPE TABLE OF zl33160_yt008. 1505 1506 *定义smartfroms 1507 DATA g_name TYPE rs38l_fnam. "SMARTFORMS 1508 DATA:formname TYPE tdsfname . 1509 DATA:control TYPE ssfctrlop. 1510 DATA:output_options TYPE ssfcompop, 1511 l_job_output_info TYPE ssfcrescl. 1512 1513 *定义返回码 1514 DATA: ok_code TYPE sy-ucomm, 1515 code_com TYPE sy-ucomm. 1516 1517 INITIALIZATION."(初始化) 1518 1519 1520 AT SELECTION-SCREEN."(屏幕跳出前) 1521 1522 START-OF-SELECTION."(取数据) 1523 PERFORM frm_get. 1524 PERFORM add. 1525 1526 END-OF-SELECTION."(展示数据) 1527 CALL SCREEN 9010. 1528 1529 *查找数据 1530 FORM frm_get. 1531 SELECT aufk~aufnr 1532 aufk~ernam 1533 aufk~erdat 1534 aufk~bukrs 1535 aufk~werks 1536 afko~plnbez 1537 afko~gasmg 1538 afko~gamng 1539 afko~gmein 1540 FROM aufk JOIN afko ON aufk~aufnr = afko~aufnr 1541 INTO CORRESPONDING FIELDS OF TABLE gt_afko_aufk 1542 WHERE aufk~aufnr IN s_aufnr 1543 AND aufk~ernam IN s_ernam 1544 AND aufk~erdat IN s_erdat 1545 AND aufk~bukrs IN s_bukrs 1546 AND aufk~werks IN s_werks 1547 AND afko~plnbez IN s_plnbez. 1548 1549 IF gt_afko_aufk IS INITIAL. 1550 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. 1551 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. 1552 ENDIF. 1553 1554 IF gt_afko_aufk IS NOT INITIAL. 1555 SELECT werks 1556 name1 1557 FROM t001w 1558 INTO CORRESPONDING FIELDS OF TABLE gt_t001w 1559 FOR ALL ENTRIES IN gt_afko_aufk 1560 WHERE werks = gt_afko_aufk-werks. 1561 1562 SELECT 1563 makt~matnr 1564 makt~maktx 1565 FROM makt 1566 INTO CORRESPONDING FIELDS OF TABLE gt_makt 1567 FOR ALL ENTRIES IN gt_afko_aufk 1568 WHERE makt~matnr = gt_afko_aufk-plnbez. 1569 ENDIF. 1570 1571 ENDFORM. 1572 *处理数据 1573 FORM add. 1574 1575 LOOP AT gt_afko_aufk INTO gs_afko_aufk. 1576 READ TABLE gt_t001w INTO gs_t001w WITH KEY werks = gs_afko_aufk-werks. 1577 IF sy-subrc = 0. 1578 gs_afko_aufk-name1 = gs_t001w-name1. 1579 ENDIF. 1580 1581 READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_afko_aufk-plnbez. 1582 IF sy-subrc = 0. 1583 gs_afko_aufk-maktx = gs_makt-maktx. 1584 ENDIF. 1585 MODIFY gt_afko_aufk FROM gs_afko_aufk. 1586 1587 ENDLOOP. 1588 1589 ENDFORM. 1590 *屏幕开发-------------------------------------------------- 1591 *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9010' ITSELF 1592 CONTROLS: tc_9010 TYPE TABLEVIEW USING SCREEN 9010. 1593 1594 *&SPWIZARD: LINES OF TABLECONTROL 'TC_9010' 1595 DATA: g_tc_9010_lines LIKE sy-loopc. 1596 1597 *DATA: OK_CODE LIKE SY-UCOMM. 1598 1599 1600 *&---------------------------------------------------------------------* 1601 *& Module STATUS_9010 OUTPUT 1602 *&---------------------------------------------------------------------* 1603 *& 1604 *&---------------------------------------------------------------------* 1605 MODULE status_9010 OUTPUT. 1606 SET PF-STATUS 'Z33160_SCREEN_STATUS'. 1607 SET TITLEBAR 'Z33160_SCREEN_TITLE'. 1608 ENDMODULE. 1609 *&---------------------------------------------------------------------* 1610 *& Module USER_COMMAND_9010 INPUT 1611 *&---------------------------------------------------------------------* 1612 * text 1613 *----------------------------------------------------------------------* 1614 MODULE user_command_9010 INPUT. 1615 PERFORM frm_select. 1616 ENDMODULE. 1617 1618 1619 FORM frm_select. 1620 DATA: lt_aufk LIKE gt_afko_aufk. 1621 DATA con_item TYPE i. 1622 DATA con_head TYPE i. 1623 DATA i TYPE i. 1624 * formname = 'ZT31724_FORM004'. "测试打印(SMARTFORM名字) 1625 * g_name = '/1BCDWB/SF00000358'. 1626 1627 formname = 'ZBD_33160_007'. "测试打印(SMARTFORM名字) 1628 g_name = '/1BCDWB/SF00000361'. 1629 1630 control-no_open = 'X'. 1631 control-no_close = 'X'. 1632 output_options-tdiexit = 'X'. "预览打印时,点打印后立即退出预览界面 1633 1634 code_com = ok_code. 1635 CLEAR ok_code. 1636 CASE code_com. 1637 1638 WHEN 'PRINT'. 1639 lt_aufk = gt_afko_aufk. 1640 DELETE lt_aufk WHERE chk IS INITIAL. 1641 SORT lt_aufk BY plnbez. 1642 DELETE ADJACENT DUPLICATES FROM lt_aufk COMPARING plnbez. 1643 CLEAR it_aufk. 1644 LOOP AT lt_aufk INTO ls_aufk. 1645 * 抬头部分 1646 1647 LOOP AT gt_afko_aufk INTO gs_afko_aufk WHERE plnbez = ls_aufk-plnbez. 1648 * 行项目部分 1649 1650 APPEND gs_afko_aufk TO it_aufk. 1651 ENDLOOP. 1652 DESCRIBE TABLE it_aufk LINES con_item. 1653 con_head = con_item MOD 8. 1654 i = 8 - con_head. 1655 DO i TIMES. 1656 APPEND INITIAL LINE TO it_aufk. 1657 ENDDO. 1658 * CLEAR it_aufk. 1659 CLEAR i. 1660 ENDLOOP. 1661 1662 CALL FUNCTION 'SSF_OPEN' 1663 EXPORTING 1664 * ARCHIVE_PARAMETERS = 1665 * USER_SETTINGS = 'X' 1666 * MAIL_SENDER = 1667 * MAIL_RECIPIENT = 1668 * MAIL_APPL_OBJ = 1669 output_options = output_options 1670 control_parameters = control 1671 * IMPORTING 1672 * JOB_OUTPUT_OPTIONS = 1673 EXCEPTIONS 1674 formatting_error = 1 1675 internal_error = 2 1676 send_error = 3 1677 user_canceled = 4 1678 OTHERS = 5. 1679 IF sy-subrc <> 0. 1680 * Implement suitable error handling here 1681 MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. 1682 EXIT. 1683 ENDIF. 1684 1685 CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' 1686 EXPORTING 1687 formname = formname 1688 * VARIANT = ' ' 1689 * DIRECT_CALL = ' ' 1690 IMPORTING 1691 fm_name = g_name 1692 EXCEPTIONS 1693 no_form = 1 1694 no_function_module = 2 1695 OTHERS = 3. 1696 IF sy-subrc <> 0. 1697 * Implement suitable error handling here 1698 ENDIF. 1699 CALL FUNCTION g_name 1700 EXPORTING 1701 * 1702 control_parameters = control 1703 gs_head = ls_aufk 1704 * 1705 TABLES 1706 gt_item = it_aufk. 1707 1708 1709 IF sy-subrc <> 0. 1710 * error handling 1711 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 1712 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1713 ENDIF. 1714 CLEAR l_job_output_info. 1715 1716 CALL FUNCTION 'SSF_CLOSE' 1717 IMPORTING 1718 job_output_info = l_job_output_info 1719 EXCEPTIONS 1720 formatting_error = 1 1721 internal_error = 2 1722 send_error = 3 1723 OTHERS = 4. 1724 IF sy-subrc <> 0. 1725 MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno 1726 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. 1727 EXIT. 1728 ENDIF. 1729 1730 1731 1732 WHEN '&F03' OR '&F12' OR '&F15'. 1733 * leave to SCREEN 0. 1734 LEAVE PROGRAM. 1735 WHEN OTHERS . 1736 ENDCASE. 1737 1738 1739 ENDFORM. 1740 1741 1742 *&---------------------------------------------------------------------* 1743 *& Module FIELD_CHECK INPUT 1744 *&---------------------------------------------------------------------* 1745 * text 1746 *----------------------------------------------------------------------* 1747 MODULE field_check INPUT. 1748 SELECT 1749 afko~plnbez 1750 makt~maktx 1751 FROM afko LEFT JOIN makt 1752 ON afko~plnbez = makt~matnr 1753 INTO CORRESPONDING FIELDS OF gs_afko_aufk 1754 WHERE afko~plnbez = gs_afko_aufk-plnbez. 1755 ENDSELECT. 1756 MODIFY gt_afko_aufk 1757 FROM gs_afko_aufk 1758 INDEX tc_9010-current_line 1759 TRANSPORTING 1760 maktx 1761 plnbez. 1762 ENDMODULE. 1763 ``` 1764 1765 ![](C:\liuliu\typora\图片\z2107_33160exam2c.png) 1766 1767 ## 3、z2107_32998_exam2_c_new 1768 1769 ```ABAP 1770 *&---------------------------------------------------------------------* 1771 *& Report Z2107_32998_EXAM2_C_NEW 1772 *&---------------------------------------------------------------------* 1773 *& 1774 *&---------------------------------------------------------------------* 1775 REPORT z2107_32998_exam2_c_new. 1776 1777 1778 TABLES: aufk , afko , makt , t001w , icon. 1779 1780 TYPES:BEGIN OF typ_makt, 1781 matnr TYPE makt-matnr, 1782 maktx TYPE makt-maktx, 1783 END OF typ_makt. 1784 TYPES:BEGIN OF typ_t001w, 1785 werks TYPE t001w-werks, 1786 name1 TYPE t001w-name1, 1787 END OF typ_t001w. 1788 DATA: gt_makt TYPE TABLE OF typ_makt, 1789 gs_makt TYPE typ_makt. 1790 1791 1792 DATA: gt_alv TYPE TABLE OF ze32998_exam2c, 1793 gt_alv2 TYPE TABLE OF ze32998_exam2c, 1794 gt_alv3 TYPE TABLE OF ze32998_exam2c, 1795 gs_alv TYPE ze32998_exam2c. 1796 DATA: con_item TYPE i, " 记录内表总行数 。 1797 * con_head TYPE i, 1798 i TYPE i, 1799 j TYPE i, 1800 k TYPE i, 1801 page_no TYPE i. " 记录当前页数 。 1802 1803 1804 1805 DATA: lt_lt TYPE TABLE OF ze32998_exam2c, 1806 ls_lt TYPE ze32998_exam2c. 1807 1808 DATA: ok_code TYPE sy-ucomm, 1809 save_ok_code TYPE sy-ucomm. 1810 1811 1812 ******************* 初始化打印数据 ************** 1813 DATA:g_name TYPE rs38l_fnam. "SMARTFORMS 1814 DATA:control TYPE ssfctrlop. 1815 DATA:output_options TYPE ssfcompop, 1816 l_job_output_info TYPE ssfcrescl. 1817 DATA:formname TYPE tdsfname . 1818 1819 g_name = '/1BCDWB/SF00000355'." . /1BCDWB/SF00000339 . 1820 formname = 'Z_32998_EXAM2CNEW'."测试打印(SMARTFORM名字)ZBD_33160_003 . 1821 "开启批量打印 1822 control-no_open = 'X'. 1823 control-no_close = 'X'. 1824 output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面 1825 1826 1827 1828 1829 * NO-EXTENSION 限制只能输入一行数据 NO INTERVALS 限制只能输入一个单元(LOW字段) 1830 *开始选择屏幕 1831 SELECT-OPTIONS: s_ernam FOR aufk-ernam NO-EXTENSION NO INTERVALS, 1832 s_aufnr FOR aufk-aufnr , 1833 s_erdat FOR aufk-erdat, 1834 s_bukrs FOR aufk-bukrs, 1835 s_werks FOR aufk-werks, 1836 s_plnbez FOR afko-plnbez. 1837 1838 INITIALIZATION."(初始化) 。 1839 PERFORM frm_init. "调用子程序 开始屏幕 1840 1841 AT SELECTION-SCREEN. " (屏幕跳出前) 。 1842 * PERFORM frm_check_screen. "调用子程序 检测开始屏幕 1843 1844 START-OF-SELECTION. " (取数据) 。 1845 1846 PERFORM frm_sel_data. "调用子程序 查数据到内表 1847 PERFORM frm_deal. "调用子程序 整合数据到gt_alv . 1848 1849 END-OF-SELECTION. " 1850 * PERFORM frm_output. "调用子程序 输出 1851 CALL SCREEN 9004. 1852 1853 1854 FORM frm_init. " 设置开始屏幕属性 1855 s_ernam-sign = 'I'. 1856 s_ernam-option = 'EQ'. 1857 s_ernam-low = sy-uname. " 获取 默认自己账号 1858 APPEND s_ernam. 1859 1860 s_erdat-sign = 'I'. 1861 s_erdat-option = 'BT'. 1862 s_erdat-low+0(4) = sy-datum+0(4). " sy-daum 获取当前日期 1863 s_erdat-low+4(4) = '0101'. " 2021/01/01 1864 s_erdat-high+0(4) = sy-datum+0(4). " sy-daum 获取当前日期 1865 s_erdat-high+4(4) = '1231'. " 2021/12/31 1866 APPEND s_erdat. 1867 ENDFORM. 1868 1869 1870 * 查询 1871 FORM frm_sel_data. 1872 * 查询多字段 1873 SELECT aufk~aufnr 1874 aufk~ernam 1875 aufk~erdat 1876 * aufk~bukrs 1877 aufk~werks 1878 afko~plnbez 1879 afko~gasmg 1880 afko~gamng 1881 afko~gmein 1882 FROM aufk JOIN afko ON aufk~aufnr = afko~aufnr 1883 INTO CORRESPONDING FIELDS OF TABLE gt_alv 1884 WHERE aufk~aufnr IN s_aufnr 1885 AND aufk~ernam IN s_ernam 1886 AND aufk~erdat IN s_erdat 1887 AND aufk~bukrs IN s_bukrs 1888 AND aufk~werks IN s_werks 1889 AND afko~plnbez IN s_plnbez. 1890 1891 IF gt_alv IS INITIAL. 1892 MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'." 提示 没有取到数据 1893 LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. " 返回开始屏幕 1894 * S成功 E错误(程序终止) W警告 I消息框(弹出消息框) A错误(弹出框) X系统错误 1895 ENDIF. 1896 1897 IF gt_alv IS NOT INITIAL. 1898 * 查询 maktx 字段 1899 SELECT makt~maktx makt~matnr 1900 FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_makt 1901 FOR ALL ENTRIES IN gt_alv 1902 WHERE matnr = gt_alv-plnbez 1903 AND spras = sy-langu. " spras = sy-langu 登陆语言。就是查询时,按自己的登陆语言进行查询, 1904 ENDIF. 1905 ENDFORM. 1906 1907 * 整合数据 1908 FORM frm_deal. 1909 LOOP AT gt_alv INTO gs_alv. 1910 * 读取数据 maktx 1911 READ TABLE gt_makt INTO gs_makt WITH KEY matnr = gs_alv-plnbez. 1912 IF sy-subrc = 0. 1913 gs_alv-maktx = gs_makt-maktx. 1914 ENDIF. 1915 * 更新 gt_lt 1916 MODIFY gt_alv FROM gs_alv. 1917 ENDLOOP. 1918 ENDFORM. 1919 1920 1921 FORM frm_user_command. "USING r_ucomm LIKE sy-ucomm 1922 "rs_selfield TYPE slis_selfield. 1923 1924 lt_lt = gt_alv. 1925 DELETE lt_lt WHERE chk IS INITIAL. 1926 SORT lt_lt BY plnbez. 1927 DELETE ADJACENT DUPLICATES FROM lt_lt COMPARING plnbez. 1928 1929 *打开Smartform 1930 CALL FUNCTION 'SSF_OPEN' 1931 EXPORTING 1932 output_options = output_options 1933 control_parameters = control 1934 * IMPORTING 1935 * JOB_OUTPUT_OPTIONS = 1936 EXCEPTIONS 1937 formatting_error = 1 1938 internal_error = 2 1939 send_error = 3 1940 user_canceled = 4 1941 OTHERS = 5. 1942 1943 * 开始打印 1944 LOOP AT lt_lt INTO ls_lt. 1945 * 抬头部分 1946 LOOP AT gt_alv INTO gs_alv WHERE plnbez = ls_lt-plnbez. 1947 * 行项目部分 将需要打印的行放入新的内表 。 1948 APPEND gs_alv TO gt_alv2. 1949 ENDLOOP. 1950 1951 DESCRIBE TABLE gt_alv2 LINES con_item. " 计算内表 gt_alv2 的行数,将行数放到变量con_item里 。 1952 i = con_item MOD 10. " 每页控制8行数据,最后页数据条数 。 1953 k = 10 - i. 1954 DO k TIMES. 1955 APPEND INITIAL LINE TO gt_alv2. " 补充缺少的空白行 。 1956 ENDDO. 1957 1958 IF sy-subrc <> 0. 1959 MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. 1960 EXIT. 1961 ELSE. 1962 CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' 1963 EXPORTING 1964 formname = formname 1965 IMPORTING 1966 fm_name = g_name 1967 EXCEPTIONS 1968 no_form = 1 1969 no_function_module = 2 1970 OTHERS = 3. 1971 IF sy-subrc <> 0. 1972 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 1973 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1974 EXIT. 1975 ENDIF. 1976 CALL FUNCTION g_name 1977 EXPORTING 1978 control_parameters = control 1979 gs_head = ls_lt " 抬头 。 1980 * page_number = page_no " 页数 。 1981 TABLES 1982 gt_item = gt_alv2. " 表体 。 1983 IF sy-subrc <> 0. 1984 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 1985 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1986 EXIT. 1987 ENDIF. 1988 ENDIF. 1989 CLEAR gt_alv2. 1990 ENDLOOP. 1991 1992 1993 *关闭Smartform,此时会弹出一个选择打印机选项 1994 CLEAR l_job_output_info. 1995 CALL FUNCTION 'SSF_CLOSE' 1996 IMPORTING 1997 job_output_info = l_job_output_info 1998 EXCEPTIONS 1999 formatting_error = 1 2000 internal_error = 2 2001 send_error = 3 2002 OTHERS = 4. 2003 IF sy-subrc <> 0. 2004 MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno 2005 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. 2006 EXIT. 2007 ENDIF. 2008 2009 IF l_job_output_info-outputdone = 'X'."打印成功 2010 MESSAGE '打印成功!' TYPE 'S' . 2011 ELSE. 2012 MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. 2013 ENDIF. 2014 ENDFORM. 2015 2016 2017 2018 *&---------------------------------------------------------------------* 2019 *& Module USER_COMMAND_9004 INPUT 2020 *&---------------------------------------------------------------------* 2021 * text 2022 *----------------------------------------------------------------------* 2023 MODULE user_command_9004 INPUT. 2024 save_ok_code = ok_code. 2025 CLEAR ok_code. 2026 CASE save_ok_code. 2027 WHEN 'PRINT1'. 2028 2029 PERFORM frm_user_command. 2030 WHEN '&F03' OR '&F12' OR '&F15'. 2031 LEAVE TO SCREEN 0. 2032 * LEAVE PROGRAM. 2033 WHEN OTHERS . 2034 ENDCASE. 2035 ENDMODULE. 2036 2037 *&---------------------------------------------------------------------* 2038 *& Module STATUS_9004 OUTPUT 2039 *&---------------------------------------------------------------------* 2040 *& 2041 *&---------------------------------------------------------------------* 2042 MODULE status_9004 OUTPUT. 2043 SET PF-STATUS 'Z32998_EXAM2C_STATUS'. 2044 SET TITLEBAR 'Z32998_EXAM2C_TITLE'. 2045 ENDMODULE. 2046 2047 2048 *&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9004' ITSELF 2049 CONTROLS: tc_9004 TYPE TABLEVIEW USING SCREEN 9004. 2050 2051 *&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE! 2052 INCLUDE z2107_32998_exam2_c_pbo . 2053 INCLUDE z2107_32998_exam2_c_pai . 2054 2055 2056 *&---------------------------------------------------------------------* 2057 *& Module REFRASH INPUT 2058 *&---------------------------------------------------------------------* 2059 * text 2060 *----------------------------------------------------------------------* 2061 MODULE refrash INPUT. 2062 SELECT 2063 afko~plnbez 2064 makt~maktx 2065 FROM afko LEFT JOIN makt 2066 ON afko~plnbez = makt~matnr 2067 INTO CORRESPONDING FIELDS OF gs_alv 2068 WHERE afko~plnbez = gs_alv-plnbez. 2069 ENDSELECT. 2070 MODIFY gt_alv 2071 FROM gs_alv 2072 INDEX tc_9004-current_line 2073 TRANSPORTING 2074 plnbez 2075 maktx. 2076 ENDMODULE. 2077 ``` 2078 2079 2080 2081 # 三、第三次考核 2082 2083 ## 1、Z2107_33160_EXAM3 2084 2085 ```ABAP 2086 *&---------------------------------------------------------------------* 2087 *& Report Z2107_33160_EXAM3 2088 *&---------------------------------------------------------------------* 2089 *& 2090 *&---------------------------------------------------------------------* 2091 REPORT z2107_33160_exam3. 2092 2093 CLASS a_event DEFINITION. 2094 PUBLIC SECTION. 2095 METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid 2096 IMPORTING e_row e_column. 2097 2098 * METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid 2099 * IMPORTING e_object e_interactive. 2100 2101 METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid 2102 IMPORTING er_data_changed 2103 e_onf4 2104 e_onf4_before 2105 e_onf4_after 2106 e_ucomm. 2107 ENDCLASS. 2108 2109 CLASS a_event IMPLEMENTATION. 2110 METHOD a_methods. 2111 CONDENSE e_row NO-GAPS. "删除字符串中的空格 2112 CONDENSE e_column NO-GAPS. 2113 2114 * IF e_column = 'LIFNR'. 2115 * SET PARAMETER ID 'BPA' FIELD lfa1-lifnr. 2116 * CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN. 2117 ** BREAK-POINT. 2118 * ENDIF. 2119 ENDMETHOD. 2120 2121 METHOD c_methods. 2122 LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). 2123 IF ls_modi-fieldname = 'HKONT'. 2124 SELECT SINGLE txt20 2125 FROM skat 2126 INTO @DATA(l_maktx) 2127 WHERE saknr = @ls_modi-value AND ktopl = 'YCOA' AND spras = @sy-langu. 2128 IF sy-subrc = 0. 2129 2130 CALL METHOD er_data_changed->modify_cell 2131 EXPORTING 2132 i_row_id = ls_modi-row_id 2133 i_tabix = ls_modi-tabix 2134 i_fieldname = 'TXT20' 2135 i_value = l_maktx. 2136 ENDIF. 2137 ENDIF. 2138 ENDLOOP. 2139 ENDMETHOD. 2140 2141 ENDCLASS. 2142 2143 DATA: a_event1 TYPE REF TO a_event. 2144 DATA:it_raw TYPE truxs_t_text_data. 2145 2146 DATA: ok_code LIKE sy-ucomm, 2147 code_com TYPE sy-ucomm. 2148 2149 *定义表结构 2150 TYPES : BEGIN OF aa, 2151 bukrs TYPE bkpf-bukrs, 2152 gjahr TYPE bkpf-gjahr, 2153 belnr TYPE bkpf-belnr, 2154 bktxt TYPE bkpf-bktxt, 2155 buzei TYPE bseg-buzei, 2156 bschl TYPE bseg-bschl, 2157 hkont TYPE bseg-hkont, 2158 txt20 TYPE skat-txt20, 2159 shkzg TYPE bseg-shkzg, 2160 dmbtr TYPE bseg-dmbtr, 2161 chk, 2162 END OF aa. 2163 2164 2165 *定义内表和表空间 2166 DATA: gt_a TYPE TABLE OF aa, 2167 gs_a TYPE aa, 2168 gt_b TYPE TABLE OF aa, 2169 gs_b TYPE aa, 2170 lt_a TYPE TABLE OF aa, 2171 rt_a TYPE TABLE OF aa, 2172 rs_a TYPE aa, 2173 gtt_a TYPE TABLE OF aa. 2174 2175 DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 2176 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 2177 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性 2178 2179 DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 2180 gs_table TYPE scrfname VALUE 'CON', "屏幕中定义的控件 2181 alv_grid TYPE REF TO cl_gui_alv_grid. 2182 2183 DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表 2184 DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表 2185 DATA p_mode TYPE c VALUE 'A'."bdc运行模式 2186 2187 2188 *选择屏幕界面 2189 PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY. 2190 2191 AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. 2192 2193 *本地文件搜索帮助 2194 PERFORM get_filename_for_upload. 2195 2196 INITIALIZATION."(初始化) 2197 *PERFORM frm_init. 2198 2199 AT SELECTION-SCREEN."(屏幕跳出前) 2200 * PERFORM frm_check. 2201 2202 START-OF-SELECTION."(取数据) 2203 PERFORM excle_upload. 2204 PERFORM frm_get. 2205 PERFORM frm_deal. 2206 CALL SCREEN 9000. 2207 2208 END-OF-SELECTION."(展示数据) 2209 2210 2211 FORM get_filename_for_upload. 2212 CALL FUNCTION 'WS_FILENAME_GET' 2213 EXPORTING 2214 * DEF_FILENAME = ' ' 2215 * DEF_PATH = ' ' 2216 mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' 2217 "mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' 2218 mode = '0 ' 2219 * TITLE = ' ' 2220 IMPORTING 2221 filename = p_file 2222 * RC = 2223 EXCEPTIONS 2224 inv_winsys = 1 2225 no_batch = 2 2226 selection_cancel = 3 2227 selection_error = 4 2228 OTHERS = 5. 2229 IF p_file = ''. 2230 MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. 2231 ENDIF. 2232 2233 IF sy-subrc <> 0. 2234 * Implement suitable error handling here 2235 ENDIF. 2236 ENDFORM. 2237 2238 FORM excle_upload . 2239 DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE. 2240 CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 2241 EXPORTING 2242 filename = p_file 2243 i_begin_col = 1 2244 i_begin_row = 1 "从第三行开始取数 2245 i_end_col = 255 2246 i_end_row = 65535 2247 TABLES 2248 intern = it_data1 2249 EXCEPTIONS 2250 inconsistent_parameters = 1 2251 upload_ole = 2 2252 OTHERS = 3. 2253 2254 IF sy-subrc <> 0. 2255 MESSAGE s000(zfi01) WITH '文件打开失败!' DISPLAY LIKE 'E'. 2256 LEAVE LIST-PROCESSING. 2257 ENDIF. 2258 FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline. 2259 SORT it_data1 BY row. 2260 *转换结构 2261 LOOP AT it_data1 ASSIGNING <wa_itab>. 2262 CASE <wa_itab>-col. 2263 WHEN '0001'. 2264 gs_a-bukrs = <wa_itab>-value. 2265 WHEN '0002'. 2266 gs_a-gjahr = <wa_itab>-value. 2267 WHEN '0003'. 2268 gs_a-belnr = <wa_itab>-value. 2269 ENDCASE. 2270 AT END OF row. 2271 APPEND gs_a TO gt_a. 2272 CLEAR gs_a. 2273 ENDAT. 2274 ENDLOOP. 2275 ENDFORM. 2276 2277 2278 FORM frm_get. 2279 SELECT bkpf~bukrs 2280 bkpf~gjahr 2281 bkpf~belnr 2282 bkpf~bktxt 2283 bseg~buzei 2284 bseg~bschl 2285 bseg~hkont 2286 skat~txt20 2287 bseg~shkzg 2288 bseg~dmbtr 2289 FROM ( bkpf JOIN bseg ON bkpf~bukrs = bseg~bukrs 2290 AND bkpf~gjahr = bseg~gjahr 2291 AND bkpf~belnr = bseg~belnr ) 2292 JOIN skat ON bseg~hkont = skat~saknr 2293 AND ktopl = 'YCOA' 2294 AND spras = sy-langu 2295 INTO CORRESPONDING FIELDS OF TABLE gt_a 2296 FOR ALL ENTRIES IN gt_a 2297 WHERE bkpf~bukrs = gt_a-bukrs 2298 AND bkpf~gjahr = gt_a-gjahr 2299 AND bkpf~belnr = gt_a-belnr. 2300 ENDFORM. 2301 2302 2303 FORM frm_deal. 2304 PERFORM frm_set_fieldcat. 2305 PERFORM frm_set_layout. 2306 ENDFORM. 2307 2308 FORM frm_set_fieldcat. 2309 PERFORM frm_build_fieldcat USING: 'CHK' '选择框' 'X' 'X', 2310 'BUKRS' '公司代码' '' '', 2311 'GJAHR' '会计年度' '' '', 2312 'BELNR' '凭证号码' '' '', 2313 'BKTXT' '凭证抬头文本' '' '', 2314 'BUZEI' '会计凭证中的行项目' '' '', 2315 'BSCHL' '过账码' '' '', 2316 'HKONT' '总账科目' 'X' '', 2317 'TXT20' '总帐科目名称' '' '', 2318 'SHKZG' '借方/贷方标识' '' '', 2319 'DMBTR' '按本位币计的金额' '' ''. 2320 ENDFORM. 2321 2322 FORM frm_set_layout . "还是ALV的一些设置 2323 "ALV 界面描述 2324 CLEAR gs_layout. 2325 gs_layout-box_fname = 'CHK'. "选择行控制 2326 gs_layout-sel_mode = 'A'. "设置行模式" 2327 gs_layout-cwidth_opt = 'X'. "优化列宽设置" 2328 gs_layout-zebra = 'X'. "设置斑马线" 2329 ENDFORM. " frm_set_layout 2330 2331 FORM frm_build_fieldcat USING fu_1 2332 fu_2 2333 fu_3 2334 fu_4. 2335 gs_fieldcat-fieldname = fu_1. 2336 gs_fieldcat-scrtext_l = fu_2. 2337 gs_fieldcat-edit = fu_3. 2338 gs_fieldcat-checkbox = fu_4. 2339 APPEND gs_fieldcat TO gt_fieldcat. 2340 ENDFORM. 2341 2342 2343 MODULE status_9000 OUTPUT. 2344 SET PF-STATUS 'Z33160_STATUS'. 2345 * SET TITLEBAR 'xxx'. 2346 IF gs_custom_container IS INITIAL. "容器 2347 2348 CREATE OBJECT gs_custom_container 2349 EXPORTING 2350 container_name = gs_table. 2351 CREATE OBJECT alv_grid 2352 EXPORTING 2353 i_parent = gs_custom_container. 2354 2355 * 设置enter事件 2356 CALL METHOD alv_grid->register_edit_event 2357 EXPORTING 2358 i_event_id = cl_gui_alv_grid=>mc_evt_modified 2359 EXCEPTIONS 2360 error = 1 2361 OTHERS = 2. 2362 2363 CREATE OBJECT a_event1. 2364 SET HANDLER a_event1->a_methods FOR alv_grid. 2365 SET HANDLER a_event1->c_methods FOR alv_grid. 2366 2367 CALL METHOD alv_grid->set_table_for_first_display "显示ALV 2368 EXPORTING 2369 is_layout = gs_layout 2370 CHANGING 2371 it_outtab = gt_a 2372 it_fieldcatalog = gt_fieldcat 2373 EXCEPTIONS 2374 invalid_parameter_combination = 1 2375 program_error = 2 2376 too_many_lines = 3 2377 OTHERS = 4. 2378 ELSE. 2379 CALL METHOD alv_grid->refresh_table_display 2380 EXCEPTIONS 2381 finished = 1 2382 OTHERS = 2. 2383 IF sy-subrc <> 0. 2384 *--异常处理 2385 ENDIF. 2386 2387 ENDIF. 2388 2389 ENDMODULE. 2390 2391 MODULE user_command_9000 INPUT. 2392 PERFORM frm_get_maktx. 2393 ENDMODULE. 2394 2395 FORM frm_get_maktx. 2396 code_com = ok_code. 2397 CLEAR ok_code. 2398 CASE code_com. 2399 WHEN '&F03' OR '&F12' OR '&F15'. 2400 LEAVE TO SCREEN 0. 2401 * LEAVE PROGRAM. 2402 * WHEN '&IC1'. 2403 * IF rs_selfield-fieldname = 'LIFNR'." 控制 鼠标双击列 2404 * SET PARAMETER ID 'ANR' FIELD rs_selfield-value. 2405 * CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN. 2406 * ENDIF. 2407 WHEN 'SAVE'. 2408 lt_a = gt_a. 2409 DELETE lt_a WHERE chk IS INITIAL. 2410 PERFORM bdc. 2411 PERFORM dd. 2412 ENDCASE. 2413 ENDFORM. 2414 2415 2416 FORM bdc. 2417 CLEAR gs_a. 2418 LOOP AT lt_a INTO gs_a. 2419 REFRESH : gt_bdcdata,gt_msgtab. 2420 2421 * SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. 2422 2423 PERFORM bdc_dynpro USING 'SAPMF05L' '0100'. 2424 PERFORM bdc_field USING 'BDC_CURSOR' 2425 'RF05L-GJAHR'. 2426 PERFORM bdc_field USING 'BDC_OKCODE' 2427 '=WEITE'. 2428 PERFORM bdc_field USING 'RF05L-BELNR' 2429 gs_a-belnr. 2430 PERFORM bdc_field USING 'RF05L-BUKRS' 2431 gs_a-bukrs. 2432 PERFORM bdc_field USING 'RF05L-GJAHR' 2433 gs_a-gjahr. 2434 PERFORM bdc_dynpro USING 'SAPMF05L' '0700'. 2435 PERFORM bdc_field USING 'BDC_CURSOR' 2436 'BKPF-BELNR'. 2437 PERFORM bdc_field USING 'BDC_OKCODE' 2438 '=VK'. 2439 PERFORM bdc_dynpro USING 'SAPMF05L' '1710'. 2440 PERFORM bdc_field USING 'BDC_CURSOR' 2441 'BKPF-BKTXT'. 2442 PERFORM bdc_field USING 'BDC_OKCODE' 2443 '=ENTR'. 2444 PERFORM bdc_field USING 'BKPF-BKTXT' 2445 gs_a-txt20. 2446 PERFORM bdc_dynpro USING 'SAPMF05L' '0700'. 2447 PERFORM bdc_field USING 'BDC_CURSOR' 2448 'BKPF-BELNR'. 2449 PERFORM bdc_field USING 'BDC_OKCODE' 2450 '=AE'. 2451 CALL TRANSACTION 'FB02' USING gt_bdcdata 2452 MODE p_mode 2453 MESSAGES INTO gt_msgtab 2454 UPDATE 'S'. "同步更新 2455 ENDLOOP. 2456 ENDFORM. 2457 2458 FORM dd. 2459 LOOP AT gt_a INTO rs_a. 2460 IF rs_a-belnr = gs_a-belnr 2461 AND rs_a-bukrs = gs_a-bukrs 2462 AND rs_a-gjahr = gs_a-gjahr 2463 AND rs_a-buzei = gs_a-buzei. 2464 rs_a-bktxt = gs_a-txt20. 2465 ENDIF. 2466 MODIFY gt_a FROM rs_a. 2467 ENDLOOP. 2468 ENDFORM. 2469 2470 FORM bdc_field USING fnam fval. 2471 CLEAR gt_bdcdata. 2472 gt_bdcdata-fnam = fnam. 2473 gt_bdcdata-fval = fval. 2474 APPEND gt_bdcdata. 2475 ENDFORM. "BDC_FIELD 2476 FORM bdc_dynpro USING program dynpro. 2477 CLEAR gt_bdcdata. 2478 gt_bdcdata-program = program. 2479 gt_bdcdata-dynpro = dynpro. 2480 gt_bdcdata-dynbegin = 'X'. 2481 APPEND gt_bdcdata. 2482 ENDFORM. 2483 ``` 2484 2485 ![](C:\liuliu\typora\图片\z2107_33160_exam3.png) 2486 2487 ```ABAP 2488 PROCESS BEFORE OUTPUT. MODULE STATUS_9000.*PROCESS AFTER INPUT. MODULE USER_COMMAND_9000. 2489 ``` 2490 2491 2492 2493 # 四、练习 2494 2495 ## 1、Z20210733160_TEST001(九九乘法表) 2496 2497 ```ABAP 2498 *&---------------------------------------------------------------------**& Report Z20210733160_TEST001*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST001.DATA: py TYPE n, px TYPE n, pr TYPE char2, pz TYPE string.WHILE py < 9. py = py + 1. WHILE px < py. px = px + 1. pr = px * py. "CONCATENATE px '*' py '=' pr INTO pz SEPARATED BY space. CONCATENATE px '*' py '=' pr INTO pz. WRITE: pz,space. "WRITE: px,'*',py,'=',pr,' '. ENDWHILE. CLEAR px. WRITE /.ENDWHILE.WRITE '工号:33160'. 2499 ``` 2500 2501 ![](C:\liuliu\typora\图片\Z20210733160_TEST001.png) 2502 2503 2504 2505 ## 2、Z20210733160_TEST002 2506 2507 ```ABAP 2508 *&---------------------------------------------------------------------**& Report Z20210733160_TEST002*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST002.*创建内表类型*自定义结构TYPES: BEGIN OF typ_mara, matnr type matnr, matkl type matkl, conum type i, maktx type maktx, END OF typ_mara.*创建内表对象data: gt_mara type TABLE OF typ_mara, "自定义结构 gt_makt type TABLE OF makt. "参考系统表或者结构,视图等*创建工作区data: gs_mara type typ_mara, gs_makt type makt.*data: gt_mara2 type TABLE OF typ_mara WITH HEADER LINE.START-OF-SELECTION.do 3 times. gs_mara-matnr = 'Amaterialtest'. gs_mara-matkl = 'B001'. gs_mara-conum = sy-index. APPEND gs_mara to gt_mara.ENDDO.**loop at gt_mara into gs_mara.* gs_mara-maktx = gs_mara-matnr && gs_mara-conum.* modify gt_mara from gs_mara.*endloop.*loop at gt_mara into gs_mara WHERE conum = 2.* gs_mara-maktx = gs_mara-matnr && gs_mara-conum.* modify gt_mara from gs_mara* TRANSPORTING matnr matkl.*endloop.*read TABLE gt_mara into gs_mara index 1.*if sy-subrc = 0.*endif.***READ TABLE gt_mara into gs_mara with key conum = 2.*if sy-subrc = 0.* gs_mara-maktx = gs_mara-maktx && 'SUC'.* modify gt_mara from gs_mara INDEX sy-tabix.*endif.*loop at gt_mara2.* modify gt_mara2.*endloop.loop at gt_mara into gs_mara WHERE conum = 2. delete gt_mara.endloop.BREAK-POINT. 2509 ``` 2510 2511 2512 2513 ## 3、Z20210733160_TEST003(奇偶) 2514 2515 ![](C:\liuliu\typora\图片\z20210733160_test003要求.png) 2516 2517 ```ABAP 2518 *&---------------------------------------------------------------------**& Report Z20210733160_TEST003*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test003.*结构TYPES: BEGIN OF typ_a, a1 TYPE string, a2 TYPE i, a3 TYPE string, END OF typ_a.*内表对象DATA: gt_a TYPE TABLE OF typ_a.*工作区DATA: gs_a TYPE typ_a, id TYPE i VALUE 1, num TYPE i, f TYPE i VALUE 0, g TYPE i.DO 100 TIMES. gs_a-a1 = id. f = f + 1. IF f > 9. f = 2. ENDIF. IF f < 6. num = f. ELSE. num = 10 - f. ENDIF. gs_a-a2 = num. g = id * num. IF g MOD 2 = 1. gs_a-a3 = '奇数'. ELSE. gs_a-a3 = '偶数'. ENDIF. APPEND gs_a TO gt_a. id = id + 1.ENDDO.LOOP AT gt_a INTO gs_a. WRITE: / gs_a-a1,' ',gs_a-a2,' ',gs_a-a3.ENDLOOP.WRITE: '工号:33160'.*DO 10 TIMES.** DO 4 TIMES.* gs_a-a1 = id.* gs_a-a2 = num.* g = id * num.* num = num + 1.* IF g MOD 2 = 1.* gs_a-a3 = '奇数'.* ELSE.* gs_a-a3 = '偶数'.* ENDIF.* APPEND gs_a TO gt_a.* id = id + 1.* ENDDO.** DO 4 TIMES.* gs_a-a1 = id.* gs_a-a2 = num.* g = id * num.* num = num - 1.* IF g MOD 2 = 1.* gs_a-a3 = '奇数'.* ELSE.* gs_a-a3 = '偶数'.* ENDIF.* APPEND gs_a TO gt_a.* id = id + 1.* ENDDO.**ENDDO. 2519 ``` 2520 2521 ![](C:\liuliu\typora\图片\z20210733160_test003.png) 2522 2523 2524 2525 ## 4、Z20210733160_TEST004(汇总) 2526 2527 ```ABAP 2528 *&---------------------------------------------------------------------**& Report Z20210733160_TEST004*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test004.TYPES: BEGIN OF typ_lips, vbeln TYPE lips-vbeln, posnr TYPE lips-posnr, vgbel TYPE lips-vgbel, vgpos TYPE lips-vgpos, lfimg TYPE lips-lfimg, END OF typ_lips.DATA: gt_lips TYPE TABLE OF typ_lips.DATA: gs_lips TYPE typ_lips.START-OF-SELECTION. SELECT vbeln, posnr, vgbel, vgpos, lfimg FROM lips WHERE vgbel IS NOT INITIAL INTO CORRESPONDING FIELDS OF TABLE @gt_lips.* UP TO 100 rows. DATA: gt_a TYPE TABLE OF typ_lips, gs_a TYPE typ_lips. DATA: gt_b TYPE TABLE OF typ_lips, gs_b TYPE typ_lips. gt_a = gt_lips. SORT gt_a BY vbeln.LOOP AT gt_a INTO gs_a. AT NEW vbeln. READ TABLE gt_a INTO gs_a INDEX sy-tabix. CLEAR gs_b. gs_b-vbeln = gs_a-vbeln. gs_b-posnr = gs_a-posnr. gs_b-vgbel = gs_a-vgbel. gs_b-vgpos = gs_a-vgpos. ENDAT. gs_b-lfimg = gs_a-lfimg + gs_b-lfimg. AT END OF vbeln. APPEND gs_b TO gt_b. ENDAT.ENDLOOP.LOOP AT gt_b INTO gs_b. WRITE: / gs_b-vbeln,gs_b-posnr,gs_b-vgbel,gs_b-vgpos,gs_b-lfimg.ENDLOOP. BREAK-POINT.*LOOP AT gt_a INTO gs_a.* AT FIRST.* ENDAT.* AT NEW vbeln.* SUM.* WRITE: / gs_a-vbeln,gs_a-posnr,gs_a-vgbel,gs_a-vgpos,gs_a-lfimg.* ENDAT.*ENDLOOP. 2529 ``` 2530 2531 ![](C:\liuliu\typora\图片\z20210733160_test004.png) 2532 2533 2534 2535 ## 5、Z20210733160_TEST005(字典) 2536 2537 ```ABAP 2538 *&---------------------------------------------------------------------**& Report Z20210733160_TEST005*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test005.TABLES: mara,vbap.DATA: ls_mara TYPE zsmara, lt_mara TYPE ztsmara.types: BEGIN OF typ_vbap, vbeln type vbeln_vl, KWMENG TYPE vbap-KWMENG, END OF typ_vbap.data: gt_vbap type TABLE OF typ_vbap.SELECT-OPTIONS: s_matnr FOR mara-matnr, s_vbeln for vbap-vbeln.START-OF-SELECTION. SELECT a~matnr matkl* maktx FROM mara as a inner join makt as k on a~matnr = k~matnr INTO CORRESPONDING FIELDS OF TABLE lt_mara WHERE a~matnr IN s_matnr* and spras = sy-langu .* and matkl = ''** APPEND ls_mara TO lt_mara.* ENDSELECT.data: l_zmeng type vbap-zmeng.SELECT max( KWMENG ) vbelnfrom vbapinto CORRESPONDING FIELDS OF TABLE gt_vbapWHERE vbeln in s_vbeln GROUP BY vbeln* ORDER BY vbeln . BREAK-POINT. 2539 ``` 2540 2541 2542 2543 ## 6、Z20210733160_TEST006(表) 2544 2545 ```ABAP 2546 *&---------------------------------------------------------------------**& Report Z20210733160_TEST006*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST006.TABLES:EKKO,EKPO,EKET,ZT33160EKKO,ZT33160EKPO,ZT33160EKET,lfa1.*SELECT-OPTIONS :s_ebeln for ekko_ebeln.DATA: gt_EKKO TYPE TABLE OF EKKO, gt_EKPO TYPE TABLE OF EKPO, gt_EKET TYPE TABLE OF EKET, gs_EKKO TYPE EKKO, gs_EKPO TYPE EKPO, gs_EKET TYPE EKET.DATA: gt_ZT33160EKKO TYPE TABLE OF ZT33160EKKO, gt_ZT33160EKPO TYPE TABLE OF ZT33160EKPO, gt_ZT33160EKET TYPE TABLE OF ZT33160EKET, gs_ZT33160EKKO TYPE ZT33160EKKO, gs_ZT33160EKPO TYPE ZT33160EKPO, gs_ZT33160EKET TYPE ZT33160EKET.*SELECT * from EKPO INTO TABLE gt_EKPO.**LOOP at gt_EKPO into gs_EKPO.* WRITE: / gs_EKPO-ebeln.*ENDLOOP.*----------------------*插入ZT33160EKET*clear gs_ZT33160EKET.*clear gs_EKET.*SELECT * from EKET INTO TABLE gt_EKET.*LOOP at gt_EKET INTO gs_EKET.* gs_ZT33160EKET-MANDT = gs_EKET-MANDT.* gs_ZT33160EKET-EBELN = gs_EKET-EBELN.* gs_ZT33160EKET-EBELP = gs_EKET-EBELP.* gs_ZT33160EKET-ETENR = gs_EKET-ETENR.* gs_ZT33160EKET-EINDT = gs_EKET-EINDT.* gs_ZT33160EKET-WEMNG = gs_EKET-WEMNG.* "insert INTO ZT33322_EKet1 VALUES Teket_s.* APPEND gs_ZT33160EKET to gt_ZT33160EKET.*ENDLOOP.*INSERT ZT33160EKET from TABLE gt_ZT33160EKET." ACCEPTING DUPLICATE KEYS.*UPDATA ZT33160EKET from TABLE gt_ZT33160EKET.*SELECT * from ZT33160EKET INTO TABLE gt_ZT33160EKET.**LOOP at gt_ZT33160EKET into gs_ZT33160EKET.* WRITE: / gs_ZT33160EKET-ebeln,gs_ZT33160EKET-ebelp.*ENDLOOP.*SELECT * from EKET INTO TABLE gt_EKET.**LOOP at gt_EKET into gs_EKET.* WRITE: / gs_EKET-ebeln,gs_EKET-ebelp.*ENDLOOP.*clear gs_EKET.*---------------------*插入ZT33160EKPO*clear gs_ZT33160EKPO.*clear gs_EKPO.*SELECT * from EKPO INTO TABLE gt_EKPO.*LOOP at gt_EKPO INTO gs_EKPO.* gs_ZT33160EKPO-MANDT = gs_EKPO-MANDT.* gs_ZT33160EKPO-EBELN = gs_EKPO-EBELN.* gs_ZT33160EKPO-EBELP = gs_EKPO-EBELP.* gs_ZT33160EKPO-WERKS = gs_EKPO-WERKS.* gs_ZT33160EKPO-MATNR = gs_EKPO-MATNR.* "gs_ZT33160EKPO-MAKTX = gs_EKPO-MAKTX.* gs_ZT33160EKPO-MENGE = gs_EKPO-MENGE.* gs_ZT33160EKPO-MEINS = gs_EKPO-MEINS.* gs_ZT33160EKPO-NETPR = gs_EKPO-NETPR.* gs_ZT33160EKPO-AEDAT = gs_EKPO-AEDAT.* gs_ZT33160EKPO-NETWR = gs_EKPO-NETWR.* "gs_ZT33160EKPO-EKGRP = gs_EKPO-EKGRP.* APPEND gs_ZT33160EKPO to gt_ZT33160EKPO.*ENDLOOP.*INSERT ZT33160EKPO from TABLE gt_ZT33160EKPO. "ACCEPTING DUPLICATE KEYS.*---------------------*插入ZT33160EKKO*clear gs_ZT33160EKKO.*clear gs_EKKO.*SELECT * from EKKO INTO CORRESPONDING FIELDS OF TABLE gt_EKKO.*LOOP at gt_EKKO INTO gs_EKKO.** gs_ZT33160EKKO-MANDT = gs_EKKO-MANDT.** gs_ZT33160EKKO-EBELN = gs_EKKO-EBELN.** gs_ZT33160EKKO-BUKRS = gs_EKKO-BUKRS.** gs_ZT33160EKKO-LIFNR = gs_EKKO-LIFNR.** gs_ZT33160EKKO-NAME1 = gs_EKKO-NAME1.* APPEND gs_ZT33160EKKO to gt_ZT33160EKKO.*ENDLOOP.*INSERT ZT33160EKKO from TABLE gt_ZT33160EKKO. "ACCEPTING DUPLICATE KEYS.**----------------------name1*TYPES BEGIN OF a.* TYPES li TYPE ekko-lifnr.* TYPES name TYPE lfa1-name1.*TYPES END OF a.**DATA: gt_a TYPE TABLE OF a,* gs_a TYPE a.*CLEAR gs_a.*SELECT ekko~lifnr lfa1~name1 from ekko left join lfa1 on ekko~lifnr = lfa1~lifnr into TABLE gt_a.*LOOP AT gt_a INTO gs_a.* UPDATE ZT33160EKKO set name1 = gs_a-name where lifnr = gs_a-li.*ENDLOOP.**----------------------mengeTYPES BEGIN OF b. TYPES eb TYPE ZT33160EKKO-ebeln. TYPES me TYPE ZT33160EKKO-menge.TYPES END OF b.DATA: gt_b TYPE TABLE OF b, gs_b TYPE b.CLEAR gs_b.SELECT ebeln sum( menge ) from ZT33160EKPO into TABLE gt_b GROUP BY ebeln.LOOP AT gt_b INTO gs_b. UPDATE ZT33160EKKO set menge = gs_b-me where ebeln = gs_b-eb.ENDLOOP.**----------------------wemng*TYPES BEGIN OF ac.* TYPES ebe TYPE ZT33160EKKO-ebeln.* TYPES we TYPE ZT33160EKKO-wemng.*TYPES END OF ac.**DATA: gt_ac TYPE TABLE OF ac,* gs_ac TYPE ac.*CLEAR gs_ac.*SELECT ebeln sum( wemng ) from ZT33160EKET into TABLE gt_ac GROUP BY ebeln.*LOOP AT gt_ac INTO gs_ac.* UPDATE ZT33160EKKO set wemng = gs_ac-we where ebeln = gs_ac-ebe.*ENDLOOP.*SELECT * from EKKO*into CORRESPONDING FIELDS OF table gt_a "CORRESPONDING FIELDS OF当查询字段与数据表中字段顺序不一致时使用*FOR ALL ENTRIES IN gt_b*where a=b. 2547 ``` 2548 2549 2550 2551 ## 7、Z20210733160_TEST007(EKKO) 2552 2553 ```ABAP 2554 *&---------------------------------------------------------------------**& Report Z20210733160_TEST007*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test007.TABLES: ekko.TYPES: BEGIN OF a1, lifnr TYPE ekko-lifnr, name1 TYPE lfa1-name1, END OF a1.DATA: gt_ekko TYPE TABLE OF zt33160ekko, gt_ekpo TYPE TABLE OF zt33160ekpo, gt_eket TYPE TABLE OF zt33160eket, gt_lfa1 TYPE TABLE OF a1, gs_ekko TYPE zt33160ekko, gs_ekpo TYPE zt33160ekpo, gs_eket TYPE zt33160eket, gs_lfa1 TYPE a1.PARAMETERS:p_bukrs type ekko-bukrs DEFAULT '2000'.SELECT-OPTIONS: s_ebeln FOR ekko-ebeln, s_bsart FOR ekko-bsart OBLIGATORY.SELECT ebeln bukrs lifnrFROM ekkoINTO CORRESPONDING FIELDS OF TABLE gt_ekkoWHERE ebeln IN s_ebeln and bukrs = p_bukrs and bsart in s_bsart.IF gt_ekko IS NOT INITIAL. SELECT ebeln ebelp werks matnr menge meins netpr aedat netwr FROM ekpo INTO CORRESPONDING FIELDS OF TABLE gt_ekpo FOR ALL ENTRIES IN gt_ekko WHERE ebeln = gt_ekko-ebeln. SELECT ebeln ebelp etenr eindt wemng FROM eket INTO CORRESPONDING FIELDS OF TABLE gt_eket FOR ALL ENTRIES IN gt_ekko WHERE ebeln = gt_ekko-ebeln. SELECT lifnr name1 FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE gt_lfa1 FOR ALL ENTRIES IN gt_ekko WHERE lifnr = gt_ekko-lifnr. SORT gt_lfa1 BY lifnr.ENDIF.LOOP AT gt_ekko INTO gs_ekko. LOOP AT gt_ekpo INTO gs_ekpo WHERE ebeln = gs_ekko-ebeln. gs_ekko-menge = gs_ekko-menge + gs_ekpo-menge. ENDLOOP. LOOP AT gt_eket INTO gs_eket WHERE ebeln = gs_ekko-ebeln. gs_ekko-wemng = gs_ekko-wemng + gs_eket-wemng. ENDLOOP. READ TABLE gt_lfa1 INTO gs_lfa1 WITH KEY lifnr = gs_ekko-lifnr BINARY SEARCH. "BINARY SEARCH二分法查找 IF sy-subrc = 0. gs_ekko-name1 = gs_lfa1-name1. ENDIF. MODIFY gt_ekko FROM gs_ekko.ENDLOOP.*IF gt_ekko IS NOT INITIAL.* "delete zt33160ekko from TABLE .* MODIFY zt33160ekko FROM TABLE gt_ekko.*ENDIF.**IF gt_ekpo IS NOT INITIAL.* "delete zt33160ekpo.* MODIFY zt33160ekpo FROM TABLE gt_ekpo.*ENDIF.**IF gt_eket IS NOT INITIAL.* MODIFY zt33160eket FROM TABLE gt_eket.*ENDIF. 2555 ``` 2556 2557 2558 2559 ## 8、Z20210733160_TEST008(选择屏幕) 2560 2561 ```ABAP 2562 *&---------------------------------------------------------------------**& Report Z20210733160_TEST008*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST008.TABLES: marc.TYPES: BEGIN OF typ_marc, werks TYPE marc-werks, matnr TYPE marc-matnr, dispo TYPE marc-dispo, kzdie TYPE marc-kzdie, plifz TYPE marc-plifz, END OF typ_marc.data: gt_marc type TABLE OF typ_marc, gs_marc type typ_marc.SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE TEXT-t01.PARAMETERS: p_werks TYPE marc-werks .SELECT-OPTIONS: s_matnr FOR marc-matnr.SELECTION-SCREEN END OF BLOCK blk.INITIALIZATION.START-OF-SELECTION.BREAK-POINT.END-OF-SELECTION. 2563 ``` 2564 2565 2566 2567 ## 9、Z20210733160_TEST009(选择屏幕输出) 2568 2569 ```ABAP 2570 *&---------------------------------------------------------------------**& Report Z20210733160_TEST009*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test009.*DEFINE mm.*include Z1.TABLES: vbap,vbak,makt.TYPES: BEGIN OF aa, kunnr TYPE vbak-kunnr, matnr TYPE vbap-matnr, maktx TYPE makt-maktx, kwmeng TYPE vbap-kwmeng, meins TYPE vbap-meins, END OF aa.TYPES: BEGIN OF bb, matnr TYPE makt-matnr, maktx TYPE makt-maktx, END OF bb.DATA: gt_a TYPE TABLE OF aa, gt_b TYPE TABLE OF bb, gs_a TYPE aa, gs_b TYPE bb.PARAMETERS:p_werks TYPE vbap-werks OBLIGATORY DEFAULT '2000'.SELECT-OPTIONS: s_kunnr FOR vbak-kunnr.CLEAR gs_a.CLEAR gs_b.*form cc using a1 type c.* using a2 type c* changing b type c.**endformPERFORM zda."CHANGING gt_t.LOOP AT gt_a INTO gs_a. SHIFT gs_a-matnr LEFT DELETING LEADING '0'. SHIFT gs_a-kunnr LEFT DELETING LEADING '0'.* CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'* EXPORTING* input = gs_a* IMPORTING* output = gs_a. MODIFY gt_a FROM gs_a. WRITE: / gs_a-kunnr,gs_a-matnr,gs_a-maktx,gs_a-kwmeng,gs_a-meins.ENDLOOP.FORM zda. "CHANGING gt_t TYPE aa. SELECT vbak~kunnr vbap~matnr vbap~kwmeng vbap~meins FROM vbak JOIN vbap ON vbak~vbeln = vbap~vbeln INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE vbap~werks = p_werks AND vbak~kunnr IN s_kunnr. IF gt_a IS NOT INITIAL. SELECT matnr maktx FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_b FOR ALL ENTRIES IN gt_a WHERE matnr = gt_a-matnr. ENDIF. LOOP AT gt_a INTO gs_a. READ TABLE gt_b INTO gs_b WITH KEY matnr = gs_a-matnr. IF sy-subrc = 0. gs_a-maktx = gs_b-maktx. ENDIF. MODIFY gt_a FROM gs_a. ENDLOOP.ENDFORM.*END-OF-DEFINITION.*初始化*INITIALIZATION.**at SELECTION-SCREEN.**at SELECTION-SCREEN OUTPUT.**START-OF-SELECTION.**END-OF-SELECTION. 2571 ``` 2572 2573 ![](C:\liuliu\typora\图片\z20210733160_test009.png) 2574 2575 2576 2577 ## 10、Z20210733160_TEST0010(模块) 2578 2579 ```ABAP 2580 *&---------------------------------------------------------------------**& Report Z20210733160_TEST010*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST010.TABLES: vbap, vbak, makt.type-POOLs:slis.TYPES: BEGIN OF typ_vbap , kunnr TYPE vbak-kunnr, matnr TYPE vbap-matnr, maktx TYPE makt-maktx, kwmeng TYPE vbap-kwmeng, meins TYPE vbap-meins, END OF typ_vbap.DATA: gt_vbap TYPE TABLE OF typ_vbap, gt_vbap1 TYPE TABLE OF typ_vbap, gs_vbap TYPE typ_vbap, gs_vbap1 TYPE typ_vbap.data: gt_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, gs_FIELDCAT type SLIS_FIELDCAT_ALV, gs_layout type SLIS_LAYOUT_ALV.PARAMETERS: p_werks TYPE vbap-werks. "OBLIGATORY.SELECT-OPTIONS: s_kunnr FOR vbak-kunnr, s_erdat FOR vbak-erdat.INITIALIZATION. PERFORM frm_init.AT SELECTION-SCREEN. PERFORM frm_check_screen.AT SELECTION-SCREEN OUTPUT.* LOOP AT SCREEN.* IF screen-name CA 'S_ERDAT'.* screen-input = 0.* MODIFY SCREEN.* ENDIF.* ENDLOOP.START-OF-SELECTION. PERFORM frm_sel_data.END-OF-SELECTION.PERFORM jgs.PERFORM frm_output.FORM frm_init. p_werks = '2000'. s_erdat-sign = 'I'. s_erdat-option = 'BT'. s_erdat-low+0(6) = sy-datum+0(6). s_erdat-low+6(2) = '01'. CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS' EXPORTING day_in = s_erdat-low IMPORTING last_day_of_month = s_erdat-high EXCEPTIONS day_in_no_date = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF. APPEND s_erdat.ENDFORM.FORM frm_check_screen. IF s_erdat IS INITIAL.* MESSAGE '创建日期没有填写' TYPE 'E'. ENDIF.ENDFORM.FORM frm_sel_data. SELECT vbak~kunnr vbap~matnr vbap~kwmeng vbap~meins FROM vbak JOIN vbap ON vbak~vbeln = vbap~vbeln INTO CORRESPONDING FIELDS OF TABLE gt_vbap WHERE vbap~werks = p_werks AND vbak~kunnr IN s_kunnr. IF gt_vbap IS NOT INITIAL. SELECT matnr maktx FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_vbap1 FOR ALL ENTRIES IN gt_vbap WHERE makt~matnr = gt_vbap-matnr. ENDIF. LOOP AT gt_vbap INTO gs_vbap. READ TABLE gt_vbap1 INTO gs_vbap1 WITH KEY matnr = gs_vbap-matnr. gs_vbap-maktx = gs_vbap1-maktx. MODIFY gt_vbap FROM gs_vbap. ENDLOOP.* LOOP AT gt_vbap INTO gs_vbap.* SHIFT gs_vbap-kunnr LEFT DELETING LEADING '0'.* PERFORM frm_matnr_output CHANGING gs_vbap-matnr.* MODIFY gt_vbap FROM gs_vbap.* CLEAR gs_vbap.* ENDLOOP.ENDFORM.FORM frm_output. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' '* I_CALLBACK_PROGRAM = ' '* I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND = ' '* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' I_GRID_TITLE = '表名'* I_GRID_SETTINGS = IS_LAYOUT = gs_layout IT_FIELDCAT = gt_FIELDCAT* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_vbap EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2 . IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.* LOOP AT gt_vbap INTO gs_vbap.* WRITE:/ gs_vbap-kunnr,gs_vbap-matnr,gs_vbap-maktx,gs_vbap-kwmeng,gs_vbap-meins.* ENDLOOP.ENDFORM.FORM frm_matnr_output CHANGING fc_matnr. CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = fc_matnr IMPORTING output = fc_matnr.ENDFORM.FORM jgs. gs_layout-colwidth_optimize = 'X'."自由拉申 gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'KUNNR'. gs_FIELDCAT-edit_mask = '==ALPHA'. "去掉前导零 gs_FIELDCAT-ref_tabname = 'VBAK'. "列名 gs_FIELDCAT-ref_fieldname = 'KUNNR'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'MATNR'. gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'MATNR'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_FIELDCAT-fieldname = 'MAKTX'.* gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'MAKT'. gs_FIELDCAT-ref_fieldname = 'MAKTX'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_FIELDCAT-fieldname = 'KWMENG'.* gs_FIELDCAT-edit_mask = '==ALPHA'. "去掉前导零 gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'KWMENG'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_FIELDCAT-fieldname = 'MEINS'.* gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'MEINS'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT.ENDFORM. 2581 ``` 2582 2583 ![](C:\liuliu\typora\图片\z20210733160_test010.png) 2584 2585 2586 2587 ## 11、Z20210733160_TEST0011(LV) 2588 2589 ```ABAP 2590 *&---------------------------------------------------------------------**& Report Z20210733160_TEST011*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST011.*--------------------------------------------------------------------**表声明*--------------------------------------------------------------------*TABLES:mara.*--------------------------------------------------------------------**ALV参数申明*--------------------------------------------------------------------*DATA:t_fieldcat TYPE lvc_t_fcat, "字段目录内表 w_fieldcat TYPE lvc_s_fcat, "字段目录工作区 w_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性*--------------------------------------------------------------------**定义类型结构*--------------------------------------------------------------------*TYPES:BEGIN OF ty_mara, matnr TYPE matnr, "物料号 pstat LIKE mara-pstat, "维护状态 mtart TYPE mtart, "物料类型 mbrsh TYPE mbrsh, "行业领域 matkl TYPE matkl, "物料组 bismt TYPE bismt, "旧物料号 meins TYPE meins, "基本计量单位 brgew TYPE brgew, "毛重 ntgew TYPE ntgew, "净重 maktx TYPE maktx, "物料描述 zline TYPE i, "当前行数 check TYPE c, END OF ty_mara.*--------------------------------------------------------------------**声明内表和工作区*--------------------------------------------------------------------*DATA: gt_mara TYPE STANDARD TABLE OF ty_mara, gs_mara TYPE ty_mara.*--------------------------------------------------------------------**定义选择屏幕参数*--------------------------------------------------------------------*SELECTION-SCREEN BEGIN OF BLOCK bl1 WITH FRAME TITLE TEXT-001. "title后的变量可以设置面板标题SELECT-OPTIONS:s_matnr FOR mara-matnr, s_matkl FOR mara-matkl NO-EXTENSION.SELECTION-SCREEN SKIP 2.SELECTION-SCREEN END OF BLOCK bl1.**INITIALIZATION.**P_DATUM = SY-datum - 1.*----------------------------------------------------------------------** ALV逻辑流*----------------------------------------------------------------------*START-OF-SELECTION.*获取取数 PERFORM frm_get_data.*设置字段属性 PERFORM frm_set_fieldcat.*设置输出格式 PERFORM frm_set_layout.*显示ALV PERFORM frm_display_alv.*&---------------------------------------------------------------------**& Form frm_get_data*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* p1 text* p1 text* p1 text* 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.ENDFORM. " frm_display_alv 2591 ``` 2592 2593 ![](C:\liuliu\typora\图片\z20210733160_test011.png) 2594 2595 2596 2597 ## 12、Z20210733160_TEST0012(案例) 2598 2599 ```ABAP 2600 *&---------------------------------------------------------------------**& Report Z20210733160_TEST012*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test012.TABLES: vbap,vbak,makt.TYPE-POOLS:slis. "引入一个类型池TYPES: BEGIN OF aa, kunnr TYPE vbak-kunnr, matnr TYPE vbap-matnr, maktx TYPE makt-maktx, kwmeng TYPE vbap-kwmeng, meins TYPE vbap-meins, END OF aa.TYPES: BEGIN OF bb, matnr TYPE makt-matnr, maktx TYPE makt-maktx, END OF bb.DATA: gt_a TYPE TABLE OF aa, gt_b TYPE TABLE OF bb, gs_a TYPE aa, gs_b TYPE bb.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, "相当于工作区 gs_fieldcat TYPE slis_fieldcat_alv, "存放输出栏位名称的列表 gs_layout TYPE slis_layout_alv. "负责整个ALV的全局属性PARAMETERS: p_werks TYPE vbap-werks OBLIGATORY DEFAULT '2000'.SELECT-OPTIONS: s_kunnr FOR vbak-kunnr, s_erdat FOR vbak-erdat.CLEAR gs_a.CLEAR gs_b.PERFORM z_data.PERFORM z_li.PERFORM z_output.*BREAK-POINT.FORM z_data. SELECT vbak~kunnr vbap~matnr vbap~kwmeng vbap~meins from vbak join vbap on vbak~vbeln = vbap~vbeln into CORRESPONDING FIELDS OF TABLE gt_a WHERE vbap~werks = p_werks and vbak~kunnr in s_kunnr. IF gt_a is NOT INITIAL. SELECT matnr maktx from makt INTO CORRESPONDING FIELDS OF TABLE gt_b FOR ALL ENTRIES IN gt_a WHERE makt~matnr = gt_a-matnr. ENDIF.* 排序* sort gt_a by matnr. LOOP AT gt_a into gs_a. READ TABLE gt_b into gs_b WITH KEY matnr = gs_a-matnr. "BINARY SEARCH.二分法查找 IF sy-subrc = 0. gs_a-maktx = gs_b-maktx. ENDIF. MODIFY gt_a from gs_a. ENDLOOP. LOOP AT gt_a INTO gs_a. SHIFT gs_a-matnr LEFT DELETING LEADING '0'. SHIFT gs_a-kunnr LEFT DELETING LEADING '0'. MODIFY gt_a FROM gs_a. ENDLOOP.endform.FORM z_li. gs_layout-colwidth_optimize = 'X'."设置ALV表格输出的时候,列宽根据数据长度自动适应 gs_layout-zebra = 'X'. "设置aLV表格输出的时候,数据行背景色交替显示* w_fieldcat的fieldname属性: 设置要输出的表格列的值,在内表中定义的字段名。* 这里引号内的字段名称必须大写! gs_FIELDCAT-fieldname = 'KUNNR'. gs_FIELDCAT-edit_mask = '==ALPHA'. "去掉前导零 gs_FIELDCAT-ref_tabname = 'VBAK'. "列名,指定这个字段参考的标准表 gs_FIELDCAT-ref_fieldname = 'KUNNR'."w_fieldcat的ref_field属性:指定这个字段参考的标准表的字段。 gs_fieldcat-emphasize = 'C100'. " 指定列的颜色【C100代表蓝绿色】* gs_FIELDCAT-seltext_s = '客户号'. " 字段的文本描述,输出时候显示。短描述* gs_FIELDCAT-seltext_l = '客户号'. " 设置要输出的表格列的列名字 字段的文本描述,输出时候显示。长描述* gs_FIELDCAT-seltext_m = '客户号'. " 字段的文本描述,输出时候显示。中描述 append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'MATNR'. gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'MATNR'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'MAKTX'.* gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'MAKT'. gs_FIELDCAT-ref_fieldname = 'MAKTX'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'KWMENG'.* gs_FIELDCAT-edit_mask = '==ALPHA'. "去掉前导零 gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'KWMENG'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. gs_FIELDCAT-fieldname = 'MEINS'.* gs_FIELDCAT-edit_mask = '==ALPHA'. gs_FIELDCAT-ref_tabname = 'VBAP'. gs_FIELDCAT-ref_fieldname = 'MEINS'. append gs_FIELDCAT to gt_FIELDCAT. CLEAR gs_FIELDCAT.ENDFORM.FORM z_output. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' '* I_CALLBACK_PROGRAM = ' '* I_CALLBACK_PF_STATUS_SET = ' '* I_CALLBACK_USER_COMMAND = ' '* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' I_GRID_TITLE = '表名'* I_GRID_SETTINGS = IS_LAYOUT = gs_layout IT_FIELDCAT = gt_FIELDCAT* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_a EXCEPTIONS PROGRAM_ERROR = 1 OTHERS = 2 .* IF sy-subrc <> 0.** Implement suitable error handling here* ENDIF.ENDFORM.FORM quchu CHANGING p_out. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = p_out IMPORTING output = p_out.ENDFORM.FORM daying.LOOP AT gt_a INTO gs_a. PERFORM quchu CHANGING gs_a-matnr. MODIFY gt_a FROM gs_a. WRITE:/ gs_a-kunnr,gs_a-matnr,gs_a-maktx,gs_a-kwmeng,gs_a-meins.ENDLOOP.ENDFORM. 2601 ``` 2602 2603 ![](C:\liuliu\typora\图片\z20210733160_test012.png) 2604 2605 2606 2607 ## 13、Z20210733160_TEST0013(函数测试) 2608 2609 ```ABAP 2610 *&---------------------------------------------------------------------**& Report Z20210733160_TEST013*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test013.DATA:i_field1 TYPE char10.DATA:i_field2 TYPE char10.DATA:e_field1 TYPE char10.DATA:e_field2 TYPE char10.i_field1 = 1.i_field2 = 2.CALL FUNCTION 'ZFM_33160_TEST001' EXPORTING i_field1 = i_field1 i_field2 = i_field2 IMPORTING e_field1 = e_field1.CALL FUNCTION 'ZFM_33160_TEST003' EXPORTING i_num1 = i_field1 i_num2 = i_field2 it_zws = i_field1 IMPORTING E_NUM = e_field2.WRITE:e_field1,e_field2.BREAK-POINT 33160. 2611 ``` 2612 2613 2614 2615 ## 14、Z20210733160_TEST0014(屏幕开发) 2616 2617 ```ABAP 2618 *&---------------------------------------------------------------------**& Report Z20210733160_TEST014*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z20210733160_TEST014.INCLUDE z20210733160_test014_statuso01.data: gs_lfa1 type lfa1, gt_lfa1 type TABLE OF lfa1.data: ok_code type sy-ucomm, code_com type sy-ucomm.INITIALIZATION.START-OF-SELECTION.call screen 9000.end-of-SELECTION.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT.PERFORM frm_get_lifnr.ENDMODULE.FORM frm_get_lifnr . code_com = ok_code. CLEAr ok_code. case code_com. when 'SEAR'. select SINGLE name1 from lfa1 into gs_lfa1-name1 WHERE lifnr = gs_lfa1-lifnr and spras = sy-langu. when 'SAVE'. call SCREEN 9100. when '&F03' or '&F12' or '&F15'.* leave to SCREEN 0. LEAVE PROGRAM. when OTHERS . ENDCASE.ENDFORM.*&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS 'Z20210733160_STATUS'. SET TITLEBAR 'Z20210733160_TITLE'.ENDMODULE.*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9000' ITSELFCONTROLS: TC_9000 TYPE TABLEVIEW USING SCREEN 9000.*&SPWIZARD: LINES OF TABLECONTROL 'TC_9000'DATA: G_TC_9000_LINES LIKE SY-LOOPC.*DATA: OK_CODE LIKE SY-UCOMM.*----------------------------------------------------------------------** INCLUDE TABLECONTROL_FORMS **----------------------------------------------------------------------**&---------------------------------------------------------------------**& Form USER_OK_TC **&---------------------------------------------------------------------* FORM USER_OK_TC USING P_TC_NAME TYPE DYNFNAM P_TABLE_NAME P_MARK_NAME CHANGING P_OK LIKE SY-UCOMM.*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA: L_OK TYPE SY-UCOMM, L_OFFSET TYPE I.*&SPWIZARD: END OF LOCAL DATA------------------------------------------**&SPWIZARD: Table control specific operations **&SPWIZARD: evaluate TC name and operations * SEARCH P_OK FOR P_TC_NAME. IF SY-SUBRC <> 0. EXIT. ENDIF. L_OFFSET = STRLEN( P_TC_NAME ) + 1. L_OK = P_OK+L_OFFSET.*&SPWIZARD: execute general and TC specific operations * CASE L_OK. WHEN 'INSR'. "insert row PERFORM FCODE_INSERT_ROW USING P_TC_NAME P_TABLE_NAME. CLEAR P_OK. WHEN 'DELE'. "delete row PERFORM FCODE_DELETE_ROW USING P_TC_NAME P_TABLE_NAME P_MARK_NAME. CLEAR P_OK. WHEN 'P--' OR "top of list 'P-' OR "previous page 'P+' OR "next page 'P++'. "bottom of list PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME L_OK. CLEAR P_OK.* WHEN 'L--'. "total left* PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.** WHEN 'L-'. "column left* PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.** WHEN 'R+'. "column right* PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.** WHEN 'R++'. "total right* PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.* WHEN 'MARK'. "mark all filled lines PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME P_TABLE_NAME P_MARK_NAME . CLEAR P_OK. WHEN 'DMRK'. "demark all filled lines PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME P_TABLE_NAME P_MARK_NAME . CLEAR P_OK.* WHEN 'SASCEND' OR* 'SDESCEND'. "sort column* PERFORM FCODE_SORT_TC USING P_TC_NAME* l_ok. ENDCASE. ENDFORM. " USER_OK_TC*&---------------------------------------------------------------------**& Form FCODE_INSERT_ROW **&---------------------------------------------------------------------* FORM fcode_insert_row USING P_TC_NAME TYPE DYNFNAM P_TABLE_NAME .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA L_LINES_NAME LIKE FELD-NAME. DATA L_SELLINE LIKE SY-STEPL. DATA L_LASTLINE TYPE I. DATA L_LINE TYPE I. DATA L_TABLE_NAME LIKE FELD-NAME. FIELD-SYMBOLS TYPE CXTAB_CONTROL. FIELD-SYMBOLSTYPE STANDARD TABLE. FIELD-SYMBOLS TYPE I.*&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (P_TC_NAME) TO.*&SPWIZARD: get the table, which belongs to the tc * CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body ASSIGN (L_TABLE_NAME) TO. "not headerline*&SPWIZARD: get looplines of TableControl * CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME. ASSIGN (L_LINES_NAME) TO.*&SPWIZARD: get current line * GET CURSOR LINE L_SELLINE. IF SY-SUBRC <> 0. " append line to table L_SELLINE =-LINES + 1.*&SPWIZARD: set top line * IF L_SELLINE >.-TOP_LINE = L_SELLINE - + 1 . ELSE.-TOP_LINE = 1. ENDIF. ELSE. " insert line into table L_SELLINE =-TOP_LINE + L_SELLINE - 1. L_LASTLINE =-TOP_LINE + - 1. ENDIF.*&SPWIZARD: set new cursor line * L_LINE = L_SELLINE --TOP_LINE + 1.*&SPWIZARD: insert initial line * INSERT INITIAL LINE INTO INDEX L_SELLINE.-LINES =-LINES + 1.*&SPWIZARD: set cursor * SET CURSOR LINE L_LINE. ENDFORM. " FCODE_INSERT_ROW*&---------------------------------------------------------------------**& Form FCODE_DELETE_ROW **&---------------------------------------------------------------------* FORM fcode_delete_row USING P_TC_NAME TYPE DYNFNAM P_TABLE_NAME P_MARK_NAME .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA L_TABLE_NAME LIKE FELD-NAME. FIELD-SYMBOLS TYPE cxtab_control. FIELD-SYMBOLS TYPE STANDARD TABLE. FIELD-SYMBOLS. FIELD-SYMBOLS <MARK_FIELD>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (P_TC_NAME) TO.*&SPWIZARD: get the table, which belongs to the tc * CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body ASSIGN (L_TABLE_NAME) TO. "not headerline*&SPWIZARD: delete marked lines * DESCRIBE TABLE LINES-LINES. LOOP AT ASSIGNING.*&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE TO <MARK_FIELD>. IF <MARK_FIELD> = 'X'. DELETE INDEX SYST-TABIX. IF SY-SUBRC = 0.-LINES =-LINES - 1. ENDIF. ENDIF. ENDLOOP. ENDFORM. " FCODE_DELETE_ROW*&---------------------------------------------------------------------**& Form COMPUTE_SCROLLING_IN_TC*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol* -->P_OK ok code*----------------------------------------------------------------------* FORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME P_OK.*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA L_TC_NEW_TOP_LINE TYPE I. DATA L_TC_NAME LIKE FELD-NAME. DATA L_TC_LINES_NAME LIKE FELD-NAME. DATA L_TC_FIELD_NAME LIKE FELD-NAME. FIELD-SYMBOLS TYPE cxtab_control. FIELD-SYMBOLS TYPE I.*&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (P_TC_NAME) TO.*&SPWIZARD: get looplines of TableControl * CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME. ASSIGN (L_TC_LINES_NAME) TO.*&SPWIZARD: is no line filled? * IF-LINES = 0.*&SPWIZARD: yes, ... * L_TC_NEW_TOP_LINE = 1. ELSE.*&SPWIZARD: no, ... * CALL FUNCTION 'SCROLLING_IN_TABLE' EXPORTING ENTRY_ACT =-TOP_LINE ENTRY_FROM = 1 ENTRY_TO =-LINES LAST_PAGE_FULL = 'X' LOOPS = OK_CODE = P_OK OVERLAPPING = 'X' IMPORTING ENTRY_NEW = L_TC_NEW_TOP_LINE EXCEPTIONS* NO_ENTRY_OR_PAGE_ACT = 01* NO_ENTRY_TO = 02* NO_OK_CODE_OR_PAGE_GO = 03 OTHERS = 0. ENDIF.*&SPWIZARD: get actual tc and column * GET CURSOR FIELD L_TC_FIELD_NAME AREA L_TC_NAME. IF SYST-SUBRC = 0. IF L_TC_NAME = P_TC_NAME.*&SPWIZARD: et actual column * SET CURSOR FIELD L_TC_FIELD_NAME LINE 1. ENDIF. ENDIF.*&SPWIZARD: set the new top line *-TOP_LINE = L_TC_NEW_TOP_LINE. ENDFORM. " COMPUTE_SCROLLING_IN_TC*&---------------------------------------------------------------------**& Form FCODE_TC_MARK_LINES*&---------------------------------------------------------------------** marks all TableControl lines*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol*----------------------------------------------------------------------*FORM FCODE_TC_MARK_LINES USING P_TC_NAME P_TABLE_NAME P_MARK_NAME.*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------* DATA L_TABLE_NAME LIKE FELD-NAME. FIELD-SYMBOLS TYPE cxtab_control. FIELD-SYMBOLS TYPE STANDARD TABLE. FIELD-SYMBOLS. FIELD-SYMBOLS <MARK_FIELD>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (P_TC_NAME) TO.*&SPWIZARD: get the table, which belongs to the tc * CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body ASSIGN (L_TABLE_NAME) TO. "not headerline*&SPWIZARD: mark all filled lines * LOOP AT ASSIGNING.*&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE TO <MARK_FIELD>. <MARK_FIELD> = 'X'. ENDLOOP.ENDFORM. "fcode_tc_mark_lines*&---------------------------------------------------------------------**& Form FCODE_TC_DEMARK_LINES*&---------------------------------------------------------------------** demarks all TableControl lines*----------------------------------------------------------------------** -->P_TC_NAME name of tablecontrol*----------------------------------------------------------------------*FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME P_TABLE_NAME P_MARK_NAME .*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------* DATA L_TABLE_NAME LIKE FELD-NAME. FIELD-SYMBOLS TYPE cxtab_control. FIELD-SYMBOLS TYPE STANDARD TABLE. FIELD-SYMBOLS. FIELD-SYMBOLS <MARK_FIELD>.*&SPWIZARD: END OF LOCAL DATA------------------------------------------* ASSIGN (P_TC_NAME) TO.*&SPWIZARD: get the table, which belongs to the tc * CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body ASSIGN (L_TABLE_NAME) TO. "not headerline*&SPWIZARD: demark all filled lines * LOOP AT ASSIGNING .*&SPWIZARD: access to the component 'FLAG' of the table header * ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE TO <MARK_FIELD>. <MARK_FIELD> = SPACE. ENDLOOP.ENDFORM. "fcode_tc_mark_lines*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!INCLUDE Z20210733160_TEST014_PBO .INCLUDE Z20210733160_TEST014_PAI .
2619 ``` 2620 2621 ![](C:\liuliu\typora\图片\z20210733160_test014.png) 2622 2623 2624 2625 ## 15、Z20210733160_TEST0015(第三周作业一) 2626 2627 ```ABAP 2628 *&---------------------------------------------------------------------**& Report Z20210733160_TEST015*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z20210733160_test015.TABLES:mkpf.TYPES: BEGIN OF aa, mblnr TYPE mkpf-mblnr, mjahr TYPE mkpf-mjahr, blart TYPE mkpf-blart, bldat TYPE mkpf-bldat, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, tcode TYPE mkpf-tcode, xblnr TYPE mkpf-xblnr, bktxt TYPE mkpf-bktxt, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, matnr TYPE mseg-matnr, werks TYPE mseg-werks, lgort TYPE mseg-lgort, shkzg TYPE mseg-shkzg, menge TYPE mseg-menge, meins TYPE mseg-meins,* id TYPE icon-id, chk, END OF aa.DATA: gt_a TYPE TABLE OF ZL33160_YT004, gtt_a TYPE TABLE OF ZL33160_YT004, gs_a TYPE ZL33160_YT004.data: ok_code type sy-ucomm, SAVE_OK_CODE type sy-ucomm.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.SELECT-OPTIONS: s_mblnr FOR mkpf-mblnr, s_mjahr FOR mkpf-mjahr, s_blart FOR mkpf-blart, s_bldat FOR mkpf-bldat, s_budat FOR mkpf-budat, s_usnam FOR mkpf-usnam.CLEAR gs_a.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)START-OF-SELECTION."(取数据) PERFORM za.END-OF-SELECTION."(展示数据) PERFORM z_output.FORM za. SELECT mkpf~mblnr mkpf~mjahr mkpf~blart mkpf~bldat mkpf~budat mkpf~usnam mkpf~tcode mkpf~xblnr mkpf~bktxt mseg~zeile mseg~bwart mseg~matnr mseg~werks mseg~lgort mseg~shkzg mseg~menge mseg~meins FROM mkpf JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE mkpf~mblnr IN s_mblnr AND mkpf~mjahr IN s_mjahr AND mkpf~blart IN s_blart AND mkpf~bldat IN s_bldat AND mkpf~budat IN s_budat AND mkpf~usnam IN s_usnam.ENDFORM.FORM z_output. gs_layout-box_fieldname = 'CHK'. "选择行 PERFORM frm_build_fieldcat USING: 'MBLNR' 'MKPF' 'MBLNR', 'MJAHR' 'MKPF' 'MJAHR', 'BLART' 'MKPF' 'BLART', 'BLDAT' 'MKPF' 'BLDAT', 'BUDAT' 'MKPF' 'BUDAT', 'USNAM' 'MKPF' 'USNAM', 'TCODE' 'MKPF' 'TCODE', 'XBLNR' 'MKPF' 'XBLNR', 'BKTXT' 'MKPF' 'BKTXT', 'ZEILE' 'MSEG' 'ZEILE', 'BWART' 'MSEG' 'BWART', 'MATNR' 'MSEG' 'MATNR', 'WERKS' 'MSEG' 'WERKS', 'LGORT' 'MSEG' 'LGORT', 'SHKZG' 'MSEG' 'SHKZG', 'MENGE' 'MSEG' 'MENGE', 'MEINS' 'MSEG' 'MEINS', 'CHK' '' ' ' . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' ' i_callback_program = sy-repid i_callback_pf_status_set = 'FRM_SET_PF_STATUS' i_callback_user_command = 'FRM_USER_COMMAND'* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' i_grid_title = '卡哇伊'* I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = gt_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_a EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname. DATA: ls_fieldcat TYPE slis_fieldcat_alv. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. ls_fieldcat-fieldname = fu_fieldname. ls_fieldcat-ref_tabname = fu_rtabname. ls_fieldcat-ref_fieldname = fu_rfieldname. APPEND ls_fieldcat TO gt_fieldcat.ENDFORM.* 选中一个格子 双击跳转 调试界面FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.* BREAK-POINT. data: lt_a like gt_a, ls_a LIKE gs_a.* ls_a type aa. CASE r_ucomm. WHEN 'SELEC'. lt_a = gt_a. DELETE lt_a WHERE chk is INITIAL. sort lt_a by mblnr. DELETE ADJACENT DUPLICATES FROM lt_a COMPARING mblnr. loop at lt_a into ls_a.* 抬头部分 loop at gt_a into gs_a WHERE mblnr = ls_a-mblnr.* 行项目部分 append gs_a to gt_a. endloop.* call function 'PRINT'* EXPORTING* head = ls_vbrk* item = lt_vbrp ENDLOOP. when 'PRINT'. lt_a = gt_a. DELETE gt_a WHERE chk is INITIAL. sort gt_a by ZEILE. DELETE ADJACENT DUPLICATES FROM gt_a COMPARING ZEILE. call screen 9100.* lt_vbrk = gt_vbrk.* DELETE lt_vbrk WHERE chk is INITIAL.* sort lt_vbrk by vbeln.* DELETE ADJACENT DUPLICATES FROM lt_vbrk COMPARING vbeln.** loop at lt_vbrk into ls_vbrk.** 抬头部分** loop at gt_vbrk into gs_vbrk WHERE vbeln = ls_vbrk-vbeln.** 行项目部分** append gs_vbrk to lt_vbrp.* endloop.* call function 'PRINT'* EXPORTING* head = ls_vbrk* item = lt_vbrp* ENDLOOP. WHEN '&IC1'." 控制双击 IF rs_selfield-fieldname = 'MBLNR'." 控制 鼠标双击列 SET PARAMETER ID 'ANR' FIELD rs_selfield-value. CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN. ENDIF. ENDCASE.ENDFORM.*FORM frm_user_command USING r_ucomm LIKE sy-ucomm* rs_selfield TYPE slis_selfield.*** BREAK-POINT.* data: lt_a TYPE TABLE OF ZL33160_YT004,* ls_a type ZL33160_YT004.* CLEAR ls_a.* CASE r_ucomm.*** WHEN 'PRINT'.* lt_a = gt_a.* DELETE lt_a WHERE chk IS INITIAL.* SORT lt_a BY mblnr.* DELETE ADJACENT DUPLICATES FROM lt_a COMPARING mblnr.* loop at lt_a into ls_a.** 抬头部分* loop at gt_a into gs_a WHERE mblnr = ls_a-mblnr AND mjahr = ls_a-mjahr.** 行项目部分* append gs_a to gtt_a.* endloop.* ENDLOOP.** DATA:g_name TYPE rs38l_fnam. "SMARTFORMS* DATA:control TYPE ssfctrlop.* DATA:output_options TYPE ssfcompop,* l_job_output_info TYPE ssfcrescl.* DATA:formname TYPE tdsfname .***g_name = '/1BCDWB/SF00000297'.* formname = 'ZBD_33160_001'."测试打印(SMARTFORM名字)**"开启批量打印* control-no_open = 'X'.* control-no_close = 'X'.* output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面****打开Smartform* CALL FUNCTION 'SSF_OPEN'* EXPORTING* output_options = output_options* control_parameters = control** IMPORTING** JOB_OUTPUT_OPTIONS =* EXCEPTIONS* formatting_error = 1* internal_error = 2* send_error = 3* user_canceled = 4* OTHERS = 5.* IF sy-subrc <> 0.* MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'.* EXIT.* ELSE.** CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'* EXPORTING* formname = formname* IMPORTING* fm_name = g_name* EXCEPTIONS* no_form = 1* no_function_module = 2* OTHERS = 3.* IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* EXIT.* ENDIF.**** CALL FUNCTION g_name* EXPORTING* control_parameters = control* TABLES* gt_item = gtt_a* gt_head = lt_a.* IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* EXIT.* ENDIF.*****关闭Smartform,此时会弹出一个选择打印机选项* CLEAR l_job_output_info.* CALL FUNCTION 'SSF_CLOSE'* IMPORTING* job_output_info = l_job_output_info* EXCEPTIONS* formatting_error = 1* internal_error = 2* send_error = 3* OTHERS = 4.* IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.* EXIT.* ENDIF.*** IF l_job_output_info-outputdone = 'X'."打印成功** MESSAGE '打印成功!' TYPE 'S' .** ELSE.* MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'.* ENDIF.* ENDIF.** ENDCASE.*ENDFORM.*增加按钮*----------------------------------------------------------------------**自定义状态*----------------------------------------------------------------------*FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM.*&---------------------------------------------------------------------**& Module USER_COMMAND_9100 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9100 INPUT. SAVE_OK_CODE = ok_code. CLEAr ok_code. case SAVE_OK_CODE. when '&F03' or '&F12' or '&F15'. leave to SCREEN 0.* LEAVE PROGRAM. when OTHERS . ENDCASE.ENDMODULE.*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9100' ITSELFCONTROLS: TC_9100 TYPE TABLEVIEW USING SCREEN 9100.*&SPWIZARD: LINES OF TABLECONTROL 'TC_9100'DATA: G_TC_9100_LINES LIKE SY-LOOPC.*DATA: OK_CODE LIKE SY-UCOMM.*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!INCLUDE Z20210733160_TEST015_PBO .INCLUDE Z20210733160_TEST015_PAI .INCLUDE Z20210733160_TEST015_INC .*&---------------------------------------------------------------------**& Module STATUS_9100 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9100 OUTPUT. SET PF-STATUS 'ZT_33160_X'. SET TITLEBAR 'ZT_33160_Y'.ENDMODULE. 2629 ``` 2630 2631 ![](C:\liuliu\typora\图片\z20210733160_test015.png) 2632 2633 2634 2635 ## 16、Z2107_33160_TEST016(屏幕) 2636 2637 ```ABAP 2638 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST016*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST016.data: gs_lfa1 type lfa1, gt_lfa1 type TABLE OF lfa1.data: ok_code type sy-ucomm, code_com type sy-ucomm, SAVE_OK_CODE type sy-ucomm.INITIALIZATION.START-OF-SELECTION.call screen 9000.end-of-SELECTION.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT.PERFORM frm_get_lifnr.ENDMODULE.FORM frm_get_lifnr . code_com = ok_code. CLEAr ok_code. case code_com. when 'SEAR'. select SINGLE name1 from lfa1 into gs_lfa1-name1 WHERE lifnr = gs_lfa1-lifnr and spras = sy-langu. when 'SAVE'. call SCREEN 9100. ENDCASE.ENDFORM.*&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS 'Z20210733160_STATUS'. SET TITLEBAR 'Z20210733160_TITLE'.ENDMODULE.*&---------------------------------------------------------------------**& Module FIELD_CHECK INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE field_check INPUT.SELECT COUNT( * )from lfa1WHERE lifnr = gs_lfa1-lifnr. if sy-subrc = 0. select SINGLE name1 from lfa1 into gs_lfa1-name1 WHERE lifnr = gs_lfa1-lifnr and spras = gs_lfa1-spras. else. MESSAGE '物料输入错误' type 'E'. endif.ENDMODULE.*&---------------------------------------------------------------------**& Module USER_EXIT_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_exit_command_9000 INPUT. SAVE_OK_CODE = ok_code. CLEAr ok_code. case SAVE_OK_CODE. when '&F03' or '&F12' or '&F15'.* leave to SCREEN 0. LEAVE PROGRAM. when OTHERS . ENDCASE.ENDMODULE.*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9000' ITSELFCONTROLS: TC_9000 TYPE TABLEVIEW USING SCREEN 9000.*&SPWIZARD: LINES OF TABLECONTROL 'TC_9000'DATA: G_TC_9000_LINES LIKE SY-LOOPC.*DATA: OK_CODE LIKE SY-UCOMM.*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!INCLUDE Z2107_33160_TEST016_PBO .INCLUDE Z2107_33160_TEST016_PAI .INCLUDE Z2107_33160_TEST016_INC .*&---------------------------------------------------------------------**& Module FILL_TABLE INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE fill_table INPUT.SELECT *from lfa1into TABLE gt_lfa1 WHERE lifnr = gs_lfa1-lifnr.ENDMODULE. 2639 ``` 2640 2641 ![](C:\liuliu\typora\图片\z20210733160_test016.png) 2642 2643 2644 2645 ## 17、Z2107_33160_TEST017(SMARTFORMS测试) 2646 2647 ```ABAP 2648 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST017*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST017.TABLES mkpf.TYPES: BEGIN OF aa, mblnr TYPE mkpf-mblnr, mjahr TYPE mkpf-mjahr, blart TYPE mkpf-blart, bldat TYPE mkpf-bldat, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, tcode TYPE mkpf-tcode, xblnr TYPE mkpf-xblnr, bktxt TYPE mkpf-bktxt, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, matnr TYPE mseg-matnr, werks TYPE mseg-werks, lgort TYPE mseg-lgort, shkzg TYPE mseg-shkzg, menge TYPE mseg-menge, meins TYPE mseg-meins, chk, END OF aa.DATA gs_mkpf TYPE ZL33160_YT004.DATA gt_mkpf TYPE TABLE OF ZL33160_YT004.DATA lt_mkpf TYPE TABLE OF ZL33160_YT004.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.DATA: ok_code TYPE sy-ucomm, save_ok_code TYPE sy-ucomm.SELECT-OPTIONS:s_mblnr FOR mkpf-mblnr, s_mjahr FOR mkpf-mjahr, s_blart FOR mkpf-blart, s_bldat FOR mkpf-bldat, s_budat FOR mkpf-budat, s_usnam FOR mkpf-usnam.START-OF-SELECTION. PERFORM main.FORM main. PERFORM select_mkpf. PERFORM build_fieldcat. PERFORM frm_output.* BREAK-POINT.ENDFORM.FORM init.ENDFORM.FORM select_mkpf. SELECT mkpf~mblnr mkpf~mjahr blart bldat budat usnam tcode xblnr bktxt zeile bwart matnr werks lgort shkzg menge meins FROM mkpf JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr INTO CORRESPONDING FIELDS OF TABLE gt_mkpf WHERE mkpf~mblnr IN s_mblnr AND mkpf~mjahr IN s_mjahr AND blart IN s_blart AND bldat IN s_bldat AND budat IN s_budat AND usnam IN s_usnam.ENDFORM.FORM build_fieldcat. gs_layout-colwidth_optimize = 'X'. "优化列宽设置 gs_layout-zebra = 'X'. "开启斑马线 gs_layout-box_fieldname = 'CHK'. PERFORM frm_build_fieldcat USING:'MBLNR' 'MKPF' 'MBLNR' ,'MJAHR' 'MKPF' 'MJAHR' ,'BLART' 'MKPF' 'BLART' ,'BLDAT' 'MKPF' 'BLDAT' ,'BUDAT' 'MKPF' 'BUDAT' ,'USNAM' 'MKPF' 'USNAM' ,'TCODE' 'MKPF' 'TCODE' ,'XBLNR' 'MKPF' 'XBLNR' ,'BKTXT' 'MKPF' 'BKTXT' ,'ZEILE' 'MSEG' 'ZEILE' ,'BWART' 'MSEG' 'BWART' ,'MATNR' 'MSEG' 'MATNR' ,'WERKS' 'MSEG' 'WERKS' ,'LGORT' 'MSEG' 'LGORT' ,'SHKZG' 'MSEG' 'SHKZG' ,'MENGE' 'MSEG' 'MENGE' ,'MEINS' 'MSEG' 'MEINS' ,'CHK' '' ''.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname. DATA: ls_fieldcat TYPE slis_fieldcat_alv. ls_fieldcat-fieldname = fu_fieldname. ls_fieldcat-ref_tabname = fu_rtabname. ls_fieldcat-ref_fieldname = fu_rfieldname. APPEND ls_fieldcat TO gt_fieldcat.ENDFORM.FORM frm_output. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' ' i_callback_program = sy-repid i_callback_pf_status_set = 'FRM_SET_PF_STATUS' i_callback_user_command = 'FRM_USER_COMMAND'* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' '* I_GRID_TITLE =* I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = gt_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_mkpf EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM.FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.* BREAK-POINT. CASE r_ucomm. WHEN 'PRINT'. lt_mkpf = gt_mkpf. DELETE lt_mkpf WHERE chk IS INITIAL. SORT lt_mkpf BY mblnr. DELETE ADJACENT DUPLICATES FROM lt_mkpf COMPARING mblnr. DATA:g_name TYPE rs38l_fnam. "SMARTFORMS DATA:control TYPE ssfctrlop. DATA:output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. DATA:formname TYPE tdsfname .g_name = '/1BCDWB/SF00000297'. formname = 'ZBD_33160_001'."测试打印(SMARTFORM名字)"开启批量打印 control-no_open = 'X'. control-no_close = 'X'. output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面*打开Smartform CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = output_options control_parameters = control* IMPORTING* JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ELSE. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = formname IMPORTING fm_name = g_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. CALL FUNCTION g_name EXPORTING control_parameters = control TABLES gt_item = lt_mkpf gt_head = lt_mkpf. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF.*关闭Smartform,此时会弹出一个选择打印机选项 CLEAR l_job_output_info. CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = l_job_output_info EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. EXIT. ENDIF. IF l_job_output_info-outputdone = 'X'."打印成功 MESSAGE '打印成功!' TYPE 'S' . ELSE. MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. ENDIF. ENDIF. ENDCASE.ENDFORM. 2649 ``` 2650 2651 ![](C:\liuliu\typora\图片\z20210733160_test017.png) 2652 2653 2654 2655 ## 18、Z2107_33160_TEST018(打印测试) 2656 2657 ```ABAP 2658 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST018*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST018.TYPE-POOLS: slis , icon. " Globale Typen*---------------------------------------------------------------------** 系统表声明 ** **---------------------------------------------------------------------**TABLES: mara.*---------------------------------------------------------------------** ALV相关——内表及结构定义 ** **---------------------------------------------------------------------*DATA gv_title TYPE lvc_title . "标题名DATA gt_fieldcat TYPE lvc_t_fcat. "列属性,内表类型DATA gs_fieldcat TYPE lvc_s_fcat. "结构DATA gs_layout TYPE lvc_s_layo.*---------------------------------------------------------------------** 取值相关——内表及结构定义 ** **---------------------------------------------------------------------*TYPES: BEGIN OF ty_alv, zbox TYPE char1, zclass TYPE char10,"班级 zname TYPE char10,"姓名 zsex TYPE char10,"性别 znumber TYPE char10,"年龄 zad TYPE char40,"家庭地址 END OF ty_alv.TYPES: BEGIN OF ty_head, zclass TYPE char10,"班级 END OF ty_head.TYPES: BEGIN OF ty_item, zclass TYPE char10,"班级 zname TYPE char10,"姓名 zsex TYPE char10,"性别 znumber TYPE char10,"年龄 zad TYPE char40,"家庭地址 END OF ty_item.DATA: gt_alv TYPE TABLE OF ty_alv, "ALV显示 gs_alv TYPE ty_alv.DATA:gt_head TYPE TABLE OF ty_head, gs_head LIKE LINE OF gt_head.DATA:gt_item TYPE TABLE OF ty_item, gs_item LIKE LINE OF gt_item.DATA: gs_stable TYPE lvc_s_stbl.gs_stable-row = 'X'."行稳定更新gs_stable-col = 'X'."列稳定更新*---------------------------------------------------------------------** 选择屏幕 ** **---------------------------------------------------------------------**SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE TEXT-001.*SELECT-OPTIONS: s_matnr FOR mara-matnr ."物料号*SELECTION-SCREEN END OF BLOCK blk1.*---------------------------------------------------------------------** 初始化界面*---------------------------------------------------------------------*INITIALIZATION.AT SELECTION-SCREEN OUTPUT.*---------------------------------------------------------------------** 取值*---------------------------------------------------------------------*START-OF-SELECTION. PERFORM frm_getdata. "获取数据END-OF-SELECTION.*---------------------------------------------------------------------** 设置ALV显示*---------------------------------------------------------------------* IF gt_alv[] IS NOT INITIAL. PERFORM frm_output . "设置ALV-layout布局 PERFORM frm_setfieldcat. "设置ALV-fielscat结构 PERFORM frm_alvout. "设置初始化ALV ELSE. MESSAGE '没有符合条件的数据!' TYPE 'I'. ENDIF.*----------------------------------------------------------------------** 设置ALV-layout布局*----------------------------------------------------------------------*FORM frm_output . gs_layout-zebra = 'X'. "斑马线 GS_LAYOUT-BOX_FNAME = 'ZBOX'. "选择标记 内表增加 BOX字段 会将选中的BOX列 标记为 X " GS_LAYOUT-DETAIL_POPUP = 'X'. "点击弹出详情 gs_layout-cwidth_opt = 'X'. "自动调节宽度 "GS_LAYOUT-EDIT = 'X'. "ALV可编辑 gs_layout-sel_mode = 'A'. "A:多行多列 B:单行多单元格 C:多行非多单元格 D:所有 "GS_LAYOUT-ctab_fname = 'CELLCOLOR'. "单元格颜色设置 , GT_OUT-CELLCOLOR字段 "GS_LAYOUT-stylefname = 'CELLSTYLES'. "控制单元格可编辑的字段 , GT_OUT-CELLSTYLES字段ENDFORM. " FRM_OUTPUT*----------------------------------------------------------------------** 设置ALV-fielscat结构 注:宏定义不利于debug,建议使用perform*----------------------------------------------------------------------*FORM frm_setfieldcat . DEFINE set_fcat. "宏定义-设置字段 CLEAR gs_fieldcat. gs_fieldcat-fieldname = &1. "字段名字 gs_fieldcat-reptext = &2. "字段描述* gs_fieldcat-key = &3. "是否主键 gs_fieldcat-outputlen = &3. "输出字段长度 (影响ALV中的筛选功能) gs_fieldcat-just = 'L'. "对其方式,L表示左对齐 gs_fieldcat-no_zero = &4. "去前导零* gs_fieldcat-emphasize = 'C710'. "整列设置颜色* gs_fieldcat-edit = 'X'. "整列可编辑 APPEND gs_fieldcat TO gt_fieldcat. END-OF-DEFINITION. set_fcat 'ZCLASS' '班级' '' ''. set_fcat 'ZNAME' '姓名' '' ''. set_fcat 'ZSEX' '性别' '' ''. set_fcat 'ZNUMBER' '年龄' '' ''. set_fcat 'ZAD' '家庭地址' '' ''.ENDFORM. " FRM_SETFIELDCAT*----------------------------------------------------------------------** 设置初始化ALV*----------------------------------------------------------------------*FORM frm_alvout . gv_title = '打印报表'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid "当前程序 i_callback_pf_status_set = 'FRM_SET_PF_STATUS' "自定义状态 i_callback_user_command = 'FRM_USER_COMMAND' "设置COMMAND命令行 i_grid_title = gv_title "标题名 is_layout_lvc = gs_layout "Layout布局 " i_save = 'A' it_fieldcat_lvc = gt_fieldcat "fieldcat结构设置 " it_events = GT_EVENTS " IT_EVENT_EXIT = GT_EVENT_EXIT " i_grid_settings = l_grid_settings TABLES t_outtab = gt_alv "与ALV相关的事件内表 EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0."调用完函数等之后,检查返回码sy-subrc的值,并做判断处理 MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.ENDFORM. " FRM_ALVOUT*----------------------------------------------------------------------** 自定义状态*----------------------------------------------------------------------*FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'STANDARD' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM. "frm_set_pf_status**----------------------------------------------------------------------** ALV取值*----------------------------------------------------------------------*FORM frm_getdata. gs_alv-zclass = '1'. gs_alv-zname = '小明'. gs_alv-zsex = '男'. gs_alv-znumber = '10'. APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv.* gs_alv-zclass = '1'.* gs_alv-zname = '小明'.* gs_alv-zsex = '男'.* gs_alv-znumber = '10'.* APPEND gs_alv to gt_alv.* CLEAR gs_alv. gs_alv-zclass = '1'. gs_alv-zname = '小天'. gs_alv-zsex = '男'. gs_alv-znumber = '17'. APPEND gs_alv to gt_alv. CLEAR gs_alv. gs_alv-zclass = '1'. gs_alv-zname = '小蓝'. gs_alv-zsex = '男'. gs_alv-znumber = '13'. APPEND gs_alv to gt_alv. CLEAR gs_alv. gs_alv-zclass = '1'. gs_alv-zname = '小虹'. gs_alv-zsex = '女'. gs_alv-znumber = '13'. APPEND gs_alv to gt_alv. CLEAR gs_alv. gs_alv-zclass = '1'. gs_alv-zname = '小紫'. gs_alv-zsex = '女'. gs_alv-znumber = '13'. APPEND gs_alv to gt_alv. CLEAR gs_alv. gs_alv-zclass = '1'. gs_alv-zname = '小红'. gs_alv-zsex = '女'. gs_alv-znumber = '13'. APPEND gs_alv to gt_alv. CLEAR gs_alv.ENDFORM. "frm_getdataFORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. DATA lr_grid TYPE REF TO cl_gui_alv_grid. DATA: ls_stable TYPE lvc_s_stbl. DATA: lt_index_rows TYPE lvc_t_row, lt_row_no TYPE lvc_t_roid, ls_index_rows TYPE lvc_s_row, ls_row_no TYPE lvc_s_roid. DATA: is_rowid TYPE lvc_s_row. DATA: is_column_id TYPE lvc_s_col. DATA: io_sender TYPE REF TO cl_gui_alv_grid . "获取当前界面ALV容器 CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR' IMPORTING e_grid = lr_grid. "获取ALV选中行 CALL METHOD lr_grid->get_selected_rows IMPORTING et_index_rows = lt_index_rows et_row_no = lt_row_no.*** CALL METHOD lr_grid->check_changed_data. rs_selfield-refresh = 'X'. CASE r_ucomm. WHEN '&A1'. REFRESH:gt_head, gt_item. SORT gt_alv by zclass. LOOP AT gt_alv INTO gs_alv WHERE zbox = 'X'. at NEW zclass. gs_head-zclass = gs_alv-zclass. APPEND gs_head to gt_head. CLEAR gs_head. ENDAT. MOVE-CORRESPONDING gs_alv to gs_item. APPEND gs_item to gt_item. CLEAR gs_item. ENDLOOP.****调用打印 PERFORM frm_print. ENDCASE.ENDFORM.FORM frm_print . EXPORT gt_head gt_item TO MEMORY ID 'Z16239_01_A'." "打印 DATA:g_name TYPE rs38l_fnam. "SMARTFORMS DATA:control TYPE ssfctrlop. DATA:output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. DATA:formname TYPE tdsfname . formname = 'Z16239_01'."测试打印(SMARTFORM名字)"开启批量打印 control-no_open = 'X'. control-no_close = 'X'. output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面*打开Smartform CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = output_options control_parameters = control* IMPORTING* JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ELSE. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = formname IMPORTING fm_name = g_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. CALL FUNCTION g_name EXPORTING control_parameters = control.* TABLES* CONTROL_PARAMETERS = L_CONTROL* t_head = gt_head* t_item = gt_item IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF.*关闭Smartform,此时会弹出一个选择打印机选项 CLEAR l_job_output_info. CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = l_job_output_info EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. EXIT. ENDIF. IF l_job_output_info-outputdone = 'X'."打印成功 MESSAGE '打印成功!' TYPE 'S' . ELSE. MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. ENDIF. ENDIF.ENDFORM. "frm_print_data 2659 ``` 2660 2661 ![](C:\liuliu\typora\图片\z20210733160_test018.png) 2662 2663 2664 2665 ## 19、Z2107_33160_TEST019(打印1) 2666 2667 ```ABAP 2668 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST019*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST019.TABLES:mkpf.TYPES: BEGIN OF aa, mblnr TYPE mkpf-mblnr, mjahr TYPE mkpf-mjahr, blart TYPE mkpf-blart, bldat TYPE mkpf-bldat, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, tcode TYPE mkpf-tcode, xblnr TYPE mkpf-xblnr, bktxt TYPE mkpf-bktxt, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, matnr TYPE mseg-matnr, werks TYPE mseg-werks, lgort TYPE mseg-lgort, shkzg TYPE mseg-shkzg, menge TYPE mseg-menge, meins TYPE mseg-meins,* id TYPE icon-id, chk, END OF aa.DATA: gt_a TYPE TABLE OF ZL33160_YT004, gtt_a TYPE TABLE OF ZL33160_YT004, gs_a TYPE ZL33160_YT004.data: ok_code type sy-ucomm, SAVE_OK_CODE type sy-ucomm.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.SELECT-OPTIONS: s_mblnr FOR mkpf-mblnr, s_mjahr FOR mkpf-mjahr, s_blart FOR mkpf-blart, s_bldat FOR mkpf-bldat, s_budat FOR mkpf-budat, s_usnam FOR mkpf-usnam.CLEAR gs_a.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)START-OF-SELECTION."(取数据) PERFORM za.END-OF-SELECTION."(展示数据) PERFORM z_output.FORM za. SELECT mkpf~mblnr mkpf~mjahr mkpf~blart mkpf~bldat mkpf~budat mkpf~usnam mkpf~tcode mkpf~xblnr mkpf~bktxt mseg~zeile mseg~bwart mseg~matnr mseg~werks mseg~lgort mseg~shkzg mseg~menge mseg~meins FROM mkpf JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE mkpf~mblnr IN s_mblnr AND mkpf~mjahr IN s_mjahr AND mkpf~blart IN s_blart AND mkpf~bldat IN s_bldat AND mkpf~budat IN s_budat AND mkpf~usnam IN s_usnam.ENDFORM.FORM z_output. gs_layout-box_fieldname = 'CHK'. "选择行 PERFORM frm_build_fieldcat USING: 'MBLNR' 'MKPF' 'MBLNR', 'MJAHR' 'MKPF' 'MJAHR', 'BLART' 'MKPF' 'BLART', 'BLDAT' 'MKPF' 'BLDAT', 'BUDAT' 'MKPF' 'BUDAT', 'USNAM' 'MKPF' 'USNAM', 'TCODE' 'MKPF' 'TCODE', 'XBLNR' 'MKPF' 'XBLNR', 'BKTXT' 'MKPF' 'BKTXT', 'ZEILE' 'MSEG' 'ZEILE', 'BWART' 'MSEG' 'BWART', 'MATNR' 'MSEG' 'MATNR', 'WERKS' 'MSEG' 'WERKS', 'LGORT' 'MSEG' 'LGORT', 'SHKZG' 'MSEG' 'SHKZG', 'MENGE' 'MSEG' 'MENGE', 'MEINS' 'MSEG' 'MEINS', 'CHK' '' ' ' . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' ' i_callback_program = sy-repid i_callback_pf_status_set = 'FRM_SET_PF_STATUS' i_callback_user_command = 'FRM_USER_COMMAND'* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' i_grid_title = '卡哇伊'* I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = gt_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_a EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname. DATA: ls_fieldcat TYPE slis_fieldcat_alv. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. ls_fieldcat-fieldname = fu_fieldname. ls_fieldcat-ref_tabname = fu_rtabname. ls_fieldcat-ref_fieldname = fu_rfieldname. APPEND ls_fieldcat TO gt_fieldcat.ENDFORM.* 选中一个格子 双击跳转 调试界面*FORM frm_user_command USING r_ucomm LIKE sy-ucomm* rs_selfield TYPE slis_selfield.** BREAK-POINT.* data: lt_a like gt_a,* ls_a LIKE gs_a.** ls_a type aa.* CASE r_ucomm.* WHEN 'SELEC'.* lt_a = gt_a.* DELETE lt_a WHERE chk is INITIAL.* sort lt_a by mblnr.* DELETE ADJACENT DUPLICATES FROM lt_a COMPARING mblnr.* loop at lt_a into ls_a.** 抬头部分** loop at gt_a into gs_a WHERE mblnr = ls_a-mblnr.** 行项目部分** append gs_a to gt_a.* endloop.*** call function 'PRINT'** EXPORTING** head = ls_vbrk** item = lt_vbrp** ENDLOOP.** when 'PRINT'.* lt_a = gt_a.* DELETE gt_a WHERE chk is INITIAL.* sort gt_a by ZEILE.* DELETE ADJACENT DUPLICATES FROM gt_a COMPARING ZEILE.* call screen 9100.** lt_vbrk = gt_vbrk.** DELETE lt_vbrk WHERE chk is INITIAL.** sort lt_vbrk by vbeln.** DELETE ADJACENT DUPLICATES FROM lt_vbrk COMPARING vbeln.**** loop at lt_vbrk into ls_vbrk.*** 抬头部分**** loop at gt_vbrk into gs_vbrk WHERE vbeln = ls_vbrk-vbeln.*** 行项目部分**** append gs_vbrk to lt_vbrp.** endloop.*** call function 'PRINT'** EXPORTING** head = ls_vbrk** item = lt_vbrp** ENDLOOP.*** WHEN '&IC1'." 控制双击* IF rs_selfield-fieldname = 'MBLNR'." 控制 鼠标双击列* SET PARAMETER ID 'ANR' FIELD rs_selfield-value.* CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.* ENDIF.* ENDCASE.*ENDFORM.FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.* BREAK-POINT. data: lt_a TYPE TABLE OF ZL33160_YT004, ls_a type ZL33160_YT004. CLEAR ls_a. CASE r_ucomm. WHEN 'PRINT'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. SORT lt_a BY mblnr. DELETE ADJACENT DUPLICATES FROM lt_a COMPARING mblnr. loop at lt_a into ls_a.* 抬头部分 loop at gt_a into gs_a WHERE mblnr = ls_a-mblnr AND mjahr = ls_a-mjahr.* 行项目部分 append gs_a to gtt_a. endloop. ENDLOOP. DATA:g_name TYPE rs38l_fnam. "SMARTFORMS DATA:control TYPE ssfctrlop. DATA:output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. DATA:formname TYPE tdsfname .g_name = '/1BCDWB/SF00000325'. formname = 'ZBD_33160_003'."测试打印(SMARTFORM名字)"开启批量打印 control-no_open = 'X'. control-no_close = 'X'. output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面*打开Smartform CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = output_options control_parameters = control* IMPORTING* JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ELSE. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = formname IMPORTING fm_name = g_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. CALL FUNCTION g_name EXPORTING control_parameters = control TABLES gt_item = gtt_a gt_head = lt_a. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF.*关闭Smartform,此时会弹出一个选择打印机选项 CLEAR l_job_output_info. CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = l_job_output_info EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. EXIT. ENDIF. IF l_job_output_info-outputdone = 'X'."打印成功 MESSAGE '打印成功!' TYPE 'S' . ELSE. MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. ENDIF. ENDIF. ENDCASE.ENDFORM.*增加按钮*----------------------------------------------------------------------**自定义状态*----------------------------------------------------------------------*FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM.*&---------------------------------------------------------------------**& Module USER_COMMAND_9100 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9100 INPUT. SAVE_OK_CODE = ok_code. CLEAr ok_code. case SAVE_OK_CODE. when '&F03' or '&F12' or '&F15'. leave to SCREEN 0.* LEAVE PROGRAM. when OTHERS . ENDCASE.ENDMODULE.*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9100' ITSELFCONTROLS: TC_9100 TYPE TABLEVIEW USING SCREEN 9100.*&SPWIZARD: LINES OF TABLECONTROL 'TC_9100'DATA: G_TC_9100_LINES LIKE SY-LOOPC.*DATA: OK_CODE LIKE SY-UCOMM.*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!INCLUDE Z20210733160_TEST015_PBO .INCLUDE Z20210733160_TEST015_PAI .INCLUDE Z20210733160_TEST015_INC .*&---------------------------------------------------------------------**& Module STATUS_9100 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9100 OUTPUT. SET PF-STATUS 'ZT_33160_X'. SET TITLEBAR 'ZT_33160_Y'.ENDMODULE. 2669 ``` 2670 2671 ![](C:\liuliu\typora\图片\z20210733160_test019.png) 2672 2673 2674 2675 ## 20、Z2107_33160_TEST020(二测试前练习) 2676 2677 ```ABAP 2678 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST020*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test020.TABLES:mkpf.TYPES: BEGIN OF aa, mblnr TYPE mkpf-mblnr, mjahr TYPE mkpf-mjahr, blart TYPE mkpf-blart, bldat TYPE mkpf-bldat, budat TYPE mkpf-budat, usnam TYPE mkpf-usnam, tcode TYPE mkpf-tcode, xblnr TYPE mkpf-xblnr, bktxt TYPE mkpf-bktxt, zeile TYPE mseg-zeile, bwart TYPE mseg-bwart, matnr TYPE mseg-matnr, werks TYPE mseg-werks, lgort TYPE mseg-lgort, shkzg TYPE mseg-shkzg, menge TYPE mseg-menge, meins TYPE mseg-meins,* id TYPE icon-id, chk, END OF aa.DATA: gt_a TYPE TABLE OF zl33160_yt004, gtt_a TYPE TABLE OF zl33160_yt004, gs_a TYPE zl33160_yt004.DATA: lt_a TYPE TABLE OF zl33160_yt004, ls_a TYPE zl33160_yt004.DATA: ok_code TYPE sy-ucomm, save_ok_code TYPE sy-ucomm.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.SELECT-OPTIONS: s_mblnr FOR mkpf-mblnr, s_mjahr FOR mkpf-mjahr, s_blart FOR mkpf-blart, s_bldat FOR mkpf-bldat, s_budat FOR mkpf-budat, s_usnam FOR mkpf-usnam.CLEAR gs_a.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)START-OF-SELECTION."(取数据) PERFORM za.END-OF-SELECTION."(展示数据)* PERFORM z_output. CALL SCREEN 9100.FORM za. SELECT mkpf~mblnr mkpf~mjahr mkpf~blart mkpf~bldat mkpf~budat mkpf~usnam mkpf~tcode mkpf~xblnr mkpf~bktxt mseg~zeile mseg~bwart mseg~matnr mseg~werks mseg~lgort mseg~shkzg mseg~menge mseg~meins FROM mkpf JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE mkpf~mblnr IN s_mblnr AND mkpf~mjahr IN s_mjahr AND mkpf~blart IN s_blart AND mkpf~bldat IN s_bldat AND mkpf~budat IN s_budat AND mkpf~usnam IN s_usnam.ENDFORM.FORM frm_user_command. "USING r_ucomm LIKE sy-ucomm "rs_selfield TYPE slis_selfield.* BREAK-POINT. DATA: lt_a TYPE TABLE OF zl33160_yt004, ls_a TYPE zl33160_yt004. CLEAR ls_a.* CASE r_ucomm.*** WHEN 'PRINT'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. SORT lt_a BY mblnr. DELETE ADJACENT DUPLICATES FROM lt_a COMPARING mblnr. LOOP AT lt_a INTO ls_a.* 抬头部分 LOOP AT gt_a INTO gs_a WHERE mblnr = ls_a-mblnr AND mjahr = ls_a-mjahr.* 行项目部分 APPEND gs_a TO gtt_a. ENDLOOP. ENDLOOP. DATA:g_name TYPE rs38l_fnam. "SMARTFORMS DATA:control TYPE ssfctrlop. DATA:output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. DATA:formname TYPE tdsfname .*g_name = '/1BCDWB/SF00000297'.* formname = 'ZBD_33160_001'."测试打印(SMARTFORM名字) g_name = '/1BCDWB/SF00000326'. formname = 'ZBD_33160_003'."测试打印(SMARTFORM名字) "开启批量打印 control-no_open = 'X'. control-no_close = 'X'. output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面*打开Smartform CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = output_options control_parameters = control* IMPORTING* JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ELSE. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = formname IMPORTING fm_name = g_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. CALL FUNCTION g_name EXPORTING control_parameters = control TABLES gt_item = gtt_a gt_head = lt_a. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF.*关闭Smartform,此时会弹出一个选择打印机选项 CLEAR l_job_output_info. CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = l_job_output_info EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. EXIT. ENDIF. IF l_job_output_info-outputdone = 'X'."打印成功 MESSAGE '打印成功!' TYPE 'S' . ELSE. MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. ENDIF. ENDIF.* ENDCASE.ENDFORM.*增加按钮*----------------------------------------------------------------------**自定义状态*----------------------------------------------------------------------*FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM.*&---------------------------------------------------------------------**& Module USER_COMMAND_9100 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9100 INPUT. save_ok_code = ok_code. CLEAR ok_code. CASE save_ok_code. WHEN 'PRINT'. PERFORM frm_user_command. WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0.* LEAVE PROGRAM. WHEN OTHERS . ENDCASE.ENDMODULE.*&---------------------------------------------------------------------**& Module STATUS_9100 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9100 OUTPUT. SET PF-STATUS 'ZT_33160_X'. SET TITLEBAR 'ZT_33160_Y'.ENDMODULE.*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC_9100' ITSELFCONTROLS: tc_9100 TYPE TABLEVIEW USING SCREEN 9100.*&SPWIZARD: LINES OF TABLECONTROL 'TC_9100'DATA: g_tc_9100_lines LIKE sy-loopc.*DATA: OK_CODE LIKE SY-UCOMM.*&SPWizard: Include inserted by SP Wizard. DO NOT CHANGE THIS LINE!INCLUDE z2107_33160_test020_pba .INCLUDE z2107_33160_test020_pai .INCLUDE z2107_33160_test020_ins .*&---------------------------------------------------------------------**& Module PBO_9000_STATUS OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------**MODULE pbo_9000_status OUTPUT.*loop at screen.* if screen-group1 = 'GR1'.* screen-input = 0.* ENDIF.* modify screen.*ENDLOOP.*ENDMODULE.*&---------------------------------------------------------------------**& Module REFRASH INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE refrash INPUT. SELECT mkpf~mblnr mkpf~mjahr blart bldat budat usnam tcode xblnr bktxt zeile bwart matnr werks lgort shkzg menge meins FROM mkpf LEFT JOIN mseg ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr INTO CORRESPONDING FIELDS OF ls_a WHERE mkpf~mblnr = gs_a-mblnr AND mkpf~mjahr = gs_a-mjahr. ENDSELECT. MODIFY gt_a FROM ls_a INDEX tc_9100-current_line TRANSPORTING mblnr mjahr blart bldat budat usnam tcode xblnr bktxt zeile bwart matnr werks lgort shkzg menge meins.ENDMODULE. 2679 ``` 2680 2681 ![](C:\liuliu\typora\图片\z20210733160_test020.png) 2682 2683 2684 2685 ## 21、Z2107_33160_TEST021(DBC练习) 2686 2687 ```ABAP 2688 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST021*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test021.TABLES:a018.TYPES: BEGIN OF aa, lifnr TYPE a018-lifnr, matnr TYPE a018-matnr, ekorg TYPE a018-ekorg, esokz TYPE a018-esokz, chk, END OF aa.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表*DATA p_mode TYPE c VALUE 'N'."bdc运行模式DATA: gt_a TYPE TABLE OF aa, gs_a TYPE aa.DATA: lt_a LIKE gt_a, ls_a LIKE gs_a.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv, gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.*SELECT-OPTIONS: s_esokz FOR a018-esokz DEFAULT 0.PARAMETERS: p_esokz TYPE a018-esokz DEFAULT 0, p_mode TYPE char1 DEFAULT 'A'.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)START-OF-SELECTION."(取数据) PERFORM za.END-OF-SELECTION."(展示数据) PERFORM z_output.* CALL SCREEN 9100.FORM za. SELECT a018~lifnr a018~matnr a018~ekorg FROM a018 INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE esokz = p_esokz.ENDFORM.FORM z_output. gs_layout-box_fieldname = 'CHK'. "选择行 PERFORM frm_build_fieldcat USING: 'LIFNR' 'A018' 'LIFNR', 'MATNR' 'A018' 'MATNR', 'EKORG' 'A018' 'EKORG'.* 'CHK' '' ' ' . CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' ' i_callback_program = sy-repid i_callback_pf_status_set = 'FRM_SET_PF_STATUS' i_callback_user_command = 'FRM_USER_COMMAND'* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' i_grid_title = '卡哇伊'* I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = gt_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_a EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname. DATA: ls_fieldcat TYPE slis_fieldcat_alv. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. ls_fieldcat-fieldname = fu_fieldname. ls_fieldcat-ref_tabname = fu_rtabname. ls_fieldcat-ref_fieldname = fu_rfieldname. APPEND ls_fieldcat TO gt_fieldcat.ENDFORM.FORM frm_set_pf_status USING pt_extab TYPE slis_t_extab.*--·状态 'STANDARD'是从系统功能组 KKBL GUI状态下的”STANDARD“下右键复制过去的 SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .*--·如果要排除按钮的话,需要在此处加上EXCLUDING PT_EXTAB* SET TITLEBAR 'TITLE'.ENDFORM.FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.* BREAK-POINT.* ls_a type aa. CASE r_ucomm. WHEN 'MODIFY'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL.* SORT gt_a BY ekorg.* DELETE ADJACENT DUPLICATES FROM gt_a COMPARING ekorg.* call screen 9100. PERFORM zb. WHEN '&IC1'." 控制双击 IF rs_selfield-fieldname = 'EKORG'." 控制 鼠标双击列 SET PARAMETER ID 'ANR' FIELD rs_selfield-value. CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN. ENDIF. ENDCASE.ENDFORM.FORM zb. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab. SHIFT gs_a-matnr LEFT DELETING LEADING '0'. SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a-lifnr. PERFORM bdc_field USING 'EINA-MATNR' gs_a-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '10'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab. ENDLOOP.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. 2689 ``` 2690 2691 ![](C:\liuliu\typora\图片\z20210733160_test021.png) 2692 2693 2694 2695 ## 22、Z2107_33160_TEST022(新语法练习) 2696 2697 ```ABAP 2698 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST022*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test022.TABLES:vbrk,vbrp.DATA: gt_fieldcat TYPE slis_t_fieldcat_alv,* gs_fieldcat TYPE slis_fieldcat_alv, gs_layout TYPE slis_layout_alv.SELECT-OPTIONS: s_vbeln FOR vbrk-vbeln, s_fkart FOR vbrk-fkart, s_vkorg FOR vbrk-vkorg, s_ernam FOR vbrk-ernam NO-EXTENSION NO INTERVALS, s_erdat FOR vbrk-erdat, s_vgbel FOR vbrp-vgbel.INITIALIZATION."(初始化)* PERFORM frm_init.AT SELECTION-SCREEN."(屏幕跳出前)*PERFORM frm_check.START-OF-SELECTION."(取数据)* PERFORM za.SELECT vbrk~vbeln, vbrk~fkart, vbrk~fktyp, vbrk~vbtyp, vbrk~waerk, vbrk~vkorg, vbrk~vtweg, vbrk~vsbed, vbrk~fkdat, vbrk~ernam, vbrk~erzet, vbrk~erdat, vbrp~posnr, vbrp~fkimg, vbrp~vrkme, vbrp~vgbel, vbrp~vgpos, vbrp~matnrFROM ( ( vbrk LEFT JOIN vbrp ON vbrk~vbeln = vbrp~vbeln ) LEFT JOIN tvkot ON tvkot~vkorg = vbrk~vkorg ) LEFT JOIN makt ON makt~matnr = vbrp~matnr INTO TABLE @DATA(gt_a) WHERE vbrk~vbeln IN @s_vbeln AND vbrk~fkart IN @s_fkart AND vbrk~vkorg IN @s_vkorg AND vbrk~ernam IN @s_ernam AND vbrk~erdat IN @s_erdat AND vbrp~vgbel IN @s_vgbel.END-OF-SELECTION."(展示数据)*PERFORM z_li. PERFORM z_output.* BREAK-POINT. IF gt_a IS INITIAL. MESSAGE '没有取到数据' TYPE 'S' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. ENDIF.*LOOP AT gt_a INTO DATA(gs_a).**ENDLOOP.FORM z_output.* gs_layout-box_fieldname = 'CHK'. "选择行 PERFORM frm_build_fieldcat USING: "'ID' '' '', 'VBELN' 'VBRK' 'VBELN', 'FKART' 'VBRK' 'FKART', 'FKTYP' 'VBRK' 'FKTYP', 'VBTYP' 'VBRK' 'VBTYP', 'WAERK' 'VBRK' 'WAERK', 'VKORG' 'VBRK' 'VKORG', 'VTEXT' 'TVKOT' 'VTEXT', 'VTWEG' 'VBRK' 'VTWEG', 'VSBED' 'VBRK' 'VSBED', 'FKDAT' 'VBRK' 'FKDAT', 'ERNAM' 'VBRK' 'ERNAM', 'ERZET' 'VBRK' 'ERZET', 'ERDAT' 'VBRK' 'ERDAT', 'POSNR' 'VBRP' 'POSNR', 'FKIMG' 'VBRP' 'FKIMG', 'VRKME' 'VBRP' 'VRKME', 'VGBEL' 'VBRP' 'VGBEL', 'VGPOS' 'VBRP' 'VGPOS', 'MATNR' 'VBRP' 'MATNR', 'MAKTX' 'MAKT' 'MAKTX'. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY' EXPORTING* I_INTERFACE_CHECK = ' '* I_BYPASSING_BUFFER = ' '* I_BUFFER_ACTIVE = ' ' i_callback_program = sy-repid* i_callback_pf_status_set = 'FRM_SET_PF_STATUS'* i_callback_user_command = 'FRM_USER_COMMAND'* I_CALLBACK_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_TOP_OF_PAGE = ' '* I_CALLBACK_HTML_END_OF_LIST = ' '* I_STRUCTURE_NAME =* I_BACKGROUND_ID = ' ' i_grid_title = '卡哇伊'* I_GRID_SETTINGS = is_layout = gs_layout it_fieldcat = gt_fieldcat* IT_EXCLUDING =* IT_SPECIAL_GROUPS =* IT_SORT =* IT_FILTER =* IS_SEL_HIDE =* I_DEFAULT = 'X'* I_SAVE = ' '* IS_VARIANT =* IT_EVENTS =* IT_EVENT_EXIT =* IS_PRINT =* IS_REPREP_ID =* I_SCREEN_START_COLUMN = 0* I_SCREEN_START_LINE = 0* I_SCREEN_END_COLUMN = 0* I_SCREEN_END_LINE = 0* I_HTML_HEIGHT_TOP = 0* I_HTML_HEIGHT_END = 0* IT_ALV_GRAPHICS =* IT_HYPERLINK =* IT_ADD_FIELDCAT =* IT_EXCEPT_QINFO =* IR_SALV_FULLSCREEN_ADAPTER =* O_PREVIOUS_SRAL_HANDLER =* IMPORTING* E_EXIT_CAUSED_BY_CALLER =* ES_EXIT_CAUSED_BY_USER = TABLES t_outtab = gt_a EXCEPTIONS program_error = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname. DATA: ls_fieldcat TYPE slis_fieldcat_alv. gs_layout-colwidth_optimize = 'X'. gs_layout-zebra = 'X'. ls_fieldcat-fieldname = fu_fieldname. ls_fieldcat-ref_tabname = fu_rtabname. ls_fieldcat-ref_fieldname = fu_rfieldname. APPEND ls_fieldcat TO gt_fieldcat.ENDFORM. 2699 ``` 2700 2701 ![](C:\liuliu\typora\图片\z20210733160_test022.png) 2702 2703 2704 2705 ## 23、Z2107_33160_TEST023(物料主数据批导) 2706 2707 ```ABAP 2708 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST023*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------**REPORT z2107_33160_test023.*&---------------------------------------------------------------------** 程序名 : ZBCB_002* 開發者 : HAND003* 事務代碼 : ZMM01* 程序類型 : 批導* 描述 : 物料主數據導入* 修正 :*&---------------------------------------------------------------------** 版本 修改版本 修改人員 修改請求號 修改原因**----------------------------------------------------------------------*REPORT z2107_33160_test023 LINE-SIZE 400 MESSAGE-ID zmm NO STANDARD PAGE HEADING.*--------------------------------------------------------------------* tables(聲明使用到的數據庫表)*--------------------------------------------------------------------TABLES: mara,marc,rmmg1,mg03steuer,smeinh,mvke,t461x,mbew, mard, marm,t024,sscrfields.*----------------------------------------------------------------------** type-pools define(定義使用到的類型池)*----------------------------------------------------------------------*TYPE-POOLS: vrm,icon.DATA: gv_name TYPE vrm_id, gv_list TYPE vrm_values, gv_value1 LIKE LINE OF gv_list.*----------------------------------------------------------------------** ALV 相關*----------------------------------------------------------------------*DATA w_layout TYPE lvc_s_layo.*DATA i_fieldcat_alv TYPE TABLE OF lvc_s_fcat WITH HEADER LINE.DATA i_fieldcat_lvc TYPE lvc_t_fcat.DATA w_fieldcat TYPE lvc_s_fcat.DATA w_repid LIKE sy-repid.DATA test_code TYPE char20.DATA: gs_fcode TYPE char10.DATA: gv_objid TYPE w3objid.DATA: gv_index TYPE i. "FIELDCATDATA: gv_error TYPE c.DATA: gs_functxt TYPE smp_dyntxt.*--------------------------------------------------------------------* define internal table(定義類型結構)*--------------------------------------------------------------------TYPES: BEGIN OF typ_result, flagf TYPE char4, matnr TYPE mara-matnr, werks TYPE marc-werks, msg(255), END OF typ_result.DATA: it_result TYPE TABLE OF typ_result.*基本視圖TYPES: BEGIN OF typ_upload_basic, matnr TYPE matnr , " 物料編碼 maktx TYPE maktx , " 物料描述(40字元) mtart TYPE mtart , " 物料類型 meins TYPE meins , " 基本計量單位 bismt TYPE bismt , " 舊物料號碼 matkl TYPE matkl , " 物料群組 extwg TYPE extwg , " 外部物料群組 brgew TYPE brgew , " 毛重 ntgew TYPE ntgew , " 淨重 gewei TYPE gewei , " 重量單位 ervoe TYPE ervoe , " 體積單位 groes TYPE groes , " 大小/尺寸 ferth TYPE ferth , " 生產/檢驗通知單 normt TYPE normt , " 標準說明 zeinr TYPE dzeinr , " 文件 zeivr TYPE dzeivr , " 文件版本 bdesc TYPE string , " 基本資料內文 meinh TYPE smeinh-meinh, "附加數據-計量單位 umren TYPE umren, "基本計量單位轉換的分母 meins2 TYPE rm03e-meins, "附加數據-計量單位 umrez TYPE umrez, "轉換為基礎計量單位的分子* spras TYPE spras, END OF typ_upload_basic.DATA: it_upload_basic TYPE TABLE OF typ_upload_basic.*物料語言TYPES: BEGIN OF typ_upload_desc, matnr TYPE matnr , " 物料編碼 spras TYPE spras_iso, "語言代碼 maktx TYPE maktx , " 物料描述(40字元) END OF typ_upload_desc.DATA: it_upload_desc TYPE TABLE OF typ_upload_desc.*分類視圖TYPES: BEGIN OF typ_upload_fenl, matnr LIKE bapi1003_key-object, "物料号 classtypenew LIKE bapi1003_key-classtype, "类别种类 classnumnew LIKE bapi1003_key-classnum, "分类类别 END OF typ_upload_fenl.DATA: it_upload_fenl TYPE TABLE OF typ_upload_fenl.*采購視圖TYPES: BEGIN OF typ_upload_pur, matnr TYPE marc-matnr , " 物料編碼(18位) werks TYPE marc-werks , " 工廠 ekgrp TYPE marc-ekgrp , " 採購群組 matkl TYPE mara-matkl , " 物料群組 xchpf TYPE marc-xchpf , " 批次管理 meins TYPE mara-meins , " 基本計量單位 bstme TYPE mara-bstme , " 訂單單位 fabkz TYPE marc-fabkz , " JIT 排程指示碼 insmk TYPE marc-insmk , " 過帳到質檢庫存 END OF typ_upload_pur.DATA: it_upload_pur TYPE TABLE OF typ_upload_pur.*生產視圖TYPES: BEGIN OF typ_upload_plant, matnr TYPE marc-matnr , " 物料編碼 werks TYPE marc-werks , " 工廠 mmsta TYPE marc-mmsta , " 特定工廠物料狀態 disgr TYPE marc-disgr, " dismm TYPE marc-dismm , " MRP類型 minbe TYPE marc-minbe , " 再訂購點 fxhor TYPE marc-fxhor, "規劃時柵* type MARC-," MRP組 dispo TYPE marc-dispo , " MRP 控制員 disls TYPE marc-disls , " 批量計算程序 bstmi TYPE marc-bstmi , " 最小批量 bstma TYPE marc-bstma , " 最大批量 mabst TYPE marc-mabst, " bstrf TYPE marc-bstrf , " 捨入值 beskz TYPE marc-beskz , " 採購類型 sobsl TYPE marc-sobsl , " 特殊採購類型 lgpro TYPE marc-lgpro , " 生產儲存地點 lgfsb TYPE marc-lgfsb , " 外部採購的預設儲存位置 dzeit TYPE marc-dzeit , " 廠內生產時間 plifz TYPE marc-plifz , " 計劃交貨天數 webaz TYPE marc-webaz , " 收貨處理時間 fhori TYPE marc-fhori, " eisbe TYPE marc-eisbe , " 安全庫存 mtvfp TYPE marc-mtvfp , " "可用度檢查* Availiability Check" strgr TYPE marc-strgr , " 策略群組 vrmod TYPE marc-vrmod , " 耗用模式 vint1 TYPE marc-vint1 , " 向後消耗 vint2 TYPE marc-vint2 , " 向前消耗 END OF typ_upload_plant.DATA: it_upload_plant TYPE TABLE OF typ_upload_plant.*工作排程TYPES: BEGIN OF typ_upload_sche, matnr TYPE marc-matnr , " 物料編碼 werks TYPE marc-werks , " 工廠 fevor TYPE marc-fevor, " 生產主管 ueeto TYPE marc-ueeto, " 過量交貨允差 END OF typ_upload_sche.DATA: it_upload_sche TYPE TABLE OF typ_upload_sche.*倉儲視圖TYPES: BEGIN OF typ_upload_mlgt, matnr TYPE mard-matnr , " 物料編碼 werks TYPE mard-werks , " 工廠 lgort TYPE mard-lgort , " 庫存地點 lgpbe TYPE mard-lgpbe , " 倉儲位置 END OF typ_upload_mlgt.DATA: it_upload_mlgt TYPE TABLE OF typ_upload_mlgt.*銷售視圖TYPES: BEGIN OF typ_upload_sd, matnr TYPE mvke-matnr , " 物料編碼 werks TYPE marc-werks , " 工廠 vkorg TYPE mvke-vkorg , " 銷售組織 vtweg TYPE mvke-vtweg , " 配銷通路 spart TYPE mara-spart, "部門 taxm1 TYPE mlan-taxm1 , " 稅分類 mtvfp TYPE marc-mtvfp, "可用性檢查 prodh TYPE mvke-prodh , " 產品階層 ktgrm TYPE mvke-ktgrm , " 科目指派群組 mtpos TYPE mvke-mtpos , " 項目種類群組 END OF typ_upload_sd.DATA: it_upload_sd TYPE TABLE OF typ_upload_sd.*國際貿易出口TYPES: BEGIN OF typ_upload_global, matnr TYPE mvke-matnr , " 物料編碼 werks TYPE marc-werks , " 工廠 vkorg TYPE mvke-vkorg , " 銷售組織 vtweg TYPE mvke-vtweg , " 配銷通路 herkl TYPE marc-herkl, "物料原產國家 herkr TYPE marc-herkr, "原產地區 END OF typ_upload_global.DATA: it_upload_global TYPE TABLE OF typ_upload_global.*物料編碼*工廠*銷售組織*配銷通路*部門*稅分類*可用性檢查*產品階層*科目指派群組*項目種類群組*財務視圖TYPES: BEGIN OF typ_upload_fi, matnr TYPE mbew-matnr , " 物料編碼 werks TYPE marc-werks , " 工廠 bklas TYPE mbew-bklas , " 評價類別 eklas TYPE mbew-eklas , " 評價種類:銷貨庫存 mlmaa TYPE mbew-mlmaa , " ML.啟動 vprsv_1 TYPE mbew-vprsv , " 價格控制 verpr TYPE mbew-verpr, stprs TYPE mbew-stprs, peinh_1 TYPE mbew-peinh , " 價格單位 ekalr TYPE mbew-ekalr , " 含QS成本估算 hkmat TYPE mbew-hkmat , " 物料來源 mmsta TYPE marc-mmsta , " 工廠特定的物料狀態 prctr TYPE marc-prctr , " 利潤中心 losgr TYPE marc-losgr , " 成本批量覈算 zplp1 TYPE mbew-zplp1 , " 計畫價格 1(BTCI) zpld1 TYPE mbew-zpld1 , " 計畫的價格日期1(BTCI) zplp2 TYPE mbew-zplp2 , " 計畫價格2 zpld2 TYPE mbew-zpld2 , " 計畫價格日期2 zplp3 TYPE mbew-zplp3 , " 計畫價格3 zpld3 TYPE mbew-zpld3 , " 計畫價格日期3 END OF typ_upload_fi.DATA: it_upload_fi TYPE TABLE OF typ_upload_fi.*-------------------------------------------------------------------* selection-screen(定義選擇屏幕)*-------------------------------------------------------------------SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.SELECTION-SCREEN FUNCTION KEY 1.PARAMETERS: p_basic RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND com1, p_desc RADIOBUTTON GROUP g1, p_fenl RADIOBUTTON GROUP g1, "N p_sale RADIOBUTTON GROUP g1, p_pur RADIOBUTTON GROUP g1, p_plant RADIOBUTTON GROUP g1, "N p_fi RADIOBUTTON GROUP g1, p_sche RADIOBUTTON GROUP g1, p_mlgt RADIOBUTTON GROUP g1, p_global RADIOBUTTON GROUP g1.SELECTION-SCREEN: END OF BLOCK b1.SELECTION-SCREEN: BEGIN OF BLOCK b5 WITH FRAME TITLE TEXT-002.* PARAMETERS:r_new RADIOBUTTON GROUP g2 DEFAULT 'X' USER-COMMAND com1,* r_upd RADIOBUTTON GROUP g2.PARAMETERS: p_path LIKE rlgrap-filename .SELECTION-SCREEN: END OF BLOCK b5.*SELECTION-SCREEN:END OF BLOCK B6 .SELECTION-SCREEN BEGIN OF SCREEN 100.SELECT-OPTIONS:s_werks FOR marc-werks NO INTERVALS NO-EXTENSION, s_matnr FOR marc-matnr OBLIGATORY, s_vkorg FOR mvke-vkorg,"销售视图 s_vtweg FOR mvke-vtweg."销售视图SELECTION-SCREEN END OF SCREEN 100.SELECTION-SCREEN FUNCTION KEY 2.*--------------------------------------------------------------------* initialization(屏幕的初始化)*--------------------------------------------------------------------INITIALIZATION. PERFORM f_init_scr.* PERFORM frm_init_comm.*------------------------------------------------------------------* at selection-screen(處理用於在選擇屏幕上的操作)*------------------------------------------------------------------AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path. PERFORM f_get_filepath USING p_path.AT SELECTION-SCREEN. PERFORM f_auth_check.* 屏幕处理 模板下载 PERFORM frm_at_sle_scr.*--------------------------------------------------------------------* start-of-selection(調用perform)*--------------------------------------------------------------------START-OF-SELECTION. PERFORM frm_check_filepath. "* set function code PERFORM f_set_fcode. "* upload data from file PERFORM f_upload_data.* 数据校验* PERFORM frm_check_data.* 导入数据 PERFORM f_maintain_data.*--------------------------------------------------------------------* end-of-selection(調用perform)*--------------------------------------------------------------------END-OF-SELECTION. PERFORM display_result.********************************************************************** subroutines(子例程)**********************************************************************&------------------------------------------------------------------**& Form f_get_filepath*&------------------------------------------------------------------** get the file to be updated*-------------------------------------------------------------------*FORM f_get_filepath USING pr_path. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING mask = ',All Files,*.*,Excel(*.XLSX;*.XLS),*.XLSX,*.XLS.' mode = 'O' IMPORTING filename = pr_path EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5.ENDFORM. " f_get_filepath*&-------------------------------------------------------------------**& Form f4_status_listbox*&-------------------------------------------------------------------*FORM f4_status_listbox USING p_field p_mtart . DATA:BEGIN OF it_matnr OCCURS 0, matnr LIKE mara-matnr, END OF it_matnr. DATA:l_lines LIKE sy-tabix, l_index LIKE sy-tabix, l_index1 LIKE sy-tabix, l_index2 LIKE sy-tabix, l_matnr LIKE mara-matnr, l_matnr1 LIKE mara-matnr, l_matnr2 LIKE mara-matnr, wa_matnr LIKE it_matnr. CLEAR: gv_list[]. gv_name = p_field. SELECT matnr INTO TABLE it_matnr FROM mara WHERE mtart = p_mtart. DESCRIBE TABLE it_matnr LINES l_lines. SORT it_matnr. l_index1 = 1. DO . IF l_index1 >= l_lines. EXIT. ENDIF. READ TABLE it_matnr INDEX l_index1. l_index2 = l_index1 + 1. READ TABLE it_matnr INTO wa_matnr INDEX l_index2. l_matnr = wa_matnr-matnr - it_matnr-matnr. IF l_matnr > 100. l_index = l_index + 1. l_matnr1 = it_matnr-matnr + 1. l_matnr2 = wa_matnr-matnr - 1. CONDENSE:l_matnr1,l_matnr2. gv_value1-key = l_index. CONCATENATE l_matnr1 '-' l_matnr2 INTO gv_value1-text . APPEND gv_value1 TO gv_list. ENDIF. l_index1 = l_index1 + 1. ENDDO. CALL FUNCTION 'VRM_SET_VALUES' EXPORTING id = gv_name values = gv_list.ENDFORM. " f4_status_listbox*&------------------------------------------------------------------**& Form f_set_fcode*&------------------------------------------------------------------*FORM f_set_fcode . CASE 'X'. WHEN p_basic. gs_fcode = 'V_BASIC'. WHEN p_fenl. gs_fcode = 'V_CLASS'. WHEN p_sale. gs_fcode = 'V_SALE'. WHEN p_pur. gs_fcode = 'V_PUR'. WHEN p_plant. gs_fcode = 'V_PLANTS'. WHEN p_fi. gs_fcode = 'V_FI'. WHEN p_desc. gs_fcode = 'V_DESC'. WHEN p_sche. gs_fcode = 'V_SCHE'. WHEN p_mlgt . gs_fcode = 'V_MLGT'. WHEN p_global. gs_fcode = 'V_GLOBAL'. ENDCASE. IF gs_fcode IS INITIAL. MESSAGE i208(00) WITH 'Please run prgram via TCode!'. STOP. ENDIF.ENDFORM.*&-------------------------------------------------------------------**& Form f_upload_data*&-------------------------------------------------------------------** Upload data for maitain material*-------------------------------------------------------------------*FORM f_upload_data . DATA l_matnr TYPE matnr. CASE gs_fcode. WHEN 'V_BASIC'. PERFORM f_upl_data TABLES it_upload_basic. LOOP AT it_upload_basic ASSIGNING FIELD-SYMBOL(<fs_basic>). PERFORM frm_matnr_input USING <fs_basic>-matnr CHANGING <fs_basic>-matnr. ENDLOOP. WHEN 'V_DESC'. PERFORM f_upl_data TABLES it_upload_desc. LOOP AT it_upload_desc ASSIGNING FIELD-SYMBOL(<fs_desc>). PERFORM frm_matnr_input USING <fs_desc>-matnr CHANGING <fs_desc>-matnr. ENDLOOP. WHEN 'V_CLASS'. PERFORM f_upl_data TABLES it_upload_fenl. LOOP AT it_upload_fenl ASSIGNING FIELD-SYMBOL(<fs_fenl>). l_matnr = <fs_fenl>-matnr. PERFORM frm_matnr_input USING l_matnr CHANGING l_matnr. <fs_fenl>-matnr = l_matnr. ENDLOOP. WHEN 'V_SALE'. PERFORM f_upl_data TABLES it_upload_sd. LOOP AT it_upload_sd ASSIGNING FIELD-SYMBOL(<fs_sd>). PERFORM frm_matnr_input USING <fs_sd>-matnr CHANGING <fs_sd>-matnr. ENDLOOP. WHEN 'V_PUR'. PERFORM f_upl_data TABLES it_upload_pur. LOOP AT it_upload_pur ASSIGNING FIELD-SYMBOL(<fs_pur>). PERFORM frm_matnr_input USING <fs_pur>-matnr CHANGING <fs_pur>-matnr. ENDLOOP. WHEN 'V_PLANTS'. PERFORM f_upl_data TABLES it_upload_plant. LOOP AT it_upload_plant ASSIGNING FIELD-SYMBOL(<fs_plant>). PERFORM frm_matnr_input USING <fs_plant>-matnr CHANGING <fs_plant>-matnr. ENDLOOP. WHEN 'V_FI'. PERFORM f_upl_data TABLES it_upload_fi. LOOP AT it_upload_fi ASSIGNING FIELD-SYMBOL(<fs_fi>). PERFORM frm_matnr_input USING <fs_fi>-matnr CHANGING <fs_fi>-matnr. ENDLOOP. WHEN 'V_MLGT'. PERFORM f_upl_data TABLES it_upload_mlgt. LOOP AT it_upload_mlgt ASSIGNING FIELD-SYMBOL(<fs_mlgt>). PERFORM frm_matnr_input USING <fs_mlgt>-matnr CHANGING <fs_mlgt>-matnr. ENDLOOP. WHEN 'V_SCHE'. PERFORM f_upl_data TABLES it_upload_sche. LOOP AT it_upload_sche ASSIGNING FIELD-SYMBOL(<fs_sche>). PERFORM frm_matnr_input USING <fs_sche>-matnr CHANGING <fs_sche>-matnr. ENDLOOP. WHEN 'V_GLOBAL'. PERFORM f_upl_data TABLES it_upload_global. LOOP AT it_upload_global ASSIGNING FIELD-SYMBOL(<fs_global>). PERFORM frm_matnr_input USING <fs_global>-matnr CHANGING <fs_global>-matnr. ENDLOOP. WHEN OTHERS. ENDCASE.* BREAK-POINT.ENDFORM. " f_upload_data*&-------------------------------------------------------------------**& Form f_upl_data*&-------------------------------------------------------------------*FORM f_upl_data TABLES pt_data . DATA: lt_raw TYPE truxs_t_text_data. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING* I_FIELD_SEPERATOR = i_line_header = 'X' "if this flag is set,first row of record will be ignored during import. i_tab_raw_data = lt_raw " working buffer i_filename = p_path " input Excel file. TABLES i_tab_converted_data = pt_data "internal table holding the Excel data EXCEPTIONS conversion_failed = 1 OTHERS = 2. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. IF pt_data[] IS INITIAL. MESSAGE s999 WITH TEXT-001 DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING AND RETURN TO SCREEN 0. ENDIF.ENDFORM. " f_upl_purchase*&-------------------------------------------------------------------**& Form f_maintain_data*&-------------------------------------------------------------------** Call BAPI to maintain material master*--------------------------------------------------------------------*FORM f_maintain_data . CHECK gv_error IS INITIAL. CASE gs_fcode. WHEN 'V_BASIC'. PERFORM f_maintain_basic. WHEN 'V_DESC'. PERFORM f_maintain_desc. WHEN 'V_CLASS'. PERFORM f_maintain_class. WHEN 'V_PUR'. PERFORM f_maintain_pur. WHEN 'V_SALE'. PERFORM f_maintain_sale. WHEN 'V_PLANTS'. PERFORM f_maintain_plant. WHEN 'V_FI'. PERFORM f_maintain_fi. WHEN 'V_MLGT'. PERFORM f_maintain_mlgt. WHEN 'V_SCHE'. PERFORM f_maintain_sche. WHEN 'V_GLOBAL'. PERFORM f_maintain_global. WHEN OTHERS. ENDCASE.ENDFORM. " f_maintain_data**&--------------------------------------------------------------***& Form f_check_material**&--------------------------------------------------------------*** Check material exist or not**----------------------------------------------------------------**FORM f_check_material USING p_matnr TYPE marc-matnr* p_werks TYPE marc-werks* CHANGING p_l_flag.* CLEAR p_l_flag.* CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'* EXPORTING* input = p_matnr* IMPORTING* output = p_matnr* EXCEPTIONS* length_error = 1* OTHERS = 2.* IF sy-subrc <> 0.* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.* ENDIF.** SELECT SINGLE * FROM mara WHERE matnr EQ p_matnr.* IF sy-subrc NE 0.* READ TABLE it_upload_basic WITH KEY matnr = p_matnr.* IF sy-subrc NE 0.* p_l_flag = 'X'.* ENDIF.* ELSE.* IF gs_fcode = 'V_MRP' AND mara-pstat NS 'K'.* p_l_flag = 'X'.* ENDIF.* ENDIF.*ENDFORM. " f_check_material*&------------------------------------------------------------------**& Form f_maintain_basic*&------------------------------------------------------------------** 基本視圖*-------------------------------------------------------------------*FORM f_maintain_basic . DATA: tmp_char TYPE char40, gt_ltxts TYPE STANDARD TABLE OF tline, lw_ltxt TYPE tline, tmp_tdname TYPE thead-tdname, l_length TYPE i, l_pos TYPE i, l_len TYPE i.* LS_ZMM0001T TYPE ZMM0001T. DATA: ls_marc TYPE bapi_te_marc, ls_marcx TYPE bapi_te_marcx, ls_extain TYPE bapiparex, ls_extainx TYPE bapiparexx, lt_extain TYPE STANDARD TABLE OF bapiparex, lt_extainx TYPE STANDARD TABLE OF bapiparexx. DATA: l_flg_unit TYPE flag, l_flg_unit2 TYPE flag. DATA: lt_tline TYPE TABLE OF tline, l_string(2055) TYPE c. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_forecastparameters LIKE bapi_mpop, lw_forecastparametersx LIKE bapi_mpopx, lw_planningdata LIKE bapi_mpgd, lw_planningdatax LIKE bapi_mpgdx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_warehousenumberdata LIKE bapi_mlgn, lw_warehousenumberdatax LIKE bapi_mlgnx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lw_materiallongtext TYPE bapi_mltx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_basic INTO DATA(ls_upload_basic) . tmp_char = sy-index + '1'. lw_headdata-material = ls_upload_basic-matnr. lw_headdata-matl_type = ls_upload_basic-mtart. lw_headdata-basic_view = 'X'.* material group IF ls_upload_basic-matkl IS NOT INITIAL. lw_clientdata-matl_group = ls_upload_basic-matkl. lw_clientdatax-matl_group = 'X'. ENDIF. lw_headdata-ind_sector = 'M'. lw_clientdata-prod_memo = ls_upload_basic-ferth . " 生產/檢驗通知單 lw_clientdatax-prod_memo = 'X'. " 生產/檢驗通知單 lw_clientdata-old_mat_no = ls_upload_basic-bismt. " 舊物料號碼 lw_clientdatax-old_mat_no = 'X'. " 舊物料號碼 lw_clientdata-extmatlgrp = ls_upload_basic-extwg. " 外部物料群組 lw_clientdatax-extmatlgrp = 'X'. " 外部物料群組 lw_clientdata-allwd_vol = ls_upload_basic-ervoe. " 體積單位 lw_clientdatax-allwd_vol = 'X'. " 體積單位 lw_clientdata-document = ls_upload_basic-zeinr." 文件 lw_clientdatax-document = 'X'." 文件 lw_clientdata-doc_vers = ls_upload_basic-zeivr. " 文件版本 lw_clientdatax-doc_vers = 'X'." 文件版本 IF ls_upload_basic-maktx IS NOT INITIAL.* lw_materialdescription-langu_iso = sy-langu.* PERFORM frm_isola_input USING sy-langu* CHANGING lw_materialdescription-langu. lw_materialdescription-langu = sy-langu. lw_materialdescription-matl_desc = ls_upload_basic-maktx. APPEND lw_materialdescription TO lt_materialdescription. ENDIF. IF ls_upload_basic-bdesc IS NOT INITIAL. l_string = ls_upload_basic-bdesc. CALL FUNCTION 'C14W_STRING_TO_TLINE' EXPORTING i_string = l_string TABLES e_tline_tab = lt_tline. LOOP AT lt_tline ASSIGNING FIELD-SYMBOL(<fs_tline>). lw_materiallongtext-applobject = 'MATERIAL'. lw_materiallongtext-text_name = ls_upload_basic-matnr. lw_materiallongtext-text_id = 'GRUN'. lw_materiallongtext-langu = sy-langu. lw_materiallongtext-text_line = <fs_tline>-tdline. APPEND lw_materiallongtext TO lt_materiallongtext. ENDLOOP. ENDIF.* wa_head-STORAGE_VIEW = 'X'.* 基本單位 PERFORM frm_cunit_input USING ls_upload_basic-meins CHANGING lw_clientdata-base_uom. MOVE 'X' TO lw_clientdatax-base_uom.* 大小/量綱 IF NOT ls_upload_basic-groes IS INITIAL. MOVE: ls_upload_basic-groes TO lw_clientdata-size_dim, 'X' TO lw_clientdatax-size_dim. ENDIF.* 行業標準描述 IF NOT ls_upload_basic-normt IS INITIAL. MOVE: ls_upload_basic-normt TO lw_clientdata-std_descr, 'X' TO lw_clientdatax-std_descr. ENDIF.* 净重 IF ls_upload_basic-ntgew IS NOT INITIAL. MOVE: ls_upload_basic-ntgew TO lw_clientdata-net_weight, 'X' TO lw_clientdatax-net_weight. ENDIF.* 重量單位 IF NOT ls_upload_basic-gewei IS INITIAL.* PERFORM FRM_CUNIT_INPUT USING LS_UPLOAD_BASIC-GEWEI* CHANGING LW_CLIENTDATA-UNIT_OF_WT. lw_clientdata-unit_of_wt = ls_upload_basic-gewei. MOVE:'X' TO lw_clientdatax-unit_of_wt.* MOVE: lw_clientdata-unit_of_wt TO gt_unit-unit_of_wt,* lw_clientdatax-unit_of_wt TO gt_unitx-unit_of_wt.** MOVE:lw_clientdata-base_uom TO gt_unit-alt_unit.* MOVE gt_unit-alt_unit TO gt_unitx-alt_unit. ENDIF.* 毛重 IF ls_upload_basic-brgew IS NOT INITIAL. lw_unitsofmeasure-alt_unit = lw_clientdata-base_uom. lw_unitsofmeasurex-alt_unit = lw_clientdata-base_uom. lw_unitsofmeasure-gross_wt = ls_upload_basic-brgew. lw_unitsofmeasurex-gross_wt = 'X' . lw_unitsofmeasure-unit_of_wt = lw_clientdata-unit_of_wt. lw_unitsofmeasurex-unit_of_wt = 'X' . APPEND lw_unitsofmeasure TO lt_unitsofmeasure. APPEND lw_unitsofmeasurex TO lt_unitsofmeasurex. CLEAR lw_unitsofmeasure. CLEAR lw_unitsofmeasurex. ENDIF. IF ls_upload_basic-umrez IS NOT INITIAL. lw_unitsofmeasure-numerator = ls_upload_basic-umrez . "轉換為基礎計量單位的分子 lw_unitsofmeasurex-numerator = 'X' . "轉換為基礎計量單位的分子 l_flg_unit = abap_true. ENDIF. IF ls_upload_basic-meinh IS NOT INITIAL. PERFORM frm_cunit_input USING ls_upload_basic-meinh CHANGING lw_unitsofmeasure-alt_unit.* lw_unitsofmeasure-alt_unit = ls_upload_basic-meinh. lw_unitsofmeasurex-alt_unit = lw_unitsofmeasure-alt_unit. "基本計量單位轉換的分母 l_flg_unit = abap_true. ENDIF. IF ls_upload_basic-umren IS NOT INITIAL. lw_unitsofmeasure-denominatr = ls_upload_basic-umren . "基本計量單位轉換的分母 lw_unitsofmeasurex-denominatr = 'X' . "基本計量單位轉換的分母 l_flg_unit = abap_true. ENDIF. IF l_flg_unit = abap_true. APPEND lw_unitsofmeasure TO lt_unitsofmeasure. APPEND lw_unitsofmeasurex TO lt_unitsofmeasurex. CLEAR lw_unitsofmeasure. CLEAR lw_unitsofmeasurex. CLEAR l_flg_unit . ENDIF.*** IF ls_upload_basic-meins2 IS NOT INITIAL.* PERFORM frm_cunit_input USING ls_upload_basic-meins2* CHANGING lw_unitsofmeasure-alt_unit.** lw_unitsofmeasure-alt_unit = ls_upload_basic-meins2.* lw_unitsofmeasurex-alt_unit = 'X' . "基本計量單位轉換的分母* l_flg_unit2 = abap_true.* ENDIF.** IF l_flg_unit2 = abap_true.* APPEND lw_unitsofmeasure TO lt_unitsofmeasure.* APPEND lw_unitsofmeasurex TO lt_unitsofmeasurex.* CLEAR l_flg_unit2 .* ENDIF.* CLEAR:gt_unit,gt_unitx,gt_basicdata. PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM. " f_maintain_basic*&------------------------------------------------------------------**& Form frm_bapi_material_savedata*&------------------------------------------------------------------*FORM frm_bapi_material_savedata TABLES ft_materialdescription STRUCTURE bapi_makt ft_unitsofmeasure STRUCTURE bapi_marm ft_unitsofmeasurex STRUCTURE bapi_marmx ft_materiallongtext STRUCTURE bapi_mltx ft_taxclassifications STRUCTURE bapi_mlan CHANGING fc_headdata LIKE bapimathead fc_clientdata LIKE bapi_mara fc_clientdatax LIKE bapi_marax fc_plantdata LIKE bapi_marc fc_plantdatax LIKE bapi_marcx fc_storagelocationdata LIKE bapi_mard fc_storagelocationdatax LIKE bapi_mardx fc_valuationdata LIKE bapi_mbew fc_valuationdatax LIKE bapi_mbewx fc_salesdata LIKE bapi_mvke fc_salesdatax LIKE bapi_mvkex fc_storagetypedata LIKE bapi_mlgt fc_storagetypedatax LIKE bapi_mlgtx. DATA: lw_return TYPE bapiret2, lw_result TYPE typ_result, lt_returnmessages TYPE TABLE OF bapi_matreturn2. CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' EXPORTING headdata = fc_headdata clientdata = fc_clientdata clientdatax = fc_clientdatax plantdata = fc_plantdata plantdatax = fc_plantdatax salesdata = fc_salesdata salesdatax = fc_salesdatax storagelocationdata = fc_storagelocationdata storagelocationdatax = fc_storagelocationdatax valuationdata = fc_valuationdata valuationdatax = fc_valuationdatax IMPORTING return = lw_return TABLES materialdescription = ft_materialdescription unitsofmeasure = ft_unitsofmeasure unitsofmeasurex = ft_unitsofmeasurex materiallongtext = ft_materiallongtext taxclassifications = ft_taxclassifications returnmessages = lt_returnmessages. lw_result-matnr = fc_headdata-material. lw_result-werks = fc_plantdata-plant. lw_result-msg = lw_return-message. IF lw_return-type EQ 'S'. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'.* wait up to 1 SECONDS. lw_result-flagf = icon_green_light. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. lw_result-flagf = icon_red_light. ENDIF. APPEND lw_result TO it_result. CLEAR: ft_materialdescription, ft_unitsofmeasure, ft_unitsofmeasurex, ft_materiallongtext, ft_taxclassifications, ft_materialdescription[], ft_unitsofmeasure[], ft_unitsofmeasurex[], ft_materiallongtext[], ft_taxclassifications[], fc_headdata , fc_clientdata, fc_clientdatax , fc_plantdata , fc_plantdatax , fc_storagelocationdata , fc_storagelocationdatax , fc_valuationdata, fc_valuationdatax , fc_salesdata , fc_salesdatax , fc_storagetypedata, fc_storagetypedatax.ENDFORM. "frm_bapi_material_savedata*&-----------------------------------------------------------------**& Form f_maintain_desc*&-----------------------------------------------------------------** 物料語言*------------------------------------------------------------------*FORM f_maintain_desc. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_desc INTO DATA(ls_upload_desc). lw_headdata-material = ls_upload_desc-matnr ." 物料編碼 lw_headdata-basic_view = 'X' . lw_materialdescription-langu_iso = ls_upload_desc-spras. PERFORM frm_isola_input USING ls_upload_desc-spras CHANGING lw_materialdescription-langu. lw_materialdescription-matl_desc = ls_upload_desc-maktx. APPEND lw_materialdescription TO lt_materialdescription. PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM. "f_maintain_desc*&-----------------------------------------------------------------**& Form f_maintain_class*&-----------------------------------------------------------------** 分類視圖*------------------------------------------------------------------*FORM f_maintain_class . DATA: lw_result TYPE typ_result, return_messages LIKE TABLE OF bapiret2 WITH HEADER LINE, l_mat LIKE bapi1003_key-object, "物料號 l_classtypenew LIKE bapi1003_key-classtype, "類別種類 l_classnumnew LIKE bapi1003_key-classnum. "分類類別 LOOP AT it_upload_fenl INTO DATA(ls_upload_fenl). CALL FUNCTION 'BAPI_OBJCL_CREATE' EXPORTING objectkeynew = ls_upload_fenl-matnr objecttablenew = 'MARA' classnumnew = ls_upload_fenl-classnumnew classtypenew = ls_upload_fenl-classtypenew standardclass = 'X'* 此處務必賦值‘X’,是爲了bapi執行成功之後,MM03查看物料可以看到分類視圖 TABLES return = return_messages. lw_result-matnr = ls_upload_fenl-matnr.* lw_result-werks = fc_plantdata-plant. READ TABLE return_messages WITH KEY type = 'S'. IF sy-subrc = 0. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. lw_result-flagf = icon_green_light. lw_result-msg = return_messages-message.* MOVE-CORRESPONDING it_upload_fenl TO it_success.* CONCATENATE return_messages-message ' ——分類視圖' INTO g_message.* MOVE g_message TO it_success-msg.* APPEND it_success. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'* IMPORTING* RETURN = . lw_result-flagf = icon_red_light. LOOP AT return_messages WHERE type = 'E' OR type = 'A' . lw_result-msg = return_messages-message. EXIT. ENDLOOP.* MOVE-CORRESPONDING it_upload_fenl TO it_failed.* MOVE return_messages-message TO it_failed-msg.* CONCATENATE it_failed-msg ' ——分類視圖' INTO it_failed-msg.* APPEND it_failed. ENDIF. APPEND lw_result TO it_result. CLEAR: ls_upload_fenl,* it_success,* it_failed, return_messages, return_messages[].* CLEAR g_message. ENDLOOP.ENDFORM. " f_maintain_class*&-----------------------------------------------------------------**& Form f_maintain_sale*&-----------------------------------------------------------------** 銷售视图*------------------------------------------------------------------*FORM f_maintain_sale. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_saledata LIKE bapi_mvke, lw_saledatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lw_taxclassifications TYPE bapi_mlan, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_sd INTO DATA(ls_upload_sd). lw_headdata-material = ls_upload_sd-matnr ." 物料編碼 lw_headdata-basic_view = 'X'. lw_headdata-sales_view = 'X' .* lw_headdata-mrp_view = 'X' . lw_plantdata-plant = ls_upload_sd-werks ." 工廠 lw_plantdatax-plant = ls_upload_sd-werks." 工廠 lw_plantdata-availcheck = ls_upload_sd-mtvfp . "可用性檢查 lw_plantdatax-availcheck = 'X' . "可用性檢查 lw_saledata-delyg_plnt = ls_upload_sd-werks ." 工廠 lw_saledatax-delyg_plnt = 'X'." 工廠 lw_saledata-sales_org = ls_upload_sd-vkorg ." 銷售組織 lw_saledatax-sales_org = ls_upload_sd-vkorg ." 銷售組織 lw_saledata-distr_chan = ls_upload_sd-vtweg ." 配銷通路 lw_saledatax-distr_chan = ls_upload_sd-vtweg." 配銷通路 IF ls_upload_sd-taxm1 IS NOT INITIAL. lw_taxclassifications-depcountry = 'TW'. lw_taxclassifications-tax_type_1 = 'MWST'. lw_taxclassifications-taxclass_1 = ls_upload_sd-taxm1 ." 稅分類 APPEND lw_taxclassifications TO lt_taxclassifications. ENDIF. lw_saledata-prod_hier = ls_upload_sd-prodh ." 產品階層 lw_saledatax-prod_hier = 'X'." 產品階層 lw_saledata-acct_assgt = ls_upload_sd-ktgrm ." 科目指派群組 lw_saledatax-acct_assgt = 'X'." 科目指派群組 lw_saledata-item_cat = ls_upload_sd-mtpos ." 項目種類群組 lw_saledatax-item_cat = 'X'." 項目種類群組* lw_plantdata-countryori = ls_upload_sd-herkl ." 原產國* lw_plantdatax-countryori = 'X'." 原產國* lw_plantdata-regionorig = ls_upload_sd-herkr ." 貨源地* lw_plantdatax-regionorig = 'X'." 貨源地 lw_clientdata-division = ls_upload_sd-spart. "部門 lw_clientdatax-division = 'X'. "部門 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax lw_saledata lw_saledatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM. "f_maintain_sale*&-----------------------------------------------------------------**& Form f_maintain_global*&-----------------------------------------------------------------** 銷售视图*------------------------------------------------------------------*FORM f_maintain_global. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_saledata LIKE bapi_mvke, lw_saledatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lw_taxclassifications TYPE bapi_mlan, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_global INTO DATA(ls_upload_global). lw_headdata-material = ls_upload_global-matnr ." 物料編碼* lw_headdata-basic_view = 'X'. lw_headdata-sales_view = 'X' .* lw_headdata-mrp_view = 'X' . lw_plantdata-plant = ls_upload_global-werks ." 工廠 lw_plantdatax-plant = ls_upload_global-werks." 工廠 lw_saledata-delyg_plnt = ls_upload_global-werks ." 工廠 lw_saledatax-delyg_plnt = 'X'." 工廠 lw_saledata-sales_org = ls_upload_global-vkorg ." 銷售組織 lw_saledatax-sales_org = ls_upload_global-vkorg ." 銷售組織 lw_saledata-distr_chan = ls_upload_global-vtweg ." 配銷通路 lw_saledatax-distr_chan = ls_upload_global-vtweg." 配銷通路 lw_plantdata-countryori = ls_upload_global-herkl ." 原產國 lw_plantdatax-countryori = 'X'." 原產國 lw_plantdata-regionorig = ls_upload_global-herkr ." 貨源地 lw_plantdatax-regionorig = 'X'." 貨源地 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax lw_saledata lw_saledatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM. "f_maintain_global********************************************************************** SUBROUTINES(子例程)**********************************************************************&------------------------------------------------------------------**& Form F_INIT_SCR*&------------------------------------------------------------------*FORM f_init_scr . gs_functxt-icon_id = icon_export. gs_functxt-icon_text = '範本下載'(t01). sscrfields-functxt_01 = gs_functxt.ENDFORM. " F_INIT_SCR*&------------------------------------------------------------------**& Form F_AUTH_CHECK*&------------------------------------------------------------------*FORM f_auth_check . DATA: lv_tcode TYPE sy-tcode. MOVE sy-tcode TO lv_tcode. " DECK901081 AUTHORITY-CHECK OBJECT 'S_TCODE' ID 'TCD' FIELD lv_tcode. IF sy-subrc NE 0. MESSAGE i172(00) WITH lv_tcode. EXIT. ENDIF.ENDFORM. " F_AUTH_CHECK*&---------------------------------------------------------------------**& Form FRM_AT_SLE_SCR*&---------------------------------------------------------------------*FORM frm_at_sle_scr . DATA: ls_wwwdata_item LIKE wwwdatatab, lv_file TYPE rlgrap-filename, lv_rc LIKE sy-subrc. CASE sscrfields-ucomm. WHEN 'FC01'. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING def_filename = '物料主數據導入範本.xlsx'(t02) def_path = 'C:\' mask = ',EXCEL FILES(*.XLSX),*.XLSX,ALL FILES(*.*),*.*,' mode = 'S' title = '選擇範本匯入檔'(t03) IMPORTING filename = lv_file EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF sy-subrc <> 0. EXIT. ENDIF. SELECT SINGLE * INTO CORRESPONDING FIELDS OF ls_wwwdata_item FROM wwwdata WHERE srtf2 = 0 AND relid = 'MI'********************************UPDATE BY HAND 20201210 START* AND OBJID = 'ZBT_PP0003I'. AND objid = 'ZGY_MM001'.********************************UPDATE BY HAND 20201210 END IF sy-subrc NE 0 OR ls_wwwdata_item-objid EQ space. MESSAGE '模版檔不存在!'(m01) TYPE 'E'. EXIT. ENDIF. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING key = ls_wwwdata_item destination = lv_file IMPORTING rc = lv_rc. IF lv_rc = 0. MESSAGE s398(00) DISPLAY LIKE 'S' WITH '模版檔下載成功'(m02). ELSE. MESSAGE s398(00) DISPLAY LIKE 'E' WITH '模版檔下載失敗'(m03). ENDIF. ENDCASE.ENDFORM.*&-----------------------------------------------------------------**& Form FRM_CHECK_FILEPATH*&-----------------------------------------------------------------** 校驗路徑*------------------------------------------------------------------*FORM frm_check_filepath . IF p_path IS INITIAL . MESSAGE s000 WITH '檔路徑為空,是否點錯了?'(m04) DISPLAY LIKE 'E'. STOP. ENDIF.ENDFORM. " FRM_CHECK_FILEPATH*&-----------------------------------------------------------------**& Form FRM_MATNR_INPUT*&-----------------------------------------------------------------*FORM frm_matnr_input USING fu_matnr TYPE matnr CHANGING fc_matnr TYPE matnr. CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' EXPORTING input = fu_matnr IMPORTING output = fc_matnr.ENDFORM.*&-----------------------------------------------------------------**& Form FRM_MATNR_OUTPUT*&-----------------------------------------------------------------*FORM frm_matnr_output USING fu_matnr CHANGING fc_matnr TYPE matnr. CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = fu_matnr IMPORTING output = fc_matnr.ENDFORM.*&-----------------------------------------------------------------**& Form FRM_CUNIT_INPUT*&-----------------------------------------------------------------*FORM frm_cunit_input USING fu_input CHANGING fc_input. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' EXPORTING input = fu_input language = sy-langu IMPORTING output = fc_input EXCEPTIONS unit_not_found = 1 OTHERS = 2.ENDFORM.*&---------------------------------------------------------------------**& Form f_maintain_plant*&---------------------------------------------------------------------**& 生產視圖*&---------------------------------------------------------------------*FORM f_maintain_plant . DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_plant INTO DATA(ls_upload_plant). lw_headdata-material = ls_upload_plant-matnr ." 物料編碼 lw_headdata-mrp_view = 'X' . lw_headdata-work_sched_view = 'X' . lw_plantdata-plant = ls_upload_plant-werks ." 工廠 lw_plantdatax-plant = ls_upload_plant-werks." 工廠 lw_plantdata-pur_status = ls_upload_plant-mmsta ." 特定工廠物料狀態 lw_plantdatax-pur_status = 'X'." 特定工廠物料狀態 lw_plantdata-mrp_group = ls_upload_plant-disgr. lw_plantdatax-mrp_group = 'X'." lw_plantdata-mrp_type = ls_upload_plant-dismm ." MRP類型 lw_plantdatax-mrp_type = 'X'." MRP類型 lw_plantdata-reorder_pt = ls_upload_plant-minbe ." 再訂購點 lw_plantdatax-reorder_pt = 'X'." 再訂購點 lw_plantdata-pl_ti_fnce = ls_upload_plant-fxhor." 規劃時柵 lw_plantdatax-pl_ti_fnce = 'X'. " 規劃時柵* = ls_upload_plant- ." MRP組* = 'X'." MRP組 lw_plantdata-mrp_ctrler = ls_upload_plant-dispo ." MRP 控制員 lw_plantdatax-mrp_ctrler = 'X'." MRP 控制員 lw_plantdata-lotsizekey = ls_upload_plant-disls ." 批量計算程序 lw_plantdatax-lotsizekey = 'X'." 批量計算程序 lw_plantdata-minlotsize = ls_upload_plant-bstmi ." 最小批量 lw_plantdatax-minlotsize = 'X'." 最小批量 lw_plantdata-maxlotsize = ls_upload_plant-bstma ." 最大批量 lw_plantdatax-maxlotsize = 'X'." 最大批量 lw_plantdata-max_stock = ls_upload_plant-mabst. lw_plantdatax-max_stock = 'X'." lw_plantdata-round_val = ls_upload_plant-bstrf ." 捨入值 lw_plantdatax-round_val = 'X'." 捨入值 lw_plantdata-proc_type = ls_upload_plant-beskz ." 採購類型 lw_plantdatax-proc_type = 'X'." 採購類型 lw_plantdata-spproctype = ls_upload_plant-sobsl ." 特殊採購類型 lw_plantdatax-spproctype = 'X'." 特殊採購類型 lw_plantdata-iss_st_loc = ls_upload_plant-lgpro ." 生產儲存地點 lw_plantdatax-iss_st_loc = 'X'." 生產儲存地點 lw_plantdata-sloc_exprc = ls_upload_plant-lgfsb ." 外部採購的預設儲存位置 lw_plantdatax-sloc_exprc = 'X'." 外部採購的預設儲存位置 lw_plantdata-inhseprodt = ls_upload_plant-dzeit ." 廠內生產時間 lw_plantdatax-inhseprodt = 'X'." 廠內生產時間 lw_plantdata-plnd_delry = ls_upload_plant-plifz ." 計劃交貨天數 lw_plantdatax-plnd_delry = 'X'." 計劃交貨天數 lw_plantdata-gr_pr_time = ls_upload_plant-webaz ." 收貨處理時間 lw_plantdatax-gr_pr_time = 'X'." 收貨處理時間 lw_plantdata-sm_key = ls_upload_plant-fhori ."浮動排程臨界碼 lw_plantdatax-sm_key = 'X'.""浮動排程臨界碼 lw_plantdata-safety_stk = ls_upload_plant-eisbe ." 安全庫存 lw_plantdatax-safety_stk = 'X'." 安全庫存 IF ls_upload_plant-mtvfp IS NOT INITIAL. lw_plantdata-availcheck = ls_upload_plant-mtvfp ." "可用度檢查availiability Check" lw_plantdatax-availcheck = 'X'." "可用度檢查availiability Check" ENDIF. lw_plantdata-plan_strgp = |{ ls_upload_plant-strgr ALPHA = IN }|. ." 策略群組 lw_plantdatax-plan_strgp = 'X'." 策略群組 lw_plantdata-consummode = ls_upload_plant-vrmod ." 耗用模式 lw_plantdatax-consummode = 'X'." 耗用模式 lw_plantdata-bwd_cons = ls_upload_plant-vint1 ." 向後消耗 lw_plantdatax-bwd_cons = 'X'." 向後消耗 lw_plantdata-fwd_cons = ls_upload_plant-vint2 ." 向前消耗 lw_plantdatax-fwd_cons = 'X'." 向前消耗 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form f_maintain_pur*&---------------------------------------------------------------------**& 采購視圖*&---------------------------------------------------------------------*FORM f_maintain_pur . DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_pur INTO DATA(ls_upload_pur). lw_headdata-material = ls_upload_pur-matnr ." 物料編碼* SELECT SINGLE mtart* FROM mara* INTO lw_headdata-matl_type* WHERE matnr = ls_upload_pur-matnr. lw_headdata-basic_view = 'X'. lw_headdata-purchase_view = 'X'. lw_plantdata-plant = ls_upload_pur-werks ." 工廠 lw_plantdatax-plant = ls_upload_pur-werks ." 工廠 lw_plantdata-pur_group = ls_upload_pur-ekgrp ." 採購群組 lw_plantdatax-pur_group = 'X'." 採購群組 lw_clientdata-matl_group = ls_upload_pur-matkl ." 物料群組 lw_clientdatax-matl_group = 'X'." 物料群組 lw_clientdata-batch_mgmt = ls_upload_pur-xchpf ." 批次管理 lw_clientdatax-batch_mgmt = 'X'." 批次管理 PERFORM frm_cunit_input USING ls_upload_pur-meins CHANGING lw_clientdata-base_uom." 基本計量單位 lw_clientdatax-base_uom = 'X'." 基本計量單位 IF ls_upload_pur-bstme IS NOT INITIAL.* PERFORM FRM_CUNIT_INPUT USING LS_UPLOAD_PUR-BSTME CHANGING LW_CLIENTDATA-PO_UNIT." 訂單單位 lw_clientdata-po_unit = ls_upload_pur-bstme."訂單單位 lw_clientdatax-po_unit = 'X'." 訂單單位 ENDIF. lw_plantdata-jit_relvt = ls_upload_pur-fabkz ." JIT 排程指示碼 lw_plantdatax-jit_relvt = 'X'." JIT 排程指示碼 lw_plantdata-ind_post_to_insp_stock = ls_upload_pur-insmk ." 過帳到質檢庫存 lw_plantdatax-ind_post_to_insp_stock = 'X'." 過帳到質檢庫存 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form f_maintain_sche*&---------------------------------------------------------------------**& 工作排程*&---------------------------------------------------------------------*FORM f_maintain_sche . DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_sche INTO DATA(ls_upload_sche). lw_headdata-material = ls_upload_sche-matnr ." 物料編碼 lw_headdata-work_sched_view = 'X' .*lw_headdata-mrp_view = 'X' . lw_plantdata-plant = ls_upload_sche-werks ." 工廠*lw_plantdata-plant = it_upload_pur-werks ." 工廠 lw_plantdatax-plant = ls_upload_sche-werks ." 工廠 lw_plantdata-production_scheduler = ls_upload_sche-fevor." 生產主管 lw_plantdatax-production_scheduler = 'X' . " 生產主管 lw_plantdata-over_tol = ls_upload_sche-ueeto." 過量交貨允差 lw_plantdatax-over_tol = 'X' . " 過量交貨允差 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form f_maintain_mlgt*&---------------------------------------------------------------------**& 倉儲視圖*&---------------------------------------------------------------------*FORM f_maintain_mlgt. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_mlgt INTO DATA(ls_upload_mlgt). lw_headdata-material = ls_upload_mlgt-matnr ." 物料編碼 lw_headdata-storage_view = 'X' . lw_plantdata-plant = ls_upload_mlgt-werks." 工廠 lw_plantdatax-plant = ls_upload_mlgt-werks." 工廠 lw_storagelocationdata-plant = ls_upload_mlgt-werks." 工廠 lw_storagelocationdata-stge_loc = ls_upload_mlgt-lgort. " 庫存地點 lw_storagelocationdata-stge_bin = ls_upload_mlgt-lgpbe." 倉儲位置 lw_storagelocationdatax-plant = ls_upload_mlgt-werks." 工廠 lw_storagelocationdatax-stge_loc = ls_upload_mlgt-lgort. " 庫存地點 lw_storagelocationdatax-stge_bin = 'X'." 倉儲位置 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax* lw_forecastparameters* lw_forecastparametersx* lw_planningdata* lw_planningdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax* lw_warehousenumberdata* lw_warehousenumberdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form f_maintain_fi*&---------------------------------------------------------------------**& 財務視圖*&---------------------------------------------------------------------*FORM f_maintain_fi. DATA: lw_headdata LIKE bapimathead, lw_clientdata LIKE bapi_mara, lw_clientdatax LIKE bapi_marax, lw_plantdata LIKE bapi_marc, lw_plantdatax LIKE bapi_marcx, lw_storagelocationdata LIKE bapi_mard, lw_storagelocationdatax LIKE bapi_mardx, lw_valuationdata LIKE bapi_mbew, lw_valuationdatax LIKE bapi_mbewx, lw_salesdata LIKE bapi_mvke, lw_salesdatax LIKE bapi_mvkex, lw_storagetypedata LIKE bapi_mlgt, lw_storagetypedatax LIKE bapi_mlgtx, lw_materialdescription TYPE bapi_makt, lw_unitsofmeasure TYPE bapi_marm, lw_unitsofmeasurex TYPE bapi_marmx, lt_materialdescription TYPE TABLE OF bapi_makt, lt_unitsofmeasure TYPE TABLE OF bapi_marm, lt_unitsofmeasurex TYPE TABLE OF bapi_marmx, lt_materiallongtext TYPE TABLE OF bapi_mltx, lt_taxclassifications TYPE TABLE OF bapi_mlan. LOOP AT it_upload_fi INTO DATA(ls_upload_fi). lw_headdata-material = ls_upload_fi-matnr ." 物料編碼 SELECT SINGLE mtart FROM mara INTO lw_headdata-matl_type WHERE matnr = ls_upload_fi-matnr.* lw_headdata-basic_view = 'X'. lw_headdata-account_view = 'X' . lw_headdata-cost_view = 'X' .* lw_headdata-work_sched_view = 'X' .* lw_headdata-storage_view = 'X' . lw_valuationdata-val_area = ls_upload_fi-werks ." 工廠 lw_valuationdatax-val_area = ls_upload_fi-werks. " 工廠 lw_plantdata-plant = ls_upload_fi-werks. lw_plantdatax-plant = ls_upload_fi-werks." 工廠 lw_valuationdata-val_class = ls_upload_fi-bklas ." 評價類別 lw_valuationdatax-val_class = 'X'." 評價類別 lw_valuationdata-vm_so_stk = ls_upload_fi-eklas ." 評價種類:銷貨庫存 lw_valuationdatax-vm_so_stk = 'X'." 評價種類:銷貨庫存 lw_valuationdata-ml_active = ls_upload_fi-mlmaa ." ML.啟動 lw_valuationdatax-ml_active = 'X'." ML.啟動 lw_valuationdata-price_ctrl = ls_upload_fi-vprsv_1 ." 價格控制 lw_valuationdatax-price_ctrl = 'X'." 價格控制 lw_valuationdata-moving_pr = ls_upload_fi-verpr ." 移動平均價 lw_valuationdatax-moving_pr = 'X'." 移動平均價 lw_valuationdata-std_price = ls_upload_fi-stprs ." 標準價格 lw_valuationdatax-std_price = 'X'." 標準價格 lw_valuationdata-price_unit = ls_upload_fi-peinh_1 ." 價格單位 lw_valuationdatax-price_unit = 'X'." 價格單位 lw_valuationdata-qty_struct = ls_upload_fi-ekalr ." 含QS成本估算 lw_valuationdatax-qty_struct = 'X'." 含QS成本估算 lw_valuationdata-orig_mat = ls_upload_fi-hkmat ." 物料來源 lw_valuationdatax-orig_mat = 'X'." 物料來源 lw_plantdata-pur_status = ls_upload_fi-mmsta ." 工廠特定的物料狀態 lw_plantdatax-pur_status = 'X'." 工廠特定的物料狀態 lw_plantdata-profit_ctr = |{ ls_upload_fi-prctr ALPHA = IN }|. ." 利潤中心 lw_plantdatax-profit_ctr = 'X'." 利潤中心 lw_plantdata-lot_size = ls_upload_fi-losgr ." 成本批量覈算 lw_plantdatax-lot_size = 'X'." 成本批量覈算 lw_valuationdata-plndprice1 = ls_upload_fi-zplp1 ." 計畫價格 1(BTCI) lw_valuationdatax-plndprice1 = 'X'." 計畫價格 1(BTCI) lw_valuationdata-plndprdate1 = ls_upload_fi-zpld1 ." 計畫的價格日期1(BTCI) lw_valuationdatax-plndprdate1 = 'X'." 計畫的價格日期1(BTCI) lw_valuationdata-plndprice2 = ls_upload_fi-zplp2 ." 計畫價格2 lw_valuationdatax-plndprice2 = 'X'." 計畫價格2 lw_valuationdata-plndprdate2 = ls_upload_fi-zpld2 ." 計畫價格日期2 lw_valuationdatax-plndprdate2 = 'X'." 計畫價格日期2 lw_valuationdata-plndprice3 = ls_upload_fi-zplp3 ." 計畫價格3 lw_valuationdatax-plndprice3 = 'X'." 計畫價格3 lw_valuationdata-plndprdate3 = ls_upload_fi-zpld3 ." 計畫價格日期3 lw_valuationdatax-plndprdate3 = 'X'." 計畫價格日期3 PERFORM frm_bapi_material_savedata TABLES lt_materialdescription lt_unitsofmeasure lt_unitsofmeasurex lt_materiallongtext lt_taxclassifications CHANGING lw_headdata lw_clientdata lw_clientdatax lw_plantdata lw_plantdatax lw_storagelocationdata lw_storagelocationdatax lw_valuationdata lw_valuationdatax lw_salesdata lw_salesdatax lw_storagetypedata lw_storagetypedatax . ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form frm_isola_input*&---------------------------------------------------------------------*FORM frm_isola_input USING fu_input CHANGING fc_output. CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT' EXPORTING input = fu_input IMPORTING output = fc_output EXCEPTIONS unknown_language = 1 OTHERS = 2. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.*&---------------------------------------------------------------------**& display_result.*&---------------------------------------------------------------------**&---------------------------------------------------------------------**& 顯示結果*&---------------------------------------------------------------------*FORM display_result. w_layout-detailtitl = 'TEST'. w_layout-cwidth_opt = 'X'. w_fieldcat-fieldname = 'FLAGF'. w_fieldcat-scrtext_l = '標記'(t04). APPEND w_fieldcat TO i_fieldcat_lvc. CLEAR w_fieldcat. w_fieldcat-fieldname = 'MATNR'. w_fieldcat-convexit = 'MATN1'. w_fieldcat-scrtext_l = '物料'(t05). APPEND w_fieldcat TO i_fieldcat_lvc. CLEAR w_fieldcat. w_fieldcat-fieldname = 'WERKS'. w_fieldcat-scrtext_l = '工廠'(t06). APPEND w_fieldcat TO i_fieldcat_lvc. CLEAR w_fieldcat. w_fieldcat-fieldname = 'MSG'. w_fieldcat-scrtext_l = '消息'(t07). APPEND w_fieldcat TO i_fieldcat_lvc. CLEAR w_fieldcat. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC' EXPORTING i_callback_program = sy-repid is_layout_lvc = w_layout it_fieldcat_lvc = i_fieldcat_lvc[] TABLES t_outtab = it_result. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM. 2709 ``` 2710 2711 2712 2713 ## 24、Z2107_33160_TEST024(新语法事例) 2714 2715 ```ABAP 2716 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST024*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST024.*************************************************************************&---------------------------------------------------------------------** 程序名 : ZGY_FI001* 开发者 : HD-AB017* 事务代码 :* 程序类型 : 报表* 描述 : 科目余额表* 修正 :*&---------------------------------------------------------------------** 版本 修改日期 修改人员 修改请求号 修改原因* 000 2021/03/019 HD-AB017 创建*----------------------------------------------------------------------*TABLES: FAGLFLEXT."数据内表类型定义TYPES: BEGIN OF TYP_ALV, RBUKRS TYPE FAGLFLEXT-RBUKRS, "公司代码(主键) BUTXT TYPE T001-BUTXT, "公司名称 RYEAR TYPE FAGLFLEXT-RYEAR, "会计年度(主键) PRCTR TYPE FAGLFLEXT-PRCTR, "利润中心(主键) PTEXT TYPE CEPCT-LTEXT, "利润中心描述 RCNTR TYPE FAGLFLEXT-RCNTR, "成本中心(主键) LTEXT TYPE CSKT-LTEXT, "成本中心描述 RFAREA TYPE FAGLFLEXT-RFAREA, "功能范围(主键) FKBTX TYPE TFKBT-FKBTX, "功能范围描述 RACCT TYPE FAGLFLEXT-RACCT, "总账科目(主键) TXT50 TYPE SKAT-TXT50, "总账科目描述 ERGSLZ TYPE FAGL_011ZC-ERGSL, "总账报表项目编号 TXT45Z TYPE FAGL_011QT-TXT45, "总账报表项目描述 BILKT TYPE SKA1-BILKT, "合并科目编号 TXT5B TYPE SKAT-TXT50, "合并科目描述 ERGSLH TYPE FAGL_011ZC-ERGSL, "合并报表项目编号 TXT45H TYPE FAGL_011QT-TXT45, "合并报表项目描述 RTCUR TYPE FAGLFLEXT-RTCUR, "货币 HSLVT TYPE FAGLFLEXT-HSLVT, "期初余额 HSL01S TYPE FAGLFLEXT-HSL01, "1期借方 HSL01H TYPE FAGLFLEXT-HSL01, "1期贷方 HSL01 TYPE FAGLFLEXT-HSL01, "1期余额 HSL02S TYPE FAGLFLEXT-HSL02, "2期借方 HSL02H TYPE FAGLFLEXT-HSL02, "2期贷方 HSL02 TYPE FAGLFLEXT-HSL02, "2期余额 HSL03S TYPE FAGLFLEXT-HSL03, "3期借方 HSL03H TYPE FAGLFLEXT-HSL03, "3期贷方 HSL03 TYPE FAGLFLEXT-HSL03, "3期余额 HSL04S TYPE FAGLFLEXT-HSL04, "4期借方 HSL04H TYPE FAGLFLEXT-HSL04, "4期贷方 HSL04 TYPE FAGLFLEXT-HSL04, "4期余额 HSL05S TYPE FAGLFLEXT-HSL05, "5期借方 HSL05H TYPE FAGLFLEXT-HSL05, "5期贷方 HSL05 TYPE FAGLFLEXT-HSL05, "5期余额 HSL06S TYPE FAGLFLEXT-HSL06, "6期借方 HSL06H TYPE FAGLFLEXT-HSL06, "6期贷方 HSL06 TYPE FAGLFLEXT-HSL06, "6期余额 HSL07S TYPE FAGLFLEXT-HSL07, "7期借方 HSL07H TYPE FAGLFLEXT-HSL07, "7期贷方 HSL07 TYPE FAGLFLEXT-HSL07, "7期余额 HSL08S TYPE FAGLFLEXT-HSL08, "8期借方 HSL08H TYPE FAGLFLEXT-HSL08, "8期贷方 HSL08 TYPE FAGLFLEXT-HSL08, "8期余额 HSL09S TYPE FAGLFLEXT-HSL09, "9期借方 HSL09H TYPE FAGLFLEXT-HSL09, "9期贷方 HSL09 TYPE FAGLFLEXT-HSL09, "9期余额 HSL10S TYPE FAGLFLEXT-HSL10, "10期借方 HSL10H TYPE FAGLFLEXT-HSL10, "10期贷方 HSL10 TYPE FAGLFLEXT-HSL10, "10期余额 HSL11S TYPE FAGLFLEXT-HSL11, "11期借方 HSL11H TYPE FAGLFLEXT-HSL11, "11期贷方 HSL11 TYPE FAGLFLEXT-HSL11, "11期余额 HSL12S TYPE FAGLFLEXT-HSL12, "12期借方 HSL12H TYPE FAGLFLEXT-HSL12, "12期贷方 HSL12 TYPE FAGLFLEXT-HSL12, "12期余额 HSL13S TYPE FAGLFLEXT-HSL13, "13期借方 HSL13H TYPE FAGLFLEXT-HSL13, "13期贷方 HSL13 TYPE FAGLFLEXT-HSL13, "13期余额 HSL14S TYPE FAGLFLEXT-HSL14, "14期借方 HSL14H TYPE FAGLFLEXT-HSL14, "14期贷方 HSL14 TYPE FAGLFLEXT-HSL14, "14期余额 HSL15S TYPE FAGLFLEXT-HSL15, "15期借方 HSL15H TYPE FAGLFLEXT-HSL15, "15期贷方 HSL15 TYPE FAGLFLEXT-HSL15, "15期余额 HSL16S TYPE FAGLFLEXT-HSL16, "16期借方 HSL16H TYPE FAGLFLEXT-HSL16, "16期贷方 HSL16 TYPE FAGLFLEXT-HSL16, "16期余额 END OF TYP_ALV.*&----------------------------------------------------------------------*内表、工作区、变量、常量、指针定义*&----------------------------------------------------------------------DATA:GR_GRID TYPE REF TO CL_GUI_ALV_GRID.DATA: GT_ALV TYPE STANDARD TABLE OF TYP_ALV, GS_ALV TYPE TYP_ALV.*&---alv相关定义DATA:GS_LAYOUT TYPE LVC_S_LAYO, GS_FIELDCAT TYPE LVC_S_FCAT, GT_FIELDCAT TYPE TABLE OF LVC_S_FCAT.SELECTION-SCREEN: BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.PARAMETERS: P_RBUKRS LIKE FAGLFLEXT-RBUKRS MEMORY ID BUK OBLIGATORY, P_RYEAR LIKE FAGLFLEXT-RYEAR DEFAULT SY-DATUM+(4) OBLIGATORY, P_RPMAX LIKE FAGLFLEXT-RPMAX DEFAULT 16 OBLIGATORY.SELECT-OPTIONS:S_PRCTR FOR FAGLFLEXT-PRCTR,S_RFAREA FOR FAGLFLEXT-RFAREA,S_RACCT FOR FAGLFLEXT-RACCT.SELECTION-SCREEN: END OF BLOCK BLK1.*&------------------------------------------------------------------**初始化处理*&------------------------------------------------------------------INITIALIZATION.*&------------------------------------------------------------------**选择屏幕*&------------------------------------------------------------------AT SELECTION-SCREEN.*&------------------------------------------------------------------**程序开始处理*&------------------------------------------------------------------START-OF-SELECTION. PERFORM FRM_GET_DATA.*&---ALV显示 PERFORM FRM_DISPLAY_ALV.*&------------------------------------------------------------------**程序结束处理*&------------------------------------------------------------------END-OF-SELECTION.*&---------------------------------------------------------------------**& Form FRM_DISPLAY_ALV*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* p1 text* 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.ENDFORM. " FRM_OUTPUT*&---------------------------------------------------------------------**& Form FRM_GET_DATA*&---------------------------------------------------------------------**& text*&---------------------------------------------------------------------**& --> p1 text*& = @SY-DATUM "@data( cast ( concat( P_RYEAR ,'1231' ) ) ) "sy-datum AND CE~KOKRS = 'BT00' LEFT JOIN CSKT AS CT ON F~RCNTR = CT~KOSTL AND CT~SPRAS = @SY-LANGU AND CT~DATBI >= @SY-DATUM "@data( cast ( concat( P_RYEAR ,'1231' ) ) ) "sy-datum AND CT~KOKRS = 'BT00' LEFT JOIN TFKBT AS TF ON F~RFAREA = TF~FKBER AND TF~SPRAS = @SY-LANGU LEFT JOIN SKAT AS SK ON F~RACCT = SK~SAKNR AND SK~KTOPL = 'BT00' AND SK~SPRAS = @SY-LANGU LEFT JOIN SKAT AS SK2 ON F~BILKT = SK2~SAKNR AND SK2~KTOPL = 'BT99' AND SK2~SPRAS = @SY-LANGU LEFT JOIN FAGL_011QT AS FZ ON FZ~VERSN = 'BT00'AND FZ~SPRAS = @SY-LANGU AND FZ~ERGSL = F~ERGSLZ LEFT JOIN FAGL_011QT AS FH ON FH~VERSN = 'BT99'AND FH~SPRAS = @SY-LANGU AND FH~ERGSL = F~ERGSLH INTO CORRESPONDING FIELDS OF TABLE @GT_ALV.* INTO TABLE @DATA(LT_FT_DES). LOOP AT GT_ALV ASSIGNING FIELD-SYMBOL(<FS_ALV>). <FS_ALV>-HSL01 = <FS_ALV>-HSL01S + <FS_ALV>-HSL01H. <FS_ALV>-HSL01H = <FS_ALV>-HSL01H * -1. <FS_ALV>-HSL02 = <FS_ALV>-HSL02S + <FS_ALV>-HSL02H. <FS_ALV>-HSL02H = <FS_ALV>-HSL02H * -1. <FS_ALV>-HSL03 = <FS_ALV>-HSL03S + <FS_ALV>-HSL03H. <FS_ALV>-HSL03H = <FS_ALV>-HSL03H * -1. <FS_ALV>-HSL04 = <FS_ALV>-HSL04S + <FS_ALV>-HSL04H. <FS_ALV>-HSL04H = <FS_ALV>-HSL04H * -1. <FS_ALV>-HSL05 = <FS_ALV>-HSL05S + <FS_ALV>-HSL05H. <FS_ALV>-HSL05H = <FS_ALV>-HSL05H * -1. <FS_ALV>-HSL06 = <FS_ALV>-HSL06S + <FS_ALV>-HSL06H. <FS_ALV>-HSL06H = <FS_ALV>-HSL06H * -1. <FS_ALV>-HSL07 = <FS_ALV>-HSL07S + <FS_ALV>-HSL07H. <FS_ALV>-HSL07H = <FS_ALV>-HSL07H * -1. <FS_ALV>-HSL08 = <FS_ALV>-HSL08S + <FS_ALV>-HSL08H. <FS_ALV>-HSL08H = <FS_ALV>-HSL08H * -1. <FS_ALV>-HSL09 = <FS_ALV>-HSL09S + <FS_ALV>-HSL09H. <FS_ALV>-HSL09H = <FS_ALV>-HSL09H * -1. <FS_ALV>-HSL10 = <FS_ALV>-HSL10S + <FS_ALV>-HSL10H. <FS_ALV>-HSL10H = <FS_ALV>-HSL10H * -1. <FS_ALV>-HSL11 = <FS_ALV>-HSL11S + <FS_ALV>-HSL11H. <FS_ALV>-HSL11H = <FS_ALV>-HSL11H * -1. <FS_ALV>-HSL12 = <FS_ALV>-HSL12S + <FS_ALV>-HSL12H. <FS_ALV>-HSL12H = <FS_ALV>-HSL12H * -1. <FS_ALV>-HSL13 = <FS_ALV>-HSL13S + <FS_ALV>-HSL13H. <FS_ALV>-HSL13H = <FS_ALV>-HSL13H * -1. <FS_ALV>-HSL14 = <FS_ALV>-HSL14S + <FS_ALV>-HSL14H. <FS_ALV>-HSL14H = <FS_ALV>-HSL14H * -1. <FS_ALV>-HSL15 = <FS_ALV>-HSL15S + <FS_ALV>-HSL15H. <FS_ALV>-HSL15H = <FS_ALV>-HSL15H * -1. <FS_ALV>-HSL16 = <FS_ALV>-HSL16S + <FS_ALV>-HSL16H. <FS_ALV>-HSL16H = <FS_ALV>-HSL16H * -1. ENDLOOP.ENDFORM.*&---------------------------------------------------------------------**& Form FRM_FIELD_LVC*&---------------------------------------------------------------------** 设置字段目录*----------------------------------------------------------------------** -->PT_FIELDCAT_LVC text* -->PV_FIELDNAME text* -->PV_REF_TABLE text* -->PV_TEXT text* -->PV_NZERO text*----------------------------------------------------------------------*FORM FRM_FIELD_LVC TABLES PT_FIELDCAT_LVC STRUCTURE LVC_S_FCAT USING PV_FIELDNAME TYPE LVC_RFNAME PV_REF_FIELD TYPE LVC_RFNAME PV_REF_TABLE TYPE LVC_TNAME PV_TEXT TYPE STRING PV_NZERO TYPE CHAR1 . DATA:LS_FIELDCAT_LVC TYPE LVC_S_FCAT. CLEAR LS_FIELDCAT_LVC. LS_FIELDCAT_LVC-FIELDNAME = PV_FIELDNAME. LS_FIELDCAT_LVC-REF_FIELD = PV_REF_FIELD. LS_FIELDCAT_LVC-REF_TABLE = PV_REF_TABLE.* LS_FIELDCAT_LVC-COLDDICTXT = 'L'. LS_FIELDCAT_LVC-SCRTEXT_L = PV_TEXT. LS_FIELDCAT_LVC-NO_ZERO = PV_NZERO.* LS_FIELDCAT_LVC-LZERO = PV_NZERO. IF PV_FIELDNAME+0(3) = 'HSL'. LS_FIELDCAT_LVC-datatype = 'CURR'. ENDIF. APPEND LS_FIELDCAT_LVC TO PT_FIELDCAT_LVC. CLEAR LS_FIELDCAT_LVC.ENDFORM. "FRM_FIELD_LVC*&---------------------------------------------------------------------**& Form FRM_PREPARE_ALV*&---------------------------------------------------------------------** 准备ALV的字段目录和布局*----------------------------------------------------------------------*FORM FRM_PREPARE_ALV . PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'RBUKRS' 'FAGLFLEXT' 'RBUKRS' '公司代码' '', 'BUTXT' 'T001' 'BUTXT' '公司名称' '', 'RYEAR' 'FAGLFLEXT' 'RYEAR' '会计年度' '', 'PRCTR' 'FAGLFLEXT' 'PRCTR' '利润中心' 'X', 'PTEXT' 'CEPCT' 'LTEXT' '利润中心描述' '', 'RCNTR' 'FAGLFLEXT' 'RCNTR' '成本中心' 'X', 'LTEXT' 'CSKT' 'LTEXT' '成本中心描述' '', 'RFAREA' 'FAGLFLEXT' 'RFAREA' '功能范围' '', 'FKBTX' 'TFKBT' 'FKBTX' '功能范围描述' '', 'RACCT' 'FAGLFLEXT' 'RACCT' '总账科目' 'X', 'TXT50' 'SKAT' 'TXT50' '总账科目描述' '', 'ERGSLZ' 'FAGL_011ZC' 'ERGSL' '总账报表项目编号' 'X', 'TXT45Z' 'FAGL_011QT' 'TXT45' '总账报表项目描述' '', 'BILKT' 'SKA1' 'BILKT' '合并科目编号' 'X', 'TXT5B' 'SKAT' 'TXT50' '合并科目描述' '', 'ERGSLH' 'FAGL_011ZC' 'ERGSL' '合并报表项目编号' 'X', 'TXT45H' 'FAGL_011QT' 'TXT45' '合并报表项目描述' '',* 'RTCUR' 'FAGLFLEXT' 'RTCUR' '货币' '', 'HSLVT' 'FAGLFLEXT' 'HSLVT' '期初余额' '', 'HSL01S' 'FAGLFLEXT' 'HSL01' '1期借方' '', 'HSL01H' 'FAGLFLEXT' 'HSL01' '1期贷方' '', 'HSL01' 'FAGLFLEXT' 'HSL01' '1期余额' ''. IF P_RPMAX > 1. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL02S' 'FAGLFLEXT' 'HSL02' '2期借方' '', 'HSL02H' 'FAGLFLEXT' 'HSL02' '2期贷方' '', 'HSL02' 'FAGLFLEXT' 'HSL02' '2期余额' ''. ENDIF. IF P_RPMAX > 2. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL03S' 'FAGLFLEXT' 'HSL03' '3期借方' '', 'HSL03H' 'FAGLFLEXT' 'HSL03' '3期贷方' '', 'HSL03' 'FAGLFLEXT' 'HSL03' '3期余额' ''. ENDIF. IF P_RPMAX > 3. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL04S' 'FAGLFLEXT' 'HSL04' '4期借方' '', 'HSL04H' 'FAGLFLEXT' 'HSL04' '4期贷方' '', 'HSL04' 'FAGLFLEXT' 'HSL04' '4期余额' ''. ENDIF. IF P_RPMAX > 4. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL05S' 'FAGLFLEXT' 'HSL05' '5期借方' '', 'HSL05H' 'FAGLFLEXT' 'HSL05' '5期贷方' '', 'HSL05' 'FAGLFLEXT' 'HSL05' '5期余额' ''. ENDIF. IF P_RPMAX > 5. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL06S' 'FAGLFLEXT' 'HSL06' '6期借方' '', 'HSL06H' 'FAGLFLEXT' 'HSL06' '6期贷方' '', 'HSL06' 'FAGLFLEXT' 'HSL06' '6期余额' ''. ENDIF. IF P_RPMAX > 6. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL07S' 'FAGLFLEXT' 'HSL07' '7期借方' '', 'HSL07H' 'FAGLFLEXT' 'HSL07' '7期贷方' '', 'HSL07' 'FAGLFLEXT' 'HSL07' '7期余额' ''. ENDIF. IF P_RPMAX > 7. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL08S' 'FAGLFLEXT' 'HSL08' '8期借方' '', 'HSL08H' 'FAGLFLEXT' 'HSL08' '8期贷方' '', 'HSL08' 'FAGLFLEXT' 'HSL08' '8期余额' ''. ENDIF. IF P_RPMAX > 8. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL09S' 'FAGLFLEXT' 'HSL09' '9期借方' '', 'HSL09H' 'FAGLFLEXT' 'HSL09' '9期贷方' '', 'HSL09' 'FAGLFLEXT' 'HSL09' '9期余额' ''. ENDIF. IF P_RPMAX > 9. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL10S' 'FAGLFLEXT' 'HSL10' '10期借方' '', 'HSL10H' 'FAGLFLEXT' 'HSL10' '10期贷方' '', 'HSL10' 'FAGLFLEXT' 'HSL10' '10期余额' ''. ENDIF. IF P_RPMAX > 10. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL11S' 'FAGLFLEXT' 'HSL11' '11期借方' '', 'HSL11H' 'FAGLFLEXT' 'HSL11' '11期贷方' '', 'HSL11' 'FAGLFLEXT' 'HSL11' '11期余额' ''. ENDIF. IF P_RPMAX > 11. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL12S' 'FAGLFLEXT' 'HSL12' '12期借方' '', 'HSL12H' 'FAGLFLEXT' 'HSL12' '12期贷方' '', 'HSL12' 'FAGLFLEXT' 'HSL12' '12期余额' ''. ENDIF. IF P_RPMAX > 12. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL13S' 'FAGLFLEXT' 'HSL13' '13期借方' '', 'HSL13H' 'FAGLFLEXT' 'HSL13' '13期贷方' '', 'HSL13' 'FAGLFLEXT' 'HSL13' '13期余额' ''. ENDIF. IF P_RPMAX > 13. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL14S' 'FAGLFLEXT' 'HSL14' '14期借方' '', 'HSL14H' 'FAGLFLEXT' 'HSL14' '14期贷方' '', 'HSL14' 'FAGLFLEXT' 'HSL14' '14期余额' ''. ENDIF. IF P_RPMAX > 14. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL15S' 'FAGLFLEXT' 'HSL15' '15期借方' '', 'HSL15H' 'FAGLFLEXT' 'HSL15' '15期贷方' '', 'HSL15' 'FAGLFLEXT' 'HSL15' '15期余额' ''. ENDIF. IF P_RPMAX > 15. PERFORM FRM_FIELD_LVC TABLES GT_FIELDCAT USING: 'HSL16S' 'FAGLFLEXT' 'HSL16' '16期借方' '', 'HSL16H' 'FAGLFLEXT' 'HSL16' '16期贷方' '', 'HSL16' 'FAGLFLEXT' 'HSL16' '16期余额' ''. ENDIF.ENDFORM. 2717 ``` 2718 2719 2720 2721 ## 25、Z2107_33160_TEST025(OOALV) 2722 2723 ```ABAP 2724 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST025*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test025.TABLES:makt,a018,icon.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS.* IF e_column = 'MATNR'.* BREAK-POINT.* ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'MATNR'. SELECT SINGLE maktx FROM makt INTO @DATA(l_maktx) WHERE matnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING* i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'MAKTX' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.TYPES: BEGIN OF aa, matnr TYPE makt-matnr, maktx TYPE makt-maktx, id TYPE icon-id, chk, END OF aa.*ALV参数申明DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性* 变量声明DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON_TAB01', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.SELECT-OPTIONS:s_matnr FOR makt-matnr.DATA: gt_a TYPE TABLE OF aa.DATA: ok_code type sy-ucomm, code_com type sy-ucomm.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据) PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.FORM frm_get. SELECT * FROM makt INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE matnr IN s_matnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.*FORM frm_set_fieldcat.* PERFORM frm_build_fieldcat USING: "'ID' '' '',* 'MATNR' 'MAKT' 'MATNR',* 'MAKTX' 'MAKT' 'MAKTX'.*ENDFORM.**FORM frm_build_fieldcat USING fu_fieldname* fu_rtabname* fu_rfieldname.** DATA: ls_fieldcat TYPE lvc_s_fcat."slis_fieldcat_alv.** gs_layout-colwidth_optimize = 'X'.* gs_layout-zebra = 'X'.* gs_fieldcat-fieldname = fu_fieldname.* gs_fieldcat-scrtext_l = fu_rtabname.* gs_fieldcat-edit_mask = fu_rfieldname.* APPEND gs_fieldcat TO gt_fieldcat.**ENDFORM.FORM frm_set_fieldcat . "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'ID'. "数据字段ID gs_fieldcat-scrtext_l = 'FLAG' . "字段描述 APPEND gs_fieldcat TO gt_fieldcat. "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'MATNR'. "数据字段ID gs_fieldcat-edit = 'X'. gs_fieldcat-edit_mask = '==MATN1'. "数据字段ID gs_fieldcat-scrtext_l = '物料号'. "字段描述 APPEND gs_fieldcat TO gt_fieldcat. "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'MAKTX'. "数据字段ID gs_fieldcat-scrtext_l = '物料描述'. "字段描述 APPEND gs_fieldcat TO gt_fieldcat.ENDFORM. " frm_set_fieldcatFORM frm_set_layout . "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layout*&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS 'ZSTANDARD'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL."看一下是否有容器 "创建容器,添加上自己新建的屏幕控件 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE . "刷新ALV CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF .ENDMODULE.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT. code_com = ok_code. CLEAR ok_code. CASE code_com."sy-ucomm. WHEN '&F03' OR '&F15' OR '&F12'. LEAVE TO SCREEN 0. WHEN '&PRINT'. MESSAGE '自行练习自定义打印功能!' TYPE 'I'. WHEN OTHERS. ENDCASE.ENDMODULE. 2725 ``` 2726 2727 ![](C:\liuliu\typora\图片\z20210733160_test025.png) 2728 2729 ## 26、Z2107_33160_TEST026(EXCEL数据批导) 2730 2731 ```ABAP 2732 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST026*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST026.*引入标准type poolTYPE-POOLS:slis,icon.*----------------------------------------------------------------------** TABLES **----------------------------------------------------------------------**----------------------------------------------------------------------** T Y P E S - 输 出 结 构 定 义 **----------------------------------------------------------------------*TYPES:BEGIN OF ty_data, mbrsh TYPE rmmg1-mbrsh, "行业领域 mtart TYPE rmmg1-mtart, "物料类型 maktx TYPE makt-maktx, "描述 meins TYPE mara-meins, "基本计量单位 icon TYPE icon_d, "ALV界面红绿灯展示 END OF ty_data.*----------------------------------------------------------------------** DATA **----------------------------------------------------------------------*DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表DATA p_mode TYPE c VALUE 'N'."bdc运行模式DATA:gt_data TYPE TABLE OF ty_data, gs_data TYPE ty_data.DATA:it_raw TYPE truxs_t_text_data.*----------------------------------------------------------------------** ALV定义*----------------------------------------------------------------------*DATA:it_fieldcat TYPE lvc_t_fcat, wa_fieldcat LIKE LINE OF it_fieldcat, it_layout TYPE TABLE OF lvc_s_layo, wa_layout TYPE lvc_s_layo, it_events TYPE slis_t_event, wa_events LIKE LINE OF it_events.*----------------------------------------------------------------------** 定义宏*----------------------------------------------------------------------*DEFINE init_fieldcat. CLEAR wa_fieldcat. wa_fieldcat-fieldname = &1. wa_fieldcat-coltext = &2. APPEND wa_fieldcat TO it_fieldcat.END-OF-DEFINITION.*----------------------------------------------------------------------** 选 择 屏 幕 定 义 块*----------------------------------------------------------------------*SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.PARAMETERS:p_file TYPE rlgrap-filename OBLIGATORY."导入文件路径SELECTION-SCREEN END OF BLOCK b1.*----------------------------------------------------------------------** 初 始 化 块 **----------------------------------------------------------------------*INITIALIZATION.*----------------------------------------------------------------------** 选 择 屏 幕 字 段 处 理 块*----------------------------------------------------------------------*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. "本地文件搜索帮助 PERFORM get_filename_for_upload.*----------------------------------------------------------------------** 逻 辑 处 理 块 **----------------------------------------------------------------------*START-OF-SELECTION. PERFORM frm_getdata. PERFORM frm_dealdata. PERFORM frm_layout. PERFORM frm_fieldcat. PERFORM frm_output.END-OF-SELECTION.*&---------------------------------------------------------------------**& Form FRM_GETDATA*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* p1 text* p1 text* p1 text* p1 text* 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. "BDC_DYNPRO*&---------------------------------------------------------------------**& Form GET_FILENAME_FOR_UPLOAD*&---------------------------------------------------------------------**& text*&---------------------------------------------------------------------**& --> p1 text*& 2733 ``` 2734 2735 2736 2737 ## 27、Z2107_33160_TEST027(OOALV a018) 2738 2739 ```ABAP 2740 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST027*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test027.TABLES:a018,icon.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS.* IF e_column = 'MATNR'.* BREAK-POINT.* ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'MATNR'. SELECT SINGLE ekorg, lifnr FROM a018 INTO @DATA(l_maktx) WHERE matnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'EKORG' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.TYPES: BEGIN OF aa, lifnr TYPE a018-lifnr, matnr TYPE a018-matnr, ekorg TYPE a018-ekorg,* id TYPE icon-id, chk, END OF aa.*ALV参数申明DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性* 变量声明DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON_TAB01', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.SELECT-OPTIONS:s_matnr FOR a018-matnr.PARAMETERS: p_mode TYPE char1 DEFAULT 'A'.DATA: gt_a TYPE TABLE OF aa, lt_a TYPE TABLE OF aa, gs_a TYPE aa.DATA: ok_code TYPE sy-ucomm, code_com TYPE sy-ucomm.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据) PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.FORM frm_get. SELECT * FROM a018 INTO CORRESPONDING FIELDS OF TABLE gt_a WHERE matnr IN s_matnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.FORM frm_set_fieldcat. PERFORM frm_build_fieldcat USING: "'ID' '' '', 'LIFNR' '供应商帐户号' '', 'MATNR' '物料号' 'X', 'EKORG' '采购信息记录分类' ''.ENDFORM.FORM frm_build_fieldcat USING fu_fieldname fu_rtabname fu_rfieldname.* DATA: ls_fieldcat TYPE lvc_s_fcat."slis_fieldcat_alv.* gs_layout-colwidth_optimize = 'X'.* gs_layout-zebra = 'X'. gs_fieldcat-fieldname = fu_fieldname. gs_fieldcat-scrtext_l = fu_rtabname. gs_fieldcat-edit = fu_rfieldname.* gs_fieldcat-edit_mask = fu_rfieldname. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.*FORM frm_set_fieldcat .* "字段属性定义* CLEAR:gs_fieldcat.* gs_fieldcat-fieldname = 'ID'. "数据字段ID* gs_fieldcat-scrtext_l = 'FLAG' . "字段描述* APPEND gs_fieldcat TO gt_fieldcat.** "字段属性定义* CLEAR:gs_fieldcat.* gs_fieldcat-fieldname = 'MATNR'. "数据字段ID* gs_fieldcat-edit = 'X'.* gs_fieldcat-edit_mask = '==MATN1'. "数据字段ID* gs_fieldcat-scrtext_l = '物料号'. "字段描述* APPEND gs_fieldcat TO gt_fieldcat.** "字段属性定义* CLEAR:gs_fieldcat.* gs_fieldcat-fieldname = 'MAKTX'. "数据字段ID* gs_fieldcat-scrtext_l = '物料描述'. "字段描述* APPEND gs_fieldcat TO gt_fieldcat.**ENDFORM. " frm_set_fieldcatFORM frm_set_layout . "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHKCK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layout*&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS 'ZSTANDARD'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL."看一下是否有容器 "创建容器,添加上自己新建的屏幕控件 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE . "刷新ALV CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF .ENDMODULE.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT. code_com = ok_code. CLEAR ok_code. CASE code_com."sy-ucomm. WHEN '&F03' OR '&F15' OR '&F12'. LEAVE TO SCREEN 0. WHEN 'MODIFY'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL.* SORT gt_a BY ekorg.* DELETE ADJACENT DUPLICATES FROM gt_a COMPARING ekorg.* call screen 9100. PERFORM zb. WHEN '&PRINT'. MESSAGE '自行练习自定义打印功能!' TYPE 'I'. WHEN OTHERS. ENDCASE.ENDMODULE.FORM zb. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab. SHIFT gs_a-matnr LEFT DELETING LEADING '0'. SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a-lifnr. PERFORM bdc_field USING 'EINA-MATNR' gs_a-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '10'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab. ENDLOOP.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. 2741 ``` 2742 2743 ![](C:\liuliu\typora\图片\z20210733160_test027.png) 2744 2745 ## 28、Z2107_33160_TEST028(数据导入网) 2746 2747 ```ABAP 2748 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST028*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST028.TABLES:mara,marc.*定义存储内表的表结构TYPES: BEGIN OF itab1, matnr LIKE mara-matnr, werks LIKE marc-werks, END OF itab1.*定义存储数据的内表和工作区DATA:gt_tab TYPE STANDARD TABLE OF itab1, gs_tab TYPE itab1.*定义EXCEL的接收表DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline.SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.PARAMETERS: p_path TYPE rlgrap-filename OBLIGATORY.SELECTION-SCREEN END OF BLOCK b1.INITIALIZATION.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path." SEACH HELP* CALL FUNCTION 'F4_FILENAME' "所有文件* EXPORTING* FIELD_NAME = 'FNAME1'* IMPORTING* FILE_NAME = FNAME1. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING mask = '*.XLS;*.XLSX;' mode = 'O' "S为保存,O为打开 IMPORTING filename = p_path EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF p_path EQ ''. MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. ENDIF.START-OF-SELECTION. PERFORM read_data. WRITE:/.FORM read_data . TRY. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_path i_begin_col = 1 i_begin_row = 1 i_end_col = 255 "字段个数 i_end_row = 65535 "行个数 TABLES intern = it_data1 "插入到内表 EXCEPTIONS inconsistent_parameters = 1 s_file_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE s000(zfi01) WITH '文件打开失败!' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF.* CATCH icx_obl_parameter_error INTO . ENDTRY. SORT it_data1 BY row.*转换结构 LOOP AT it_data1 ASSIGNING <wa_itab>. CASE <wa_itab>-col. WHEN '0001'. gs_tab-werks = <wa_itab>-value. WHEN '0002'. gs_tab-matnr = <wa_itab>-value. ENDCASE. AT END OF row. APPEND gs_tab TO gt_tab. CLEAR gs_tab. ENDAT. ENDLOOP.ENDFORM. 2749 ``` 2750 2751 2752 2753 ## 29、Z2107_33160_TEST029(数据导入 OOALV DBC) 2754 2755 ```ABAP 2756 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST029*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test029.TABLES:lfa1.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS. IF e_column = 'LIFNR'.* SET PARAMETER ID 'BPA' FIELD wt100-lifnr. CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN.* BREAK-POINT. ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'LIFNR'. SELECT SINGLE name1 FROM lfa1 INTO @DATA(l_maktx) WHERE lifnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'NAME1' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.DATA:it_raw TYPE truxs_t_text_data.DATA: ok_code LIKE sy-ucomm, code_com TYPE sy-ucomm.TYPES : BEGIN OF aa, lifnr TYPE lfa1-lifnr, name1 TYPE lfa1-name1, chk, END OF aa.DATA: gt_a TYPE TABLE OF aa, lt_a TYPE TABLE OF aa, gs_a TYPE aa.DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON_TAB01', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表*定义接受EXCEL表格数据的内表TYPES:BEGIN OF bb,"导航 lifnr LIKE lfa1-lifnr, END OF bb.DATA:gt_b TYPE TABLE OF bb, gs_b TYPE bb.*选择屏幕界面PARAMETERS: p_mode TYPE char1.PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.*p_file为导入文件的路径如" C:\Users\Xiaowei\Desktop\ZBDC_DEMO.xlsx "*获取p_file,在选择屏幕中响应事件,跳出弹出框,选择屏幕响应事件p_file加在如下:AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.*本地文件搜索帮助 PERFORM get_filename_for_upload.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据) PERFORM excle_upload.* PERFORM frm_getdata. PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.FORM get_filename_for_upload. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING* DEF_FILENAME = ' '* DEF_PATH = ' ' mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' mode = '0 '* TITLE = ' ' IMPORTING filename = p_file* RC = EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF p_file = ''. MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. ENDIF. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM excle_upload . DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 1 i_end_col = 222 i_end_row = 222 TABLES intern = it_data1 EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF. FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline. SORT it_data1 BY row.*转换结构 LOOP AT it_data1 ASSIGNING <wa_itab>. CASE <wa_itab>-col. WHEN '0001'. gs_b-lifnr = <wa_itab>-value. ENDCASE. AT END OF row. APPEND gs_b TO gt_b. CLEAR gs_b. ENDAT. ENDLOOP.ENDFORM.FORM frm_getdata. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING i_line_header = 'X' " Not include file header i_tab_raw_data = it_raw " Work Table i_filename = p_file TABLES i_tab_converted_data = gt_b EXCEPTIONS conversion_failed = 1 OTHERS = 2.ENDFORM.FORM frm_get.*加前导零 LOOP AT gt_b INTO gs_b. gs_b-lifnr = |{ gs_b-lifnr ALPHA = IN }|. MODIFY gt_b FROM gs_b. ENDLOOP. SELECT * FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE gt_a FOR ALL ENTRIES IN gt_b WHERE lifnr = gt_b-lifnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.FORM frm_set_fieldcat. PERFORM frm_build_fieldcat USING: 'CHK' '选择框' 'X' 'X', 'LIFNR' '供应商帐户号' 'X' '', 'NAME1' '描述' '' ''.ENDFORM.FORM frm_set_layout . "还是ALV的一些设置 "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layoutFORM frm_build_fieldcat USING fu_1 fu_2 fu_3 fu_4. gs_fieldcat-fieldname = fu_1. gs_fieldcat-scrtext_l = fu_2. gs_fieldcat-edit = fu_3. gs_fieldcat-checkbox = fu_4. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.MODULE status_9000 OUTPUT. SET PF-STATUS 'Z33160_STATUS'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL. "容器 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE. CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF.ENDMODULE.MODULE user_command_9000 INPUT. PERFORM frm_get_maktx.ENDMODULE.FORM frm_get_maktx. code_com = ok_code. CLEAR ok_code. CASE code_com. WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0.* LEAVE PROGRAM.* WHEN '&IC1'.* IF rs_selfield-fieldname = 'LIFNR'." 控制 鼠标双击列* SET PARAMETER ID 'ANR' FIELD rs_selfield-value.* CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.* ENDIF. WHEN 'MODIFY'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab. SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a-lifnr.* PERFORM bdc_field USING 'EINA-MATNR'* gs_lfa1-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '1'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab. ENDLOOP. ENDCASE.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. 2757 ``` 2758 2759 2760 2761 ## 30、Z2107_33160_TEST030(数据导入 OOALV DBC2) 2762 2763 ```ABAP 2764 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST030*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST030.TABLES:lfa1.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS. IF e_column = 'LIFNR'.* SET PARAMETER ID 'BPA' FIELD wt100-lifnr. CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN.* BREAK-POINT. ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'LIFNR'. SELECT SINGLE name1 FROM lfa1 INTO @DATA(l_maktx) WHERE lifnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'NAME1' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.DATA:it_raw TYPE truxs_t_text_data.DATA: ok_code LIKE sy-ucomm, code_com TYPE sy-ucomm.TYPES : BEGIN OF aa, lifnr TYPE lfa1-lifnr, name1 TYPE lfa1-name1, chk, END OF aa.DATA: gt_a TYPE TABLE OF aa, gs_a TYPE aa, zt_a TYPE TABLE OF aa, zs_a TYPE aa, lt_a TYPE TABLE OF aa.DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON_TAB01', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表**定义接受EXCEL表格数据的内表*TYPES:BEGIN OF bb,"导航* lifnr LIKE lfa1-lifnr,* END OF bb.*DATA:gt_b TYPE TABLE OF bb,* gs_b TYPE bb.*选择屏幕界面PARAMETERS: p_mode TYPE char1.PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.*p_file为导入文件的路径如" C:\Users\Xiaowei\Desktop\ZBDC_DEMO.xlsx "*获取p_file,在选择屏幕中响应事件,跳出弹出框,选择屏幕响应事件p_file加在如下:AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.*本地文件搜索帮助 PERFORM get_filename_for_upload.INITIALIZATION."(初始化)AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据)* PERFORM excle_upload. PERFORM frm_getdata. PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.FORM get_filename_for_upload. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING* DEF_FILENAME = ' '* DEF_PATH = ' ' mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' mode = '0 '* TITLE = ' ' IMPORTING filename = p_file* RC = EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5.* IF p_file = ''.* MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'.* ENDIF. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM frm_getdata. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING i_line_header = 'X' " Not include file header i_tab_raw_data = it_raw " Work Table i_filename = p_file TABLES i_tab_converted_data = gt_a EXCEPTIONS conversion_failed = 1 OTHERS = 2.ENDFORM.FORM frm_get. SELECT lfa1~lifnr lfa1~name1 FROM lfa1 INTO TABLE zt_a. LOOP AT gt_a INTO gs_a. gs_a-lifnr = |{ gs_a-lifnr ALPHA = IN }|. READ TABLE zt_a INTO zs_a WITH KEY lifnr = gs_a-lifnr. IF sy-subrc = 0. MODIFY gt_a FROM zs_a. ENDIF. ENDLOOP.**加前导零* LOOP AT gt_b INTO gs_b.* gs_b-lifnr = |{ gs_b-lifnr ALPHA = IN }|.* MODIFY gt_b FROM gs_b.* ENDLOOP.* SELECT ** FROM lfa1* INTO CORRESPONDING FIELDS OF TABLE gt_a* FOR ALL ENTRIES IN gt_b* WHERE lifnr = gt_b-lifnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.FORM frm_set_fieldcat. PERFORM frm_build_fieldcat USING: 'CHK' '选择框' 'X' 'X', 'LIFNR' '供应商帐户号' 'X' '', 'NAME1' '描述' '' ''.ENDFORM.FORM frm_set_layout . "还是ALV的一些设置 "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layoutFORM frm_build_fieldcat USING fu_1 fu_2 fu_3 fu_4. gs_fieldcat-fieldname = fu_1. gs_fieldcat-scrtext_l = fu_2. gs_fieldcat-edit = fu_3. gs_fieldcat-checkbox = fu_4. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.MODULE status_9000 OUTPUT. SET PF-STATUS 'Z33160_STATUS'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL. "容器 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE. CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF.ENDMODULE.MODULE user_command_9000 INPUT. PERFORM frm_get_maktx.ENDMODULE.FORM frm_get_maktx. code_com = ok_code. CLEAR ok_code. CASE code_com. WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0.* LEAVE PROGRAM.* WHEN '&IC1'.* IF rs_selfield-fieldname = 'LIFNR'." 控制 鼠标双击列* SET PARAMETER ID 'ANR' FIELD rs_selfield-value.* CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.* ENDIF. WHEN 'MODIFY'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab. SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a-lifnr.* PERFORM bdc_field USING 'EINA-MATNR'* gs_lfa1-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '1'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab. ENDLOOP. ENDCASE.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. 2765 ``` 2766 2767 ![](C:\liuliu\typora\图片\z20210733160_test030.png) 2768 2769 ## 31、Z2107_33160_TEST031(输入数据 OOALV DBC2) 2770 2771 ```ABAP 2772 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST031*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST031.TABLES:lfa1.*定义存储内表的表结构TYPES: BEGIN OF itab1, lifnr LIKE lfa1-lifnr, name1 TYPE lfa1-name1, chk, END OF itab1.*定义存储数据的内表和工作区DATA:gt_tab TYPE STANDARD TABLE OF itab1, gs_tab TYPE itab1.*定义EXCEL的接收表DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE.FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline.*ooalvDATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_container TYPE REF TO cl_gui_custom_container, gs_table TYPE scrfname VALUE 'CON001', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.CLASS cl_event_receiver DEFINITION. PUBLIC SECTION. "ALV表格双击事件 METHODS double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. "初始化ALV工具栏对象事件,如增加按钮并设定属性 METHODS handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive. "数据改变 METHODS handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS cl_event_receiver IMPLEMENTATION. " 双击事件方法的实现 METHOD double_click. CONDENSE e_row NO-GAPS. CONDENSE e_column NO-GAPS. DATA: WT100 TYPE lfa1. IF e_column = 'LIFNR'. SET PARAMETER ID 'BPA' FIELD wt100-lifnr. CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN. ENDIF. ENDMETHOD. METHOD handle_data_changed. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'LIFNR'. SELECT SINGLE name1 FROM lfa1 INTO @DATA(l_lfa) WHERE lifnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'NAME1' i_value = l_lfa. ENDIF. ENDIF. ENDLOOP. ENDMETHOD. METHOD handle_toolbar. ENDMETHOD.ENDCLASS.DATA: event_receiver TYPE REF TO cl_event_receiver. "定义类对象的引用 ooalvTYPES : BEGIN OF typ_makt, lifnr TYPE lfa1-lifnr, name1 TYPE lfa1-name1, id TYPE icon-id, chk, END OF typ_makt.DATA: gt_makt TYPE TABLE OF typ_makt, gs_makt TYPE typ_makt.DATA:lt_tab LIKE gt_tab. "按钮定义SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.PARAMETERS: p_path TYPE rlgrap-filename OBLIGATORY.SELECTION-SCREEN END OF BLOCK b1.INITIALIZATION.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path." SEACH HELP* CALL FUNCTION 'F4_FILENAME' "所有文件* EXPORTING* FIELD_NAME = 'FNAME1'* IMPORTING* FILE_NAME = FNAME1. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING* mask = '*.XLS;*.XLSX;' mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' mode = 'O' "S为保存,O为打开 IMPORTING filename = p_path EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF p_path EQ ''. MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. ENDIF.START-OF-SELECTION. PERFORM read_data. PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.END-OF-SELECTION.FORM read_data . TRY. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_path i_begin_col = 1 i_begin_row = 3 i_end_col = 255 "字段个数 i_end_row = 65535 "行个数 TABLES intern = it_data1 "插入到内表 EXCEPTIONS inconsistent_parameters = 1 s_file_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE s000(zfi01) WITH '文件打开失败!' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF.* CATCH icx_obl_parameter_error INTO . ENDTRY. SORT it_data1 BY row.*转换格式 LOOP AT it_data1 ASSIGNING <wa_itab>. CASE <wa_itab>-col. WHEN '0001'. gs_tab-lifnr = <wa_itab>-value. WHEN '0002'. gs_tab-name1 = <wa_itab>-value. ENDCASE. AT END OF row. APPEND gs_tab TO gt_tab. CLEAR gs_tab. ENDAT. ENDLOOP.ENDFORM.*ooalvFORM frm_get. SELECT lifnr name1 FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE gt_makt. LOOP AT gt_tab INTO gs_tab. gs_tab-lifnr = |{ gs_tab-lifnr ALPHA = IN }|. READ TABLE gt_makt INTO gs_makt WITH KEY lifnr = gs_tab-lifnr. IF sy-subrc = 0. MODIFY gt_tab FROM gs_makt. ENDIF. ENDLOOP.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.*&---------------------------------------------------------------------**& Module STATUS_9000 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9000 OUTPUT. SET PF-STATUS 'ZSTATUS001'.* SET TITLEBAR 'xxx'. IF gs_container IS INITIAL."看一下是否有容器 "创建容器,添加上自己新建的屏幕控件 CREATE OBJECT gs_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT event_receiver. SET HANDLER event_receiver->double_click FOR alv_grid. SET HANDLER event_receiver->handle_data_changed FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_tab it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE . "刷新ALV CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF .ENDMODULE.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT. CASE sy-ucomm. WHEN '&F03' OR '&F15' OR '&F12'. LEAVE TO SCREEN 0. WHEN 'BTN'. lt_tab = gt_tab. DELETE lt_tab WHERE chk IS INITIAL.* PERFORM:deal_dat. "BDC WHEN OTHERS. ENDCASE.ENDMODULE.FORM frm_set_fieldcat . "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'CHK'. "数据字段ID 。 gs_fieldcat-edit = 'X'. " 当前列可编辑 . gs_fieldcat-checkbox = 'X'. gs_fieldcat-scrtext_l = '选择框'. "字段描述 。 APPEND gs_fieldcat TO gt_fieldcat. "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'LIFNR'. "数据字段ID gs_fieldcat-edit = 'X'.* gs_fieldcat-edit_mask = '==LIFNR'. "数据字段ID gs_fieldcat-scrtext_l = '供应商或债权人的帐号'. "字段描述 APPEND gs_fieldcat TO gt_fieldcat. "字段属性定义 CLEAR:gs_fieldcat. gs_fieldcat-fieldname = 'NAME1'. "数据字段ID gs_fieldcat-scrtext_l = '名称 1'. "字段描述 APPEND gs_fieldcat TO gt_fieldcat.ENDFORM. " frm_set_fieldcatFORM frm_set_layout . "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'.ENDFORM. " frm_set_layout*BDCDATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.PARAMETERS:p_mode TYPE char1.FORM deal_dat. LOOP AT lt_tab INTO gs_tab.* SHIFT gs_a018-lifnr LEFT DELETING LEADING '0'. SHIFT gs_tab-lifnr LEFT DELETING LEADING '0'. REFRESH:bdcdata,messtab. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_tab-lifnr. PERFORM bdc_field USING 'EINA-MATNR' gs_tab-name1. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'MT06E-MAKTX'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '=EN'. PERFORM bdc_dynpro USING 'SAPLSPO1' '0100'. PERFORM bdc_field USING 'BDC_OKCODE' '=CANC'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '=BU'. CALL TRANSACTION 'ME12' USING bdcdata MODE p_mode MESSAGES INTO messtab. ENDLOOP.ENDFORM.FORM bdc_dynpro USING program dynpro. CLEAR bdcdata. bdcdata-program = program. bdcdata-dynpro = dynpro. bdcdata-dynbegin = 'X'. APPEND bdcdata.ENDFORM.*----------------------------------------------------------------------** Insert field **----------------------------------------------------------------------*FORM bdc_field USING fnam fval.* IF FVAL <> NODATA. CLEAR bdcdata. bdcdata-fnam = fnam. bdcdata-fval = fval. APPEND bdcdata.* ENDIF.ENDFORM. 2773 ``` 2774 2775 ![](C:\liuliu\typora\图片\z20210733160_test031.png) 2776 2777 ## 32、Z2107_33160_TEST032(EXCEL数据导入 OOALV DBC 打印综合) 2778 2779 ```ABAP 2780 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST032*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test032.TABLES:lfa1.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS. IF e_column = 'LIFNR'. SET PARAMETER ID 'BPA' FIELD lfa1-lifnr. CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN.* BREAK-POINT. ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'LIFNR'. SELECT SINGLE name1 FROM lfa1 INTO @DATA(l_maktx) WHERE lifnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'NAME1' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.DATA:it_raw TYPE truxs_t_text_data.DATA: ok_code LIKE sy-ucomm, code_com TYPE sy-ucomm.*定义表结构TYPES : BEGIN OF aa, lifnr TYPE lfa1-lifnr, name1 TYPE lfa1-name1, chk, END OF aa.*定义内表和表空间DATA: gt_a TYPE TABLE OF aa, gs_a TYPE aa, gt_b TYPE TABLE OF aa, gs_b TYPE aa, lt_a TYPE TABLE OF aa, rt_a TYPE TABLE OF aa, rs_a TYPE aa, gtt_a TYPE TABLE OF aa.DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表*选择屏幕界面PARAMETERS: p_mode TYPE char1.PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.*SELECT-OPTIONS: s_bldat FOR mkpf-bldat,* s_budat FOR mkpf-budat,* s_usnam FOR mkpf-usnam.*p_file为导入文件的路径如" C:\Users\Xiaowei\Desktop\ZBDC_DEMO.xlsx "*获取p_file,在选择屏幕中响应事件,跳出弹出框,选择屏幕响应事件p_file加在如下:AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.*本地文件搜索帮助PERFORM get_filename_for_upload.INITIALIZATION."(初始化)*PERFORM frm_init.AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据) PERFORM excle_upload.* PERFORM frm_getdata. PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.*FORM frm_init.* s_ernam-sign = 'I'.* s_ernam-option = 'EQ'.* s_ernam-low = sy-uname.* APPEND s_ernam.** s_erdat-sign = 'I'.* s_erdat-option = 'BT'.* s_erdat-low+0(4) = sy-datum+0(4).* s_erdat-low+4(4) = '0101'.* s_erdat-high+0(4) = sy-datum+0(4).* s_erdat-high+4(4) = '1231'.* APPEND s_erdat.*ENDFORM.FORM get_filename_for_upload. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING* DEF_FILENAME = ' '* DEF_PATH = ' ' mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' mode = '0 '* TITLE = ' ' IMPORTING filename = p_file* RC = EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF p_file = ''. MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. ENDIF. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM excle_upload . DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 3 "从第三行开始取数 i_end_col = 255 i_end_row = 65535 TABLES intern = it_data1 EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE s000(zfi01) WITH '文件打开失败!' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline. SORT it_data1 BY row.*转换结构 LOOP AT it_data1 ASSIGNING <wa_itab>. CASE <wa_itab>-col. WHEN '0001'. gs_a-lifnr = <wa_itab>-value. ENDCASE. AT END OF row. APPEND gs_a TO gt_a. CLEAR gs_a. ENDAT. ENDLOOP.ENDFORM.FORM frm_getdata. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING i_line_header = 'X' " Not include file header i_tab_raw_data = it_raw " Work Table i_filename = p_file TABLES i_tab_converted_data = gt_a EXCEPTIONS conversion_failed = 1 OTHERS = 2.ENDFORM.FORM frm_get.* SELECT* lfa1~lifnr* lfa1~name1* FROM lfa1 INTO TABLE gt_b.***加前导零* LOOP AT gt_a INTO gs_a.* gs_a-lifnr = |{ gs_a-lifnr ALPHA = IN }|.* READ TABLE gt_b INTO gs_b WITH KEY lifnr = gs_a-lifnr.* IF sy-subrc = 0.* MODIFY gt_a FROM gs_b.* ENDIF.* ENDLOOP.*加前导零 LOOP AT gt_a INTO gs_a. gs_a-lifnr = |{ gs_a-lifnr ALPHA = IN }|. MODIFY gt_a FROM gs_a. ENDLOOP. SELECT * FROM lfa1 INTO CORRESPONDING FIELDS OF TABLE gt_a FOR ALL ENTRIES IN gt_a WHERE lifnr = gt_a-lifnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.FORM frm_set_fieldcat. PERFORM frm_build_fieldcat USING: 'CHK' '选择框' 'X' 'X', 'LIFNR' '供应商帐户号' 'X' '', 'NAME1' '描述' '' ''.ENDFORM.FORM frm_set_layout . "还是ALV的一些设置 "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layoutFORM frm_build_fieldcat USING fu_1 fu_2 fu_3 fu_4. gs_fieldcat-fieldname = fu_1. gs_fieldcat-scrtext_l = fu_2. gs_fieldcat-edit = fu_3. gs_fieldcat-checkbox = fu_4. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.MODULE status_9000 OUTPUT. SET PF-STATUS 'Z33160_STATUS'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL. "容器 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE. CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF.ENDMODULE.MODULE user_command_9000 INPUT. PERFORM frm_get_maktx.ENDMODULE.FORM frm_get_maktx. code_com = ok_code. CLEAR ok_code. CASE code_com. WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0.* LEAVE PROGRAM.* WHEN '&IC1'.* IF rs_selfield-fieldname = 'LIFNR'." 控制 鼠标双击列* SET PARAMETER ID 'ANR' FIELD rs_selfield-value.* CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.* ENDIF. WHEN 'MODIFY'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. WHEN 'PRINT'. rt_a = gt_a. DELETE rt_a WHERE chk IS INITIAL. SORT rt_a BY lifnr. DELETE ADJACENT DUPLICATES FROM rt_a COMPARING lifnr. PERFORM da. ENDCASE.ENDFORM.FORM BDC. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab. SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a-lifnr.* PERFORM bdc_field USING 'EINA-MATNR'* gs_lfa1-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '1'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab. ENDLOOP.ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM.FORM da. loop at rt_a into rs_a.* 抬头部分 loop at gt_a into gs_a WHERE lifnr = rs_a-lifnr.* 行项目部分 append gs_a to gtt_a. endloop. ENDLOOP. DATA:g_name TYPE rs38l_fnam. "SMARTFORMS DATA:control TYPE ssfctrlop. DATA:output_options TYPE ssfcompop, l_job_output_info TYPE ssfcrescl. DATA:formname TYPE tdsfname .g_name = '/1BCDWB/SF00000325'. formname = 'ZBD_33160_003'."测试打印(SMARTFORM名字)"开启批量打印 control-no_open = 'X'. control-no_close = 'X'. output_options-tdiexit = 'X'."预览打印时,点打印后立即退出预览界面*打开Smartform CALL FUNCTION 'SSF_OPEN' EXPORTING output_options = output_options control_parameters = control* IMPORTING* JOB_OUTPUT_OPTIONS = EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 user_canceled = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE '用户已取消输出!' TYPE 'S' DISPLAY LIKE 'E'. EXIT. ELSE. CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME' EXPORTING formname = formname IMPORTING fm_name = g_name EXCEPTIONS no_form = 1 no_function_module = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. CALL FUNCTION g_name EXPORTING control_parameters = control TABLES gt_item = gtt_a gt_head = rt_a. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF.*关闭Smartform,此时会弹出一个选择打印机选项 CLEAR l_job_output_info. CALL FUNCTION 'SSF_CLOSE' IMPORTING job_output_info = l_job_output_info EXCEPTIONS formatting_error = 1 internal_error = 2 send_error = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'. EXIT. ENDIF. IF l_job_output_info-outputdone = 'X'."打印成功 MESSAGE '打印成功!' TYPE 'S' . ELSE. MESSAGE '打印未完成!' TYPE 'S' DISPLAY LIKE 'W'. ENDIF. ENDIF.ENDFORM. 2781 ``` 2782 2783 2784 2785 ## 33、Z2107_33160_TEST033() 2786 2787 ```ABAP 2788 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST033*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST033.TYPE-POOLS: truxs.CLASS lei DEFINITION."定义类 PUBLIC SECTION. METHODS fangfa1 FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column. METHODS fangfa2 FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive. METHODS fangfa3 FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING e_onf4 e_onf4_before e_onf4_after e_ucomm er_data_changed.ENDCLASS.CLASS lei IMPLEMENTATION."实现类 METHOD fangfa1. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS. IF e_column = 'MATNR'.* SET PARAMETER ID 'BPA' FIELD wt100-lifnr. CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN. ENDIF. ENDMETHOD. METHOD fangfa2. ENDMETHOD. METHOD fangfa3. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'MATNR'. SELECT SINGLE ekorg"改了这里 FROM a018 INTO @DATA(l_maktx) WHERE matnr = @ls_modi-value. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'EKORG' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.DATA: leis TYPE REF TO lei.DATA: ok_code LIKE sy-ucomm, code_com TYPE sy-ucomm.DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON_TAB01', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.PARAMETERS: p_mode TYPE char1.TYPES:BEGIN OF ty_data,"导航 lifnr TYPE a018-matnr, END OF ty_data.TYPES : BEGIN OF typ_a018, lifnr TYPE a018-lifnr, matnr TYPE a018-matnr, ekorg TYPE a018-ekorg, chk, END OF typ_a018.DATA : gt_a018 TYPE TABLE OF typ_a018, lt_a018 TYPE TABLE OF typ_a018, gs_a018 TYPE typ_a018.DATA bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA :it_messtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE, "bdc返回信息表 wa_messtab LIKE LINE OF it_messtab.DATA:gt_data TYPE STANDARD TABLE OF ty_data WITH HEADER LINE, gs_data TYPE ty_data.PARAMETERS p_file TYPE rlgrap-filename OBLIGATORY.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. PERFORM filename_get. PERFORM excle_upload. PERFORM frm_deal. PERFORM aa. CALL SCREEN 9000.*&---------------------------------------------------------------------**& Form FILENAME_GET*&---------------------------------------------------------------------**& text*&---------------------------------------------------------------------**& --> p1 text*& 0.* Implement suitable error handling here ENDIF.ENDFORM.*&---------------------------------------------------------------------**& Form EXCLE_UPLOAD*&---------------------------------------------------------------------**& text*&---------------------------------------------------------------------**& --> p1 text*& 0.* Implement suitable error handling here ENDIF. WRITE : 's'.ENDFORM.*&---------------------------------------------------------------------**& Form AA*&---------------------------------------------------------------------**& text*&---------------------------------------------------------------------**& --> p1 text*& register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified. CREATE OBJECT leis. SET HANDLER leis->fangfa1 FOR alv_grid. SET HANDLER leis->fangfa3 FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a018 it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE. CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF.ENDMODULE.*&---------------------------------------------------------------------**& Module USER_COMMAND_9000 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9000 INPUT. PERFORM frm_get_maktx.ENDMODULE.FORM frm_get_maktx . DATA: lt_rows TYPE lvc_t_row. code_com = ok_code. CLEAR ok_code. CASE sy-ucomm. WHEN '&F03' OR '&F12' OR '&F15'.* leave to SCREEN 0. LEAVE PROGRAM. WHEN 'DAYIN'. DATA(aa) = 'aaaaa'. lt_a018 = gt_a018. DELETE lt_a018 WHERE chk IS INITIAL.*** call SCREEN 9003. LOOP AT lt_a018 INTO gs_a018. REFRESH : bdcdata,it_messtab.* SHIFT gs_a018-matnr LEFT DELETING LEADING '0'.* SHIFT gs_a018-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMM06I' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MATNR'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-LIFNR' gs_a018-lifnr. PERFORM bdc_field USING 'EINA-MATNR' gs_a018-matnr. PERFORM bdc_field USING 'RM06I-NORMB' 'X'. PERFORM bdc_dynpro USING 'SAPMM06I' '0101'. PERFORM bdc_field USING 'BDC_CURSOR' 'EINA-MAHN1'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. PERFORM bdc_field USING 'EINA-MAHN1' '1'.* PERFORM bdc_field USING 'EINA-MEINS'* 'pc'.* PERFORM bdc_field USING 'EINA-UMREZ'* '1'.* PERFORM bdc_field USING 'EINA-UMREN'* '1'. PERFORM bdc_dynpro USING 'SAPMM06I' '0103'. PERFORM bdc_field USING 'BDC_CURSOR' 'RM06I-LTEX1(01)'. PERFORM bdc_field USING 'BDC_OKCODE' '/00'. CALL TRANSACTION 'ME12' USING bdcdata MODE p_mode MESSAGES INTO it_messtab. ENDLOOP. ENDCASE.ENDFORM.FORM alv_grid1 USING aa bb cc dd. gs_fieldcat-fieldname = aa. gs_fieldcat-scrtext_l = bb. gs_fieldcat-edit = cc. gs_fieldcat-checkbox = dd. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.FORM bdc_dynpro USING program dynpro. CLEAR bdcdata. bdcdata-program = program. bdcdata-dynpro = dynpro. bdcdata-dynbegin = 'X'. APPEND bdcdata.ENDFORM.FORM bdc_field USING fnam fval. CLEAR bdcdata. bdcdata-fnam = fnam. bdcdata-fval = fval. APPEND bdcdata.ENDFORM. 2789 ``` 2790 2791 2792 2793 ## 34、Z2107_33160_TEST034() 2794 2795 ```ABAP 2796 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST034*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST034.CLASS a_event DEFINITION. PUBLIC SECTION. METHODS a_methods FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row e_column.* METHODS b_methods FOR EVENT handle_toolbar OF cl_gui_alv_grid* IMPORTING e_object e_interactive. METHODS c_methods FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.ENDCLASS.CLASS a_event IMPLEMENTATION. METHOD a_methods. CONDENSE e_row NO-GAPS. "删除字符串中的空格 CONDENSE e_column NO-GAPS.* IF e_column = 'LIFNR'.* SET PARAMETER ID 'BPA' FIELD lfa1-lifnr.* CALL TRANSACTION 'BP' AND SKIP FIRST SCREEN.** BREAK-POINT.* ENDIF. ENDMETHOD. METHOD c_methods. LOOP AT er_data_changed->mt_good_cells INTO DATA(ls_modi). IF ls_modi-fieldname = 'HKONT'. SELECT SINGLE txt20 FROM skat INTO @DATA(l_maktx) WHERE saknr = @ls_modi-value AND ktopl = 'YCOA' AND spras = @sy-langu. IF sy-subrc = 0. CALL METHOD er_data_changed->modify_cell EXPORTING i_row_id = ls_modi-row_id i_tabix = ls_modi-tabix i_fieldname = 'TXT20' i_value = l_maktx. ENDIF. ENDIF. ENDLOOP. ENDMETHOD.ENDCLASS.DATA: a_event1 TYPE REF TO a_event.DATA:it_raw TYPE truxs_t_text_data.DATA: ok_code LIKE sy-ucomm, code_com TYPE sy-ucomm.*定义表结构TYPES : BEGIN OF aa, bukrs TYPE bkpf-bukrs, gjahr TYPE bkpf-gjahr, belnr TYPE bkpf-belnr, bktxt TYPE bkpf-bktxt, buzei TYPE bseg-buzei, bschl TYPE bseg-bschl, hkont TYPE bseg-hkont, txt20 TYPE skat-txt20, shkzg TYPE bseg-shkzg, dmbtr TYPE bseg-dmbtr, chk, END OF aa.*定义内表和表空间DATA: gt_a TYPE TABLE OF aa, gs_a TYPE aa, gt_b TYPE TABLE OF aa, gs_b TYPE aa, lt_a TYPE TABLE OF aa, rt_a TYPE TABLE OF aa, rs_a TYPE aa, gtt_a TYPE TABLE OF aa.DATA:gt_fieldcat TYPE lvc_t_fcat, "字段目录内表 gs_fieldcat TYPE lvc_s_fcat, "字段目录工作区 gs_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性DATA: gs_custom_container TYPE REF TO cl_gui_custom_container, "容器 gs_table TYPE scrfname VALUE 'CON', "屏幕中定义的控件 alv_grid TYPE REF TO cl_gui_alv_grid.DATA gt_bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE. "bdc执行内表DATA gt_msgtab TYPE TABLE OF bdcmsgcoll WITH HEADER LINE. "bdc返回信息表DATA p_mode TYPE c VALUE 'A'."bdc运行模式*选择屏幕界面PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.*本地文件搜索帮助 PERFORM get_filename_for_upload.INITIALIZATION."(初始化)*PERFORM frm_init.AT SELECTION-SCREEN."(屏幕跳出前)* PERFORM frm_check.START-OF-SELECTION."(取数据) PERFORM excle_upload. PERFORM frm_get. PERFORM frm_deal. CALL SCREEN 9000.FORM get_filename_for_upload. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING* DEF_FILENAME = ' '* DEF_PATH = ' ' mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' "mask = ',excel.xlsx,*.xlsx,.Excel 文件 (*.xls;*.xlsx)|*.xls;*.xlsx. ' mode = '0 '* TITLE = ' ' IMPORTING filename = p_file* RC = EXCEPTIONS inv_winsys = 1 no_batch = 2 selection_cancel = 3 selection_error = 4 OTHERS = 5. IF p_file = ''. MESSAGE s000(zfi01) WITH '未选择文件!' DISPLAY LIKE 'E'. ENDIF. IF sy-subrc <> 0.* Implement suitable error handling here ENDIF.ENDFORM.FORM excle_upload . DATA:it_data1 TYPE STANDARD TABLE OF alsmex_tabline WITH HEADER LINE. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING filename = p_file i_begin_col = 1 i_begin_row = 1 "从第三行开始取数 i_end_col = 255 i_end_row = 65535 TABLES intern = it_data1 EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE s000(zfi01) WITH '文件打开失败!' DISPLAY LIKE 'E'. LEAVE LIST-PROCESSING. ENDIF. FIELD-SYMBOLS: <wa_itab> TYPE alsmex_tabline. SORT it_data1 BY row.*转换结构 LOOP AT it_data1 ASSIGNING <wa_itab>. CASE <wa_itab>-col. WHEN '0001'. gs_a-bukrs = <wa_itab>-value. WHEN '0002'. gs_a-gjahr = <wa_itab>-value. WHEN '0003'. gs_a-belnr = <wa_itab>-value. ENDCASE. AT END OF row. APPEND gs_a TO gt_a. CLEAR gs_a. ENDAT. ENDLOOP.ENDFORM.FORM frm_get.* SELECT ** FROM bkpf* INTO CORRESPONDING FIELDS OF TABLE gt_a* FOR ALL ENTRIES IN gt_a* WHERE bukrs = gt_a-bukrs AND gjahr = gt_a-gjahr AND belnr = gt_a-belnr.** SELECT ** FROM bseg* INTO CORRESPONDING FIELDS OF TABLE gt_a* FOR ALL ENTRIES IN gt_a* WHERE bukrs = gt_a-bukrs AND gjahr = gt_a-gjahr AND belnr = gt_a-belnr.** SELECT ** FROM skat* INTO CORRESPONDING FIELDS OF TABLE gt_a* FOR ALL ENTRIES IN gt_a* WHERE saknr = gt_a-hkont AND ktopl = 'YCOA' AND spras = sy-langu. SELECT bkpf~bukrs bkpf~gjahr bkpf~belnr bkpf~bktxt bseg~buzei bseg~bschl bseg~hkont skat~txt20 bseg~shkzg bseg~dmbtr FROM ( bkpf JOIN bseg ON bkpf~bukrs = bseg~bukrs AND bkpf~gjahr = bseg~gjahr AND bkpf~belnr = bseg~belnr ) JOIN skat ON bseg~hkont = skat~saknr AND ktopl = 'YCOA' AND spras = sy-langu INTO CORRESPONDING FIELDS OF TABLE gt_a FOR ALL ENTRIES IN gt_a WHERE bkpf~bukrs = gt_a-bukrs AND bkpf~gjahr = gt_a-gjahr AND bkpf~belnr = gt_a-belnr.* SELECT* bkpf~bukrs,* bkpf~gjahr,* bkpf~belnr,* bktxt,* buzei,* bschl,* hkont,* txt20,* shkzg,* dmbtr** FROM bkpf* JOIN bseg ON bkpf~bukrs = bseg~bukrs* AND bkpf~gjahr = bseg~gjahr* AND bkpf~belnr = bseg~belnr* JOIN skat ON bseg~hkont = skat~saknr* AND ktopl = 'YCOA'* AND spras = @sy-langu* INTO CORRESPONDING FIELDS OF TABLE @gt_a* FOR ALL ENTRIES IN @gt_a* WHERE bkpf~bukrs = @gt_a-bukrs* AND bkpf~gjahr = @gt_a-gjahr* AND bkpf~belnr = @gt_a-belnr.ENDFORM.FORM frm_deal. PERFORM frm_set_fieldcat. PERFORM frm_set_layout.ENDFORM.FORM frm_set_fieldcat. PERFORM frm_build_fieldcat USING: 'CHK' '选择框' 'X' 'X', 'BUKRS' '公司代码' '' '', 'GJAHR' '会计年度' '' '', 'BELNR' '凭证号码' '' '', 'BKTXT' '凭证抬头文本' '' '', 'BUZEI' '会计凭证中的行项目' '' '', 'BSCHL' '过账码' '' '', 'HKONT' '总账科目' 'X' '', 'TXT20' '总帐科目名称' '' '', 'SHKZG' '借方/贷方标识' '' '', 'DMBTR' '按本位币计的金额' '' ''.ENDFORM.FORM frm_set_layout . "还是ALV的一些设置 "ALV 界面描述 CLEAR gs_layout. gs_layout-box_fname = 'CHK'. "选择行控制 gs_layout-sel_mode = 'A'. "设置行模式" gs_layout-cwidth_opt = 'X'. "优化列宽设置" gs_layout-zebra = 'X'. "设置斑马线"ENDFORM. " frm_set_layoutFORM frm_build_fieldcat USING fu_1 fu_2 fu_3 fu_4. gs_fieldcat-fieldname = fu_1. gs_fieldcat-scrtext_l = fu_2. gs_fieldcat-edit = fu_3. gs_fieldcat-checkbox = fu_4. APPEND gs_fieldcat TO gt_fieldcat.ENDFORM.MODULE status_9000 OUTPUT. SET PF-STATUS 'Z33160_STATUS'.* SET TITLEBAR 'xxx'. IF gs_custom_container IS INITIAL. "容器 CREATE OBJECT gs_custom_container EXPORTING container_name = gs_table. CREATE OBJECT alv_grid EXPORTING i_parent = gs_custom_container.* 设置enter事件 CALL METHOD alv_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. CREATE OBJECT a_event1. SET HANDLER a_event1->a_methods FOR alv_grid. SET HANDLER a_event1->c_methods FOR alv_grid. CALL METHOD alv_grid->set_table_for_first_display "显示ALV EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_a it_fieldcatalog = gt_fieldcat EXCEPTIONS invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 OTHERS = 4. ELSE. CALL METHOD alv_grid->refresh_table_display EXCEPTIONS finished = 1 OTHERS = 2. IF sy-subrc <> 0.*--异常处理 ENDIF. ENDIF.ENDMODULE.MODULE user_command_9000 INPUT. PERFORM frm_get_maktx.ENDMODULE.FORM frm_get_maktx. code_com = ok_code. CLEAR ok_code. CASE code_com. WHEN '&F03' OR '&F12' OR '&F15'. LEAVE TO SCREEN 0.* LEAVE PROGRAM.* WHEN '&IC1'.* IF rs_selfield-fieldname = 'LIFNR'." 控制 鼠标双击列* SET PARAMETER ID 'ANR' FIELD rs_selfield-value.* CALL TRANSACTION 'CO03' AND SKIP FIRST SCREEN.* ENDIF. WHEN 'SAVE'. lt_a = gt_a. DELETE lt_a WHERE chk IS INITIAL. PERFORM bdc. ENDCASE.ENDFORM.FORM bdc. CLEAR gs_a. LOOP AT lt_a INTO gs_a. REFRESH : gt_bdcdata,gt_msgtab.* SHIFT gs_a-lifnr LEFT DELETING LEADING '0'. PERFORM bdc_dynpro USING 'SAPMF05L' '0100'. PERFORM bdc_field USING 'BDC_CURSOR' 'RF05L-GJAHR'. PERFORM bdc_field USING 'BDC_OKCODE' '=WEITE'. PERFORM bdc_field USING 'RF05L-BELNR' gs_a-belnr. PERFORM bdc_field USING 'RF05L-BUKRS' gs_a-bukrs. PERFORM bdc_field USING 'RF05L-GJAHR' gs_a-gjahr. PERFORM bdc_dynpro USING 'SAPMF05L' '0700'. PERFORM bdc_field USING 'BDC_CURSOR' 'BKPF-BELNR'. PERFORM bdc_field USING 'BDC_OKCODE' '=VK'. PERFORM bdc_dynpro USING 'SAPMF05L' '1710'. PERFORM bdc_field USING 'BDC_CURSOR' 'BKPF-BKTXT'. PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'. PERFORM bdc_field USING 'BKPF-BKTXT' gs_a-txt20. PERFORM bdc_dynpro USING 'SAPMF05L' '0700'. PERFORM bdc_field USING 'BDC_CURSOR' 'BKPF-BELNR'. PERFORM bdc_field USING 'BDC_OKCODE' '=AE'. CALL TRANSACTION 'FB02' USING gt_bdcdata MODE p_mode MESSAGES INTO gt_msgtab UPDATE 'S'. ENDLOOP. LOOP AT gt_a INTO rs_a. IF rs_a-belnr = gs_a-belnr AND rs_a-bukrs = gs_a-bukrs AND rs_a-gjahr = gs_a-gjahr AND rs_a-buzei = gs_a-buzei. rs_a-bktxt = gs_a-txt20. ENDIF. modify gt_a FROM rs_a. ENDLOOP.ENDFORM.*FORM frm_get_rows.* CLEAR: lt_bkpf.* LOOP AT lt_rows INTO ls_rows .* CLEAR pt_bkpf.* READ TABLE gt_bkpf INTO gs_data INDEX ls_rows-index.* IF sy-subrc = 0.* gs_data-bktxt = gs_data-txt20.* APPEND gs_data TO lt_bkpf.* LOOP AT gt_bkpf INTO gs_bkpf.* IF gs_bkpf-bukrs = gs_data-bukrs* AND gs_bkpf-gjahr = gs_data-gjahr* AND gs_bkpf-belnr = gs_data-belnr* AND gs_bkpf-BUZEI = gs_data-BUZEI.* gs_bkpf = gs_data.* ENDIF.* APPEND gs_bkpf TO pt_bkpf.* ENDLOOP.* ENDIF.* gt_bkpf = pt_bkpf.* ENDLOOP.*ENDFORM.FORM bdc_field USING fnam fval. CLEAR gt_bdcdata. gt_bdcdata-fnam = fnam. gt_bdcdata-fval = fval. APPEND gt_bdcdata.ENDFORM. "BDC_FIELDFORM bdc_dynpro USING program dynpro. CLEAR gt_bdcdata. gt_bdcdata-program = program. gt_bdcdata-dynpro = dynpro. gt_bdcdata-dynbegin = 'X'. APPEND gt_bdcdata.ENDFORM. 2797 ``` 2798 2799 2800 2801 ## 35、Z2107_33160_TEST035(获取到alv数据到内表) 2802 2803 ```ABAP 2804 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST035*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT z2107_33160_test035.TABLES:aufk,afko.TYPES:BEGIN OF ty_itab, aufnr TYPE aufk-aufnr, "vl03n ernam TYPE aufk-ernam, erdat TYPE aufk-erdat, bukrs TYPE aufk-bukrs, werks TYPE aufk-werks, name1 TYPE t001w-name1, plnbez TYPE afko-plnbez, maktx TYPE makt-maktx, gasmg TYPE afko-gasmg, gamng TYPE afko-gamng, gamng1 TYPE icon-id, gmein TYPE afko-gmein, id TYPE icon-id, END OF ty_itab.DATA:itab TYPE TABLE OF ty_itab WITH HEADER LINE, ls_itab TYPE ty_itab.FIELD-SYMBOLS:<lt_data> TYPE ANY TABLE.DATA:lr_data TYPE REF TO data.CALL METHOD cl_salv_bs_runtime_info=>set EXPORTING display = abap_false metadata = abap_false data = abap_true.SELECT-OPTIONS: s_ernam FOR aufk-ernam NO-EXTENSION NO INTERVALS, s_aufnr FOR aufk-aufnr, s_erdat FOR aufk-erdat, s_bukrs FOR aufk-bukrs, s_werks FOR aufk-werks, s_plnbez FOR afko-plnbez. SUBMIT Z2107_33160EXAM1C WITH aufk-ernam IN s_ernam WITH aufk-aufnr IN s_aufnr WITH aufk-erdat IN s_erdat WITH aufk-bukrs IN s_bukrs WITH aufk-werks IN s_werks WITH afko-plnbez IN s_plnbez EXPORTING LIST TO MEMORY VIA SELECTION-SCREEN AND RETURN.TRY. "获取ALV显示数据 CALL METHOD cl_salv_bs_runtime_info=>get_data_ref IMPORTING r_data = lr_data. ASSIGN lr_data->* TO <lt_data>. REFRESH itab. CLEAR itab. MOVE-CORRESPONDING <lt_data>[] TO itab[]. CATCH cx_salv_bs_sc_runtime_info.ENDTRY."结束cl_salv_bs_runtime_info=>clear_all( ).LOOP AT itab INTO ls_itab. WRITE /: ls_itab-aufnr.ENDLOOP. 2805 ``` 2806 2807 ![](C:\liuliu\typora\图片\z20210733160_test035.png) 2808 2809 ## 36、Z2107_33160_TEST036(z2017_33160exam1b alv输出) 2810 2811 ```ABAP 2812 *&---------------------------------------------------------------------**& Report Z2107_33160_TEST036*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT Z2107_33160_TEST036.DATA:t_fieldcat TYPE lvc_t_fcat, "字段目录内表 w_fieldcat TYPE lvc_s_fcat, "字段目录工作区 w_layout TYPE lvc_s_layo. "用于定义ALV表单的相关格式、属性TYPES:BEGIN OF ty_mara, matnr TYPE matnr, "物料号 pstat LIKE mara-pstat, "维护状态 mtart TYPE mtart, "物料类型 mbrsh TYPE mbrsh, "行业领域 matkl TYPE matkl, "物料组 bismt TYPE bismt, "旧物料号 meins TYPE meins, "基本计量单位 brgew TYPE brgew, "毛重 ntgew TYPE ntgew, "净重 maktx TYPE maktx, "物料描述 zline TYPE i, "当前行数 check TYPE c, END OF ty_mara.DATA:gt_s TYPE TABLE OF ty_mara, gs_s TYPE ty_mara.FIELD-SYMBOLS:<t_table> TYPE ANY TABLE.DATA:t_data TYPE REF TO data.CALL METHOD cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false metadata = abap_false data = abap_true ).SUBMIT Z20210733160_TEST011 AND RETURN.TRY. "获取ALV显示数据 CALL METHOD cl_salv_bs_runtime_info=>get_data_ref IMPORTING r_data = t_data. ASSIGN t_data->* TO <t_table>. REFRESH gt_s. CLEAR gt_s. MOVE-CORRESPONDING <t_table>[] TO gt_s[]. CATCH cx_salv_bs_sc_runtime_info. MESSAGE '查询结果为空!' TYPE 'E'.ENDTRY."结束cl_salv_bs_runtime_info=>clear_all( ).*设置字段属性 PERFORM frm_set_fieldcat.*设置输出格式 PERFORM frm_set_layout.*显示ALV PERFORM frm_display_alv.*LOOP AT gt_s INTO gs_s.* WRITE /: gs_s-matnr.*ENDLOOP.FORM frm_set_fieldcat . "字段属性定义 CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MATNR'. w_fieldcat-scrtext_l = '物料号'. w_fieldcat-ref_table = 'MARA'. w_fieldcat-ref_field = 'MATNR'. w_fieldcat-emphasize = 'C100'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'PSTAT'. w_fieldcat-scrtext_l = '维护状态'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MTART'. w_fieldcat-scrtext_l = '物料类型'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MBRSH'. w_fieldcat-scrtext_l = '行业领域'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MATKL'. w_fieldcat-scrtext_l = '物料组'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'BISMT'. w_fieldcat-scrtext_l = '旧物料号'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MEINS'. w_fieldcat-scrtext_l = '基本计量单位'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'BRGEW'. w_fieldcat-scrtext_l = '毛重'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'NTGEW'. w_fieldcat-scrtext_l = '净重'.* w_fieldcat-edit = 'X'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'MAKTX'. w_fieldcat-scrtext_l = '物料描述'. APPEND w_fieldcat TO t_fieldcat. CLEAR:w_fieldcat. w_fieldcat-fieldname = 'ZLINE'. w_fieldcat-scrtext_l = '行数'. APPEND w_fieldcat TO t_fieldcat.ENDFORM. " frm_set_fieldcat*&---------------------------------------------------------------------**& Form frm_set_layout*&---------------------------------------------------------------------** text*----------------------------------------------------------------------** --> p1 text* p1 text* 0.* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.ENDFORM. 2813 ``` 2814 2815 ![](C:\liuliu\typora\图片\z20210733160_test036.png) 2816 2817 # 五、
定义Tables的时候,一般会加上TYPE-POOLS SLIS.
slis应该是个Package.声明了它后就可以用它包括的函数、类、消息等。