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

Help for creating a simple loop.....

Former Member
0 Likes
784

Hi i have 2 internal tables

itab OCCURS 0 ,

posnv LIKE vbfa-posnv,

vbeln LIKE vbfa-vbeln,

vbtyp_n LIKE vbfa-vbtyp_n,

vbelv LIKE vbfa-vbelv,

flag TYPE i,

END OF itab.

and

itab1 OCCURS 0,

vbelv LIKE vbfa-vbelv,

flag TYPE i,

END OF itab1.

they are declared according to the fields in the table vbfa

and i want to set the itab1-flag to 1 if there's a situation when a record in itab contains the following values

itab - vbelv = itab1-vbelv

and

itab-vbtyp_n='M'

so i have used the following code

LOOP AT itab.

LOOP AT itab1.

IF itab-vbelv = itab1-vbelv AND itab-vbtyp_n = 'M'.

itab1-flag = 1.

ENDIF.

ENDLOOP.

ENDLOOP.

but its not working. Please help me

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
764

Hi,

loop at itab1.

lv_tabix = sy-tabix.

read table itab with key vbelv = itab1-vbelv

vbtyp_n = 'M' .

if sy-subrc = 0.

itab1-flag = 1.

modify itab1 index lv_tabix.

endif.

endloop.

Regards,

Ravi

6 REPLIES 6
Read only

Former Member
0 Likes
765

Hi,

loop at itab1.

lv_tabix = sy-tabix.

read table itab with key vbelv = itab1-vbelv

vbtyp_n = 'M' .

if sy-subrc = 0.

itab1-flag = 1.

modify itab1 index lv_tabix.

endif.

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
764

Hi,

You need to modify the code as follows:

LOOP AT itab.

LOOP AT itab1 where vbelv = itab-vbelv and itab-vbtyp_n = 'M'.

if sy-subrc eq 0.

itab1-flag = 1.

modify itab1 transporting flag.

clear itab1.

ENDIF.

ENDLOOP.

clear: itab.

ENDLOOP.

Read only

Former Member
0 Likes
764

Hi Musarrat,

You have done it but in the opposite way try this

LOOP AT itab1.

LOOP AT itab.

IF itab-vbelv = itab1-vbelv AND itab-vbtyp_n = 'M'.

itab1-flag = 1.

ENDIF.

ENDLOOP.

ENDLOOP.

I think this will do, try this.

If this really worked then dont forget to award the points.

Thanks and regards

Vipin Das

Read only

Former Member
0 Likes
764

LOOP AT itab assigning <wa>.

LOOP AT itab1 assigning <wa1>.

IF <wa>-vbelv = <wa1>-vbelv AND <wa>-vbtyp_n = 'M'.

<wa1>-flag = 1.

ENDIF.

ENDLOOP.

ENDLOOP.

Read only

Former Member
0 Likes
764

Hi,

you have to change the loop as shown here........



loop at itab1.

loop at itab where vbeln = itab1-vbeln.

IF itab-vbelv = itab1-vbelv AND itab-vbtyp_n = 'M'.
itab1-flag = 1.
ENDIF.
endloop

MODIFY ITAB1 TRANSPORTING FLAG.

endloop.

Thanks and Regards,
Kunjal Patel

Read only

Former Member
0 Likes
764

hi musarrat,

try out this,

loop at itab1.

read table itab wit key vbelv

if itab-vbelv = itab1-vbelv and itab-vbelv = 'M'.

itab1-flag = 1.

endif.

endloop