Hey yall,
This is somewhat complicated, but if you can help me out I'd appreciate it.
I'm having some difficulty with the following situation:
I have a table ZCatFld that contains the catalog name and the field name (within that catalog).
I then try to search through the catalog to find the KEY value of the record where the field (as defined in the selection screen) matches the value entered by the user.
In the selection screen, there is an option to enter in values for GLAcct or CustNO.
Zcatfld's Identifier is this field <value of either 'GLacct' or 'Custno'.>
So I do the following:
IF GLACCT-LOW IS INITIAL.
SEARCHEDFLD = 'GLACCT'.
EnteredValue = GLACCT-LOW.
ELSE.
IF CUSTNO-LOW IS INITIAL.
SEARCHEDFLD = 'CUSTNO'.
EnteredValue = CUSTNO-LOW.
ENDIF.
ELSE.
EXIT.
ENDIF.
SELECT catalogname INTO (TABLENAME) FROM Zcatfld WHERE SearchedFld EQ SearchFld.
SELECT FLD FROM zcatfld INTO (FIELDNAME) WHERE SearchedFld EQ SearchFld.
SELECT Key INTO varKey FROM (TABLENAME) WHERE (FIELDNAME) EQ EnteredValue.
<i>the (fieldname) does not work as I thought it would. I thought that by enclosing it in ( ) it would be dynamic and still be respected as a field structure. Can someone please help? I'd appreciate it. Thankyou.</i>
N L
Hi Natasha,
This is how you need to modify your code.
DATA: BEGIN OF lt_cond OCCURS 0 , cond_line(60) TYPE c , END OF lt_cond . IF glacct-low IS INITIAL. searchedfld = 'GLACCT'. enteredvalue = glacct-low. ELSEIF custno-low IS INITIAL. searchedfld = 'CUSTNO'. enteredvalue = custno-low. ELSE. EXIT. ENDIF. SELECT catalogname fld INTO (tablename,fieldname) FROM zcatfld WHERE searchedfld EQ searchfld. ENDSELECT. REFRESH lt_cond. CLEAR lt_cond. CONCATENATE fieldname 'EQ' enteredvalue '.' INTO lt_cond-cond_line SEPARATED BY space . APPEND lt_cond . CLEAR lt_cond. SELECT key INTO varkey FROM (tablename) WHERE (lt_cond). ENDSELECT.
Make sure that the field name and the table name are in uppercase.
Let us know if this helped.
Srinivas
Hi Natasha
For dynamic WHERE condition try this:
DATA: BEGIN OF lt_cond OCCURS 0 , cond_line(60) TYPE c , END OF lt_cond . REFRESH lt_cond . CONCATENATE fieldname 'EQ' enteredvalue '.' INTO lt_cond-cond_line SEPARATED BY space . APPEND lt_cond . SELECT SINGLE key INTO varkey FROM (tablename) WHERE lt_cond .
Hope this helps...
*--Serdar
As Charles said, Use field symbols to do this.
data: xmara type mara. parameters: p_field(10) type c default 'XMARA'. field-symbols: <fs>. assign (p_field) to <fs>. select single * from mara into <fs> where matnr in s_matnr. check sy-subrc = 0.
Regards,
Rich Heilman
Message was edited by: Rich Heilman
Add a comment