‎2006 Jun 26 4:28 PM
Hi Experts,
I want to create ranges dynamically....
Suppose user enters tabelname and fieldname
then I want to create ranges accordingly....
Any Help?
Regards
Dnyanesh
‎2006 Jun 26 4:38 PM
Hi Tamboli,
Ranges are like a select option like a low and a high.
Suppose for me lets take the date. low - 22/06/06, high - 26/06/06. I need to create a range for this dates.
data: ws_date type sy-datum.
Ranges f_date for ws_date.
f_date-low = 20060622.
f_date-high = 20060626.
f_date-sign = 'I'.
f_date-option = 'BT'.
append f_date.
now this range f_date will have the value between 22/06/06 to 26/06/06. If you have to check the value between these two dates you check by this.
ws_prdate = 20060624. (24/06/06)
if ws_prdate in f_date.
write: / "Valid date".
endif.
Hope this solves ur issue.
Regards,
Tushar
‎2006 Jun 26 4:42 PM
Hi,
check below code.............
RANGES: d_proto FOR rspotype-deldate,
clear : d_proto.
refresh:d_proto
d_proto-option = 'EQ'.
d_proto-sign = 'I'.
d_proto-high = '20061231'.
d_proto-low = '20060101'.
append d_proto.
Laxman
‎2006 Jun 26 4:46 PM
Hi, ranges and select-options are really internal tables. So you can achieve this just be creating a dynamic internal table. Please see the program below. This should show you want you need to do . Here the example is creating a range for the MATNR of MARA.
report zrich_0001.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<fs>.
data: it_fldcat type lvc_t_fcat.
data: imara type table of mara with header line.
selection-screen begin of block b1 with frame title text-001.
parameters: p_tabnm(30) type c default 'MARA'.
parameters: p_field(30) type c default 'MATNR'.
parameters: p_matnr type mara-matnr.
selection-screen end of block b1.
start-of-selection.
* Build the range
perform build_dyn_itab.
* Add a range to the range
assign component 'SIGN' of structure <dyn_wa> to <fs>.
<fs> = 'I'.
assign component 'OPTION' of structure <dyn_wa> to <fs>.
<fs> = 'EQ'.
assign component 'LOW' of structure <dyn_wa> to <fs>.
<fs> = p_matnr.
append <dyn_wa> to <dyn_table>.
* Do the selection.
select * from mara into table imara
where matnr in <dyn_table>.
loop at imara.
write:/ imara-matnr, imara-mtart.
endloop.
************************************************************************
* Build_dyn_itab
************************************************************************
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'SIGN'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 1.
wa_it_fldcat-outputlen = 1.
append wa_it_fldcat to it_fldcat .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'OPTION'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 2.
wa_it_fldcat-outputlen = 2.
append wa_it_fldcat to it_fldcat .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'LOW'.
wa_it_fldcat-ref_field = p_field.
wa_it_fldcat-ref_table = p_tabnm.
append wa_it_fldcat to it_fldcat .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'HIGH'.
wa_it_fldcat-ref_field = p_field.
wa_it_fldcat-ref_table = p_tabnm.
append wa_it_fldcat to it_fldcat .
* Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
* Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
Regards,
Rich Heilman
‎2006 Jun 26 4:51 PM
Hi Dnyanesh,
The following statement.
Ranges: R_test for tab-field.
is similar to
DATA: BEGIN OF R_test OCCURS 10,
SIGN(1),
OPTION(2),
LOW LIKE f,
HIGH LIKE f,
END OF R_test.
you can try assigning LOW and HIGH value dynamically depending upon table and field.
hope this helps.
Regards,
Kinshuk
‎2006 Jun 26 6:30 PM