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

Reading internal table with dynamic fields

Former Member
0 Likes
661

Hi Gurus,

I'm trying to read an internal table with dynamic field.

Here is the scenario:

1) In the main program I have an internal table itab with fields a, b ,c ,d marked with X's

2) I call a perform in one of my modules and pass the field name of the internal table itab

in parameter p_field.

3) This is where I'm stuck. How do I read or even loop thru the internal table passing the field name in a parameter?

FORM get_field USING P_field

CHANGING P_HIDE_COL.

Read the table with key p_det_scrnm

Loop at internal table ITAB.

ENDFORM. " get_field

Any suggestion on the syntax?

Tnx

P

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
626

hi ,

I believe the column can be dynamic ...but not the entire WITH KEY..

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.

4 REPLIES 4
Read only

Former Member
0 Likes
626

can you explore more in this.

/Kiran

Read only

0 Likes
626

Hi

Not sure what you mean by Explore more on this? Do you mean explain more?

tnx

P

Read only

Former Member
0 Likes
627

hi ,

I believe the column can be dynamic ...but not the entire WITH KEY..

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
626

Thank you , thank you Venkat,

It worked!!!!!!

Its weird 'coz I did try something similar before I went all crazy doing differenct things but it didn't work. I guess I must have messed up on some comma or period somewhere.