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: 

Unassign field symbol of Loop while modifying the contents

kiran_k8
Active Contributor
11,295

Folks,

Is it the right way to unassign a field symbol of the concerned loop ie <fs_itab1>?

If I Unassign within the loop it is going for dump whereas outside the loop it is not.

Do we have any other better ways to clear ie unassign the field symbol of loop within the loop at the end of every iteration.?

Is it wrong to unassign the field symbol of the concerned loop within the loop at the end of every iteration ?


DATA:itab1  TYPE STANDARD TABLE OF ztable1,

        itab2      TYPE STANDARD TABLE OF ztable2.           


FIELD-SYMBOLS:<fs_itab1>  TYPE ztable1,

                                 <fs_itab2>    TYPE ztable2,


LOOP AT itab1 ASSIGNING <fs_itab1>.

READ TABLE itab2 ASSIGNING <fs_itab2> WITH KEY fp_irn = <fs_itab1>-fp_irn

                                                                               pspid = iv_pspid

                                                                               grp_taskid = iv_task_id.

IF sy-subrc = 0.

  <fs_itab1>-upd_user = sy-uname.

  ENDIF.

UNASSIGN:<fs_itab2>.

ENDLOOP.

UNASSIGN:<fs_itab1>.


Thanks,

K.Kiran.

6 REPLIES 6

Tomas_Buryanek
Active Contributor
0 Kudos
1,977

Why do you want to unassign it inside loop?

Field symbol is re-assigned at each itteration so you do not need worry about manual unassig.

-- Tomas --

Former Member
0 Kudos
1,977

Hi,

one thing could be to have the unassign inside the if statement, so the <fs_itab2> only gets assigned if the read table returns a value. Otherwise it is not assigned and it will dump I suppose.

Br,

Tim

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,977

clear ie unassign the field symbol of loop

CLEAR & UNASSIGN are not the same for FIELD-SYMBOL.

kiran_k8
Active Contributor
0 Kudos
1,977

Yes Suhas.I realised that while debugging.

But,why shouldn't we unassign a field symbol of the loop at the end of every iteration when anyway we are assigning it again at the start of every iteration ?

Thanks,

K.Kiran.

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Kudos
1,977

Press F1 & RTFM (F = Funny)!

former_member185537
Participant
0 Kudos
1,977

Hi Kiran,

What do you want to achieve