mirror of
https://github.com/abap2xlsx/abap2xlsx.git
synced 2025-05-05 13:46:17 +08:00
Convert currency amount to external format (#1147)
Fix #1145 * Convert currency amount to external format Fetching currency reference field from ALV and use the value from this field convert the value to external format * Missing field catalog update * Little changes proposed * Code best positioned, delete unused declaration Latest changes proposed by darnoc312
This commit is contained in:
parent
ccda3a0aa8
commit
c1a20e870b
|
@ -133,6 +133,7 @@ CLASS zcl_excel_common DEFINITION
|
||||||
CLASS-METHODS number_to_excel_string
|
CLASS-METHODS number_to_excel_string
|
||||||
IMPORTING
|
IMPORTING
|
||||||
VALUE(ip_value) TYPE numeric
|
VALUE(ip_value) TYPE numeric
|
||||||
|
ip_currency TYPE waers_curc OPTIONAL
|
||||||
RETURNING
|
RETURNING
|
||||||
VALUE(ep_value) TYPE zexcel_cell_value .
|
VALUE(ep_value) TYPE zexcel_cell_value .
|
||||||
CLASS-METHODS recursive_class_to_struct
|
CLASS-METHODS recursive_class_to_struct
|
||||||
|
@ -944,6 +945,15 @@ CLASS zcl_excel_common IMPLEMENTATION.
|
||||||
<fcat>-scrtext_s = ls_salv_t_column_ref-r_column->get_short_text( ).
|
<fcat>-scrtext_s = ls_salv_t_column_ref-r_column->get_short_text( ).
|
||||||
<fcat>-scrtext_m = ls_salv_t_column_ref-r_column->get_medium_text( ).
|
<fcat>-scrtext_m = ls_salv_t_column_ref-r_column->get_medium_text( ).
|
||||||
<fcat>-scrtext_l = ls_salv_t_column_ref-r_column->get_long_text( ).
|
<fcat>-scrtext_l = ls_salv_t_column_ref-r_column->get_long_text( ).
|
||||||
|
<fcat>-currency_column = ls_salv_t_column_ref-r_column->get_currency_column( ).
|
||||||
|
" If currency column not in structure then clear the field again
|
||||||
|
IF <fcat>-currency_column IS NOT INITIAL.
|
||||||
|
READ TABLE lt_salv_t_column_ref WITH KEY columnname = <fcat>-currency_column TRANSPORTING NO FIELDS.
|
||||||
|
IF sy-subrc <> 0.
|
||||||
|
CLEAR <fcat>-currency_column.
|
||||||
|
ENDIF.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
IF ip_conv_exit_length = abap_false.
|
IF ip_conv_exit_length = abap_false.
|
||||||
<fcat>-abap_type = lo_salv_column_table->get_ddic_inttype( ).
|
<fcat>-abap_type = lo_salv_column_table->get_ddic_inttype( ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
@ -1007,7 +1017,11 @@ CLASS zcl_excel_common IMPLEMENTATION.
|
||||||
METHOD number_to_excel_string.
|
METHOD number_to_excel_string.
|
||||||
DATA: lv_value_c TYPE c LENGTH 100.
|
DATA: lv_value_c TYPE c LENGTH 100.
|
||||||
|
|
||||||
|
IF ip_currency IS INITIAL.
|
||||||
WRITE ip_value TO lv_value_c EXPONENT 0 NO-GROUPING NO-SIGN.
|
WRITE ip_value TO lv_value_c EXPONENT 0 NO-GROUPING NO-SIGN.
|
||||||
|
ELSE.
|
||||||
|
WRITE ip_value TO lv_value_c EXPONENT 0 NO-GROUPING NO-SIGN CURRENCY ip_currency.
|
||||||
|
ENDIF.
|
||||||
REPLACE ALL OCCURRENCES OF ',' IN lv_value_c WITH '.'.
|
REPLACE ALL OCCURRENCES OF ',' IN lv_value_c WITH '.'.
|
||||||
|
|
||||||
ep_value = lv_value_c.
|
ep_value = lv_value_c.
|
||||||
|
@ -1691,4 +1705,5 @@ CLASS zcl_excel_common IMPLEMENTATION.
|
||||||
|
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
ENDCLASS.
|
ENDCLASS.
|
||||||
|
|
|
@ -45,6 +45,9 @@ CLASS lcl_excel_common_test DEFINITION FOR TESTING
|
||||||
METHODS date_to_excel_string4 FOR TESTING RAISING cx_static_check.
|
METHODS date_to_excel_string4 FOR TESTING RAISING cx_static_check.
|
||||||
METHODS date_to_excel_string5 FOR TESTING RAISING cx_static_check.
|
METHODS date_to_excel_string5 FOR TESTING RAISING cx_static_check.
|
||||||
METHODS date_to_excel_string6 FOR TESTING RAISING cx_static_check.
|
METHODS date_to_excel_string6 FOR TESTING RAISING cx_static_check.
|
||||||
|
METHODS amount_to_excel_string1 FOR TESTING RAISING cx_static_check.
|
||||||
|
METHODS amount_to_excel_string2 FOR TESTING RAISING cx_static_check.
|
||||||
|
METHODS amount_to_excel_string3 FOR TESTING RAISING cx_static_check.
|
||||||
METHODS: encrypt_password FOR TESTING.
|
METHODS: encrypt_password FOR TESTING.
|
||||||
METHODS: excel_string_to_date FOR TESTING.
|
METHODS: excel_string_to_date FOR TESTING.
|
||||||
METHODS excel_string_to_time1 FOR TESTING RAISING cx_static_check.
|
METHODS excel_string_to_time1 FOR TESTING RAISING cx_static_check.
|
||||||
|
@ -467,6 +470,47 @@ CLASS lcl_excel_common_test IMPLEMENTATION.
|
||||||
|
|
||||||
ENDMETHOD.
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD amount_to_excel_string1.
|
||||||
|
DATA ep_value TYPE zexcel_cell_value.
|
||||||
|
|
||||||
|
ep_value = zcl_excel_common=>number_to_excel_string( ip_value = '1003.99'
|
||||||
|
ip_currency = 'EUR' ).
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = ep_value
|
||||||
|
exp = '1003.99'
|
||||||
|
msg = 'Wrong currency amount conversion'
|
||||||
|
level = if_aunit_constants=>critical ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD amount_to_excel_string2.
|
||||||
|
DATA ep_value TYPE zexcel_cell_value.
|
||||||
|
|
||||||
|
ep_value = zcl_excel_common=>number_to_excel_string( ip_value = '-1003.99'
|
||||||
|
ip_currency = 'HUF' ).
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = ep_value
|
||||||
|
exp = '-100399'
|
||||||
|
msg = 'Wrong currency amount conversion'
|
||||||
|
level = if_aunit_constants=>critical ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
|
METHOD amount_to_excel_string3.
|
||||||
|
DATA ep_value TYPE zexcel_cell_value.
|
||||||
|
|
||||||
|
ep_value = zcl_excel_common=>number_to_excel_string( ip_value = '0'
|
||||||
|
ip_currency = 'HUF' ).
|
||||||
|
|
||||||
|
cl_abap_unit_assert=>assert_equals(
|
||||||
|
act = ep_value
|
||||||
|
exp = '0'
|
||||||
|
msg = 'Wrong currency amount conversion'
|
||||||
|
level = if_aunit_constants=>critical ).
|
||||||
|
|
||||||
|
ENDMETHOD.
|
||||||
|
|
||||||
METHOD encrypt_password.
|
METHOD encrypt_password.
|
||||||
* ========================
|
* ========================
|
||||||
|
|
|
@ -172,6 +172,7 @@ CLASS zcl_excel_worksheet DEFINITION
|
||||||
VALUE(iv_default_descr) TYPE c OPTIONAL
|
VALUE(iv_default_descr) TYPE c OPTIONAL
|
||||||
!iv_no_line_if_empty TYPE abap_bool DEFAULT abap_false
|
!iv_no_line_if_empty TYPE abap_bool DEFAULT abap_false
|
||||||
!ip_conv_exit_length TYPE abap_bool DEFAULT abap_false
|
!ip_conv_exit_length TYPE abap_bool DEFAULT abap_false
|
||||||
|
!ip_conv_curr_amt_ext TYPE abap_bool DEFAULT abap_false
|
||||||
EXPORTING
|
EXPORTING
|
||||||
!es_table_settings TYPE zexcel_s_table_settings
|
!es_table_settings TYPE zexcel_s_table_settings
|
||||||
RAISING
|
RAISING
|
||||||
|
@ -499,6 +500,7 @@ CLASS zcl_excel_worksheet DEFINITION
|
||||||
!ip_hyperlink TYPE REF TO zcl_excel_hyperlink OPTIONAL
|
!ip_hyperlink TYPE REF TO zcl_excel_hyperlink OPTIONAL
|
||||||
!ip_data_type TYPE zexcel_cell_data_type OPTIONAL
|
!ip_data_type TYPE zexcel_cell_data_type OPTIONAL
|
||||||
!ip_abap_type TYPE abap_typekind OPTIONAL
|
!ip_abap_type TYPE abap_typekind OPTIONAL
|
||||||
|
!ip_currency TYPE waers_curc OPTIONAL
|
||||||
!it_rtf TYPE zexcel_t_rtf OPTIONAL
|
!it_rtf TYPE zexcel_t_rtf OPTIONAL
|
||||||
!ip_column_formula_id TYPE mty_s_column_formula-id OPTIONAL
|
!ip_column_formula_id TYPE mty_s_column_formula-id OPTIONAL
|
||||||
!ip_conv_exit_length TYPE abap_bool DEFAULT abap_false
|
!ip_conv_exit_length TYPE abap_bool DEFAULT abap_false
|
||||||
|
@ -975,7 +977,8 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
|
|
||||||
CONSTANTS:
|
CONSTANTS:
|
||||||
lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'A',
|
lc_top_left_column TYPE zexcel_cell_column_alpha VALUE 'A',
|
||||||
lc_top_left_row TYPE zexcel_cell_row VALUE 1.
|
lc_top_left_row TYPE zexcel_cell_row VALUE 1,
|
||||||
|
lc_no_currency TYPE waers_curc VALUE IS INITIAL.
|
||||||
|
|
||||||
DATA:
|
DATA:
|
||||||
lv_row_int TYPE zexcel_cell_row,
|
lv_row_int TYPE zexcel_cell_row,
|
||||||
|
@ -1001,7 +1004,8 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
<ls_field_catalog> TYPE zexcel_s_fieldcatalog,
|
<ls_field_catalog> TYPE zexcel_s_fieldcatalog,
|
||||||
<ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog,
|
<ls_field_catalog_custom> TYPE zexcel_s_fieldcatalog,
|
||||||
<fs_table_line> TYPE any,
|
<fs_table_line> TYPE any,
|
||||||
<fs_fldval> TYPE any.
|
<fs_fldval> TYPE any,
|
||||||
|
<fs_fldval_currency> TYPE waers.
|
||||||
|
|
||||||
ls_settings = is_table_settings.
|
ls_settings = is_table_settings.
|
||||||
|
|
||||||
|
@ -1100,6 +1104,7 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
LOOP AT ip_table ASSIGNING <fs_table_line>.
|
LOOP AT ip_table ASSIGNING <fs_table_line>.
|
||||||
|
|
||||||
ASSIGN COMPONENT <ls_field_catalog>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>.
|
ASSIGN COMPONENT <ls_field_catalog>-fieldname OF STRUCTURE <fs_table_line> TO <fs_fldval>.
|
||||||
|
|
||||||
" issue #290 Add formula support in table
|
" issue #290 Add formula support in table
|
||||||
IF <ls_field_catalog>-formula EQ abap_true.
|
IF <ls_field_catalog>-formula EQ abap_true.
|
||||||
IF <ls_field_catalog>-style IS NOT INITIAL.
|
IF <ls_field_catalog>-style IS NOT INITIAL.
|
||||||
|
@ -1151,18 +1156,26 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
ip_column_formula_id = ls_column_formula-id ).
|
ip_column_formula_id = ls_column_formula-id ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
ELSE.
|
ELSE.
|
||||||
|
IF <ls_field_catalog>-currency_column IS INITIAL OR ip_conv_curr_amt_ext = abap_false.
|
||||||
|
ASSIGN lc_no_currency TO <fs_fldval_currency>.
|
||||||
|
ELSE.
|
||||||
|
ASSIGN COMPONENT <ls_field_catalog>-currency_column OF STRUCTURE <fs_table_line> TO <fs_fldval_currency>.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
IF <ls_field_catalog>-style IS NOT INITIAL.
|
IF <ls_field_catalog>-style IS NOT INITIAL.
|
||||||
IF <ls_field_catalog>-abap_type IS NOT INITIAL.
|
IF <ls_field_catalog>-abap_type IS NOT INITIAL.
|
||||||
me->set_cell( ip_column = lv_column_alpha
|
me->set_cell( ip_column = lv_column_alpha
|
||||||
ip_row = lv_row_int
|
ip_row = lv_row_int
|
||||||
ip_value = <fs_fldval>
|
ip_value = <fs_fldval>
|
||||||
ip_abap_type = <ls_field_catalog>-abap_type
|
ip_abap_type = <ls_field_catalog>-abap_type
|
||||||
|
ip_currency = <fs_fldval_currency>
|
||||||
ip_style = <ls_field_catalog>-style
|
ip_style = <ls_field_catalog>-style
|
||||||
ip_conv_exit_length = ip_conv_exit_length ).
|
ip_conv_exit_length = ip_conv_exit_length ).
|
||||||
ELSE.
|
ELSE.
|
||||||
me->set_cell( ip_column = lv_column_alpha
|
me->set_cell( ip_column = lv_column_alpha
|
||||||
ip_row = lv_row_int
|
ip_row = lv_row_int
|
||||||
ip_value = <fs_fldval>
|
ip_value = <fs_fldval>
|
||||||
|
ip_currency = <fs_fldval_currency>
|
||||||
ip_style = <ls_field_catalog>-style
|
ip_style = <ls_field_catalog>-style
|
||||||
ip_conv_exit_length = ip_conv_exit_length ).
|
ip_conv_exit_length = ip_conv_exit_length ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
@ -1171,11 +1184,13 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
me->set_cell( ip_column = lv_column_alpha
|
me->set_cell( ip_column = lv_column_alpha
|
||||||
ip_row = lv_row_int
|
ip_row = lv_row_int
|
||||||
ip_abap_type = <ls_field_catalog>-abap_type
|
ip_abap_type = <ls_field_catalog>-abap_type
|
||||||
|
ip_currency = <fs_fldval_currency>
|
||||||
ip_value = <fs_fldval>
|
ip_value = <fs_fldval>
|
||||||
ip_conv_exit_length = ip_conv_exit_length ).
|
ip_conv_exit_length = ip_conv_exit_length ).
|
||||||
ELSE.
|
ELSE.
|
||||||
me->set_cell( ip_column = lv_column_alpha
|
me->set_cell( ip_column = lv_column_alpha
|
||||||
ip_row = lv_row_int
|
ip_row = lv_row_int
|
||||||
|
ip_currency = <fs_fldval_currency>
|
||||||
ip_value = <fs_fldval>
|
ip_value = <fs_fldval>
|
||||||
ip_conv_exit_length = ip_conv_exit_length ).
|
ip_conv_exit_length = ip_conv_exit_length ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
@ -3905,6 +3920,11 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
cl_abap_typedescr=>typekind_decfloat OR
|
cl_abap_typedescr=>typekind_decfloat OR
|
||||||
cl_abap_typedescr=>typekind_decfloat16 OR
|
cl_abap_typedescr=>typekind_decfloat16 OR
|
||||||
cl_abap_typedescr=>typekind_decfloat34.
|
cl_abap_typedescr=>typekind_decfloat34.
|
||||||
|
IF lv_value_type = cl_abap_typedescr=>typekind_packed
|
||||||
|
AND ip_currency IS NOT INITIAL.
|
||||||
|
lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_value>
|
||||||
|
ip_currency = ip_currency ).
|
||||||
|
ELSE.
|
||||||
lo_addit = cl_abap_elemdescr=>get_f( ).
|
lo_addit = cl_abap_elemdescr=>get_f( ).
|
||||||
CREATE DATA lo_value_new TYPE HANDLE lo_addit.
|
CREATE DATA lo_value_new TYPE HANDLE lo_addit.
|
||||||
ASSIGN lo_value_new->* TO <fs_numeric>.
|
ASSIGN lo_value_new->* TO <fs_numeric>.
|
||||||
|
@ -3912,6 +3932,7 @@ CLASS zcl_excel_worksheet IMPLEMENTATION.
|
||||||
<fs_numeric> = <fs_value>.
|
<fs_numeric> = <fs_value>.
|
||||||
lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ).
|
lv_value = zcl_excel_common=>number_to_excel_string( ip_value = <fs_numeric> ).
|
||||||
ENDIF.
|
ENDIF.
|
||||||
|
ENDIF.
|
||||||
|
|
||||||
WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string OR cl_abap_typedescr=>typekind_num OR
|
WHEN cl_abap_typedescr=>typekind_char OR cl_abap_typedescr=>typekind_string OR cl_abap_typedescr=>typekind_num OR
|
||||||
cl_abap_typedescr=>typekind_hex.
|
cl_abap_typedescr=>typekind_hex.
|
||||||
|
|
|
@ -117,6 +117,12 @@
|
||||||
<ADMINFIELD>0</ADMINFIELD>
|
<ADMINFIELD>0</ADMINFIELD>
|
||||||
<COMPTYPE>E</COMPTYPE>
|
<COMPTYPE>E</COMPTYPE>
|
||||||
</DD03P>
|
</DD03P>
|
||||||
|
<DD03P>
|
||||||
|
<FIELDNAME>CURRENCY_COLUMN</FIELDNAME>
|
||||||
|
<ROLLNAME>REFFIELD</ROLLNAME>
|
||||||
|
<ADMINFIELD>0</ADMINFIELD>
|
||||||
|
<COMPTYPE>E</COMPTYPE>
|
||||||
|
</DD03P>
|
||||||
</DD03P_TABLE>
|
</DD03P_TABLE>
|
||||||
<I18N_LANGS>
|
<I18N_LANGS>
|
||||||
<LANGU>1</LANGU>
|
<LANGU>1</LANGU>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user