*----------------------------------------------------------------------* * DECLARATIONS * *----------------------------------------------------------------------* DATA: gt_fcat TYPE lvc_t_fcat, gs_fcat TYPE lvc_s_fcat. FIELD-SYMBOLS: <gf_table> TYPE STANDARD TABLE, <gf_line> TYPE any, <gf_campo> TYPE any. *----------------------------------------------------------------------* * LAYOUT * *----------------------------------------------------------------------* SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001. PARAMETERS: pa_begda TYPE begda OBLIGATORY, pa_endda TYPE endda OBLIGATORY, pa_kurst TYPE kurst OBLIGATORY, pa_fname TYPE string LOWER CASE, pa_fout TYPE localfile. SELECTION-SCREEN END OF BLOCK b1. *----------------------------------------------------------------------* * EVENTS * *----------------------------------------------------------------------* AT SELECTION-SCREEN OUTPUT. pa_fname = 'Exchange_Rates.csv'. CONCATENATE '/IFR/' sy-sysid '/EXPORT/' INTO pa_fout. *----------------------------------------------------------------------* * PROGRAM BODY * *----------------------------------------------------------------------* START-OF-SELECTION. PERFORM get_data. END-OF-SELECTION. PERFORM save_remote. *----------------------------------------------------------------------* * FORM GET_DATA * *----------------------------------------------------------------------* FORM get_data. DATA: lv_col_pos TYPE i, lt_newtable TYPE REF TO data, lt_newline TYPE REF TO data, lr_waers TYPE RANGE OF waers, lv_datum TYPE datum, lv_gdatu TYPE gdatu_inv, lv_dest(6) TYPE c. DATA: BEGIN OF lt_tcurr OCCURS 0. INCLUDE STRUCTURE tcurr. DATA: END OF lt_tcurr. SELECT sign opti low high FROM tvarvc INTO TABLE lr_waers WHERE name = 'ZCUKY' AND type = 'S'. ADD 1 TO lv_col_pos. gs_fcat-col_pos = lv_col_pos. gs_fcat-fieldname = 'KTEXT'. gs_fcat-tabname = 'ITAB'. gs_fcat-key = 'X'. gs_fcat-emphasize = 'K41'. gs_fcat-datatype = 'CHAR'. gs_fcat-inttype = 'C'. gs_fcat-intlen = '15'. gs_fcat-lowercase = 'X'. gs_fcat-reptext = 'valuta target'. gs_fcat-domname = 'TEXT15'. gs_fcat-dd_outlen = '15'. gs_fcat-scrtext_l = 'Target currency'. gs_fcat-scrtext_m = 'Target currency'. gs_fcat-scrtext_s = 'Target currency'. APPEND gs_fcat TO gt_fcat. LOOP AT lr_waers INTO DATA(ls_waers). ADD 1 TO lv_col_pos. gs_fcat-col_pos = lv_col_pos. gs_fcat-fieldname = ls_waers-low. gs_fcat-datatype = 'DEC'. gs_fcat-inttype = 'P'. gs_fcat-intlen = '9'. gs_fcat-lowercase = ''. gs_fcat-reptext = ls_waers-low. gs_fcat-domname = 'UKURS'. gs_fcat-dd_outlen = '12'. gs_fcat-decimals = '5'. gs_fcat-scrtext_l = ls_waers-low. gs_fcat-scrtext_m = ls_waers-low. gs_fcat-scrtext_s = ls_waers-low. APPEND gs_fcat TO gt_fcat. ENDLOOP. ADD 1 TO lv_col_pos. gs_fcat-col_pos = lv_col_pos. gs_fcat-fieldname = 'DATUM'. gs_fcat-datatype = 'DATS'. gs_fcat-inttype = 'D'. gs_fcat-intlen = '8'. gs_fcat-reptext = 'Date'. gs_fcat-domname = 'DATUM'. gs_fcat-dd_outlen = '10'. gs_fcat-decimals = '0'. gs_fcat-scrtext_l = 'Date'. gs_fcat-scrtext_m = 'Date'. gs_fcat-scrtext_s = 'Date'. APPEND gs_fcat TO gt_fcat. CALL METHOD cl_alv_table_create=>create_dynamic_table EXPORTING it_fieldcatalog = gt_fcat IMPORTING ep_table = lt_newtable EXCEPTIONS generate_subpool_dir_full = 1 OTHERS = 2. IF sy-subrc IS INITIAL. ASSIGN lt_newtable->* TO <gf_table>. ENDIF. APPEND INITIAL LINE TO <gf_table>. CREATE DATA lt_newline LIKE LINE OF <gf_table>. ASSIGN lt_newline->* TO <gf_line>. CASE sy-sysid. WHEN 'PRD'. lv_dest = 'PRD001'. WHEN 'DEV'. lv_dest = 'DEV001'. WHEN OTHERS. lv_dest = 'QAS001'. ENDCASE. CALL FUNCTION 'ZFM_READ_TCURR' DESTINATION lv_dest EXPORTING i_kurst = pa_kurst i_tcurr = 'EUR' i_begda = pa_begda i_endda = pa_endda TABLES t_tcurr = lt_tcurr. DELETE lt_tcurr WHERE fcurr NOT IN lr_waers. lv_datum = pa_begda. WHILE lv_datum <= pa_endda. CONVERT DATE lv_datum INTO INVERTED-DATE lv_gdatu. LOOP AT lt_tcurr INTO DATA(ls_tcurr) WHERE gdatu = lv_gdatu. ASSIGN COMPONENT ls_tcurr-fcurr OF STRUCTURE <gf_line> TO <gf_campo>. IF ls_tcurr-ukurs < 0. <gf_campo> = ls_tcurr-ukurs * -1. ENDIF. IF ls_tcurr-ffact > 1. <gf_campo> = ls_tcurr-ukurs * ls_tcurr-ffact. ENDIF. IF ls_tcurr-tfact > 1. <gf_campo> = ls_tcurr-ukurs * ls_tcurr-tfact. ENDIF. ENDLOOP. IF <gf_campo> IS ASSIGNED. ASSIGN COMPONENT 'KTEXT' OF STRUCTURE <gf_line> TO <gf_campo>. <gf_campo> = 'Euro'. ASSIGN COMPONENT 'DATUM' OF STRUCTURE <gf_line> TO <gf_campo>. <gf_campo> = lv_datum. APPEND <gf_line> TO <gf_table>. ENDIF. CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL' EXPORTING date = lv_datum days = 1 months = 0 signum = '+' years = 0 IMPORTING calc_date = lv_datum. UNASSIGN <gf_campo>. ENDWHILE. DELETE <gf_table> INDEX 1. ENDFORM. *----------------------------------------------------------------------* * FORM SAVE_REMOTE * *----------------------------------------------------------------------* FORM save_remote. DATA: lt_exec_protocol TYPE TABLE OF btcxpm, lv_file TYPE btcxpgpar, lv_localfile TYPE localfile, lv_line TYPE string, lv_char(10), lv_index TYPE i, lv_type TYPE c. CONCATENATE pa_fout pa_fname INTO lv_localfile. OPEN DATASET lv_localfile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT. LOOP AT gt_fcat INTO gs_fcat. CONCATENATE lv_line '"' gs_fcat-scrtext_l '"' ';' INTO lv_line. ENDLOOP. TRANSFER lv_line TO lv_localfile. CLEAR lv_line. LOOP AT <gf_table> ASSIGNING <gf_line>. DO. ADD 1 TO lv_index. ASSIGN COMPONENT lv_index OF STRUCTURE <gf_line> TO <gf_campo>. IF sy-subrc = 0. CLEAR lv_type. DESCRIBE FIELD <gf_campo> TYPE lv_type. CASE lv_type. WHEN 'P'. lv_char = <gf_campo>. TRANSLATE lv_char USING '.,'. CONDENSE lv_char. CONCATENATE lv_line '"' lv_char '"' ';' INTO lv_line. WHEN 'D'. CONCATENATE lv_line '"' <gf_campo>+6(2) '/' <gf_campo>+4(2) '/' <gf_campo>+0(4) '"' ';' INTO lv_line. WHEN OTHERS. CONCATENATE lv_line '"' <gf_campo> '"' ';' INTO lv_line. ENDCASE. ELSE. CLEAR lv_index. EXIT. ENDIF. ENDDO. TRANSFER lv_line TO lv_localfile. CLEAR lv_line. ENDLOOP. CLOSE DATASET lv_localfile. lv_file = lv_localfile. CALL FUNCTION 'SXPG_CALL_SYSTEM' EXPORTING commandname = 'ZCHMOD777' additional_parameters = lv_file TABLES exec_protocol = lt_exec_protocol. WRITE 'File correctly exported'. ENDFORM. *----------------------------------------------------------------------*
lunedì 26 ottobre 2020
Creazione dinamica di tabelle interne
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento