Skip to Content
1
Mar 28 at 08:03 AM

Nested reads

95 Views

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:

  1. Check if fields are equal
  2. Check if default component name of rollname matches the BAPI fieldname
  3. Check if rollnames are equal

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