SAP ABAP HCM: Test and Upload Data to Decoupled Infotype
Below is sample program to test and upload a record in a decoupled infotype. Methods ‘test_infty9000_entry’ and ‘execute_infty9000_entry’ will have code specific to handle the decoupled infotype.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
REPORT zhrpy_upload_infty. *--------------------------------------------------------------------* * CLASS *--------------------------------------------------------------------* CLASS lcl_main DEFINITION FINAL. PUBLIC SECTION. CONSTANTS: c_icon_green TYPE icon_d VALUE '@08@', c_icon_yellow TYPE icon_d VALUE '@09@', c_icon_red TYPE icon_d VALUE '@0A@'. TYPES: ty_s_xlsx_layout TYPE zhrpy_st_9000_xlsx_layout, ty_t_xlsx_layout TYPE zhrpy_tt_9000_xlsx_layout, BEGIN OF ty_s_message, status_icon TYPE icon_d, message TYPE bapi_msg, pernr TYPE ty_s_xlsx_layout-pernr, * subty TYPE ty_s_xlsx_layout-subty, * objps TYPE ty_s_xlsx_layout-objps, * sprps TYPE ty_s_xlsx_layout-sprps, begda TYPE ty_s_xlsx_layout-begda, endda TYPE ty_s_xlsx_layout-endda, * seqnr TYPE ty_s_xlsx_layout-seqnr, cate TYPE categ, * type TYPE bapi_mtype, * id TYPE symsgid, * number TYPE symsgno, * message TYPE bapi_msg, * log_no TYPE balognr, * log_msg_no TYPE balmnr, END OF ty_s_message, ty_t_alv_layout TYPE STANDARD TABLE OF ty_s_message WITH DEFAULT KEY, ty_o_message_handler TYPE REF TO cl_hrpa_message_list. DATA: a_t_message TYPE ty_t_alv_layout. * CLASS-METHODS: * class_constructor. METHODS: constructor IMPORTING im_p_lclpth TYPE string im_p_srvpth TYPE string im_p_test TYPE flag im_p_ovrwrt TYPE flag, upload, show_log. * PROTECTED SECTION. PRIVATE SECTION. DATA: a_lclpth TYPE string, a_srvpth TYPE string, a_ovrwrt TYPE flag, a_test TYPE flag, a_o_xlsx_data_typed TYPE REF TO data. METHODS: process_upload, validate_population IMPORTING im_pernr TYPE persno im_begda TYPE begda im_endda TYPE endda RETURNING VALUE(rv_flag) TYPE boole_d, search_future_infty9000 IMPORTING im_pernr TYPE persno im_begda TYPE begda im_endda TYPE endda RETURNING VALUE(rv_flag) TYPE boole_d, test_infty9000_entry IMPORTING im_s_xlsx_record TYPE ty_s_xlsx_layout, execute_infty9000_entry IMPORTING im_s_xlsx_record TYPE ty_s_xlsx_layout, add_msg IMPORTING im_s_msg TYPE ty_s_message im_o_message_handler TYPE ty_o_message_handler OPTIONAL im_s_bapireturn1 TYPE bapireturn1 OPTIONAL. ENDCLASS. CLASS lcl_main IMPLEMENTATION. * METHOD class_constructor. * ENDMETHOD. METHOD constructor. CREATE DATA: a_o_xlsx_data_typed TYPE ty_t_xlsx_layout. "zhrpy_tt_0008_xlsx_layout. a_lclpth = im_p_lclpth. a_srvpth = im_p_srvpth. a_test = im_p_test. a_ovrwrt = im_p_ovrwrt. ENDMETHOD. METHOD process_upload. FIELD-SYMBOLS: <lft_xlsx_itab_typed> TYPE ty_t_xlsx_layout. DATA: ls_return TYPE bapireturn1, ls_message TYPE ty_s_message, lv_error TYPE boole_d. ASSIGN a_o_xlsx_data_typed->* TO <lft_xlsx_itab_typed>. LOOP AT <lft_xlsx_itab_typed> ASSIGNING FIELD-SYMBOL(<lfs_xlsx_record>). "When editing line then removing information, xlsx uploads a blank line. CHECK <lfs_xlsx_record>-pernr IS NOT INITIAL. CLEAR: ls_message, ls_return, lv_error. "Validate if employee is from zzz population IF validate_population( im_pernr = <lfs_xlsx_record>-pernr im_begda = <lfs_xlsx_record>-begda im_endda = <lfs_xlsx_record>-endda ) = abap_false. ls_message-pernr = <lfs_xlsx_record>-pernr. * ls_message-subtype = '0'. ls_message-begda = <lfs_xlsx_record>-begda. ls_message-endda = <lfs_xlsx_record>-endda. ls_return-type = 'E'. ls_return-message = 'Error: Employee does not participate in Company Code zzz, Personnel subarea 0000.'(008). me->add_msg( im_s_msg = ls_message im_s_bapireturn1 = ls_return ). lv_error = 'X'. ENDIF. "Validate if there are not future records IF a_ovrwrt = abap_false. IF search_future_infty9000( im_pernr = <lfs_xlsx_record>-pernr im_begda = <lfs_xlsx_record>-begda * im_endda = '99991231' ) = abap_true. im_endda = <lfs_xlsx_record>-endda ) = abap_true. MOVE-CORRESPONDING <lfs_xlsx_record> TO ls_message. ls_return-type = 'E'. ls_return-message = 'Error: Record in infotype 9000 already exists and it will be replaced by new entry. Upload canceled.'(009). me->add_msg( im_s_msg = ls_message im_s_bapireturn1 = ls_return ). lv_error = 'X'. ENDIF. ENDIF. * "Only process records without error CHECK lv_error IS INITIAL. IF a_test = abap_true. me->test_infty9000_entry( im_s_xlsx_record = <lfs_xlsx_record> ). ELSE. me->execute_infty9000_entry( im_s_xlsx_record = <lfs_xlsx_record> ). ENDIF. ENDLOOP. ENDMETHOD. METHOD validate_population. DATA: lt_p0001 TYPE TABLE OF p0001. TRY. cl_hrpa_read_infotype=>get_instance( * EXPORTING * masterdata_buffer = " HR: Buffer for Access to Master Data IMPORTING infotype_reader = DATA(lo_infty) " Reading Infotype Records ). lo_infty->read( EXPORTING tclas = 'A' " Transaction Class for Data Storage pernr = im_pernr " Personnel Number infty = '0001' " Infotype * subty = '*' " Subtype * objps = '*' " Object Identification * sprps = '*' " Lock Indicator for HR Master Data Record begda = im_begda " Valid from date endda = im_endda " Valid To Date no_auth_check = '' " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") IMPORTING infotype_tab = DATA(lt_infty_data) " HR: Primary and Secondary Infotype and Acct Assignment Data * data_exists = DATA(lv_data_found) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") * missing_auth = DATA(lv_authorization) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") ). * CHECK lt_infty_data[] IS NOT INITIAL. IF lt_infty_data[] IS INITIAL. lo_infty->read( EXPORTING tclas = 'A' " Transaction Class for Data Storage pernr = im_pernr " Personnel Number infty = '0001' " Infotype * subty = '*' " Subtype * objps = '*' " Object Identification * sprps = '*' " Lock Indicator for HR Master Data Record begda = lo_infty->low_date " Valid from date endda = lo_infty->high_date " Valid To Date no_auth_check = '' " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") IMPORTING infotype_tab = lt_infty_data " HR: Primary and Secondary Infotype and Acct Assignment Data * data_exists = lv_data_found " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") * missing_auth = lv_authorization " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") ). ENDIF. CHECK lt_infty_data[] IS NOT INITIAL. CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn_tab EXPORTING prelp_tab = lt_infty_data IMPORTING pnnnn_tab = lt_p0001. LOOP AT lt_p0001 INTO DATA(ls_p0001). IF ls_p0001-bukrs = 'ZZZ' AND ls_p0001-btrtl = '0000'. rv_flag = abap_true. EXIT. ENDIF. ENDLOOP. CATCH cx_hrpa_violated_assertion. CLEAR rv_flag. ENDTRY. ENDMETHOD. METHOD search_future_infty9000. DATA: lt_p9000 TYPE TABLE OF p9000. TRY. cl_hrpa_read_infotype=>get_instance( * EXPORTING * masterdata_buffer = " HR: Buffer for Access to Master Data IMPORTING infotype_reader = DATA(lo_infty) " Reading Infotype Records ). lo_infty->read( EXPORTING tclas = 'A' " Transaction Class for Data Storage pernr = im_pernr " Personnel Number infty = '9000' " Infotype subty = '' " Subtype * objps = '*' " Object Identification * sprps = '*' " Lock Indicator for HR Master Data Record begda = im_begda " Valid from date endda = im_endda " Valid To Date no_auth_check = '' " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") IMPORTING infotype_tab = DATA(lt_infty_data) " HR: Primary and Secondary Infotype and Acct Assignment Data * data_exists = DATA(lv_data_found) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") * missing_auth = DATA(lv_authorization) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") ). CHECK lt_infty_data[] IS NOT INITIAL. CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn_tab EXPORTING prelp_tab = lt_infty_data IMPORTING pnnnn_tab = lt_p9000. LOOP AT lt_p9000 INTO DATA(ls_p9000). IF ls_p9000-begda >= im_begda. rv_flag = abap_true. EXIT. ENDIF. ENDLOOP. CATCH cx_hrpa_violated_assertion. CLEAR rv_flag. ENDTRY. ENDMETHOD. METHOD upload. CALL METHOD zcl_xlsx_file=>retrieve_itab_from_xlsx_file EXPORTING im_lclpth = a_lclpth im_srvpth = a_srvpth CHANGING ch_o_data = a_o_xlsx_data_typed. me->process_upload( ). ENDMETHOD. METHOD test_infty9000_entry. DATA: ls_bapireturn1 TYPE bapireturn1, ls_message TYPE ty_s_message, ls_p9000 TYPE p9000, ls_prelp TYPE prelp, ls_prelp2 TYPE prelp, ls_pref TYPE pref. DATA(lo_message_handler) = NEW cl_hrpa_message_list( ). MOVE-CORRESPONDING im_s_xlsx_record TO: ls_p9000, ls_message. ls_p9000-infty = '9000'. CALL METHOD cl_hr_pnnnn_type_cast=>pnnnn_to_prelp EXPORTING pnnnn = ls_p9000 IMPORTING prelp = ls_prelp. " HR Master Data Buffer DATA(lo_infty_9000) = NEW zcl_hrpa_infotype_9000( tclas = 'A' infty = '9000' ). TRY . lo_infty_9000->if_hrpa_infty_legacy_adapter~check_insert( EXPORTING tclas = 'A' " Transaction Class for Data Storage * massn = " Action Type * massg = " Reason for Action message_handler = lo_message_handler " HR Master Data: Messages IMPORTING is_ok = DATA(lv_ok) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") CHANGING pnnnn = ls_prelp " HR Master Data Buffer pnnnn2 = ls_prelp2 " HR Master Data Buffer pref = ls_pref " Assignment Values for HR Objects ). IF lv_ok = abap_false OR ( lv_ok = abap_true AND lo_message_handler->has_message( ) = abap_true ). me->add_msg( EXPORTING im_s_msg = ls_message im_o_message_handler = lo_message_handler ). ELSE. ls_bapireturn1-type = 'S'. ls_bapireturn1-message = 'Simulation performed successfully.'(003). me->add_msg( im_s_msg = ls_message im_s_bapireturn1 = ls_bapireturn1 ). ENDIF. CATCH cx_hrpa_violated_assertion INTO DATA(lo_obj). ls_bapireturn1-type = 'E'. ls_bapireturn1-message = lo_obj->get_text( ). me->add_msg( EXPORTING im_s_msg = ls_message im_s_bapireturn1 = ls_bapireturn1 ). ENDTRY. ENDMETHOD. METHOD execute_infty9000_entry. DATA: ls_bapireturn1 TYPE bapireturn1, ls_message TYPE ty_s_message, ls_pskey TYPE pskey, * lo_container_nnnn TYPE REF TO cl_hrpa_infotype_container, lo_container_nnnn TYPE REF TO if_hrpa_infty_container_data, ls_p9000 TYPE p9000. DATA(lo_message_handler) = NEW cl_hrpa_message_list( ). MOVE-CORRESPONDING im_s_xlsx_record TO: ls_pskey, ls_p9000, ls_message. ls_pskey-infty = '9000'. ls_p9000-infty = '9000'. TRY . CALL METHOD cl_hrpa_masterdata_enq_deq=>enqueue_by_pernr EXPORTING tclas = 'A' " Transaction Class for Data Storage pernr = ls_p9000-pernr " Personnel Number * promote_to_exclusive = abap_true " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") message_handler = lo_message_handler " HR Master Data: Messages * enq_scope = '2' " Control Lock Behavior When Calling the Update Task * enq_wait = SPACE " Flag Indicating Whether Lock Attempt Is to Be Repeated * enq_collect = 'X' " Indicator Whether Locks Should Only Be Collected First IMPORTING is_ok = DATA(lv_ok) " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") * locking_user = " SAP System, User Logon Name . IF lv_ok = abap_false. me->add_msg( EXPORTING im_s_msg = ls_message im_o_message_handler = lo_message_handler ). RETURN. * ELSE. * * ls_bapireturn1-type = 'S'. * ls_bapireturn1-message = 'PERNR lock performed successfully.'(004). * * me->add_msg( * im_s_msg = ls_message * im_s_bapireturn1 = ls_bapireturn1 ). ENDIF. CALL METHOD cl_hrpa_masterdata_factory=>get_business_logic IMPORTING business_logic = DATA(lo_masterdata_bl). * CALL METHOD cl_hrpa_masterdata_bl=>get_instance( * IMPORTING * masterdata_bl = DATA(lo_masterdata_bl) ). lo_masterdata_bl->get_infty_container( EXPORTING tclas = 'A' " Transaction Class for Data Storage pskey = ls_pskey " Keys for HR Master Data * itbld = " Infotype screen control * massn = " Action Type * massg = " Reason for Action * no_auth_check = " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") message_handler = lo_message_handler " HR Master Data: Messages IMPORTING container = DATA(lo_container) " HR: Master Data, Reference to Infotype Container is_ok = lv_ok ). " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") lo_container_nnnn ?= lo_container. lo_container ?= lo_container_nnnn->modify_primary_record( primary_record = ls_p9000 ). lo_masterdata_bl->insert( EXPORTING * massn = " Action Type * massg = " Reason for Action * update_mode = " Which Posting Functions Are to Be Deactivated? * no_auth_check = " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") message_handler = lo_message_handler " Error Handler IMPORTING is_ok = lv_ok " Data Element for Domain BOOLE: TRUE (="X") and FALSE (=" ") CHANGING container = lo_container ). " HR: Master Data, Reference to Infotype Container * CATCH cx_hrpa_violated_assertion. " IF lv_ok = abap_false OR ( lv_ok = abap_true AND lo_message_handler->has_message( ) = abap_true ). me->add_msg( EXPORTING im_s_msg = ls_message im_o_message_handler = lo_message_handler ). CALL METHOD lo_masterdata_bl->flush EXPORTING no_commit = abap_true. ELSEIF lv_ok = abap_true. ls_bapireturn1-type = 'S'. ls_bapireturn1-message = 'Record uploaded successfully.'(013). me->add_msg( im_s_msg = ls_message im_s_bapireturn1 = ls_bapireturn1 ). CALL METHOD lo_masterdata_bl->flush EXPORTING no_commit = abap_false. ENDIF. CALL METHOD cl_hrpa_masterdata_enq_deq=>dequeue_by_pernr EXPORTING tclas = 'A' " Transaction Class for Data Storage pernr = ls_p9000-pernr. " Standard Selections for HR Master Data Reporting * ls_bapireturn1-type = 'S'. * ls_bapireturn1-message = 'PERNR unlock performed successfully.'(007). me->add_msg( * im_s_msg = ls_message * im_s_bapireturn1 = ls_bapireturn1 ). CATCH cx_hrpa_violated_assertion INTO DATA(lo_obj). IF lo_message_handler->has_message( ) = abap_true. me->add_msg( EXPORTING im_s_msg = ls_message im_o_message_handler = lo_message_handler ). ENDIF. IF lo_obj->get_text( ) IS NOT INITIAL. ls_bapireturn1-type = 'E'. ls_bapireturn1-message = lo_obj->get_text( ). me->add_msg( EXPORTING im_s_msg = ls_message im_s_bapireturn1 = ls_bapireturn1 ). ENDIF. ENDTRY. ENDMETHOD. METHOD show_log. DATA: lo_alv TYPE REF TO cl_salv_table, lo_functions TYPE REF TO cl_salv_functions_list, lo_display_settings TYPE REF TO cl_salv_display_settings, lo_columns TYPE REF TO cl_salv_columns_table. TRY. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = lo_alv CHANGING t_table = a_t_message[]. "AT_LOG is your log table with all the entries CATCH cx_salv_msg . "... errors, success ... whatever RETURN. ENDTRY. TRY . "Set texto to non DDIC columns lo_alv->get_columns( )->get_column( 'STATUS_ICON' )->set_short_text( CONV #('Status'(019) ) ). "Allow leading zeros to PERNR field lo_alv->get_columns( )->get_column( 'EMPLOYEENUMBER' )->set_leading_zero( ). lo_alv->get_columns( )->get_column( 'TYPE' )->set_technical( value = if_salv_c_bool_sap=>true ). CATCH cx_salv_not_found. ENDTRY. lo_columns = lo_alv->get_columns( ). lo_columns->set_optimize( ). lo_display_settings = lo_alv->get_display_settings( ). lo_display_settings->set_striped_pattern( if_salv_c_bool_sap=>true ). lo_functions = lo_alv->get_functions( ). lo_functions->set_all( ). * lo_display_settings->set_list_header( ' ' ). "The title of you ALV lo_alv->display( ). "Method to display ENDMETHOD. METHOD add_msg. DATA: lt_msg TYPE hrpad_message_tab, ls_msg LIKE LINE OF lt_msg, ls_bapireturn TYPE bapiret1, ls_message LIKE LINE OF a_t_message[]. MOVE-CORRESPONDING im_s_msg TO ls_message. IF im_o_message_handler IS SUPPLIED. IF im_o_message_handler->has_warning( ) = 'X'. CALL METHOD im_o_message_handler->get_warning_list IMPORTING messages = lt_msg. ELSEIF im_o_message_handler->has_abend( ) = 'X'. CALL METHOD im_o_message_handler->get_abend_list IMPORTING messages = lt_msg. ELSEIF im_o_message_handler->has_error( ) = 'X'. CALL METHOD im_o_message_handler->get_error_list IMPORTING messages = lt_msg. ENDIF. LOOP AT lt_msg INTO ls_msg. CALL FUNCTION 'BALW_BAPIRETURN_GET1' EXPORTING type = ls_msg-msgty cl = ls_msg-msgid number = ls_msg-msgno par1 = ls_msg-msgv1 par2 = ls_msg-msgv2 par3 = ls_msg-msgv3 par4 = ls_msg-msgv4 IMPORTING bapireturn = ls_bapireturn. MOVE-CORRESPONDING ls_bapireturn TO ls_message. "Message type: S Success, E Error, W Warning, I Info, A Abort CASE ls_bapireturn-type. WHEN 'S' OR 'I'. ls_message-status_icon = c_icon_green. WHEN 'W'. ls_message-status_icon = c_icon_yellow. WHEN 'E' OR 'A'. ls_message-status_icon = c_icon_red. ENDCASE. INSERT ls_message INTO TABLE a_t_message[]. ENDLOOP. * " in case infotype is not updated and still no messages were captured IF ( "g_is_ok IS INITIAL AND lt_msg[] IS INITIAL ). ls_bapireturn-id = 'HRESS_CLMS_MSG'. ls_bapireturn-number = '073'. ls_bapireturn-message_v1 = 'Error uploading data.'(014). MOVE-CORRESPONDING ls_bapireturn TO ls_message. INSERT ls_message INTO TABLE a_t_message[]. ENDIF. ENDIF. IF im_s_bapireturn1 IS SUPPLIED. MOVE-CORRESPONDING im_s_bapireturn1 TO ls_message. "Message type: S Success, E Error, W Warning, I Info, A Abort CASE im_s_bapireturn1-type. WHEN 'S' OR 'I'. ls_message-status_icon = c_icon_green. WHEN 'W'. ls_message-status_icon = c_icon_yellow. WHEN 'E' OR 'A'. ls_message-status_icon = c_icon_red. ENDCASE. INSERT ls_message INTO TABLE a_t_message[]. ENDIF. ENDMETHOD. ENDCLASS. *--------------------------------------------------------------------* * Selection screen *--------------------------------------------------------------------* "Test mode SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002. PARAMETERS: p_test TYPE flag AS CHECKBOX DEFAULT 'X'. SELECTION-SCREEN END OF BLOCK b2. "Input file path SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS: p_lclpth TYPE string, p_srvpth TYPE string. SELECTION-SCREEN END OF BLOCK b1. "Overwriting option SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-010. SELECTION-SCREEN BEGIN OF LINE. PARAMETERS: p_ovrwrt TYPE flag AS CHECKBOX. SELECTION-SCREEN: COMMENT 3(58) TEXT-011. SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK b3. *--------------------------------------------------------------------* INITIALIZATION. *--------------------------------------------------------------------* SET PF-STATUS 'DEFAULT'. *--------------------------------------------------------------------* AT SELECTION-SCREEN. *--------------------------------------------------------------------* CASE sy-ucomm. WHEN 'ONLI'. "Run IF p_lclpth IS NOT INITIAL AND p_srvpth IS NOT INITIAL. SET CURSOR FIELD 'P_LCLPTH'. MESSAGE e016(pn) WITH 'Please enter only local or server path.'(005). ENDIF. IF p_lclpth IS INITIAL AND p_srvpth IS INITIAL. SET CURSOR FIELD 'P_LCLPTH'. MESSAGE e016(pn) WITH 'Please enter local or application server path'(012). ENDIF. WHEN '&XXL'. DATA: lt_xlsx_download TYPE lcl_main=>ty_t_xlsx_layout, lv_file TYPE string, lv_file_char(200) TYPE c. DATA(lo_xlsx_file) = NEW zcl_xlsx_file( sheet_content = lt_xlsx_download[] * p_row_height_header = C_DEFAULT_ROW_HEIGHT * p_row_height_body = C_DEFAULT_ROW_HEIGHT * p_color_column = p_autofit_column_width = ABAP_TRUE ). lo_xlsx_file->build( * EXPORTING add_default_header = abap_true add_techn_names_header = abap_true add_autofilter = abap_true * p_freeze_header = ABAP_TRUE ). zcl_xlsx_file=>browse_client_fs( CHANGING ch_path = lv_file ). IF lv_file IS INITIAL. MESSAGE s016(pn) WITH 'Download canceled.'(015). ELSE. lo_xlsx_file->save_file_to_client( EXPORTING fs_filename = lv_file start_excel = abap_true ). lv_file_char = lv_file. MESSAGE s016(pn) WITH 'File downloaded to '(016) lv_file_char(50) lv_file_char+50(50) '.'. ENDIF. WHEN OTHERS. ENDCASE. *--------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. *--------------------------------------------------------------------* LOOP AT SCREEN. IF screen-name CS 'PNPBTRTL'. screen-input = '0'. MODIFY SCREEN. ELSEIF screen-name CS 'PNPBUKRS'. screen-input = '0'. MODIFY SCREEN. ENDIF. ENDLOOP. *--------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lclpth. *--------------------------------------------------------------------* zcl_xlsx_file=>browse_client_fs( CHANGING ch_path = p_lclpth ). *--------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_srvpth. *--------------------------------------------------------------------* zcl_xlsx_file=>browse_server_fs( CHANGING ch_path = p_srvpth ). *--------------------------------------------------------------------* START-OF-SELECTION. *--------------------------------------------------------------------* DATA(go_main) = NEW lcl_main( im_p_lclpth = p_lclpth im_p_srvpth = p_srvpth im_p_test = p_test im_p_ovrwrt = p_ovrwrt ). go_main->upload( ). *--------------------------------------------------------------------* END-OF-SELECTION. *--------------------------------------------------------------------* IF go_main->a_t_message[] IS INITIAL. DATA lv_string TYPE string. IF p_lclpth IS NOT INITIAL. lv_string = p_lclpth. ELSE. lv_string = p_srvpth. ENDIF. lv_string = 'No data uploaded from:'(017) && ` ` && lv_string && '. Please check your file.'(018). WRITE lv_string. ELSE. go_main->show_log( ). ENDIF. |