从另一个 table ABAP 动态获取值字段
Get value field dynamically from another table ABAP
帮我报告Abap。
我有 2 table.
- Itab 头
Z1
Z2
Z3
A
B
C
- Itab 必填字段
Fieldname
Z2
我应该创建一个只有 itab2 字段(itab 必填字段)但 itab 头的值的文件。
文件将是:
标签文件
Z2
B
Itab2 告诉我 itab1 的哪个字段是创建 itab 文件所必需的。
这让您了解如何使用 ASSIGN
进行动态字段选择。
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.
帮我报告Abap。 我有 2 table.
- Itab 头
Z1 | Z2 | Z3 |
---|---|---|
A | B | C |
- Itab 必填字段
Fieldname |
---|
Z2 |
我应该创建一个只有 itab2 字段(itab 必填字段)但 itab 头的值的文件。
文件将是:
标签文件
Z2 |
---|
B |
Itab2 告诉我 itab1 的哪个字段是创建 itab 文件所必需的。
这让您了解如何使用 ASSIGN
进行动态字段选择。
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.