10-26-2007 2:19 PM
hi
I am having a problem while using COLLECT statement.
I have a table ITAB1 with field WERKS.
I want collect statement to run only if ITAB-WERKS is not equal to 2130. and the output is required in table ITAB.
This is the code i have written. without IF statement the output is coming as expected but with IF statemnt its not working . can anyone suggest what is to be done.
code:
LOOP AT ITAB1.
IF ITAB1-WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
ELSE.
MOVE CORRESPONDING ITAB1 INTO ITAB.
ENDIF.
ENDLOOP.
10-26-2007 2:22 PM
Hello Gautam,
Try this way:
LOOP AT ITAB1 where WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
endloop.
LOOP AT ITAB1 where WERKS EQ '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
append itab.
ENDLOOP.
Regards,
Naimesh Patel
10-26-2007 2:22 PM
Hello Gautam,
Try this way:
LOOP AT ITAB1 where WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
endloop.
LOOP AT ITAB1 where WERKS EQ '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
append itab.
ENDLOOP.
Regards,
Naimesh Patel
10-26-2007 2:24 PM
Hi gautam,
Try like this...
LOOP AT ITAB1 where WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
ENDLOOP.
and can you to tell me what are all other fields in itab1.
Message was edited by:
Perez C
10-26-2007 2:24 PM
Hi,
try this:
LOOP AT ITAB1 where WERKS <> '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
ENDLOOP.
Regards, Dieter
10-26-2007 2:25 PM
Hi Gautam,
Try this:
LOOP AT ITAB1 where WERKS NE '2130'.
MOVE CORRESPONDING ITAB1 INTO ITAB.
COLLECT ITAB.
endloop.
Reward if Useful
Regards,
Chitra
10-26-2007 2:48 PM
you can not move both branches into itab
LOOP AT itab1.
IF itab1-werks NE '2130'.
MOVE CORRESPONDING itab1 INTO itab.
COLLECT itab.
ELSE.
MOVE CORRESPONDING itab1 INTO itab2.
APPEND itab2.
ENDIF.
ENDLOOP.
APPEND LINES OF itab2 to itab.
Yours did not work because there is no append for the else branch.
And the Collect does not like it if you change the table itab with other
command. The collect will then becomes extremely slow (implicit hashed
key is destroyed) !
Siegfried
10-26-2007 4:22 PM
be aware, the solution above with the 2 loops at WHERE is slower as the single loop!
This is because the LOOP AT WHERE can not find efficiently the lines fulfilling the WHERE condition. For a standard table no sort order can be assumed.