*------------------------------------------------------------------------------------------- * program : ZHR_RPLLAEN0_HARVESTER * title : Harvest the output of multiple RPLLAEN0 reports * functional area : HR Wage return: Collective return overview * environment : 4.7 * program Function : This report calls the SAP standard RPLLAEN0 - Wage * return: Collective return overview - report, for a series * if legal persons. The output is adjusted somewhat, to * cater for a single report output. The first 2 columns * are added with the aansluitnummer and legal person. * Documentation : .. * Previous version : This is the initial version * Developer name : Wim Maasdam * Development date : 14/10/2015 * Version : 0.1 *--------------------------------------------------------------------- * Change list: * Date Description * 14/10/2015 Initial release *--------------------------------------------------------------------- report ZHR_RPLLAEN0_HARVESTER line-size 1023. TYPE-POOLS sscr. tables: P05T_AE_ADM_STAT. data: gt_abaplist type standard table of abaplist, gt_lines type standard table of char780, gt_lines_all type standard table of char780, gw_line type char780, gv_dataset type string, lw_pa_juper type juper, lw_header_line type char780, lv_tabix type sy-tabix, lv_lastline type sy-tabix, lv_columnheaderline type sy-tabix, begin of lw_tokenizer, dummy type c length 50, aansluitnummer type c length 50, rechtspersoon type c length 50, month type c length 2, year type c length 4, end of lw_tokenizer, lt_tokens type STANDARD TABLE OF string, lv_system type c length 15, lv_system_str type string, lv_period type c length 6, lv_Afwijkende_indeling type boolean. *--------------------------------------------------------------------- * C L A S S D E F I N I T I O N *--------------------------------------------------------------------- class lcl_f4_processing definition. public section. class-methods: f4_presentation_file importing title type any changing filepath type any, f4_server_file changing filepath type any. endclass. "lcl_f4_processing DEFINITION *--------------------------------------------------------------------- * S E L E C T I O N - S C R E E N *--------------------------------------------------------------------- selection-screen begin of line. selection-screen comment 1(27) lbl_a1 for field so_juper. SELECT-OPTIONS: so_juper for P05T_AE_ADM_STAT-juper no INTERVALS obligatory. selection-screen end of line. selection-screen begin of line. selection-screen comment 1(30) lbl_a2 for field pa_year. PARAMETERS: pa_year TYPE p05t_laipj default sy-datum(4). selection-screen end of line. selection-screen begin of line. selection-screen comment 1(30) lbl_a3 for field pa_inper. PARAMETERS: pa_inper TYPE p05t_laipm default sy-datum+4(2). selection-screen end of line.selection-screen begin of line. selection-screen comment 1(30) lbl_a4 for field pa_anprj. PARAMETERS: pa_anprj TYPE p05t_cojvj. selection-screen end of line.selection-screen begin of line. selection-screen comment 1(30) lbl_a5 for field pa_perv. PARAMETERS: pa_perv TYPE p05t_laddpf default 1. selection-screen end of line.selection-screen begin of line. selection-screen comment 1(30) lbl_a6 for field pa_pert. PARAMETERS: pa_pert TYPE p05t_laddpt default 12. selection-screen end of line.selection-screen begin of line. PARAMETERS: pa_corr TYPE p05t_display_deltas as checkbox DEFAULT space MODIF ID RO. selection-screen comment 3(28) lbl_a7 for field pa_corr. selection-screen end of line. selection-screen skip. selection-screen begin of line. parameters: pa_locl as checkbox. selection-screen comment 3(28) lbl_03 for field pa_filen. parameters: pa_filen type c length 100 lower case visible length 56. selection-screen end of line. selection-screen begin of line. parameters: pa_serv as checkbox. selection-screen comment 3(28) lbl_04 for field pa_file2. parameters: pa_file2 type c length 100 lower case visible length 56. selection-screen end of line. selection-screen begin of line. parameters: pa_appen as checkbox. selection-screen comment 3(28) lbl_05 for field pa_appen. selection-screen end of line. data: lw_juper like line of so_juper. at selection-screen on value-request for pa_filen. lcl_f4_processing=>f4_presentation_file( exporting title = 'Choose file' changing filepath = pa_filen ). at selection-screen on value-request for pa_file2. lcl_f4_processing=>f4_server_file( changing filepath = pa_file2 ). AT SELECTION-SCREEN on pa_filen. if not pa_filen is initial and not ( pa_filen cp '*.txt' or pa_filen cp '*.csv' or pa_filen cp '*.TXT' or pa_filen cp '*.CSV' ). message 'Bestandsnaam moet eindigen op .txt or .csv' type 'E'. endif. *--------------------------------------------------------------------- * A T S E L E C T I O N - S C R E E N O U T P U T *--------------------------------------------------------------------- at selection-screen output. if pa_filen is initial and sy-batch is initial. data: lv_filename type string. cl_gui_frontend_services=>directory_get_current( changing current_directory = lv_filename ). cl_gui_cfw=>flush( ). concatenate lv_filename 'RPLLAEN0_{S}_{P}_{D}_{T}.txt' into pa_filen separated by '\'. endif. if pa_file2 is initial. data: lw_pars type spfpflpar, lv_separator type c length 1. lw_pars-parname = 'DIR_HOME'. call function 'RSAN_SYSTEM_PARAMETER_READ' exporting i_name = lw_pars-parname importing e_value = lw_pars-pvalue exceptions others = 0. lv_separator = lw_pars-pvalue(1). if lv_separator <> '/'. lv_separator = '\'. endif. concatenate lw_pars-pvalue 'RPLLAEN0_{S}_{D}_{T}.txt' into pa_file2 separated by lv_separator. endif. loop at screen. if screen-group1 = 'RO'. screen-input = 0. MODIFY SCREEN. endif. endloop. * Restrict the select-options for the JUPER field, no ranges allowed! * Auxiliary objects for filling i_RESTRICT DATA: lw_optlist TYPE sscr_opt_list, lw_ass TYPE sscr_ass, * Define the object to be passed to the RESTRICTION parameter lw_restrict TYPE sscr_restrict. clear: lw_optlist, lw_ass, lw_restrict-opt_list_tab[], lw_restrict-ass_tab[], lw_restrict. lw_optlist-name = 'NO_RANGES'. "Name of the option set lw_optlist-options-eq = 'X'. "Only available option APPEND lw_optlist TO lw_restrict-opt_list_tab. lw_ass-kind = 'S'. "type: Select-option lw_ass-name = 'SO_JUPER'. "Name of the select option lw_ass-sg_main = 'I'. lw_ass-sg_addy = space. lw_ass-op_main = 'NO_RANGES'. "Option set to apply APPEND lw_ass TO lw_restrict-ass_tab. CALL FUNCTION 'SELECT_OPTIONS_RESTRICT' EXPORTING RESTRICTION = lw_restrict EXCEPTIONS OTHERS = 0. *--------------------------------------------------------------------- * C L A S S I M P L E M E N T A T I O N *--------------------------------------------------------------------- class lcl_f4_processing implementation. method f4_presentation_file. data: lt_files type standard table of sdokpath, lw_file type sdokpath. call function 'TMP_GUI_FILE_OPEN_DIALOG' exporting window_title = title default_filename = filepath tables file_table = lt_files exceptions others = 4. if sy-subrc <> 0. message 'Front end file open error' type 'E'. else. read table lt_files index 1 into lw_file. filepath = lw_file-pathname. endif. endmethod. "f4_presentation_file method f4_server_file. data: lv_old_filepath type string. lv_old_filepath = filepath. call function '/SAPDMC/LSM_F4_SERVER_FILE' exporting directory = filepath filemask = ' ' importing serverfile = filepath exceptions canceled_by_user = 1 others = 2. case sy-subrc. when 1. filepath = lv_old_filepath. when 2. message 'Server file open error' type 'E'. endcase. endmethod. "f4_server_file endclass. "lcl_f4_processing IMPLEMENTATION *--------------------------------------------------------------------- * I N I T I A L I Z A T I O N *--------------------------------------------------------------------- initialization. * All texts for this report have been set up as hard-coded texts (no use * of the report text-pool). Reason: easy copying of report source code. * lbl_01 = 'Rapportage'. lbl_a1 = 'Rechtspersonen'. lbl_a2 = 'In-periode jaar'. lbl_a3 = 'In-periode maand'. lbl_a4 = 'Losse cor. jaar'. lbl_a5 = 'Periode van'. lbl_a6 = 'Periode tot'. lbl_a7 = 'Verschillen weergeven'. lbl_03 = 'Lokaal opslaan'. lbl_04 = 'Opslaan op de server'. lbl_05 = 'Toevoegen aan bestand'. *--------------------------------------------------------------------- * S T A R T - O F - S E L E C T I O N *--------------------------------------------------------------------- start-of-selection. clear: gt_lines_all[], lw_header_line, lv_Afwijkende_indeling. * Execute these steps for every JUPER available: loop at so_juper into lw_juper. clear: gt_abaplist[], gt_lines[]. * Clear the last list(s) from memory (to avoid picking up an old list) call function 'LIST_FREE_MEMORY'. * Run the report using the specified variant, return results write lw_juper-low to lw_pa_juper RIGHT-JUSTIFIED. submit RPLLAEN0 with pa_juper = lw_pa_juper with pa_year = pa_year with pa_inper = pa_inper with pa_anprj = pa_anprj with pa_perv = pa_perv with pa_pert = pa_pert with pa_corr = pa_corr exporting list to memory and return. * List output from memory into ABAPLIST - transform into readable form call function 'LIST_FROM_MEMORY' tables listobject = gt_abaplist exceptions others = 4. if sy-subrc <> 0. message 'Submit failed - no output could be found' type 'S'. else. * Transform to more readable format call function 'LIST_TO_ASCI' exporting with_line_break = 'X' tables listasci = gt_lines listobject = gt_abaplist exceptions others = 0. * Process the title line, from which 2 bits of info are derived: read table gt_lines index 1 into gw_line. delete gt_lines index 1. condense gw_line. if sy-langu = 'E'. split gw_line at space into lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-aansluitnummer lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-rechtspersoon lw_tokenizer-dummy. else. split gw_line at space into lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-aansluitnummer lw_tokenizer-dummy lw_tokenizer-dummy lw_tokenizer-rechtspersoon lw_tokenizer-dummy. endif. * Remove the vertical lines loop at gt_lines into gw_line. if gw_line cs '--------'. delete gt_lines. endif. endloop. read table gt_lines index 1 into gw_line. CONDENSE gw_line NO-GAPS. if lw_header_line = gw_line. delete gt_lines index 1. "< this is where irrelevant ;0; lines are removed clear lv_columnheaderline. else. if not lw_header_line is initial and sy-batch = space. lv_Afwijkende_indeling = abap_true. endif. lw_header_line = gw_line. lv_columnheaderline = 1. endif. * The option to process Query output into a .csv file: describe table gt_lines lines lv_lastline. loop at gt_lines into gw_line. lv_tabix = sy-tabix. REPLACE ALL OCCURRENCES OF ';' IN gw_line WITH ','. REPLACE ALL OCCURRENCES OF '|' IN gw_line WITH ';'. if lv_tabix = lv_columnheaderline. * The line contains fields with mm-yyyy, which should be altered to yyyy-mm: split gw_line at ';' into TABLE lt_tokens. clear gw_line. loop at lt_tokens into lw_tokenizer-dummy. shift lw_tokenizer-dummy LEFT DELETING LEADING space. split lw_tokenizer-dummy at '-' into lw_tokenizer-month lw_tokenizer-year. if not lw_tokenizer-year is initial. concatenate lw_tokenizer-year lw_tokenizer-month into lw_tokenizer-dummy SEPARATED BY '-'. endif. concatenate gw_line lw_tokenizer-dummy into gw_line SEPARATED BY ';'. endloop. gw_line = gw_line+1. "Remove the first character (;) concatenate 'Rechtspersoon' ';' 'Aansluitnummer' ';' '0' gw_line ';' into gw_line. elseif lv_tabix = lv_lastline. concatenate lw_tokenizer-rechtspersoon ';' lw_tokenizer-aansluitnummer ';' '2' gw_line into gw_line. else. concatenate lw_tokenizer-rechtspersoon ';' lw_tokenizer-aansluitnummer ';' '1' gw_line into gw_line. endif. modify gt_lines from gw_line. endloop. endif. append lines of gt_lines to gt_lines_all. endloop. if lv_Afwijkende_indeling = abap_true. message 'Afwijkende indeling weergaves periodes' type 'I'. endif. *--------------------------------------------------------------------- * Prepare path and filename concatenate sy-sysid sy-mandt into lv_system separated by '_'. condense lv_system no-gaps. lv_system_str = lv_system. concatenate pa_year pa_inper into lv_period. *--------------------------------------------------------------------- if pa_locl = 'X'. move pa_filen to gv_dataset. replace '{S}' with lv_system_str into gv_dataset. replace '{D}' with sy-datum into gv_dataset. replace '{T}' with sy-uzeit into gv_dataset. replace '{H}' with sy-uzeit(2) into gv_dataset. replace '{M}' with sy-uzeit+2(2) into gv_dataset. replace '{P}' with lv_period into gv_dataset. call function 'GUI_DOWNLOAD' exporting filename = gv_dataset filetype = 'ASC' append = pa_appen tables data_tab = gt_lines_all exceptions others = 4. if sy-subrc <> 0. message 'Save failed' type 'S'. endif. endif. *--------------------------------------------------------------------- if pa_serv = 'X'. move pa_file2 to gv_dataset. replace '{S}' with lv_system_str into gv_dataset. replace '{D}' with sy-datum into gv_dataset. replace '{T}' with sy-uzeit into gv_dataset. replace '{H}' with sy-uzeit(2) into gv_dataset. replace '{M}' with sy-uzeit+2(2) into gv_dataset. replace '{P}' with lv_period into gv_dataset. if pa_appen = space. OPEN DATASET gv_dataset FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. else. OPEN DATASET gv_dataset FOR APPENDING IN TEXT MODE ENCODING DEFAULT. endif. if sy-subrc = 0. loop at gt_lines_all into gw_line. transfer gw_line to gv_dataset. endloop. close dataset gv_dataset. else. message 'Could not open server file' type 'S'. endif. endif. *--------------------------------------------------------------------- if pa_locl is initial and pa_serv is initial. "Dump on the screen loop at gt_lines_all into gw_line. write: / gw_line. endloop. endif.