‎2008 Jan 23 6:37 AM
hi all,
below shown is my select query how can i replace it by defining globally the field and using it in select instead of writing dty01 to dty20. please suggest me some procedure with example.
SELECT pernr endda begda depcv
dty01 dty01 dty02 dty02
dty03 dty03 dty04 dty04
dty05 dty05 dty06 dty06
dty07 dty07 dty08 dty08
dty09 dty09 dty10 dty10
dty11 dty11 dty12 dty12
dty13 dty13 dty14 dty14
dty15 dty15 dty16 dty16
dty17 dty17 dty18 dty18
dty19 dty19 dty20 dty20
INTO TABLE g_i_pa0167
FROM pa0167
FOR ALL ENTRIES IN g_i_pa0000
WHERE pernr EQ g_i_pa0000-pernr
AND begda LE g_begda
AND endda GE g_endda.
‎2008 Jan 23 6:39 AM
Hi Abinash,
It is not possible to use Variables within a Select query as an alternative for the field names that are needed to be selected.
Reward points if this clarifies,
Kiran
‎2008 Jan 23 6:44 AM
Hi,
There is no way of avoiding field specification in Select query.
But you can do one thing. Define 'g_i_pa0167' with the same strucutre of table 'pa0167' and use '*'(asterisk) in the Select.
this is the only option available.
Select * FROM pa0617
‎2008 Jan 23 6:53 AM
hi,
if u r using this query again and again u can do this.......
select (column_syntax) from...........
... (column_syntax)
Effect
Instead of static data, a data object column_syntax in brackets can be specified, which, when the command is executed, either contains the syntax shown with the static data, or is initial. The data object column_syntax can be a character-type data object or an internal table with a character-type data type. The syntax in column_syntax, like in the ABAP editor, is not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows.
If column_syntax is initial when the command is executed, columns is implicitly set to * and all columns are read.
If columns are specified dynamically without the SINGLE addition, the resulting set is always regarded as having multiple rows.
Notes
Before Release 6.10, you could only specify an internal table with a flat character-type row type for column_syntax with a maximum of 72 characters. Also, before Release 6.10, if you used the DISTINCT addition for dynamic access to pool tables or cluster tables, this was ignored, but since release 6.10, this causes a known exception.
If column_syntax is an internal table with header line, the table body and not the header line is evaluated.
Example
Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field.
PERFORM my_select USING `CITYFROM`.
ULINE.
PERFORM my_select USING `CITYTO`.
FORM my_select USING l_group TYPE string.
DATA: l_columns TYPE TABLE OF string,
l_container TYPE string,
l_count TYPE i.
APPEND l_group TO l_columns.
APPEND `count( * )` TO l_columns.
SELECT (l_columns)
FROM spfli
INTO (l_container, l_count)
GROUP BY (l_group).
WRITE: / l_count, l_container.
ENDSELECT.
ENDFORM.
‎2008 Jan 23 6:56 AM
Hi,
Fields specification is madatory while using a select statement.
Onle alternative to it can be as follows:
You can define a zstructure with the fields dty01 to dty20 (having same type as the similar elements from pa0167 table )in it and then use:
Step 1: Declare an internal table itab
Data: itab TYPE TABLE OF ZStructure WITH HEADER LINE.
and then
Select * from pa0167 into CORRESPONDING FIELDS OF TABLE ITAB.
Rewards if useful,
Regards,
Saurabh