2006 Mar 21 4:39 AM
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.
2006 Mar 21 4:54 AM
sort it by tcode changenr descending.
loop at it.
at new tcode.
read table it index sy-tabix.
write:/ it-changeno.
endat.
endloop.
2006 Mar 21 4:48 AM
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
2006 Mar 21 4:50 AM
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
2006 Mar 21 4:50 AM
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
2006 Mar 21 4:52 AM
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
2006 Mar 21 4:54 AM
sort it by tcode changenr descending.
loop at it.
at new tcode.
read table it index sy-tabix.
write:/ it-changeno.
endat.
endloop.
2006 Mar 21 5:38 AM
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.
2006 Mar 21 5:52 AM
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.
2006 Mar 21 8:16 AM
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.
2006 Mar 21 8:20 AM
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.
2006 Mar 21 8:39 AM
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
2006 Mar 21 10:44 PM
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'.
2006 Mar 21 5:41 AM
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