Skip to Content
author's profile photo Former Member
Former Member

Dynamic (Field) -- in DYNAMIC SELECT

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Feb 25, 2005 at 06:54 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 25, 2005 at 05:26 PM

    Use field symbols to reference the INTO area. You can create this area dynamically with CREATE DATA...

    ASSIGN <FS> to wa.
    SELECT ... INTO <FS>

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 25, 2005 at 05:59 PM

    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

    ssimsekler@yahoo.com

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hey Serdar- thanks for helping.

      For some reason, when I debug this, the portion of code you sent me isn't picking up any key value.

      I entered in a GLACCT -- I know glacct has a catalog and a catalog field in the CatalogLookup table Zdoltarc02.

      And I manually looked in that catalog and that field to make sure the value I entered has a corresponding key.

      But when I step through the debugger, nothing is retrieved into the varKey.

      Can you offer any advice? I'm reading up on field symbols as Charles had previously suggested, but I don't know if they are necessary.

      Thanks,

      Natasha 😊

      REPORT ZINDEXEDTEST2 .

      *****************************************

      DATA: BEGIN OF lt_cond OCCURS 0 ,

      cond_line(60) TYPE c ,

      END OF lt_cond .

      data: wa_skas TYPE skas,

      wa_kna1 TYPE KNA1,

      searchedfld type string,

      enteredvalue LIKE SKAS-SAKNR,

      tablename LIKE dd02t-tabname,

      varkey LIKE zarixfi3-ARCHIVEKEY.

      SELECT-OPTIONS ACCT_NO FOR wa_skas-saknr.

      SELECT-OPTIONS CUSTNO FOR wa_kna1-KUNNR.

      REFRESH lt_cond .

      IF acct_no-LOW <> ''.

      SEARCHEDFLD = 'acct_no'.

      EnteredValue = acct_no-LOW.

      ENDIF.

      IF CUSTNO-LOW <> ''.

      SEARCHEDFLD = 'CUSTNO'.

      EnteredValue = CUSTNO-LOW.

      ENDIF.

      IF ACCT_NO-LOW EQ '' AND CUSTNO-LOW EQ ''.

      EXIT.

      ENDIF.

      SELECT aiscatalog INTO (TABLENAME) FROM zdoltarc02 WHERE SearchFld EQ SearchedFld.

      CONCATENATE searchedfld 'EQ' enteredvalue '.'

      INTO lt_cond-cond_line

      SEPARATED BY space .

      APPEND lt_cond .

      SELECT SINGLE archivekey INTO varkey

      FROM (tablename)

      WHERE (lt_cond) .

      ENDSELECT.

      WRITE:/ 'VARKEY:', VARKEY.

  • Posted on Feb 25, 2005 at 05:25 PM

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 25, 2005 at 05:36 PM

    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
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.