Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP Code to transpose rows to columns

amrita_goswami
Participant
0 Kudos

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

7 REPLIES 7

FredericGirod
Active Contributor
0 Kudos

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

0 Kudos

This code is not for ALV display. It is being used to transform data within BW.

former_member184569
Active Contributor
0 Kudos

Check this document.

http://scn.sap.com/docs/DOC-42525

0 Kudos

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

former_member209120
Active Contributor
0 Kudos

Hi Amrita Goswami,

Follow Susmitha's suggested document http://scn.sap.com/docs/DOC-42525

it is excellent document, it solves your problem.....

0 Kudos

This document is not available now. Can you help to get the solution?

bharat_rathod2
Active Participant
0 Kudos

Dear,

kindly refer above link.

First create dynamic internal table and use FIeld symbols to put data.