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

sorted tables

Former Member
0 Likes
762

eg. is this way of doing correct for building sorted table?

will this lose the binary properties for quick access?


sort standard_itab by a b c.
sorteditab[] = standard_itab[]

or should it be this way? using insert?


loop at standard_itab into wa.
  insert wa into sorteditab.
endloop.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
731

Hi,

Actually with insert statement, compiler will take care of the sorting where else using sort command, you explicitly sort the table....

Regards,

6 REPLIES 6
Read only

Former Member
0 Likes
732

Hi,

Actually with insert statement, compiler will take care of the sorting where else using sort command, you explicitly sort the table....

Regards,

Read only

Former Member
0 Likes
731

hi,

try this

sort standard_itab by <field1>.

loop at standard_itab into wa.

insert wa into sorteditab.

endloop.

if helpful reward plz

ravi

Read only

Former Member
0 Likes
731

The first form is an effective way of doing things. I would suggest going with the first way of moving the body of the internal table to other, there will be no loss ofbinary properties moreover it is more efficient in terms of performance

Read only

Clemenss
Active Contributor
0 Likes
731

Hi Charles,


sorteditab[] = standard_itab[]

is correct but will cause a dump if you have duplicate keys in the standard_itab.


loop at standard_itab into wa.
  insert wa into sorteditab.
endloop.

is comparably very slow because for all loops the table line is copied to the work area. And it is syntacticalkly not correct because you must use into table ... when inserting into sorted itabs.

Do it using field-symbols, optional remember duplicates:


field-symbols:
  <itab> like standard_itab.
data:
  lt_itab_dup like sorteditab.
loop at standard_itab assigning <itab>.
  insert <itab> into table sorteditab. "Note: must use TABLE otherwise syntax error
  check sy-subrc <> 0. "Record akready exists
  insert <itab> into table lt_itab_dup.
endloop.

Now it won't fail under any circumstances. And you have the duplicate key records in table lt_itab_dup for evaulation purposes.

Regards,

Clemens

Read only

Former Member
0 Likes
731

I thought according to SAP...using field-symbols would NOT be efficient if the the WA size is small.. it would benefit if size is huge?

Read only

Clemenss
Active Contributor
0 Likes
731

Hi Charles,

using Field-symbols will not be <b>slower</b> under any circumstances.

WA size small means: 1 field or less

Regards,

Clemens