Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic Range

Former Member
0 Likes
2,617

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

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,091

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

3 REPLIES 3
Read only

Former Member
0 Likes
1,091

Please refer => [dynamic range |https://www.sdn.sap.com/irj/scn/advancedsearch?query=dynamicrange&cat=sdn_all]

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,092

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

Read only

Former Member
0 Likes
1,091

Thank You so much!

The problem has been solved and points have been awarded...!

Happy New Year to you!

Cheers!

Sanjiv