Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check structure against another structure by value

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.
like image 964
stego Avatar asked Apr 29 '26 13:04

stego


1 Answers

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.
like image 154
Sandra Rossi Avatar answered May 01 '26 16:05

Sandra Rossi