‎2008 Mar 13 3:04 PM
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
‎2008 Mar 13 4:04 PM
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.
‎2008 Mar 13 3:52 PM
‎2008 Mar 13 4:04 PM
Hi
Not sure what you mean by Explore more on this? Do you mean explain more?
tnx
P
‎2008 Mar 13 4:04 PM
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.
‎2008 Mar 13 4:12 PM
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.