小白记录一次开发.按开发要求,需提供一个重分类会计凭证生成与冲销的功能(本月与次月同时生成),于是找到BAPI:BAPI_ACC_DOCUMENT_POST(生成凭证)、BAPI: BAPI_ACC_DOCUMENT_REV_POST)(冲销凭证)。
以下我建了个ZFIS002结构来附加过账码,ZFIT002表来存储生成的凭证
需要注意的是创建的结构还需要在SE19实现BADI增强:BADI_ACC_DOCUMENT,(此DADI详细可百度)
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 |
*&---------------------------------------------------------------------* *& Form frm_user_commandr *&---------------------------------------------------------------------* *& text 控件 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield. DATA:go_grid TYPE REF TO cl_gui_alv_grid, "object gs_stbl TYPE lvc_s_stbl. "稳定刷新 CASE r_ucomm. WHEN '&SET'. PERFORM frm_creation_voucher."创建凭证 PERFORM frm_get_data. WHEN'&WASH'. PERFORM frm_wash_voucher."冲销凭证 PERFORM frm_get_data. WHEN'&HISTORY'. PERFORM frm_history_data."凭证历史 ENDCASE. gs_stbl-row = 'X'. gs_stbl-col = 'X'. CALL METHOD go_grid->refresh_table_display ""稳定刷新 EXPORTING is_stable = gs_stbl. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_creation_voucher *&---------------------------------------------------------------------* *& text 生成凭证 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_creation_voucher. DATA:lt_rows TYPE lvc_t_row, ls_rows LIKE LINE OF lt_rows. "取得所有选择行 CALL METHOD go_grid->get_selected_rows IMPORTING et_index_rows = lt_rows. DATA(g_lines) = lines( lt_rows ). IF g_lines = 0 . MESSAGE '请选择一行数据!' TYPE 'I'. EXIT. ELSEIF g_lines <> 1 AND g_lines <> 0 . MESSAGE '请勿选择多行数据!' TYPE 'I'. EXIT. ENDIF. DATA : ls_doc_header TYPE bapiache09, "抬头表 lt_acc_gl TYPE TABLE OF bapiacgl09, "总帐科目项 ls_acc_gl TYPE bapiacgl09, lt_acc_cur TYPE TABLE OF bapiaccr09, "货币项目 ls_acc_cur TYPE bapiaccr09, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2, lt_acc_exe TYPE TABLE OF bapiparex, "附加结构表 ls_acc_exe TYPE bapiparex, ls_zfis002 TYPE zfis002. "过账码附加结构 DATA: date TYPE sy-datum, "日期 text TYPE char20, "文本 lv_item TYPE i VALUE 1, "行号 racct_a TYPE acdoca-racct, "项目科目 racct_b TYPE acdoca-racct, "项目科目2 lt_msg TYPE tsmesg, ls_msg LIKE LINE OF lt_msg, lv_msg_text TYPE char100, ls_zfit002 TYPE zfit002. "MODIFY TO ZFIT002 "凭证日期,过账日期为查询期间年度的最后一天(查询期间年度为:2022003,则日期为20220331) date = p_fisc+0(4) && p_fisc+5(2) && '01'. CALL FUNCTION 'LAST_DAY_OF_MONTHS' EXPORTING day_in = date IMPORTING last_day_of_month = date. LOOP AT gt_out INTO gs_out WHERE sel = abap_true. IF p_lifnr = abap_true. "抬头文本 text = '供应商重分类'. "科目 racct_a = gs_out-racct2. racct_b = gs_out-racct1. ELSEIF p_kunnr = abap_true. "抬头文本 text = '客户重分类'. "科目 racct_a = gs_out-racct1. racct_b = gs_out-racct2. ENDIF. ***------- 重分类本月凭证生成 BEGIN ------------**** "抬头表数据 CLEAR:ls_doc_header. ls_doc_header = VALUE #( username = sy-uname "录入人 comp_code = gs_out-rbukrs "公司代码 doc_date = date "凭证日期 pstng_date = date "过账日期 doc_type = 'Z3' "凭证类型 header_txt = p_fisc && gs_out-rbukrs && text"抬头文本 ). **---- 40 科目 BEGIN -----** "总帐科目项数据 CLEAR:ls_acc_gl. ls_acc_gl = VALUE #( itemno_acc = lv_item "行号 gl_account = racct_a "科目 item_text = p_fisc && gs_out-rbukrs && text "项目文本 ). APPEND ls_acc_gl TO lt_acc_gl . "项目金额数据1 CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl "期末余额(本币) curr_type = '10' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目金额数据2(需重复添加金额,否则冲销异常) CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl "期末余额(本币) curr_type = '00' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目过账码 CLEAR:ls_zfis002. ls_zfis002 = VALUE #( itemno_acc = lv_item "行号 bschl = '40' "过账码 ). "过账码至附加结构中 ls_acc_exe-structure = 'ZFIS002'. ls_acc_exe-valuepart1 = ls_zfis002. APPEND ls_acc_exe TO lt_acc_exe. **---- 40 科目 END -----** **---- 50 科目 BEGIN -----** lv_item = lv_item + 1."行号 "总帐科目项数据 CLEAR:ls_acc_gl. ls_acc_gl = VALUE #( itemno_acc = lv_item "行号 gl_account = racct_b "科目 item_text = p_fisc && gs_out-rbukrs && text "项目文本 ). APPEND ls_acc_gl TO lt_acc_gl . "项目金额数据1 CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl * -1"期末余额(本币) curr_type = '10' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目金额数据2(需重复添加金额,否则冲销异常) CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl * -1"期末余额(本币) curr_type = '00' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目过账码 CLEAR:ls_zfis002. ls_zfis002 = VALUE #( itemno_acc = lv_item "行号 bschl = '50' "过账码 ). "过账码至附加结构中 ls_acc_exe-structure = 'ZFIS002'. ls_acc_exe-valuepart1 = ls_zfis002. APPEND ls_acc_exe TO lt_acc_exe. **---- 50 科目 END -----** "CHECK DATA CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK' EXPORTING documentheader = ls_doc_header TABLES accountgl = lt_acc_gl currencyamount = lt_acc_cur return = lt_return extension2 = lt_acc_exe. READ TABLE lt_return INTO ls_return WITH KEY type = 'E'. IF sy-subrc <> 0. " POST DATA CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = ls_doc_header TABLES accountgl = lt_acc_gl currencyamount = lt_acc_cur return = lt_return extension2 = lt_acc_exe. "返回操作界面信息 READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. CLEAR:ls_msg. ls_msg-zeile = 1. ls_msg-msgty = ls_return-type. ls_msg-arbgb = 'ZMM001'. ls_msg-txtnr = '010'. ls_msg-msgv1 = '重分类本月凭证生成成功,凭证号:' && ls_return-message_v2+0(10) && '公司:' && ls_return-message_v2+10(4) && '年度:' && ls_return-message_v2+14(4). APPEND ls_msg TO lt_msg. "更新至 应收应付重分类生成凭证存储表 中的数据 CLEAR:ls_zfit002. ls_zfit002 = VALUE #( racct = gs_out-racct lifnr = gs_out-lifnr kunnr = gs_out-kunnr num = gs_out-num + 1"序号 biaoshi = ''"冲销标识 belnr1 = ls_return-message_v2+0(10)"重分类本月凭证 fiscyearper = gs_out-fiscyearper"期间/年度 uname = sy-uname ). ENDIF. ELSE. CLEAR:lv_msg_text. LOOP AT lt_return INTO ls_return. lv_msg_text = lv_msg_text && ls_return-message . ENDLOOP. MESSAGE '重分类本月凭证生成失败' && lv_msg_text TYPE 'I' DISPLAY LIKE 'E'. EXIT. ENDIF. ***------- 重分类本月凭证生成 EDN ------------**** ***------- 重分类次月凭证生成 BEGIN ------------**** date = date + 1. "日期为次月1号 lv_item = 1."行项目重置 CLEAR:ls_doc_header,lt_acc_gl[],lt_acc_cur[],lt_acc_exe[]. "抬头表数据 ls_doc_header = VALUE #( username = sy-uname "录入人 comp_code = gs_out-rbukrs "公司代码 doc_date = date "凭证日期 pstng_date = date "过账日期 doc_type = 'Z3' "凭证类型 header_txt = '冲销' && p_fisc && gs_out-rbukrs && text"抬头文本 ). **---- 40 科目 BEGIN -----** "总帐科目项数据 CLEAR:ls_acc_gl. ls_acc_gl = VALUE #( itemno_acc = lv_item "行号 gl_account = racct_b "科目 item_text = '冲销' && p_fisc && gs_out-rbukrs && text "项目文本 ). APPEND ls_acc_gl TO lt_acc_gl . "项目金额数据1 CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl "期末余额(本币) curr_type = '10' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目金额数据2(需重复添加金额,否则冲销异常) CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl "期末余额(本币) curr_type = '00' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目过账码 CLEAR:ls_zfis002. ls_zfis002 = VALUE #( itemno_acc = lv_item "行号 bschl = '40' "过账码 ). "过账码至附加结构中 ls_acc_exe-structure = 'ZFIS002'. ls_acc_exe-valuepart1 = ls_zfis002. APPEND ls_acc_exe TO lt_acc_exe. **---- 40 科目 END -----** **---- 50 科目 BEGIN -----** lv_item = lv_item + 1."行号 "总帐科目项数据 CLEAR:ls_acc_gl. ls_acc_gl = VALUE #( itemno_acc = lv_item "行号 gl_account = racct_a "科目 item_text = '冲销' && p_fisc && gs_out-rbukrs && text "项目文本 ). APPEND ls_acc_gl TO lt_acc_gl . "项目金额数据1 CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl * -1"期末余额(本币) curr_type = '10' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目金额数据2(需重复添加金额,否则冲销异常) CLEAR:ls_acc_cur. ls_acc_cur = VALUE #( itemno_acc = lv_item "行号 amt_doccur = gs_out-hsl * -1"期末余额(本币) curr_type = '00' "货币和评估视图 currency = 'CNY' "货币 ). APPEND ls_acc_cur TO lt_acc_cur. "项目过账码 CLEAR:ls_zfis002. ls_zfis002 = VALUE #( itemno_acc = lv_item "行号 bschl = '50' "过账码 ). "过账码至附加结构中 ls_acc_exe-structure = 'ZFIS002'. ls_acc_exe-valuepart1 = ls_zfis002. APPEND ls_acc_exe TO lt_acc_exe. **---- 50 科目 END -----** "CHECK DATA CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK' EXPORTING documentheader = ls_doc_header TABLES accountgl = lt_acc_gl currencyamount = lt_acc_cur return = lt_return extension2 = lt_acc_exe. READ TABLE lt_return INTO ls_return WITH KEY type = 'E'. IF sy-subrc <> 0. " POST DATA CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST' EXPORTING documentheader = ls_doc_header TABLES accountgl = lt_acc_gl currencyamount = lt_acc_cur return = lt_return extension2 = lt_acc_exe. "返回操作界面信息 READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. CLEAR:ls_msg. ls_msg-zeile = 2. ls_msg-arbgb = 'ZMM001'. ls_msg-txtnr = '010'. ls_msg-msgty = ls_return-type. ls_msg-msgv1 = '重分类次月凭证生成成功,凭证号:' && ls_return-message_v2+0(10) && '公司:' && ls_return-message_v2+10(4) && '年度:' && ls_return-message_v2+14(4). APPEND ls_msg TO lt_msg. "重分类次月凭证 ls_zfit002-belnr2 = ls_return-message_v2+0(10). ENDIF. ELSE. CLEAR:lv_msg_text. LOOP AT lt_return INTO ls_return. lv_msg_text = lv_msg_text && ls_return-message . ENDLOOP. MESSAGE '重分类次月凭证生成失败' && lv_msg_text TYPE 'I' DISPLAY LIKE 'E'. EXIT. ENDIF. ***------- 重分类次月凭证生成 EDN ------------**** " 应收应付重分类生成凭证存储表 更新 MODIFY zfit002 FROM ls_zfit002. "提交 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. "信息弹出框 CALL FUNCTION 'FB_MESSAGES_DISPLAY_POPUP' EXPORTING it_smesg = lt_msg * ID_SMESG_ZEILE = * IT_RETURN = * ID_SEND_IF_ONE = EXCEPTIONS no_messages = 1 popup_cancelled = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_wash_voucher *&---------------------------------------------------------------------* *& text 冲销凭证 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_wash_voucher . DATA:lt_rows TYPE lvc_t_row, ls_rows LIKE LINE OF lt_rows. "取得所有选择行 CALL METHOD go_grid->get_selected_rows IMPORTING et_index_rows = lt_rows. DATA(g_lines) = lines( lt_rows ). IF g_lines = 0 . MESSAGE '请选择一行数据!' TYPE 'I'. EXIT. ELSEIF g_lines <> 1 AND g_lines <> 0 . MESSAGE '请勿选择多行数据!' TYPE 'I'. EXIT. ENDIF. DATA: ls_reversal TYPE bapiacrev, lv_obj_sys TYPE bapiache09-obj_sys, lt_return TYPE TABLE OF bapiret2, ls_return LIKE LINE OF lt_return, lt_msg TYPE tsmesg, ls_msg LIKE LINE OF lt_msg, lv_msg_text TYPE char100, ls_zfit002 TYPE zfit002. "MODIFY TO ZFIT002. "取得系统 LOGICAL SYSTEM CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET' IMPORTING own_logical_system = lv_obj_sys. LOOP AT gt_out INTO gs_out WHERE sel = abap_true. ***-------冲销本月凭证----- BEGIN --*** SELECT SINGLE glvor,awtyp,awkey FROM bkpf INTO @DATA(ls_bkpf1) WHERE bukrs = @gs_out-rbukrs AND belnr = @gs_out-belnr1 AND gjahr = @p_fisc+0(4) AND xreversal = ''. CLEAR:ls_reversal. ls_reversal = VALUE #( obj_type = ls_bkpf1-awtyp obj_key_r = ls_bkpf1-awkey obj_key = ls_bkpf1-awkey obj_sys = lv_obj_sys comp_code = gs_out-rbukrs * ac_doc_no = gs_out-belnr1 reason_rev = '03' ). "冲销凭证 CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST' EXPORTING reversal = ls_reversal bus_act = ls_bkpf1-glvor TABLES return = lt_return. READ TABLE lt_return INTO ls_return WITH KEY type = 'E'. IF sy-subrc = 0. CLEAR:lv_msg_text. LOOP AT lt_return INTO ls_return. lv_msg_text = lv_msg_text && ls_return-message. ENDLOOP. MESSAGE '重分类本月凭证冲销失败' && lv_msg_text TYPE 'I' DISPLAY LIKE 'E'. EXIT. ELSE. READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. CLEAR:ls_msg. ls_msg-zeile = 1. ls_msg-msgty = ls_return-type. ls_msg-arbgb = 'ZMM001'. ls_msg-txtnr = '010'. ls_msg-msgv1 = '重分类本月凭证冲销成功,凭证号:' && ls_return-message_v2+0(10) && '公司:' && ls_return-message_v2+10(4) && '年度:' && ls_return-message_v2+14(4). APPEND ls_msg TO lt_msg. ENDIF. "更新至 应收应付重分类生成凭证存储表 中的数据 CLEAR:ls_zfit002. ls_zfit002 = VALUE #( racct = gs_out-racct lifnr = gs_out-lifnr kunnr = gs_out-kunnr num = gs_out-num + 1"序号 biaoshi = 'X'"冲销标识 belnr1 = ls_return-message_v2+0(10)"重分类本月冲销凭证 uname = sy-uname fiscyearper = gs_out-fiscyearper"期间/年度 ). ENDIF. ***-------冲销本月凭证----- END --*** ***-------冲销次月凭证----- BEGIN --*** SELECT SINGLE glvor,awtyp,awkey FROM bkpf INTO @DATA(ls_bkpf2) WHERE bukrs = @gs_out-rbukrs AND belnr = @gs_out-belnr2 AND gjahr = @p_fisc+0(4) AND xreversal = ''. CLEAR:ls_reversal. ls_reversal = VALUE #( obj_type = ls_bkpf2-awtyp obj_key_r = ls_bkpf2-awkey obj_key = ls_bkpf2-awkey obj_sys = lv_obj_sys comp_code = gs_out-rbukrs * ac_doc_no = gs_out-belnr1 reason_rev = '03' ). "冲销凭证 CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST' EXPORTING reversal = ls_reversal bus_act = ls_bkpf2-glvor TABLES return = lt_return. READ TABLE lt_return INTO ls_return WITH KEY type = 'E'. IF sy-subrc = 0. CLEAR:lv_msg_text. LOOP AT lt_return INTO ls_return. lv_msg_text = lv_msg_text && ls_return-message. ENDLOOP. MESSAGE '重分类次月凭证冲销失败' && lv_msg_text TYPE 'I' DISPLAY LIKE 'E'. EXIT. ELSE. READ TABLE lt_return INTO ls_return WITH KEY type = 'S'. IF sy-subrc = 0. CLEAR:ls_msg. ls_msg-zeile = 2. ls_msg-msgty = ls_return-type. ls_msg-arbgb = 'ZMM001'. ls_msg-txtnr = '010'. ls_msg-msgv1 = '重分类次月凭证冲销成功,凭证号:' && ls_return-message_v2+0(10) && '公司:' && ls_return-message_v2+10(4) && '年度:' && ls_return-message_v2+14(4). APPEND ls_msg TO lt_msg. ENDIF. "重分类次月冲销凭证 ls_zfit002-belnr2 = ls_return-message_v2+0(10). ENDIF. ***-------冲销次月凭证----- END --*** " 应收应付重分类生成凭证存储表 更新 MODIFY zfit002 FROM ls_zfit002. "提交 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. "弹出框 CALL FUNCTION 'FB_MESSAGES_DISPLAY_POPUP' EXPORTING it_smesg = lt_msg * ID_SMESG_ZEILE = * IT_RETURN = * ID_SEND_IF_ONE = EXCEPTIONS no_messages = 1 popup_cancelled = 2 OTHERS = 3. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. ENDLOOP. ENDFORM. *&---------------------------------------------------------------------* *& Form frm_history_data *&---------------------------------------------------------------------* *& text 凭证历史查看 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM frm_history_data . DATA:lt_rows TYPE lvc_t_row, ls_rows LIKE LINE OF lt_rows. "取得所有选择行 CALL METHOD go_grid->get_selected_rows IMPORTING et_index_rows = lt_rows. DATA(g_lines) = lines( lt_rows ). IF g_lines = 0 . MESSAGE '请选择一行数据!' TYPE 'I'. EXIT. ELSEIF g_lines <> 1 AND g_lines <> 0 . MESSAGE '请勿选择多行数据!' TYPE 'I'. EXIT. ENDIF. DATA:go_alv TYPE REF TO cl_salv_table, go_funlst TYPE REF TO cl_salv_functions_list. DATA:itab TYPE STANDARD TABLE OF zfit002. DATA:cxroot TYPE REF TO cx_root, excmsg TYPE string. LOOP AT gt_out INTO gs_out WHERE sel = abap_true. SELECT * FROM zfit002 INTO CORRESPONDING FIELDS OF TABLE itab WHERE racct = gs_out-racct AND lifnr = gs_out-lifnr AND kunnr = gs_out-kunnr AND fiscyearper = gs_out-fiscyearper. ENDLOOP. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = go_alv CHANGING t_table = itab[] ). CATCH cx_root INTO cxroot. excmsg = cxroot->get_text( ). MESSAGE e000(oo) WITH excmsg. ENDTRY. go_funlst = go_alv->get_functions( ). go_funlst->set_all('X'). IF go_alv IS BOUND. go_alv->set_screen_popup( start_column = 10 end_column = 110 start_line = 5 end_line = 15 ). go_alv->display( ). ENDIF. ENDFORM. |
1 条评论