2007 Dec 24 11:11 AM
hi,
i would like to know if this is possible.
i would like to sort internal table base on fieldX. if fieldX is initial then sort with condition as below else system default sort sequence.
i know the syntax incorrect. need advice with example.
loop at itab
if itab-fieldX is initial.
sort itab[] by fieldA ascending fieldB descending.
endif.
endloop.
thanks
2007 Dec 24 11:16 AM
U dont need loop at for sorting.
What exactly are u cheking FieldX
sort itab[] by fieldA ascending fieldB descending. would be sufficient
Awrd Points if useful
Bhupal
2007 Dec 24 11:17 AM
Hi,
Declare another internal table of the same type as ITAB.
Loop at ITAB check the field and sort the new internal table in the loop.
DATA ITAB_NEW like ITAB.
loop at itab
if itab-fieldX is initial.
sort itab_new[] by fieldA ascending fieldB descending.
endif.
endloop.
Regards,
Pankaj
2007 Dec 24 11:21 AM
this is not a way.
would you please specify about the requirement?
Regards
ANUPAM
2007 Dec 24 11:30 AM
hai,
better you can use read command for your validations.
dont use sort command inside the loop bcose evry loop count itab has altered .
reward points if useful.
regards,
jai.m
2007 Dec 24 11:30 AM
Hi,
The reqt is quite different.
Because in a internal table we may have some 100 records.
In that 100 records for 10 records you have fieldX is initail.And for some other 10 records fieldY is initial.
And for some 10 records both fieldx fieldY are initial means you cant do with loop processing.
You can do in otherway ..
v_fieldx_count = 0. "Type I
v_fieldy_count = 0.
loop at itab.
if itab-fieldX is initial AND fieldY is initial .
v_fieldx_count = v_fieldx_count + 1.
v_fieldy_count = v_fieldy_count +1.
elseif itab-fieldX is initial.
v_fieldx_count = v_fieldx_count + 1.
elseif itab-fieldY is initial.
v_fieldY_count = v_fieldY_count + 1.
endif.
endlloop.
If v_fieldx_count GE v_fieldY_count .
sort itab by fieldX.
else.
sort itab by fieldY.
Endif.
Like that you can proceed.
Regds
Parvathi
Please reward points if helpful.............
2007 Dec 24 11:31 AM
Hi,
You need not required to loop at internal table for sorting the table.
just use the sort statement followed by fields on which you want to sort the internal table.
sort itab by field1 ascending field2 descending.
Reward Points, if useful.
Regards,
Manoj Kumar