Application Development and Automation 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: 
Read only

Dynamic select Statements

Former Member
0 Likes
1,000

Hi all,

can the fields in my select statement be called dynamically

Lets assume my select statement will be something like --

SELECT FIRSTNAME

LASTNAME

CITY

FROM TABLE

INTO ITAB.

These field names will be in a flat file on the application server.

"First name,Last Name,City"

I need to read that file on the application server

and place those fields in the select statement.

can this be done.??

Warm regards,

Hari Kiran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
928

Yes it can be done. You can build the list of fields in a string type variable by simply concatenating and then in SELECT (g_string) FROM table INTO ...

8 REPLIES 8
Read only

Former Member
0 Likes
928

Dear Hari,

please look into this thread.

Regards,

Flavya

Read only

Former Member
0 Likes
928

Please check this will get some information form this link.

http://help.sap.com/saphelp_nw70/helpdata/en/67/93b80914a911d2953c0000e8353423/content.htm

Read only

Former Member
0 Likes
928

Hi ,

Please ref the SAPTECHNICAL.com

you will find one good tutorial over there about the dynanic select stamnts.

regards,

Ajay reddy

Read only

Former Member
0 Likes
930

Yes it can be done. You can build the list of fields in a string type variable by simply concatenating and then in SELECT (g_string) FROM table INTO ...

Read only

0 Likes
928

Hi Ankesh,

Thanks for replying.

That was what I was looking for...

I will use Read dataset and Open Dataset

commands to read the file on the application server.

Then place the contents in a string variable.

Then write the select statement with the variable in it

containing the field names.

I would like to thank everyone for answering.

I will test it and let you all know .

Warm regards,

Hari Kiran

Read only

0 Likes
928

Hi all,

It's working.

Here's the code---

DATA: BEGIN OF it0006 OCCURS 0.

INCLUDE STRUCTURE p0006.

DATA: END OF it0006.

DATA: w_fields(200) TYPE c.

PARAMETERS: fields TYPE localfile DEFAULT 'D:\usr\sap\trans\data\FIELDS.txt'.

  • " flat file contains fields separated by space.

OPEN DATASET fields FOR INPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc EQ 0.

DO.

READ DATASET fields INTO w_fields.

IF sy-subrc NE 0.

EXIT.

ENDIF.

ENDDO.

ENDIF.

CLOSE DATASET fields.

SELECT (w_fields) "pernr

  • anssa

  • name2

  • stras

  • locat

  • pstlz

  • ort01

  • ort02

  • state

  • land1

  • telnr

FROM pa0006

INTO CORRESPONDING FIELDS OF TABLE it0006.

w_fields now holds the fields which need to placed in the select statement.

Thanking you all once again.

Warm regards,

Hari Kiran

Read only

rainer_hbenthal
Active Contributor
0 Likes
928

Yes, it can be done. Read the only help about the syntax before asking question wehre the answer can be easily retrieved from the online help.

Read only

0 Likes
928

I am sorry Rainer,

I will do a better search before placing a question.

I did go through SDN though...

Warm regards,

Hari Kiran