2009 Jan 02 5:48 PM
Hi,
I want to create a dynamic range in my program.
e.g I have an input field where a user can enter a FIELDNAME....
In my program I want to be able to create a 'RANGE' for this field with LOW, HIGH, SIGN & OPTIONs...
So the range needs to be dynamically created....
Can anyone help me in this?
Thanks,
Sanjiv
2009 Jan 02 6:12 PM
Just create an internal table with the appropriate fields and types.
TYPE-POOLS:
abap.
DATA:
gr_structdescr TYPE REF TO cl_abap_structdescr,
gr_tabledescr TYPE REF TO cl_abap_tabledescr,
gr_datadescr TYPE REF TO cl_abap_datadescr,
gr_typedescr type ref to cl_abap_typedescr,
gt_components TYPE abap_component_tab,
gw_component TYPE LINE OF abap_component_tab,
gr_wa TYPE REF TO data,
gr_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.
PARAMETERS: p_field type fieldname.
START-OF-SELECTION.
* determine components of structure -> GT_COMPONENTS
MOVE 'SIGN' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 1 ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'OPTION' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 2 ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'LOW' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>describe_by_name( p_field ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'HIGH' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>describe_by_name( p_field ).
INSERT gw_component INTO TABLE gt_components.
* get structure descriptor -> GR_STRUCTDESCR
gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
* create work area of structure GR_STRUCTDESCR -> GR_WA
CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
ASSIGN gr_wa->* TO <fs_wa>.
gr_datadescr ?= gr_structdescr.
gr_tabledescr ?= cl_abap_tabledescr=>create( gr_datadescr ).
* Create dynmaic internal table
CREATE DATA gr_tab TYPE HANDLE gr_tabledescr.
ASSIGN gr_tab->* TO <fs_tab>.
In this example, <fs_tab> would be your range, since ranges are nothing more than internal tables.
Regards,
Rich Heilman
Edited by: Rich Heilman on Jan 2, 2009 1:15 PM
2009 Jan 02 6:05 PM
Please refer => [dynamic range |https://www.sdn.sap.com/irj/scn/advancedsearch?query=dynamicrange&cat=sdn_all]
2009 Jan 02 6:12 PM
Just create an internal table with the appropriate fields and types.
TYPE-POOLS:
abap.
DATA:
gr_structdescr TYPE REF TO cl_abap_structdescr,
gr_tabledescr TYPE REF TO cl_abap_tabledescr,
gr_datadescr TYPE REF TO cl_abap_datadescr,
gr_typedescr type ref to cl_abap_typedescr,
gt_components TYPE abap_component_tab,
gw_component TYPE LINE OF abap_component_tab,
gr_wa TYPE REF TO data,
gr_tab TYPE REF TO data.
FIELD-SYMBOLS: <fs_wa> TYPE ANY.
FIELD-SYMBOLS: <fs_tab> TYPE table.
PARAMETERS: p_field type fieldname.
START-OF-SELECTION.
* determine components of structure -> GT_COMPONENTS
MOVE 'SIGN' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 1 ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'OPTION' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 2 ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'LOW' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>describe_by_name( p_field ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'HIGH' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>describe_by_name( p_field ).
INSERT gw_component INTO TABLE gt_components.
* get structure descriptor -> GR_STRUCTDESCR
gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
* create work area of structure GR_STRUCTDESCR -> GR_WA
CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
ASSIGN gr_wa->* TO <fs_wa>.
gr_datadescr ?= gr_structdescr.
gr_tabledescr ?= cl_abap_tabledescr=>create( gr_datadescr ).
* Create dynmaic internal table
CREATE DATA gr_tab TYPE HANDLE gr_tabledescr.
ASSIGN gr_tab->* TO <fs_tab>.
In this example, <fs_tab> would be your range, since ranges are nothing more than internal tables.
Regards,
Rich Heilman
Edited by: Rich Heilman on Jan 2, 2009 1:15 PM
2009 Jan 02 6:28 PM
Thank You so much!
The problem has been solved and points have been awarded...!
Happy New Year to you!
Cheers!
Sanjiv