Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ABAP Code to transpose rows to columns

Hi All,

I am looking for help with some ABAP code which will transpose data from rows to columns.

For example, I have a records with 3 measures (Let us call this it). Here Sales Order and Item are the key fields for the data:

Sales OrderItemDateQtyRevenueDiscount
11001009/07/131002005

I want to tranpose this data to create 3 records, one for each measure. Here Sales Order, Item and Measure Name are the key fields for the data. Let us call this structure lw1:

Sales OrderItemDateMeasure NameValue
11001009/07/13Qty100
11001009/07/13Revenue200
11001009/07/13Discount5

Is there any way to make this code dynamic?

Right now we are reading each column and appending records to arrive at the second table.

IF it-Qty is not initial.

  lw1-Sales Order = it-Sales Order

  lw1-Item = it-Item

  lw1-Measure Name = 'Qty'

  lw1-value = it-Qty.

Append lw1 to table lt1.

ENDIF.

IF it-Revenue is not initial.

  lw1-Sales Order = it-Sales Order

  lw1-Item = it-Item

  lw1-Measure Name = 'Revenue'

  lw1-value = it-Revenue.

Append lw1 to table lt1.

ENDIF.

IF it-Discount is not initial.

  lw1-Sales Order = it-Sales Order

  lw1-Item = it-Item

  lw1-Measure Name = 'Discount'

  lw1-value = it-Discount.

Append lw1 to table lt1.

ENDIF.

Since we have 180 measures in the source table this is leading to 6000 lines of code.

Please suggest if there is a dynamic way to do this.

Thanks in Advance

AG

Moderator message - Failed to search properly. Un-marked as question.

Message was edited by: Suhas Saha

Not what you were looking for? View more on this topic or Ask a question