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: 

grouping records based on a condition...

aris_hidalgo
Contributor
0 Kudos

Hello experts,

I am currently having a problem on how to go about this. What I need to do is to group equipments with their respective subordinates. Just like a parent-child relationship and display that using ALV. Now here is my problem, when I loop through the itab it looks like this:

EQUNR | HEQUI

000000000000002448 |

000000000000900599 |

000000000000000164 | 000000000000000168

000000000000000165 |

000000000000000166 |

000000000000000167 |

000000000000000168 |

Now, if an equipment(equnr) has a value in HEQUI, it means that it is a child equipment of the value found in HEQUI. In my example, equipment 000000000000000164 is a child equipment of equipment 000000000000000168. Now, how can I display this using ALV in a format similar to this:

EQUIPMENT PARENT DESCRIPTION...

000000000000000168

000000000000000164 000000000000000168

Help would be greatly appreciated as well points being rewarded.Thanks again guys!

Message was edited by: viraylab

Message was edited by: viraylab

1 ACCEPTED SOLUTION

Former Member
0 Kudos

create 2 more itabs.

Data: itab1 like itab0, (ur current)

itab2 like itab0.

itab1[] = itab0[]

loop at itab0.

if not itab0-hequi is initial.

read table itab1 with table key itab1-equinr = itab0-hequi.

if sy-subrc = 0.

itab2-equnr = itab1-equnr.

itab2-hequi = itab1-hequi.

append itab2.

endif.

itab2-equnr = itab0-equnr.

itab2-hequi = itab0-hequi.

append itab2.

endloop.

In the end display itab2.

Hope this helps

Rohit

Dont forget about points.

5 REPLIES 5

Former Member
0 Kudos

You should use the ALV TREE controls (ALV / SIMPLE / COLUMN tree Controls). Take a look DWDM examples for tree controls and choose the appropriate one.

Regards,

Ravi

former_member188685
Active Contributor
0 Kudos

hi viray,

this can be done using hierarchial list, for reference check BALVHD01. that matches your requirement. for this you need to have two internal tables, one id for parent, the other is for child.check the example...

Regards

vijay

Former Member
0 Kudos

Hi Viraj,

You can do this using any ALV , simple or OO.

Just populate ur itab with the records u need to display and use it in REUSE_ALV_GRID_DISPLAY..

if u need any help as far as ALV is concerned,

i shall send u some tutorial documents..

Regards,

Tanveer.

Mark helpful answers.

Former Member
0 Kudos

create 2 more itabs.

Data: itab1 like itab0, (ur current)

itab2 like itab0.

itab1[] = itab0[]

loop at itab0.

if not itab0-hequi is initial.

read table itab1 with table key itab1-equinr = itab0-hequi.

if sy-subrc = 0.

itab2-equnr = itab1-equnr.

itab2-hequi = itab1-hequi.

append itab2.

endif.

itab2-equnr = itab0-equnr.

itab2-hequi = itab0-hequi.

append itab2.

endloop.

In the end display itab2.

Hope this helps

Rohit

Dont forget about points.