‎2007 Jun 19 6:20 AM
Hi all
i have to perform a dynamic selection of table and it's field. using select option i have to fetch some records and the update them according to my needs.
i am able to fetch the table and its fields dynamically into an internal table. but i am not able to code for the select option i.e how to specify the dynamic table name and field while declaring the select option(please refer to the code below)
also we cannot use function modules.
REPORT z_dynamic.
Tables: vbak.
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE standard TABLE,
<dyn_wa>,
<dyn_field>.
DATA: dy_table TYPE REF TO data ,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
PARAMETERS: p_field(10) TYPE c.
<b>Select-options: s_Range for ??????</b>
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
&----
*& Form get_structure
&----
text
----
--> p1 text
<-- p2 text
----
form get_structure .
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform. " get_structure
&----
*& Form create_dynamic_itab
&----
text
----
--> p1 text
<-- p2 text
----
form create_dynamic_itab .
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
assign dy_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform. " create_dynamic_itab
&----
*& Form get_data
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
Select Data from table.
select * into table <dyn_table>
from (p_table).
endform. " get_data
&----
*& Form write_out
&----
text
----
--> p1 text
<-- p2 text
----
form write_out .
Write out data from table.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc <> 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
endform. " write_out
-
Thanks in advance
Regards,
Swati Garg
‎2007 Jun 19 6:36 AM
Hi,
data city(50).
Select-options: s_Range for city.
This will work.You can read these in F1 Help for select-options.
Kindly reward points if it helps.
‎2007 Jun 19 6:36 AM
Hi,
data city(50).
Select-options: s_Range for city.
This will work.You can read these in F1 Help for select-options.
Kindly reward points if it helps.
‎2007 Jun 19 7:14 AM
Thanks Jayanthi.
Now my problem is how to use where clause so that it fetch only those rows which lie in the range of select option.Remember here Table is selected dynamically.so fields and select option ranges is also dynamic according to table.
Plz Help.
Thanks in advance.
Regards,
Swati Garg