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

Create multiple ranges dynamically with unique name

Former Member
0 Likes
1,571

Hi Friends,

i have a requirement to create a program to select data from table. User will maintain the condition (i.e. where) to be applied in select statement in a database table.

Select * from (Table) into <target Table> where (lc_where).

In order to create the dynamic where clause, i need to create dynamic range table with unique name and populate the condtion.

WHERE COMPCODE  IN <FS_COMPCODE>

     AND INVOICENO    IN <FS_INVOICENO>

     AND FISCALYEAR IN <FS_FISCALYEAR>

Plese let me know how we can address this requirement.

Regards

Suresh Kumar

2 REPLIES 2
Read only

amy_king
Active Contributor
0 Likes
709

Hi Suresh,

You could write a subroutine or a macro to build the range tables. I've often used macros for this though a subroutine would achieve the same result...

*&---------------------------------------------------------------------*
*&      Macro  APPEND_RANGE
*&---------------------------------------------------------------------*
*       Using sign and option from &1, appends low value &2 to range
*       table &4 via intermediate structure &3.
*----------------------------------------------------------------------*

define append_range.

   if not &2 is initial.
     concatenate &1 &2 into &3.
     append &3 to &4.
   endif.

end-of-definition.


Then elsewhere in the code you can call the macro. I often use this approach to add multiple LOW values to the same range...


   append_range 'IEQ' lv_value_type_1 ls_r_wrttp lr_wrttp.
   append_range 'IEQ'
lv_value_type_2 ls_r_wrttp lr_wrttp.
   append_range 'IEQ'
lv_value_type_3 ls_r_wrttp lr_wrttp.

But you could also use the approach to build different ranges...

   append_range 'IEQ'  low_value_1  ls_structure_1  lr_range_1.

   append_range 'IEQ'  low_value_2  ls_structure_2  lr_range_2.

   append_range 'IEQ'  low_value_3  ls_structure_3  lr_range_3.

It occurs to me though that if you're storing selection conditions in a database table anyway, why not use table TVARVC (maintained through transaction STVARV) to store the ranges? Instead of using a custom database table to store these conditions, create the ranges in TVARVC as Selection Options and use them directly in your SQL queries.

Cheers,

Amy

Message was edited by: Amy King

Read only

Sijin_Chandran
Active Contributor
0 Likes
709

Hi Suresh ,

You can declare three data structures with  TYPE RANGE OF declaration for your requirement.

Say for eg:

DATA :  R_ COMPCODE TYPE RANGE OF BUKRS WITH HEADER LINE ,

             R_INVOICENO TYPE RANGE OF BELNR_D WITH HEADER LINE,

             FISCALYEAR TYPE RANGE OF GJAHR WITH HEADER LINE.

And you can fill these ranges as per requirement , like as follows

REFRESH : R_COMPCODE.

CLEAR : R_COMPCODE.

R_COMPCODE-SIGN = 'I'.

R_COMPCODE-OPTION = 'EQ'

R_COMPCODE-LOW = '1000'.    "these values can be hard coded or selected from other structures as well

APPEND R_COMPCODE.

Similarly you can carry on with other range variables also.. and after that use in the where clause like a select-option variable

eg:

WHERE COMPCODE  IN R_COMPCODE

     AND INVOICENO    IN R_INVOICENO

     AND FISCALYEAR IN R_FISCALYEAR