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: 

Internal table looping problem.

Former Member
0 Kudos

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......

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

12 REPLIES 12

Former Member
0 Kudos

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

GauthamV
Active Contributor
0 Kudos

hi,

Do like this.


loop at itab.
if itab-mtart = 'XXX' or itab-mtart = 'YYY' or itab-mtart = 'ZZZ'.

.............
............

endif.
endloop.

Former Member
0 Kudos

>

> 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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi

Try this out


LOOP AT itab .
 IF ( ( itab-mtart = 'xxx') OR  ( itab-mtart = 'yyy') OR ( itab-mtart =
'zzz')  ).


  ENDIF.
ENDLOOP.

regards

Kumar M

Former Member
0 Kudos

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

Former Member
0 Kudos
LOOP AT itab WHERE mtart = 'XXX' OR mtart = 'YYY' OR mtart = 'ZZZ'.
  APPEND itab to itab1.
ENDLOOP.

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi,

Change the condition From OR to and and try.

Thanks,

Krishna.

Former Member
0 Kudos

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

Former Member
0 Kudos

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.