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 dynamic internal table

Former Member
0 Likes
1,670

Hi,

Below is my code.

LOOP AT <t_dyntable_ord> ASSIGNING <t_line_tmp>." WHERE check EQ 'X'.
            ASSIGN COMPONENT 1 OF STRUCTURE <t_line_tmp> to <tmp>.
            if <tmp> = 'X'.
            lv_counter = lv_counter + 1.
            "  LOOP AT it_index_rows INTO wa_index_rows.
            ASSIGN COMPONENT 2 OF STRUCTURE <t_line_tmp> to <mat>.
            SET PARAMETER ID 'MAT' FIELD <mat>.
            "READ TABLE it_prd_pld INTO wa_prd_pld WITH KEY
            SET PARAMETER ID 'WRK' FIELD p_werks.
            CALL TRANSACTION 'MD02' AND SKIP FIRST SCREEN.
            endif.
          ENDLOOP.

Can we have a condition while looping the dynamic internal table?

In the above code where condition is not working for me.

I solved the problem by inserting if condition ->

ASSIGN COMPONENT 1 OF STRUCTURE <t_line_tmp> to <tmp>.
            if <tmp> = 'X'.

but this will cause the performance problem.

Please sujjest.

Regards,

Prathap

5 REPLIES 5
Read only

Former Member
0 Likes
712

Did you try using the WHERE clause of the LOOP AT statement ?

I am not sure, however, if you can access one of the components of the assigned worked area.

Hope it helps

Avraham

Read only

Former Member
0 Likes
712

If you've an internal table with the structure of your dynamic table u can use it in order to change the data:

DATA: <WA> TYPE ANY,

<FIELD> TYPE ANY.

LOOP AT <ITAB> ASSIGNING <WA>.

LOOP AT STRUT_TAB WHERE FIELDNAME = .......

ASSIGN COMPONENT STRUT_TAB-FIELDNAME OF STRUCTURE <WA> TO <FIELD>.

CASE STRUT_TAB-FIELDNAME.

WHEN ......... <FIELD> = ......

WHEN ........ <FIELD> = ......

ENDCASE.

ENDIF.

ENDLOOP.

ENDLOOP.

or try like this.

LOOP AT <dyn_table> INTO <dyn_wa>.

DO.

ASSIGN COMPONENT sy-index

OF STRUCTURE <dyn_wa> TO <dyn_field>.

IF sy-subrc 0.

EXIT.

ENDIF.

IF sy-index = 1.

WRITE:/ <dyn_field>.

  • ELSEIF sy-index = 4.

  • <dyn_field> = 'ABCD'.

  • WRITE: <dyn_field>.

ELSE.

WRITE: <dyn_field>.

ENDIF.

ENDDO.

ENDLOOP.

i hope you get some idea

check this link too

Read only

0 Likes
712

I have 1000s of records in my internal table, but only few of them have the status code checked.

I need to select only those records for which the status if 'X'.

if i loop through the internal table it follows 1000s of iterations,

My code is now doing that.

I tried inserting where clause in LOOP AT statement but it din't work.

Please suggest how this can be done?

Regards,

Prathap

Read only

0 Likes
712

Solved

Read only

0 Likes
712

how ?