2013 Jul 17 9:58 AM
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 Order | Item | Date | Qty | Revenue | Discount |
1100 | 10 | 09/07/13 | 100 | 200 | 5 |
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 Order | Item | Date | Measure Name | Value |
1100 | 10 | 09/07/13 | Qty | 100 |
1100 | 10 | 09/07/13 | Revenue | 200 |
1100 | 10 | 09/07/13 | Discount | 5 |
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
2013 Jul 17 10:25 AM
Hi,
you need to get the field catalog (used the function you use when you create an ALV Grid), you need field-symbols.
you make a loop on the field catalog (you could exclude fieldname) and make code like this
concatenante 'MY_TABLE_NAME-' is_fcat-fieldname into w_field.
assign (w_field) to <field>.
check <field> is assigned.
if <field> ne space.
move ...
append ..
endif.
endloop.
w_field is type char40
<field> is field-symbol type any
regards
Fred
2013 Jul 17 11:20 AM
This code is not for ALV display. It is being used to transform data within BW.
2013 Jul 17 11:28 AM
2013 Jul 23 7:04 AM
Hi Susmitha,
I am writing a code on function Module to display the detailed report in tree structure.
I am stucked in displaying the values--I will send the code...could you please let me know where am I going wrong.
Regards
Naveen
2013 Jul 17 11:46 AM
Hi Amrita Goswami,
Follow Susmitha's suggested document http://scn.sap.com/docs/DOC-42525
it is excellent document, it solves your problem.....
2023 Mar 15 8:59 PM
This document is not available now. Can you help to get the solution?
2013 Jul 17 12:07 PM
Dear,
kindly refer above link.
First create dynamic internal table and use FIeld symbols to put data.