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: 

Max value of itab

Former Member
0 Kudos

Hi experts,

select * from cdhdr into table itab.

After this statement i have to select the max value of changenr record details from itab for each tcode.Please help me.

previously i used

select max( changenr ) from cdhdr into table

itab where...group by tcode.

loop at itab.

select * from cdhdr into table it_cdhdr.

endloop.

its working. but some performance issue is there.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

sort it by tcode changenr descending.

loop at it.

at new tcode.

read table it index sy-tabix.

write:/ it-changeno.

endat.

endloop.

12 REPLIES 12

Former Member
0 Kudos

Hi Silviya,

Sort the table by ascending/descending order on the respective columns. The first row in itab will give the least/largest value.

Regards,

Anjali

Former Member
0 Kudos

Silviya,

Instead of SORTING the table after reading, you can create a SORTED table and then SELECT the values into the table. The data will be stored in the SORTED manner and then you can read the TOP row.

Regards,

Ravi

Former Member
0 Kudos

HI,

after select:

select * from cdhdr into table itab.

sort itab by changenr ascending/decending.

read table itab index 1.

Hope that solves your problem.

Regards,

Anjali

Former Member
0 Kudos

Hi Siliviya,

Make use of SORT .

Samples : SORT itab by changenr .

U can use ascending as weel as descending in order to get the max. and min value.

Cheers

Sunny

Rewrd points, if found helpful

Former Member
0 Kudos

sort it by tcode changenr descending.

loop at it.

at new tcode.

read table it index sy-tabix.

write:/ it-changeno.

endat.

endloop.

Former Member
0 Kudos

Hi Sravanthi,

I have coded like this. But i am not getting max change number details for each tcode.

select * from cdhdr into table it_cdhdr

where udate between date_from and

sy-datum and tcode in r_tcode.

sort it_cdhdr by tcode changenr descending.

loop at it_cdhdr .

at new tcode.

read table it_cdhdr index sy-tabix.

struct1-mandant = it_cdhdr-mandant.

struct1-objectclas = it_cdhdr-objectclas. struct1-objectid = it_cdhdr-objectid.

struct1-keyvalue = w_kvalue.

struct1-changenr = it_cdhdr-changenr. struct1-username = it_cdhdr-username.

struct1-udate = it_cdhdr-udate. struct1-utime = it_cdhdr-utime.

struct1-tcode = it_cdhdr-tcode.

endat.

endloop.

0 Kudos

Hi Silviya,

because the table has the same structure as CDHDR your at NEW will be processed for every table entry (because TCODE is a column to the right of CHANGENR).

If you are only interested in these entries you could insert a DELETE ADJACENT DUPLICATES COMPARING TCODE after your sort. You will then only have one entry per TCODE which will be the most recent. You can then change the loop by removing the 'at' and 'endat' and it should then work.

0 Kudos

Hi Experts,

i have coded like this. But this condition is not working fine. how to code it?

if cdpos-tabname eq 'DMAKT'

or cdpos-tabname eq 'MARA'

or cdpos-tabname eq 'MAKT'.

do something...

else.

do something.

endif.

0 Kudos

Hi Experts,

i have coded like this. But this condition is not working fine. how to code it?

if cdpos-tabname eq 'DMAKT'

or cdpos-tabname eq 'MARA'

or cdpos-tabname eq 'MAKT'.

do something...

elseif cdpos-tabname ne 'DMAKT'

or cdpos-tabname ne 'MARA'

or cdpos-tabname ne'MAKT'.

do something.

else.

do something.

endif.

0 Kudos

Hi,

data : begin of it_cdhdr occurs 0,

tcode type cdhdr-tcode,

cdhdr type cdhdr-cdhdr,

end of it_cdhdr.

select tcode max( cdhdr ) from cdhdr into table it_cdhdr

where udate between date_from and

sy-datum and tcode in r_tcode group by tcode.

loop at it_cdhdr.

write : / it_cdhdr-tcode, it_cdhdr-cdhdr.

endloop.

Kindly reward points if it helps.

Message was edited by: Jayanthi Jayaraman

0 Kudos

Hi Silviya, this should really be another thread now... but how is it not working? Give more info.

I can only see a slight problem with your 'if'. The elseif could really be coded as an 'else' as anything NOT passing the 'if' will by definition pass the 'elseif', therefore in your current code nothing will ever fall through to the 'else'.

Former Member
0 Kudos

Hi Silviya,

I can see that you need only the column name "changenr".

So when you are selecting the columns from the cdhdr table use the column name changenr.

For eg.

data: begin of it_changenr.
changenr like cdhdr-changenr.
end of itab.

Select changenr from cdhdr into table it_changenr.

Your previous code will work fine with this modification.

Hope it helps.

Regards,

Maheswaran.b