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

internal tables

Former Member
0 Likes
810

Hi

My internal table output is as follows :-

city sales

HYD 100

RJY 153

BVM 500

SEC 550

. .

. .

Now i have to get the top two cities of high sales.please send that coding

Regards

M.Srikanth

<u></u>

7 REPLIES 7
Read only

Former Member
0 Likes
782

Hi,

SORT ITAB BY SALES DESCENDING.

READ TABLE ITAB INDEX 1.

WRITE: / 'TOP CITY- ', ITAB-CITY.

READ TABLE ITAB INDEX 2.

WRITE: / 'SECOND TOP CITY- ', ITAB-CITY.

Thanks,

Naren

Read only

Former Member
0 Likes
782

Hi Srikanth ,

Code will be

Sort it_1 by SALES DESCENDING.

READ TABLE IT_1 INDEX 1.

READ TABLE IT_ INDEX 2.

Regards

Arun

Read only

Former Member
0 Likes
782

Hai Srikanth

Check the following Code

data : begin of itab occurs 0,

city(3) type c,

sales type i,

end of itab.

itab-city = 'HYD'.

itab-sales = 100.

append itab.

itab-city = 'RJY'.

itab-sales = 153.

append itab.

itab-city = 'BVM'.

itab-sales = 500.

append itab.

itab-city = 'SEC'.

itab-sales = 550.

append itab.

if not itab[] is initial.

Sort itab by SALES DESCENDING.

loop at itab.

write 😕 itab-city,

itab-sales.

endloop.

endif.

Regards

Sreeni

Message was edited by:

Sreenivasulu Ponnadi

Message was edited by:

Sreenivasulu Ponnadi

Read only

Former Member
0 Likes
782

Hi

sort internal table using sales descending. write first two records.

OR

Declare one variables. loop the intenal table compare sales value of sales with variable. & if the value of sales greater than variable assign value to variable.

e.g.:

clear v1.

Loop at internal table.

if itab-sales > v1.

v1 = itab-sales.

endloop.

Ashven

Read only

Former Member
0 Likes
782

Hi,

SORT ITAB BY SALES DESCENDING.

LOOP AT ITAB FROM 1 TO 2.

WRITE: /ITAB-CITY 20 ITAB-SALES.

ENDLOOP.

Reward points if the answer is helpful.

Regards,

Mukul

Read only

0 Likes
782

Hi,

if cities appear more than once, you must collect before:

itab_coll like table of itab with header line
loop at itab
collect itab into itabv_coll
endloop.
sort itab_coll bý sales descending.
loop at itab_coll from 1 to 2.
write: /  itab_coll-city,  itab_coll-sales.
endloop.

Regards,

Clemens

Read only

Former Member
0 Likes
782

sort itab by sales descending.

delete itab from 3.

loop at itab.

write : / itab-city,itab-sales.

endloop.

now your itab only contain those two rows which have highest sales value.

regards

shiba dutta