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

Dynamic Select Statement......

Hi,

I am writing this dynamic select statement.

SELECT (W_FIELDLIST) FROM (P_TNAME) INTO <FS_DYNTABLE> WHERE KUNNR = P_KUNNR

I am getting runtime error for this statement. I passed three different values too W_FIELDLIST but none

is working.

W_FILEDLIST = KUNNR LAND1 NAME1 ORT01 TELF1 and also

W_FILEDLIST = KUNNR, LAND1, NAME1, ORT01, TELF1 and also

W_FILEDLIST = KUNNR,LAND1,NAME1,ORT01,TELF1.

What is the correct format?

Help will be appreciated..

Thanks,

Ibrahim

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 07:03 AM

    Hi Mohammed,

    You have to add each field as a separte row to an internal table.

    DATA : BEGIN OF w_fieldlist OCCURS 0,

    fld(1028) type c,

    END OF w_fieldlist.

    w_fieldlist-fld = 'KUNNR'.

    append w_fieldlist.

    clear w_fiedllist.

    w_fieldlist-fld = 'LAND1'.

    append w_fieldlist.

    clear w_fiedllist.

    w_fieldlist-fld = 'NAME1'.

    append w_fieldlist.

    clear w_fiedllist.

    w_fieldlist-fld = 'ORT01'.

    append w_fieldlist.

    clear w_fiedllist.

    w_fieldlist-fld = 'TELF1'.

    append w_fieldlist.

    clear w_fiedllist.

    Regards,

    Anil

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 06:51 AM

    Try this way.

    Data: fld TYPE TABLE OF STRING. 
    
    APPEND 'KUNNR' TO fld. 
    APPEND 'LAND1'  TO fld. 
    
    SELECT (fld) FROM (P_TNAME) INTO <FS_DYNTABLE> WHERE KUNNR = P_KUNNR

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 06:51 AM

    Hi,

    Ur first format is the correct one.

    W_FILEDLIST = KUNNR LAND1 NAME1 ORT01 TELF1 and also

    chk the declaration of W_FIELDLIST, is it string?

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Than Please test following Sample Code where Suppose you are entering in the parameter VBELN ERDAT.

      PARAMETERS: fields TYPE string.
      
      DATA: it_vbak LIKE STANDARD TABLE OF vbak WITH HEADER LINE.
      DATA: $fields TYPE string.
      
      $fields = fields.
      
      SELECT ($fields) from vbak
        INTO CORRESPONDING FIELDS OF TABLE it_vbak.
      
      loop at it_vbak INTO it_vbak.
        WRITE: / it_vbak-vbeln, it_vbak-erdat.
      ENDLOOP.

      Please Reply if else Issue,

      Kind Regards,

      Faisal

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 06:58 AM

    Hi Mohammed,

    You can select list of fields as given below, this will work perfectly.

    DATA: it_fieldlist TYPE TABLE OF fieldname,
              wa_fieldlist LIKE LINE OF it_fieldlist.
    
    wa_fieldlist = 'KUNNR'.
    APPEND wa_fieldlist TO it_fieldlist.
    
    wa_fieldlist = 'LAND1'.
    APPEND wa_fieldlist TO it_fieldlist.
    
    "Like this append all the fields you want.
    "Then write the query as 
    
    SELECT (it_fieldlist) FROM (p_tname) INTO <fs_dyntable> WHERE kunnr = p_kunnr.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 24, 2009 at 06:59 AM

    Hi,

    U can use this:

    W_FILEDLIST = KNA1~KUNNR KNA1~LAND1 KNA1~NAME1 KNA1~ORT01 KNA1~TELF1

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 24, 2009 at 07:00 AM

    Hi

    w_fieldlist need not be string type just char type with enough space

    W_FILEDLIST = KUNNR LAND1 NAME1 ORT01 TELF1

    or concatenate KUNNR LAND1 NAME1 ORT01 TELF1 into w_filedlist separated by space.

    Try hard coding other dynamic options in your select statement like table name ,FS_DYNTABLE

    and then check .

    Hope it helps!

    Viquar Iqbal

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 24, 2009 at 07:04 AM

    Hi,

    Please Test my Sample Code in the following Thread this will Solve out your problem

    [Dynamic Select Statement |dynamic select statement;

    Please Reply if any Issue,

    Kind Regards,

    Faisal

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 08:11 AM

    Hi Mohammed,

    As I have mentioned above fill an int table with field names and use that in the select query.

    Refer my first post of this thread.

    Regards,

    Manoj Kumar P

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 08:26 AM

    Try this,

    Data: w_fieldlist TYPE TABLE OF STRING.

    Append the values to w_fieldlist.

    Regards,

    Joan

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 24, 2009 at 10:40 AM

    Hey Anil....u were right dear.

    Thanks everyone

    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.