-1

help me for report Abap. I have 2 table.

  1. Itab head
Z1 Z2 Z3
A B C
  1. Itab obbligatory field
Fieldname
Z2

i should create a file with only fields of itab2(itab obbligatory field) but the value of itab head.

The file will be:

tab file

Z2
B

Itab2 say me which field of itab1 are obbligatory for create itab file.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
  • It can be done with FIELD-SYMBOL, it is just not clear for me at this point, whether "2. Itab obligatory field" is a single field, is it a strucure or a table as well? You write it is a table, but than it can have several lines, and the whole thing does not make any sense (at least for me...) – József Szikszai Dec 17 '20 at 19:34
  • Itab2 is a table have the fieldname of itab1 obbligatory for create a file. In example the field was 1 but can have some fieldname of itab1..So i match 2 table for create file but i have no idea – raffaele basilicata Dec 17 '20 at 19:37
  • so, itab2 can have several lines, i.e. several fieldnames? And you want all of these fields into the file? – József Szikszai Dec 17 '20 at 19:45
  • Yes, itab2 can have all the fieldnames or some filednames of itab1..so my problem is how I get the value of itab1 started by fieldname itab2. – raffaele basilicata Dec 17 '20 at 19:53

1 Answers1

2

This gives you an idea of what to do using ASSIGN for dynamic field selection.

  LOOP AT itab_a INTO DATA(wa_itab_a).     " your data tab
    LOOP AT itab_b INTO DATA(wa_itab_b).   " your obligatory field list
      TRANSLATE wa_itab_b-fieldname TO UPPER CASE. " important if they are not already in uppercase
      ASSIGN COMPONENT wa_itab_b-fieldname OF STRUCTURE wa_itab_a TO FIELD-SYMBOL(<fs_field>).
      " ... in <FS_FIELD> you will have the values of the obligatory fields
      " so you can concatenate, par example, to file line
      CONCATENATE wa_file-line <fs_field> INTO wa_file-line SEPARATED BY c_separator.
    ENDLOOP.
    " append file line here, something like this:
    APPEND wa_file TO itab_file.
    CLEAR wa_file.
  ENDLOOP.
cape_bsas
  • 638
  • 5
  • 13