-1

帮我报告 Abap。我有 2 张桌子。

  1. 伊塔布头
Z1 Z2 Z3
一个 C
  1. Itab 必填字段
字段名
Z2

我应该创建一个只有 itab2 字段(itab 必填字段)但 itab head 的值的文件。

该文件将是:

选项卡文件

Z2

Itab2 告诉我 itab1 的哪个字段是创建 itab 文件的强制性字段。

4

1 回答 1

2

这让您了解如何使用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.
于 2020-12-17T20:27:08.313 回答