Skip to content
Advertisement

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

I have a table which have fields like fieldname and fieldvalue. I am trying to turn this table into another format.

For example, I have below table with fields and values:

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

I want to create a internal table with the following column names and values like this:

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

How can I do this?

Advertisement

Answer

You can use conditional aggregation:

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;
   
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement