使用 ABAP 中另一个 table 列数据的列名和值创建内部 table

Create internal table with column names and values from another tables column data in ABAP

我有一个 table,它有像字段名和字段值这样的字段。我正在尝试将此 table 转换为另一种格式。

例如,我有以下 table 字段和值:

-----------------------------
|  Fieldname   | Fieldvalue |
-----------------------------
|   Matnr      |  001       |
|   Werks      | 1000       |
|   Statu      |   01       |
-----------------------------

我想创建一个内部 table,其中包含以下列名称和值,如下所示:

-------------------------------
|  Matnr  |  Werks  |  Statu  |
-------------------------------
   001       1000       01

我该怎么做?

您可以使用条件聚合:

select max(case when fieldname = 'Matnr' then fieldvalue end) as matnr,
       max(case when fieldname = 'Werks' then fieldvalue end) as Werks,
       max(case when fieldname = 'Statu' then fieldvalue end) as Statu
from t;