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

Dyamic Loop

Former Member
0 Likes
687

Hi guys,

I have two dynamic tables <it_pro> and <it_acor>, and I need to make a loop statement for one of then depending on the column of an ALV that was edited.

How can I do in order to do a loop dynamically?

Regards,

Eric

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
664

HI,

Why don't you use the DO loop, then write an EXIT command where ever required

Regards

Sudheer

6 REPLIES 6
Read only

Former Member
0 Likes
665

HI,

Why don't you use the DO loop, then write an EXIT command where ever required

Regards

Sudheer

Read only

0 Likes
664

Hi Sudheer,

Why I want to do is to use the same loop for the two validations in order to save lines of code.

For example,

IF ls_mod_cell-fieldname = 'PROPUESTA'.

I want to make this: LOOP AT <it_pro> INTO <wa_pro>.

else

LOOP AT <it_acor> INTO <wa_pro>.

endif.

I want to make it like this because all the code inside the loop is the same.

Regards,

Eric

Read only

0 Likes
664

Hello Eric

Perhaps you are looking for something like this:

field-symbols:
  <lt_itab>       TYPE TABLE,
  <ls_line>       TYPE ANY,
  <ld_fld>         TYPE ANY.


  IF ( ls_mod_cell-fieldname = 'PROPUESTA' ).
    ASSIGN <lt_itab> TO <it_pro>.
  ELSE.
    ASSIGN <lt_itab> TO <it_acor>.
  ENDIF.

  LOOP AT <lt_Itab> ASSIGNING <ls_line>.
    ASSIGN ls_mod_cell-fieldname OF STRUCTURE <ls_line> TO <ld_fld>.

*   Now validate the changed data...
    IF ( <ld_fld> .... ).

    ELSE.

    ENDIF.
  ENDLOOP.

Regards

Uwe

Read only

0 Likes
664

Hi Uwe,

I think this will work, I'm gonna try and let you know.

Regards,

Eric

Read only

0 Likes
664

Thanks again Uwe,

This was what I needed.

field-symbols:

<lt_itab> TYPE TABLE,

<ls_line> TYPE ANY,

<ld_fld> TYPE ANY.

IF ( ls_mod_cell-fieldname = 'PROPUESTA' ).

ASSIGN <it_pro>< TO lt_itab>.

ELSE.

ASSIGN <it_acor>< TO lt_itab>.

ENDIF.

LOOP AT <lt_Itab> ASSIGNING <ls_line>.

....

Regards,

Eric

Read only

0 Likes
664

You can try these code below:


IF ( ls_mod_cell-fieldname = 'PROPUESTA' ).
  itab_name = 'it_pro'.
ELSE.
  itab_name = 'it_acor'.
ENDIF.

LOOP AT (itab_name) ASSIGNING <ls_line>.
....

If it can run correctly, it wil be high performance.

-


Sorry, unable to interpret the expression "(itab_name)".

It is error.

Message was edited by:

Meng Yuxin