Hey there!
I tried a little bit using nested reads.
The objective is to map fields of one (internal or normal) structure to a BAPI structure with the following access:
These are the reads to perform the access:
LOOP AT components_int INTO DATA(component_int).
CLEAR field.
field-int = component_int-fieldname.
TRY.
field-bapi = components_bapi[ fieldname = component_int-fieldname ]-fieldname.
field-origin = c_origin_fields_equal.
CATCH cx_sy_itab_line_not_found.
TRY.
field-bapi = components_bapi[ fieldname = component_int-deffdname ]-fieldname.
field-origin = c_origin_default_component.
CATCH cx_sy_itab_line_not_found.
TRY.
field-bapi = components_bapi[ rollname = component_int-rollname ]-fieldname.
field-origin = c_origin_rollname_equal.
CATCH cx_sy_itab_line_not_found.
field-origin = c_origin_no_match.
ENDTRY.
ENDTRY.
ENDTRY.
APPEND field TO fields.
ENDLOOP.
But I didn't like the nested TRY-CATCH commands and tried various other versions.
One version is the following nested VALUE - DEFAULT command:
field-bapi = VALUE #( components_bapi[ fieldname = component_int-fieldname ]-fieldname DEFAULT VALUE #( components_bapi[ fieldname = component_int-deffdname ]-fieldname DEFAULT VALUE #( components_bapi[ rollname = component_int-rollname ]-fieldname ) ) ).
But this version has an insuffiency: The information, which access level was found will not be transported.
therefore I tried the following:
field = VALUE #( bapi = VALUE #( components_bapi[ fieldname = component_int-fieldname ]-fieldname
DEFAULT VALUE ts_field( bapi = VALUE #( components_bapi[ fieldname = component_int-deffdname ]-fieldname
DEFAULT VALUE ts_field( bapi = VALUE #( components_bapi[ rollname = component_int-rollname ]-fieldname
DEFAULT VALUE ts_field( bapi = space origin = c_origin_no_match )
) origin = c_origin_rollname_equal )
) origin = c_origin_default_component )
) origin = c_origin_fields_equal ) .
But this version does not work. The origin fields equal will always be used.
And I do not find out, why... :(
Here is the complete code on github if you might want to test by yourself.
Disclaimer: I know that this version is totally confusing and hardly to maintain, but I want to understand, what I am doing wrong here.
thanks for any hints.
Enno