Application Development and Automation 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: 
Read only

Rows to Column Conversion in ABAP

Former Member
0 Likes
719

Hello guys,

I wanted to create a report in which I need to convert rows in to column.

e.g.

I have a itab_col which contains my column header as follows.

itab_col-plant itab_col-name

1000 Plant A

2000 Plant B

3000 Plant C

I have a itab_data which contains my data as follows .

itab_data-date itab_data-qty itab_data-plant

01.06.2006 10 1000

01.06.2006 20 1000

01.06.2006 50 2000

02.06.2006 20 3000

I need to print the report as follows

Date Plant A Plant B Plant C

01.06.2006 30 50 0

02.06.2006 0 0 20

Could you tell me how I can do it in abap.

3 REPLIES 3
Read only

Former Member
0 Likes
520

Hi,

Try this code...

data : itab_data1 like itab_data occurs 0 with header line.

loop at itab_data.

move-corresponding itab_data to itab_data1.

collect itab_data1.

endloop.

sort itab_data1 by date.

loop at itab_data1.

at first.

wtite : /2 'date'.

wtite : 12 'plant A'.

wtite : 25 'plant B'.

wtite : 40 'plant C'.

endat

at new date.

write : /2 itab_data1-date

endat.

if itab_data1-plant = '1000'.

wtite : 12 itab_data1-qty.

elseif itab_data1-plant = '2000'.

wtite : 25 itab_data1-qty.

elseif itab_data1-plant = '3000'.

wtite : 40 itab_data1-qty.

endif.

endloop.

Sreedhar

Read only

Former Member
0 Likes
520

Hi,

first create table with following attribute.

*----


table_row_to_column

1. date

2. Plant A

3. Plant B

4. Plant C.

.............D E F ..number of plant possible.

Sum Up The data

01.06.2006 10 1000

01.06.2006 20 1000

01.06.2006 50 2000

02.06.2006 20 3000

\ /

01.06.2006 30 1000

01.06.2006 50 2000

02.06.2006 20 3000

-


to new data_table_sum_value

<b>for that u have to</b>

1) Sort the table date & plant.

2) sum up records for similar plant based on date

<b>Convert rows in to column.</b>

loop at data_table_sum_value.


  case data_table_sum_value-plant.
    when 1000.
       table_row_to_column-plant_A = data_table_sum_value-qnty.
    when 2000.
       table_row_to_column-plant_B = data_table_sum_value-qnty.
    when 3000.
       table_row_to_column-plant_C = data_table_sum_value-qnty.
    when 4000.
       table_row_to_column-plant_D = data_table_sum_value-qnty.
    when 5000.
       table_row_to_column-plant_E = data_table_sum_value-qnty.
  endcase.


   at end of date.
     append table_row_to_column.
   endat.

endloop.

<b>Please Mark Helpful Answers & Rewards Points.

Dont Forget to mark as problem solved if solved</b>

Regards

Read only

0 Likes
520

Thanks for your reply,

Both the solutions will work fine no doubt about that as long as I know the plant code and plant name.

Since I dont know how many plants would be there in future I cant Hard code it rather I want the dynamic solution, no matter how many plants are there I should be able to print the sum of qty under that plant name without hard coding it.