I have this piece of dynamic coding. Where I need to check if a structure of keys is in another structure. Without checking the value of each field (if possible).
Logically it should be something like this:
IF ls_keys IN ls_data_struc.
"do stuff
ENDIF.
yes I know that coding snippet doesn't work, but I think that shows best what I am asking.
TYPES: BEGIN OF tys_keys,
matnr TYPE matnr,
vkorg TYPE vkorg,
END OF tys_keys.
TYPES: BEGIN OF tys_data,
matnr TYPE matnr,
vkorg TYPE vkorg,
mtpos TYPE mtpos,
END OF tys_data.
DATA: ls_keys TYPE tys_keys,
ls_data_struc TYPE tys_data.
Example that should work:
ls_keys-matnr = '009988776655443322'.
ls_keys-vkorg = '0001'.
ls_data_struc-matnr = '009988776655443322'.
ls_data_struc-vkorg = '0001'.
ls_data_struc-mtpos = 'ALEN'.
IF ls_keys IN ls_data_struc.
"do something
ENDIF.
Example that shouldn't work:
ls_keys-matnr = '112233445566778899'.
ls_keys-vkorg = '3145'.
ls_data_struc-matnr = '009988776655443322'.
ls_data_struc-vkorg = '0001'.
ls_data_struc-mtpos = 'ALEN'.
IF ls_keys IN ls_data_struc.
"do something
ENDIF.
To only compare the component values of both structures, the simplest solution is to use the constructor operator CORRESPONDING:
IF ls_keys = CORRESPONDING tys_keys( ls_data_struc ).
"do something
ENDIF.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With