on 2006 Mar 23 3:41 PM
Hai,
I have problem in my select query,
My previous select query:
SELECT rrcty
ryear
rbukrs
rzzpspid
SUM( hslvt )
SUM( hsl01 )
SUM( hsl02 )
SUM( hsl03 )
SUM( hsl04 )
SUM( hsl05 )
SUM( hsl06 )
SUM( hsl07 )
SUM( hsl08 )
SUM( hsl09 )
SUM( hsl10 )
SUM( hsl11 )
SUM( hsl12 )
SUM( mslvt )
SUM( msl01 )
SUM( msl02 )
SUM( msl03 )
SUM( msl04 )
SUM( msl05 )
SUM( msl06 )
SUM( msl07 )
SUM( msl08 )
SUM( msl09 )
SUM( msl10 )
SUM( msl11 )
SUM( msl12 )
FROM zzsl5t
INTO TABLE it_erbproj
WHERE rldnr EQ c_rldnr AND
rrcty EQ c_rrcty AND
ryear EQ v_srr_fyear AND
rbukrs EQ v_srr_ccode AND
racct EQ v_racct AND
rzzpspid IN r_zzpspid
GROUP BY RRCTY ryear RBUKRS rzzpspid.
now i want change the above select query as,
If user enters input period 03 means,
i have to select
SELECT rrcty
ryear
rbukrs
rzzpspid
SUM( hslvt )
SUM( hsl01 )
SUM( hsl02 )
SUM( hsl03 )
SUM( mslvt )
SUM( msl01 )
SUM( msl02 )
SUM( msl03 )
only, not to select all the periods.
how can i give fields dynamically.
please suggest me.
Elamaran
You need to define an internal table having one field like dd03l-fieldname. Append your fieldnames dynamically to this internal table and then you can have the select statement as follows.
SELECT (itab) FROM zzsl5t
INTO CORRESPONDING FIELDS OF TABLE it_erbproj.
You have to be careful about the INTO option as now your number of fields selected is varying and you cannot simply say INTO.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is an example. I took MARA as an example, but it can be made even more dynamic code than this. But it shows how you can dynamically build the fields to be selected from a table.
REPORT ztestaks1 MESSAGE-ID 00 NO STANDARD PAGE HEADING
LINE-SIZE 160.
DATA: BEGIN OF i_fields OCCURS 0,
fieldname LIKE dd03l-fieldname.
DATA: END OF i_fields.
DATA: BEGIN OF i_objects_selected OCCURS 0.
INCLUDE STRUCTURE rseui_f4.
DATA: END OF i_objects_selected.
DATA: BEGIN OF i_mara OCCURS 0.
INCLUDE STRUCTURE mara.
DATA: END OF i_mara.
DATA: v_table LIKE dd02l-tabname VALUE 'MARA'.
START-OF-SELECTION.
CALL FUNCTION 'REPOSITORY_INFO_SYSTEM_F4'
EXPORTING
object_type = 'TABL_FIELD'
object_name = '*'
enclosing_object = v_table
suppress_selection = 'X'
* VARIANT = ' '
* LIST_VARIANT = ' '
* DISPLAY_FIELD =
multiple_selection = 'X'
* SELECT_ALL_FIELDS = ' '
* WITHOUT_PERSONAL_LIST = ' '
* PACKAGE = ' '
* USE_ALV_GRID = ' '
* IMPORTING
* OBJECT_NAME_SELECTED =
* ENCLOSING_OBJECT_SELECTED =
* STRUCINF =
TABLES
objects_selected = i_objects_selected
EXCEPTIONS
cancel = 1
wrong_type = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
IF NOT i_objects_selected[] IS INITIAL.
LOOP AT i_objects_selected.
i_fields-fieldname = i_objects_selected-obj_name.
APPEND i_fields.
CLEAR i_fields.
ENDLOOP.
ENDIF.
SELECT (i_fields) FROM (v_table)
INTO CORRESPONDING FIELDS OF TABLE i_mara.
LOOP AT i_mara.
ENDLOOP.
User | Count |
---|---|
68 | |
11 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.