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: 

Append with where condition

Former Member
0 Kudos

Hi all,

For the sake of performance i'm want to get the requirement as below.....

i have three internal tables for example...itab1 itab2 and itab3....

itab1 has all the records......for some reason i need to split this itab1 records material type wise into itab2 and itab3...

for this sake i'm using....

append lines of itab1 to itab2.

append lines of itab1 to itab3.

delete itab2 where <material type> NE 'X''.

delete itab3 where <material type> NE 'Y'.

This works fine for few entries but for the sake of performance can append lines of itab1 to itab2 with some conditions of reference or with fieldsymbols so that i would have to write the delete statement.......and i should achieve the same requirement as above........Correct answere will be awarded........

5 REPLIES 5

Former Member
0 Kudos

you can do something like this......

sort itab1.

loop at itab1.

read table itab1 with key field1 = ' gfgf'

field 2 = 'fgfd'.

move itab1-field1 to itab2 -field2.

move

move..

endloop.

loop at itab1.

read table itab1 with key field 1 = 'fgdf'

field 2 =fgff.

move itab1-field1 to itab3 -fiel1.

endloop

i hope it helps.

thanks

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

As long as u r not using the delete statement in side the loop it is ok to use.

But i have 2 ideas to make the ur delete statement more effective.

1. SORT: itab1 BY <material type>.

itab2[] = itab3[] = itab1[].

delete itab2 where <material type> NE 'X''.

delete itab3 where <material type> NE 'Y'.

If u r not able to sort itab1 then dort itab2 and itab3 and then delete the records.

2.

We have one addition for APPEND LINES OF itab

i.e From INDEX 1 to n.

SORT itab1 BY material type.

Find the starting and ending positions for material type X in itab1.

APPEND LINES OF itab1 to itab2 FROM 1 TO n(high value for material type X).

APPEND LINES OF itab1 to itab2 FROM (n+1) to end position.

Start position will be 1 and end position u can get from DESCRIBE TABLE statement. Middle position u have to use some logic based on ur requirement.

I suggest u to use first solution which will be easier and effective than the second one.

Thanks,

Vinod.

Former Member
0 Kudos

Hi

I would do it like you did it.

But if it is not fast enough then try this (I;m not sure if this will be faster though - think not):


SORT itab1 BY <material type>.
LOOP AT itab1 INTO lwa_itab1.
  IF lwa_itab1-<material type> <> 'X'.
    APPEND lwa_itab1 TO lwa_itab2.
  ENDIF.
  IF lwa_itab1-<material type> <> 'Y'.
    APPEND lwa_itab1 TO lwa_itab3.
  ENDIF.
ENDLOOP.

Anyway, what do you want to do? Maybe you should change your SELECT?

Rgds

Mat

Former Member
0 Kudos

I've resolved it

javier_alonso
Participant
0 Kudos

You can use VALUE...FOR operator:

itab2 = VALUE #( FOR <i> IN itab1 WHERE ( material_type EQ 'X' ) ( <i> ) ).