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

Dynamic internal table and dynamic read statements.

krishna_maram
Participant
0 Likes
1,775

Hi,

My Scenario :

I have two dynamic internal tables.

I am looping at one internal table and trying to read another table.

In the read statement how do I mention the key dyamically.

Example code below :

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

  • read second dynamic internal table.

enloop.

The key which I want use for reading say it is keyed in the selection criteria....

Also based on the value I read I want to modify the first internal table field value.

Remember I dont want to explicity mention the key

How do I do that?

Thanks

Krishna.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
678

Hi

U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

    LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
        
        ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA2> TO <FS>.
        
        CHECK <FS> IN (=) .......
            ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA> TO <FS2>.
            <FS2> = .......
            EXIT.
    ENDLOOP. 
ENDLOOP.

Max

4 REPLIES 4
Read only

Former Member
0 Likes
678

Check this Example..

code

DATA: itab TYPE STANDARD TABLE OF mara.

DATA: wa TYPE mara.

DATA: where(72).

DATA: where1(72).

Populate.

wa-matnr = 'TEST'.

wa-mtart = 'M1'.

APPEND wa TO itab.

Where clause

where = 'MATNR'.

where1 = 'MTART'.

READ TABLE itab INTO wa WITH KEY (WHERE) = 'TEST'

(WHERE1) = 'M1'.

IF sy-subrc = 0.

WRITE: / 'found'.

ENDIF.

[/code]

regards,

venkat.

Read only

0 Likes
678

Hi,

READ TABLE itab INTO wa WITH KEY (WHERE) = 'TEST'

'TEST' should not be hardcoded as well.

That will be the field from first internal table.

Thanks,

krishna.

Read only

Former Member
0 Likes
679

Hi

U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

    LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
        
        ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA2> TO <FS>.
        
        CHECK <FS> IN (=) .......
            ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA> TO <FS2>.
            <FS2> = .......
            EXIT.
    ENDLOOP. 
ENDLOOP.

Max

Read only

0 Likes
678

Hi Max,

Thankyou . I got it.

Sample coding :

LOOP AT <dyn_table> ASSIGNING <dyn_wa>.

READ TABLE ifc INTO wa_ifc WITH KEY fieldname = p_fname.

IF sy-subrc EQ 0.

ASSIGN COMPONENT p_fname OF STRUCTURE <dyn_wa> TO <dyn_wa1>.

READ TABLE it_maptab

WITH KEY matkl = <dyn_wa1> ASSIGNING <fs_tab3>.

<dyn_wa1> = <fs_tab3>-znew_matgrp.

ENDIF.

ENDLOOP.

points rewarded.

Thanks,

Krishna.