‎2008 Nov 19 5:00 AM
Hi all,
i have a prob in looping internal table.
i want to copy some fields of itab to itab1 but onlly those fields where Material type is 'XXX' , 'YYY' , 'ZZZ'.
i have tried it by doing
loop at itab where mtart = 'XXX' or 'YYY' or 'ZZZ'.
but its not working ..
is thr any other way of doing this if yes then plz help me out...
thanxxxxx......
‎2008 Nov 19 5:03 AM
HI,
From your syntax,I think your itab is a itab with header line and both itab and itab1 are of same structure.
try with
loop at itab where itab-mtart = 'XXX' or itab-mtart ='YYY' or itab-mtart ='ZZZ'.
move-corresponding itab to itab1.
append itab to itab1.
endloop.if it is without header line , then take an work area wa compatible itab and itab1 and try with
loop at itab into wa where wa-mtart = 'XXX' or wa-mtart ='YYY' or wa-mtart ='ZZZ'.
move-corresponding itab to itab1.
append wa to itab1.
endloop.Regards,
Anirban
‎2008 Nov 19 5:03 AM
HI,
From your syntax,I think your itab is a itab with header line and both itab and itab1 are of same structure.
try with
loop at itab where itab-mtart = 'XXX' or itab-mtart ='YYY' or itab-mtart ='ZZZ'.
move-corresponding itab to itab1.
append itab to itab1.
endloop.if it is without header line , then take an work area wa compatible itab and itab1 and try with
loop at itab into wa where wa-mtart = 'XXX' or wa-mtart ='YYY' or wa-mtart ='ZZZ'.
move-corresponding itab to itab1.
append wa to itab1.
endloop.Regards,
Anirban
‎2008 Nov 19 5:04 AM
hi,
Do like this.
loop at itab.
if itab-mtart = 'XXX' or itab-mtart = 'YYY' or itab-mtart = 'ZZZ'.
.............
............
endif.
endloop.
‎2008 Nov 19 5:04 AM
>
> Hi all,
> i have a prob in looping internal table.
> i want to copy some fields of itab to itab1 but onlly those fields where Material type is 'XXX' , 'YYY' , 'ZZZ'.
> i have tried it by doing
> loop at itab where mtart = 'XXX' or 'YYY' or 'ZZZ'.
>
> but its not working ..
> is thr any other way of doing this if yes then plz help me out...
> thanxxxxx......
Hi Nilesh,
Do like this.
*SELECT SINGLE * FROM itab1 into corresponding fields of itab2*
where <condition>.
Thanks.
NItesh
‎2008 Nov 19 5:05 AM
Hi,
Inside the loop give a If statement to check the mtart with 'XXX' or 'YYY' or 'ZZZ' and then copy it to itab1 inside if condition.
Regards
Mudit
‎2008 Nov 19 5:08 AM
Hi
Try this out
LOOP AT itab .
IF ( ( itab-mtart = 'xxx') OR ( itab-mtart = 'yyy') OR ( itab-mtart =
'zzz') ).
ENDIF.
ENDLOOP.
regards
Kumar M
‎2008 Nov 19 5:09 AM
Hi,
Try in this way
loop at itab into wtab where mtart = 'XXX' or mtart ='YYY' or mtart ='ZZZ'.
here wtab is the work area for the internal table.
Thanks and regards,
kaza
‎2008 Nov 19 5:23 AM
LOOP AT itab WHERE mtart = 'XXX' OR mtart = 'YYY' OR mtart = 'ZZZ'.
APPEND itab to itab1.
ENDLOOP.
‎2008 Nov 19 5:52 AM
Dear Nilesh,
You can follow the below code.
loop at itab where MTART = 'XXX' or MTART = 'YYY' or MTART = 'ZZZ'.
move-corresponding itab to itab1.
Append itab1.
<Your Code>
-
-
-
endloop.
Regards
Arindam
‎2008 Nov 19 5:55 AM
Hi,
if your itab is with header line, then you can use:
loop at itab where mtart = 'XXX' or mtart = 'YYY' or mtart = 'ZZZ'.
append itab into itab1.
endloop.
if your itab is not with header line, then you can use a workarea:
loop at itab into wa where mtart = 'XXX' or mtart = 'YYY' or mtart = 'ZZZ'.
append wa into itab1.
endloop.Hope it helps.
Regards,
Chris Gu
‎2008 Nov 19 5:58 AM
Hi,
Change the condition From OR to and and try.
Thanks,
Krishna.
‎2008 Nov 19 6:20 AM
REPORT ZSRK_068 .
DATA : BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
END OF ITAB.
DATA : ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE.
ITAB-MATNR = 'M1'.
ITAB-MTART = 'XYX'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M2'.
ITAB-MTART = 'XXX'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M3'.
ITAB-MTART = 'XXY'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M4'.
ITAB-MTART = 'XYX'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M5'.
ITAB-MTART = 'YYY'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M6'.
ITAB-MTART = 'ZZZ'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M7'.
ITAB-MTART = 'XZZ'.
APPEND ITAB.
CLEAR ITAB.
ITAB-MATNR = 'M8'.
ITAB-MTART = 'XXX'.
APPEND ITAB.
CLEAR ITAB.
SORT ITAB BY MATNR MTART.
LOOP AT ITAB WHERE MTART EQ 'XXX' OR MTART EQ 'YYY' OR MTART EQ 'ZZZ'.
MOVE: ITAB-MATNR TO ITAB1-MATNR,
ITAB-MTART TO ITAB1-MTART.
APPEND ITAB1.
CLEAR ITAB1.
ENDLOOP.
LOOP AT ITAB1.
WRITE : / ITAB1-MATNR , ITAB1-MTART.
ENDLOOP.
o/p
M2 XXX
M5 YYY
M6 ZZZ
M8 XXX
‎2008 Nov 19 6:48 AM
Hi,
Create a Range and populate it with required values and use it in Where condition.
Ranges: r_range for mara-mtart.
r_range-sign = 'I'.
r_range-option = 'EQ'.
r_range-low = 'XXX'.
append r_range.
r_range-low = 'YYY'.
append r_range.
r_range-low = 'ZZZ'.
append r_range.
Loop at itab where mtart in r_range.
endloop.
Thanks,
Lakshmi.