‎2008 Dec 12 9:28 AM
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
‎2008 Dec 12 9:32 AM
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 ...
‎2008 Dec 12 9:30 AM
‎2008 Dec 12 9:30 AM
Please check this will get some information form this link.
http://help.sap.com/saphelp_nw70/helpdata/en/67/93b80914a911d2953c0000e8353423/content.htm
‎2008 Dec 12 9:31 AM
Hi ,
Please ref the SAPTECHNICAL.com
you will find one good tutorial over there about the dynanic select stamnts.
regards,
Ajay reddy
‎2008 Dec 12 9:32 AM
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 ...
‎2008 Dec 12 9:47 AM
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
‎2008 Dec 12 11:17 AM
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
‎2008 Dec 12 9:32 AM
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.
‎2008 Dec 12 9:37 AM
I am sorry Rainer,
I will do a better search before placing a question.
I did go through SDN though...
Warm regards,
Hari Kiran