‎2010 Aug 03 10:01 AM
Hello Friends,
I have a requirement as mentioned below.
There is an internal table ITAB1 containing field names (say 'BUKRS', 'GJAHR', 'BLART' etc).
It is required to loop in the above internal table ITAB1 and in each iteration define/create a separate range (sign/option/low/high) with a unique name.
Say in the first iteration i.e. for field BUKRS, it is required to define/create a range R_BUKRS, for the 2nd iteraction i.e. for field GJAHR, it is required to define/create a range R_GJAHR and so on.
Please share your inputs for the above requirement.
Thanks in advance.
Indrajit
‎2010 Aug 03 10:28 AM
Hi,
use sort for the fields you want to use as range.
After sort read the first and last repord and it into the range table ((sign/option/low/high).
Regards, Dieter
‎2010 Aug 03 10:32 AM
You can create dynamic tables at runtime. Just search the forum to find out how to do it.
‎2010 Aug 03 10:34 AM
Hi,
You can use conditional statement "At End of" in side the loop and then upload the data in to range.
‎2010 Aug 03 10:45 AM
The issue is not to populate an internal table dynamically, that is simple.
But this requirement demands to define an internal table (with a dynamic name) dynamically.
‎2010 Aug 03 10:58 AM
Here in each loop pass the field symbol <fs> will act as a range for each field in the internal table
TYPE-POOLS : abap.
TYPES:BEGIN OF type1,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
END OF type1.
DATA : i_details TYPE abap_compdescr_tab,
wa_comp TYPE abap_compdescr,
i_tab1 TYPE TABLE OF type1,
wa_tab1 TYPE type1,
ref_descr TYPE REF TO cl_abap_structdescr.
FIELD-SYMBOLS:<fs> TYPE table.
DATA:
lr_sign_descr TYPE REF TO cl_abap_elemdescr,
lr_option_descr TYPE REF TO cl_abap_elemdescr,
lr_value_descr TYPE REF TO cl_abap_elemdescr,
lr_struct_descr TYPE REF TO cl_abap_structdescr,
lr_table_descr TYPE REF TO cl_abap_tabledescr,
component TYPE cl_abap_structdescr=>component,
lt_components TYPE cl_abap_structdescr=>component_table,
rt_range_table TYPE REF TO data.
ref_descr ?= cl_abap_typedescr=>describe_by_data( wa_tab1 ).
i_details[] = ref_descr->components[].
lr_sign_descr ?= cl_abap_elemdescr=>describe_by_name( 'DDSIGN' ).
lr_option_descr ?= cl_abap_elemdescr=>describe_by_name( 'DDOPTION' ).
LOOP AT i_details INTO wa_comp.
CLEAR lt_components[].
CASE wa_comp-type_kind.
WHEN 'N'.
lr_value_descr ?= cl_abap_elemdescr=>get_n( p_length = wa_comp-length ).
WHEN 'C'.
lr_value_descr ?= cl_abap_elemdescr=>get_c( p_length = wa_comp-length ).
WHEN 'X'.
lr_value_descr ?= cl_abap_elemdescr=>get_x( p_length = wa_comp-length ).
WHEN 'P'.
lr_value_descr ?= cl_abap_elemdescr=>get_p( p_length = wa_comp-length p_decimals = wa_comp-decimals ).
WHEN OTHERS.
lr_value_descr ?= cl_abap_elemdescr=>describe_by_name( wa_comp-name ).
ENDCASE.
component-name = 'SIGN'.
component-type = lr_sign_descr.
INSERT component INTO TABLE lt_components.
component-name = 'OPTION'.
component-type = lr_option_descr.
INSERT component INTO TABLE lt_components.
component-name = 'LOW'.
component-type = lr_value_descr.
INSERT component INTO TABLE lt_components.
component-name = 'HIGH'.
component-type = lr_value_descr.
INSERT component INTO TABLE lt_components.
lr_struct_descr = cl_abap_structdescr=>create( p_components = lt_components p_strict = abap_true ).
lr_table_descr = cl_abap_tabledescr=>create( p_line_type = lr_struct_descr ).
CREATE DATA rt_range_table TYPE HANDLE lr_table_descr.
ASSIGN rt_range_table->* TO <fs>.
ENDLOOP.
‎2010 Aug 03 11:06 AM
Hi Keshav,
Thanks for your response.
But it will not solve my requirement.
The code snippet provided by you will cause the field symbol <fs> changed in each loop pass and point to a different range.
So after the last loop pass there is no way to access the ranges excpet the one created in last loop iteration.
The reason I need separate range names (or pointers) is beacuse I will use the same to populate 'where' clause of a select statement that gets executed after
the loop is over. So when the select statement gets executed, all the ranges should exist, else results will be erroneous.
Thanks
Indrajit
‎2010 Aug 03 11:11 AM
Is the number of ranges you need specific? If so define as many field-symbols as you need.
Edited by: Kerem Kayacan on Aug 3, 2010 1:11 PM
‎2010 Aug 03 11:13 AM
No that is dynamic based on records maintained in a config table.
But in the program I am fetching the records from the config table, so I can find out the number of records in the config table i.e. number of ranges that need to be created dynamically.
‎2010 Aug 03 11:14 AM
Is your internal table dynamic ?
No that is dynamic based on records maintained in a config table.
But in the program I am fetching the records from the config table, so I can find out the number of records in the config table i.e. number of ranges that need to be created dynamically.
Its pretty confusing ... does the internal table data hold the field names or your want to create ranges based on the fields of internal tabe ?
‎2010 Aug 03 11:25 AM
The internal table ITAB1 is NOT DYNAMIC and is used in the program to store data from a config (database) table.
It has got 2 fields -
(1) Field name FNAME (say 'BUKRS','GJAHR','BLART' etc)
(2) A deep structure VALUES to hold a range for the specified field name.
Now I am looping in this internal table and in each loop pass I need to do the following.
(1) Define a new range with an unique name using the deep structure VALUES for the field FNAME
(2) Form a dynamic where clause for a select - '(fname) IN <range>' and add to an internal table LT_DYN_COND.
After the loop I am using the table LT_DYN_COND for selection from a database table.
SELECT *
FROM bsad
INTO TABLE lt_bsad
WHERE (lt_dyn_cond).
So the range name has to different for the different fields in ITAB1 table, else the select statement will not give properly filtered results.
‎2010 Aug 03 3:09 PM
Hello Indrajit,
Keshav has given you the core logic for your requirement. I'll use this as a reference.
The reason I need separate range names (or pointers) is beacuse I will use the same to populate 'where' clause of a select statement that gets executed after the loop is over.
I made some adjustments to his code which will help retain the values of the ranges for each loop iteration:
DATA: it_rng TYPE STANDARD TABLE OF REF TO data,
wa_rng TYPE REF TO data.
LOOP AT i_details INTO wa_comp.
IF <fs> IS ASSIGNED.
UNASSIGN <fs>.
ENDIF.
..........................................
..........................................
CREATE DATA rt_range_table TYPE HANDLE lr_table_descr.
ASSIGN rt_range_table->* TO <fs>.
APPEND rt_range_table TO it_rng.
ENDLOOP.Hope this helps.
BR,
Suhas
‎2010 Aug 03 2:48 PM
Try this Way it may resolve your Issue.
REPORT Z_EX_RANGES.
*-> Macro to Create Ranges Dynamically in run time
define d_ranges.
ranges : r_&1 for &2.
end-of-definition.
start-of-selection.
*-> Call Macro D_RANGES
d_ranges BUKRS "&1 "ITAB1-FIELD
'T001-BUKRS'. "&2 "REF FIELD
*-> Fill R_BUKRS from Internal Table "ITAB1-Value
r_bukrs-sign = 'I'.
r_bukrs-option = 'EQ'.
r_bukrs-low = '1000'.
append r_bukrs.
‎2012 May 07 6:29 PM
I just stumbled onto this when searching for a similar need. In my case, I needed to create a subroutine that would check ranges dynamically.
Note that you can do something like this and it will work:
concatenate 'GR_' p_fieldname '[]' into lv_assign.
assign (lv_assign) to <lfs_rangetab>.
check itab-field in <lfs_rangetab>.
I found this very helpful that when you dynamically construct a fieldname, if you put the brackets at the end, SAP does in fact interpret it as an internal table.
So, in my case, I defined a bunch of ranges:
ranges:
gr_vkorg for mvke-vkorg,
gr_vtweg for mvke-vtweg,
etc.
Then, in my code, I wanted to make sure my extract was only exporting values which were collected earlier.
So, I dynamically assigned the fields to the global range tables using this construct.
hope it helps...
‎2012 Nov 13 8:09 AM
Hi Indrajit.
I have a similar requirement to create a dynamic range table with unique name.
I need to populate the range table and then i have to create a dynamic where clause to fetch data from table dynamically.
Please let me how we can approach this requirement
Regards
Suresh Kumar
‎2016 Jan 20 4:11 PM
https://mysapgw.wordpress.com/2012/01/25/filter-string-how-to/
Hate to dig this one up from the grave, but I have the exact requirement. Now I found a solution however it involves creating static tables that I use to uniquely identify my ranges. My need is to have the ranges created dynamically AND be unique. Above is the original solution I found.
I see that a possible solution has been posted by Suhas, but I'm not sure how the itab would make the ranges unique.
Please assist.
Thanks!
Rene