Skip to Content

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 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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Jul 17, 2013 at 10:28 AM

    Check this document.

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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Jul 17, 2013 at 09: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

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 17, 2013 at 10: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.....

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 17, 2013 at 11:07 AM

    Dear,

    kindly refer above link.

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

    Add comment
    10|10000 characters needed characters exceeded