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

Logic help..

Former Member
0 Likes
807

Experts help me to construct my logic regarding this scenario.

It would be much unclear if I would explain it so I just made a visual example.

this is one my itab.

Name: itab.

itab has two fields:

name number

shine 1

mary 1

mary 2

arenas 1

gilbert 1

gilbert 2

gilbert 3

if you notice my numbering depends upon if the name change if not my numbering will just be sorted.

Now I want to have an internal table like this.

my reference is my above itab.

I want to have an internal table like this.

name numbering

shine 1

mary 2

arenas 1

gilbert 3.

if you noticed in my second(expected) Itab my numbering would be the maximum number that a name gets. since shine has only one number in my previous itab then the number would be 1. but since mary has a maximum number of two the numbering of mary will be number 2.so on and so fort.

Could help me on my logic.I have used on change of itab-name my problem is in numbering on how to get the max number per name.

Please help me..

6 REPLIES 6
Read only

Former Member
0 Likes
785

Hi,

You can sort your internal table itab like this :

Sort itab by name number descending.

This would give you the maximum number for a name.

Then loop your Itab.

data : w_name like itab-name.

loop at itab.

if w_name NE itab-name.

move itab to itab1. **itab1 is the 2nd internal table.

clear w_name.

else.

w_name = itab-name.

continue.

endif.

endloop.

This would meet your requirement.

Reward if useful.

Thanks,

Lalit

Read only

Former Member
0 Likes
785

hi salma,

you can code like this.

data : itab2 like itab occurs 0 wit h header line.

data : itab_temp like itab occurs 0 with header line.

data : p_tabix like sy-tabix.

loop at itab.

p_tabix = sy-tabix + 1.

read table itab index p_tabix into itab_temp.

if itab_temp-name <> itab-name.

itab2-name = itab-name.

itab2-number = itab-number.

append itab2.

clear itab_temp.

endif.

endloop.

itab2 will have the required data

reward if useful

Gaurav

Read only

Former Member
0 Likes
785

Hi Salma,

Try somethin like this.

*consider itab has name and number as field and jtab has name and numbering as field.

*Sort your internal table by name and number in descending order as below..

Sort itab by name number descending.

loop at itab.

on change of itab-name.

jtab-name = itab-name.

jtab-numbering = itab-number.

append jtab.

end on.

endloop.

*finally sort jtab by ascending order as below.

sort jtab by name.

This will fullfill ur logic.

Read only

Former Member
0 Likes
785

Hi,

First sort your itab in the Descending order on the base of name and number.

then for displaying only max number use this logic....

loop at itab.

on change of itab-name.

write:/ itab-name,

itab-number.

endon.

endloop.

regards,

paras

Read only

Former Member
0 Likes
785

Hi,

Try this code,.

data: fs_temp like fs_itab.

sort itab.

loop at itab into fs_tab.

w_tabix = sy-tabix + 1.

read table itab into fs_temp with index w_tabix.

if fs_itab-name = fs_temp-name and

fs_itab-number gt fs_temp-number.

write : fs_itab-name,

fs_itab-number.

endif.

endloop.

plzz reward points if it helps.

Message was edited by:

manjari kotta

Read only

Former Member
0 Likes
785

sort itab by name ascending numbering descending.

now contents of itab will be

<u> name number</u>

arenas 1

gilbert 3

gilbert 2

gilbert 1

mary 2

mary 1

shine 1

declare wa_itab as work area

and itab2 as another inernal table just like itab with header line

loop at itab into wa_itab.

if wa_itab-name <> itab2-name.

append wa into itab2.

endloop.

now itab2 contains the desired result