Application Development 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: 

How to use field symbols in dynamic select query

Former Member
0 Kudos

I have a requirement to take the table name from selection screen and get data from that table

SELECT * FROM (P_TBLNM)

INTO TABLE <ITAB>

WHERE <condition>.

I have declared field symbol as type any table , but i am getting dump saying fieldsymbol is not getting assigned .

Any pointers , please help.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Laxmi ,

Use the below code.

DATA: gv_dref TYPE REF TO data,

gi_konp like standard table of konp WITH HEADER LINE,

FIELD-SYMBOLS: <gf_itab> TYPE STANDARD TABLE,

<wa> .

PARAMETERS:p_table TYPE rsrd1-tbma_val.

START-OF-SELECTION.

"Create Dynamic internal table

CREATE DATA gv_dref TYPE TABLE OF (p_table).

ASSIGN gv_dref->* TO <gf_itab>.

"Select query

SELECT * FROM (p_table) INTO TABLE <gf_itab> up to 100 rows . " OR use where ( YOUR CONDITION ).

field-SYMBOLS : <field1>.

loop at <gf_itab> assigning <wa>.

ASSIGN COMPONENT 'KNUMH' OF STRUCTURE <wa> TO <field1>.

select single * from konp into gi_konp where knumh = <field1> .

append gi_konp.

endloop.

Hope your problem will solve.

Thanks

8 REPLIES 8

Former Member
0 Kudos

Hi Laxmi,

Kindly go through below link, read all there carefully, I hope you will find a solution.

[http://wiki.sdn.sap.com/wiki/display/stage/Workingwithdynamictablesusingfieldsymbols]

[;

Kindly set to resolved, if it helps you.

Regards

Abhii...

Edited by: Abhii on Nov 17, 2009 7:01 AM

Former Member
0 Kudos

Hi Laxmi,

Have you done this before inserting data into <ITAB> using select query:-

ASSIGN (P_TBLNM) TO <ITAB>.

If not do this before SELECT query.

Kindly set to resolved if it helps you.

Regards

Abhii...

Edited by: Abhii on Nov 17, 2009 7:09 AM

venkat_o
Active Contributor
0 Kudos

Hi Laxmi, <li>Try this way.


REPORT ztest.
DATA: gv_dref            TYPE REF TO data.
FIELD-SYMBOLS: <gf_itab> TYPE STANDARD TABLE,
               <wa>      TYPE ANY.

PARAMETERS:p_table TYPE rsrd1-tbma_val.

START-OF-SELECTION.
  "Create Dynamic internal table
  CREATE DATA gv_dref TYPE TABLE OF (p_table).
  ASSIGN gv_dref->* TO <gf_itab>.
  "Select query
  SELECT * FROM (p_table) INTO TABLE <gf_itab> UP TO 100 ROWS.
  BREAK-POINT.
Thanks Venkat.O

Former Member
0 Kudos

Hi laxmi,

Why do you have 2 post for this issue? anyways, try this:

DATA : ref_table_des TYPE REF TO cl_abap_structdescr,

<itab> TYPE STANDARD TABLE,

<wtab> TYPE ANY,

dref TYPE REF TO DATA.

ref_table_des ?= cl_abap_typedescr=>describe_by_name( P_TBLNM ).

create data dref type handle ref_table_des.

assign dref->* to <wtab>.

create data dref like standard table of <wtab>.

assign dref->* to <itab>.

SELECT * FROM (P_TBLNM)

INTO TABLE <itab>

WHERE <condition>.

Regards,

Richard

0 Kudos

Hi Richard ,

After this select query

SELECT * FROM (P_TBLNM)

INTO TABLE <ITAB>

WHERE KNUMH IN SO_KNUMH

AND DATBI GE SYST-DATLO.

I have to do this

SELECT * FROM KONP INTO TABLE GI_KONP FOR ALL ENTRIES IN <itab>

WHERE KNUMH = <itab>-KNUMH.

Please help.

0 Kudos

Hi laxmi,

for your second question, try this one:

DATA : ref_table_des TYPE REF TO cl_abap_structdescr,

<itab> TYPE STANDARD TABLE,

<wtab> TYPE ANY,

dref TYPE REF TO DATA.

DATA: <knumh>.

ref_table_des ?= cl_abap_typedescr=>describe_by_name( P_TBLNM ).

create data dref type handle ref_table_des.

assign dref->* to <wtab>.

create data dref like standard table of <wtab>.

assign dref->* to <itab>.

SELECT * FROM (P_TBLNM)

INTO TABLE <itab>

WHERE <condition>.

LOOP AT <itab> ASSIGNING <wtab>.

assign component 'KNUMH' of structure <wtab> to <knumh>.

SELECT * FROM KONP

APPENDING TABLE GI_KONP

WHERE KNUMH = <knumh>.

ENDLOOP.

Regards,

Richard

Edited by: richard santos on Nov 17, 2009 8:16 AM

Former Member
0 Kudos

Hi Laxmi ,

Use the below code.

DATA: gv_dref TYPE REF TO data,

gi_konp like standard table of konp WITH HEADER LINE,

FIELD-SYMBOLS: <gf_itab> TYPE STANDARD TABLE,

<wa> .

PARAMETERS:p_table TYPE rsrd1-tbma_val.

START-OF-SELECTION.

"Create Dynamic internal table

CREATE DATA gv_dref TYPE TABLE OF (p_table).

ASSIGN gv_dref->* TO <gf_itab>.

"Select query

SELECT * FROM (p_table) INTO TABLE <gf_itab> up to 100 rows . " OR use where ( YOUR CONDITION ).

field-SYMBOLS : <field1>.

loop at <gf_itab> assigning <wa>.

ASSIGN COMPONENT 'KNUMH' OF STRUCTURE <wa> TO <field1>.

select single * from konp into gi_konp where knumh = <field1> .

append gi_konp.

endloop.

Hope your problem will solve.

Thanks

Former Member
0 Kudos

Hi Laxmi,

If you assign the table to the field symbol as I said before it will work.

ASSIGN (P_TBLNM) to <ITAB>.

Hope it helps...

Regards

Abhii...

Edited by: Abhii on Nov 17, 2009 8:17 AM