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

Looping problem please help

Former Member
0 Likes
1,010

Hello Gurus,

I have a prob please help.

-


var=mat1.

IQC Material

01 mat1

6030 mat1

100 mat2

04 mat3

if Material field = mat1 then

output should be like this:

var1 = 01, 6030

how do i code this?

thanks!

1 ACCEPTED SOLUTION
Read only

former_member386202
Active Contributor
0 Likes
990

Hi,

Try like this

Loo at itab.

if ITab-matnr = mat1.

write : /itab-var1.

endif.

endloop.

Regards,

Prashant

8 REPLIES 8
Read only

former_member386202
Active Contributor
0 Likes
991

Hi,

Try like this

Loo at itab.

if ITab-matnr = mat1.

write : /itab-var1.

endif.

endloop.

Regards,

Prashant

Read only

Former Member
0 Likes
990

Hi,

Use the VAR1 variable as a string varaible or char variaable..

When ever the condition satisfies u can concatenate them like as follows

here both v_lang and v_lang1 are char(70).

clear : v_lang1 ,v_lang.

loop at it_lang where materail = 'MAT1'.

v_lang1 = itab-<fieldname>

concatenate v_lang1 ',' v_lang into v_lang.

endloop.

REWARD IF USEFUL

Read only

Former Member
0 Likes
990

IF

IQC Material

01 mat1

6030 mat1

100 mat2

04 mat3

is in ur itab den

data : var(255) type c,
         matf      type matnr,
         f.

move var to matf.
clear var.

loop at itab where material = matf.
if f <> 'X'.
move itab-material to var.
else.
concatenate var ',' itab-material into var.
endif.
move 'X' to f.
endloop.

Read only

0 Likes
990

field ITAB is unknown..

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
990

data:begin of itab occurs 0,

matnr type marc-matnr,

var(50) type c,

end of itab.

consider the above as your itab with matnr as first field.

sort itab by matnr ascending.

data:wk_var(50).

loop at itab.

concatenate wk_var itab-var ',' into wk_var.

condense wk_var.

at end of matnr.

write at 10 itab-matnr.

write:/ 25 wk_var.

clear wk_var.

endat.

If u donot want to wite the value..move it to another itab.

Read only

Former Member
0 Likes
990

ok let me revise my question:

example i got the material JPQ11

table is kinda like this:

table: QMAT

Number Material

1020 JPQ11

3040 JPaaa

1090 JPQ11

1970 JP12e

8667 JPttta

Now since there is 2 JPQ11 in field Material, I wanted to get is corresponding field Number

Output should be like this:

1020, 1090

hope everyone understand thanks!

Read only

0 Likes
990

Hi,

You can try the below code, but it may be bit difficult :

declare itab1 and itab2 similar to itab.

sort itab by material.

loop at itab.

loop at itab1 where itab-matnr.

move : itab1 to itab2.

append itab2.

clear itab2.

endloop.

describe table itab2 lines sy-tfill.

if sy-tfill GE 2.

loop at itab2.

write : / itab2-number.

endloop.

endif.

Refresh itab2.

Clear itab2.

endloop.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
990

thank you all!