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: 

How to merge two rows in a column in ALV

Former Member
0 Kudos

Hi All,

I have a requirement in which I need to merge two rows in a particular column in ALV grid display.

Example:- There are two rows in a column one is having no value and the other row is having some value(Quantity).

Can I merge the two rows into a single row?

Thanks in Advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Nihar,

Check this link. Search the forum. This has been discussed many times.

http://scn.sap.com/thread/1586270

Regards,

Shravan

15 REPLIES 15

Former Member
0 Kudos

Hi Nihar,

Check this link. Search the forum. This has been discussed many times.

http://scn.sap.com/thread/1586270

Regards,

Shravan

0 Kudos

Dear Shravan,

This is only applicable if the data in both the rows are same but my requirement is that in one row there is no data while in the second row I have data.So I want to merge these two rows in that particular column into one row having the particular data.

Thanks in Advance

0 Kudos

Hi Nihar,

Can you give an example in an xls or something similar. The requirement is not clear to me.

Regards,

Shravan

0 Kudos

Dear Shravan,

Please find below the example

as per the above example I have sorted material number. Now column1 will contain some quantity

so I will pick the first 3 quantities i.e 5,4,3 based on some condition and add it and will show it in column2 and then I will add the quantity 8 and 7 based on another condition and will put it in column3 .

Thanks

0 Kudos

Hi Nihar,

Make sure your internal table has the data as below and then use the code as you have used for the material.

F1   F2 F3 F4

123 5   12 15

123 4   12 15

123 3   12 15

123 7   12 15

123 8   12 15

data lt_sort TYPE STANDARD TABLE OF slis_sortinfo_alv.

               DATA: lwa_sort  TYPE slis_sortinfo_alv.

MOVE: 'F3' TO lwa_sort-fieldname,

                'X' TO lwa_sort-up.

APPEND lwa_sort TO lt_sort.

MOVE: 'F4' TO lwa_sort-fieldname,

                'X' TO lwa_sort-up.

APPEND lwa_sort TO lt_sort.

MOVE: 'F1' TO lwa_sort-fieldname,

                'X' TO lwa_sort-up.

APPEND lwa_sort TO lt_sort.

Regards,

Shravan

0 Kudos
Hi,
So why not simply fill your table accordingly and use the SORT command?
Material noColumn1Column2Column3
12351215
12341215
12331215
12381215
12371215
An alternative could be to use the class CL_DD_DOCUMENT to display your table (e.g. check pgm DD_ADD_TABLE)...
Kr,
Manu.

0 Kudos

Dear Shravan,

What you have suggested is correct but I am doing the addition AT-END of material 123, so the final value say suppose 12 will come AT-END of material 123 so it is getting populated at the last row so how can I populate the internal table as suggested by you.

0 Kudos

You can take the starting index of the combination in AT-NEW OF and  when the AT-END of is triggered update from that index to the current index.

Say when AT-NEW OF is triggered , the index of table was 3 then and when AT-END OF is triggered the index is 8, then update the table from 3 to 8 with the relevant value.

You should also check out Manu's answer.

Thanks,

Shambu

0 Kudos

Dear Manu,

Kindly let me know how can I use CL_DD_DOCUMENT to achieve my requirement.

Thanks in Advance.

0 Kudos

Hi,

Well I still think the easier way is the one suggested by Nihar/Shambu, you just need to update your table correctly so that each cell has the correct value. And then use the ALV sort... (no need to fetch start and end index however, since the material number is known and can be used to update the related rows)

If you want to go with DD_DOCUMENT however, you should first check program DD_ADD_TABLE and particulary table 2.1 (search the code to see how it is built). When I have some more time, I'll try and give you an example with your data...

Cheers,

Manu.

0 Kudos

If you are providing the sums under AT END, you could simply add a modify statement to update all related column2 & 3:

    

LOOP AT gt_data ASSIGNING <d>.

    AT END OF matnr.

     "At this point, you calculate column2 and column3

     "...

      MODIFY gt_data FROM <d> TRANSPORTING column2 column3
            WHERE matnr = <d>-matnr.
    ENDAT.

"...

ENDLOOP.

Kr,

Manu.

0 Kudos

Dear Manu,

Thanks a ton ......

The issue is resolved.

0 Kudos

Dear Shravan,

Can't we sort column having quantity fields ?

When ever I am going to sort the column having quantity field though sort symbol is coming but the cells having same quantity are not getting merged .

Thanks in Advance

0 Kudos

Solved myself ...I have converted the quantity filed to character format....now the sort is working properly for quantity field......

Thanks to all for your valuable suggestions....

Former Member
0 Kudos

This message was moderated.