Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method GET_VALUE_TYPE of class ZCL_EXCEL_WORKSHEET causes problems when converted value doesn't fit in the import field #320

Closed
gregorwolf opened this issue May 2, 2014 · 4 comments · Fixed by #982
Assignees

Comments

@gregorwolf
Copy link
Collaborator

In the demo report ZDEMO_EXCEL33 the table T005T is used to provide the sample data. It has the column SPRAS with the data type SPRAS which is only one character long. For this field the conversion exit CONVERSION_EXIT_ISOLA_OUTPUT is found in method GET_VALUE_TYPE of class ZCL_EXCEL_WORKSHEET. That causes the input value i.e. 'D' to be converted to 'DE'. But as the input value is the template for the value which holds the output of method GET_VALUE_TYPE in method SET_CELL

First we get reference into local var.
CREATE DATA lo_value LIKE ip_value.
ASSIGN lo_value->
TO <fs_value>.
<fs_value> = ip_value.

the result in <fs_value> is again 'D'. That is no problem with German or English. But if the input language is Bulgarian where the SAP language code is 'W' then the conversion exit returns 'BG' which is stored in the Excel file as 'B'. When this value is read back from Excel to ABAP the 'B' will be interpreted as the SAP language code and will result in Hebrew.

Here you can find some SAP language codes: http://help.sap.com/saphelp_nw04/helpdata/en/c1/ae563cd2ad4f0ce10000000a11402f/content.htm

Please let's discuss how we tackle this problem.

@rplantiko
Copy link
Contributor

The problem here is that the result of an CONVERSION_EXIT...OUTPUT was expected to have the same datatype as the source element. But actually the result of the OUTPUT conversion is of type C (representing the text field on a screen which represents the data for a human), like the field lv_target in

WRITE LV_SOURCE TO LV_TARGET USING EDIT MASK '==ALPHA'

(e.g. for conversion exit ALPHA). (By the way - how about engaging this write to ... using edit mask idiom in method get_value_type for simplicification of code, instead of determining the exit function module and calling it explicitly?)

In other cases, when there is no conversion exit present, it seems desired by the author of class ZCL_EXCEL_WORKSHEET to have the output type to be equal the input type.

For a correction, I would therefore suggest not to import the field-symbol holding the result as parameter to GET_VALUE_TYPE in the implementation of SET_CELL - as it is now:

        get_value_type( EXPORTING ip_value      = ip_value
                        IMPORTING ep_value      = <fs_value>
                                  ep_value_type = lv_value_type ). 

but instead to pass the reference to the result data object as a changing parameter :

        get_value_type( EXPORTING ip_value      = ip_value
                        IMPORTING ep_value_type = lv_value_type
                        CHANGING co_value = lo_value ).
        assign lo_value->* to <fs_value>.

This way, the data reference can be switched in the method GET_VALUE_TYPE if necessary. Observe that in this proposal the assign to the field-symbol has to be performed after the call of GET_VALUE_TYPE.

In the implementation of GET_VALUE_TYPE, once the conversion exit case is detected, you can change co_value to a reference to a type C field with the field's output-length (you can determine the output-length with the describe field statement).

describe field ip_value output-length lv_olen.
create data co_value type c length lv_olen.

Then, still in the GET_VALUE_TYPE implementation, assign the new reference to a field-symbol of type C (or any) and import the result of the conversion exit call into that field symbol.

So far for my proposal. Hope it helps.

@ivanfemia
Copy link
Collaborator

Is this issue fixed?

@StefanSchmoecker
Copy link
Contributor

Not really - the problem ist deeper and will arise again if we face complex/unexpected conversion exits.
First thing that comes to mind is the conversion exit for wbs-elements which converts from an 8-digit numerical value to a 24-character output.
I fear a closer inspection is still needed before this can be settled

@sandraros
Copy link
Collaborator

Proposing solution #982.
So that abap2xlsx behaves by default the same as before, let's add new parameters and options. If the new behavior is selected, abap2xlsx uses the output length if a conversion exit is defined:

  • ZCL_EXCEL_WORKSHEET: new parameter for SET_CELL and BIND_TABLE
  • ZCL_EXCEL_COMMON: new parameter for GET_FIELDCATALOG
  • ZCL_EXCEL_CONVERTER: new field in the options of SET_OPTION
  • ZDEMO_EXCEL33: new checkbox to use the output length (the language column is output on 2 characters, like "EN" instead of "E"). ZDEMO_EXCEL33 is using ZCL_EXCEL_CONVERTER.
    image
  • ZDEMO_EXCEL49: new demo program to show the output length and conversion exit with BIND_TABLE.
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants