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

Possible to solve easily with RANGE object?

Former Member
0 Likes
1,433

Hello xperts,

despite searching thru SDN I still dont have been able to figure out if using RANGE is possible for our requirements.

I have defined the following as a start (pseudo-code):


TYPES: BEGIN OF ZARCH_RANGE_LINE,
         SIGN   TYPE RALDB_SIGN,
         OPT    TYPE RSZ_OPERATOR,
         LOW    TYPE RSCHAVL,
         HIGH   TYPE RSCHAVL,
       END OF ZARCH_RANGE_LINE.

TYPES: BEGIN OF ZARCH_IOBJ_RANGEOBJECT,
         IOBJNM             TYPE RSIOBJNM,
         ZARCH_RANGE_OBJECT TYPE ZARCH_RANGE_LINE,
       END OF ZARCH_IOBJ_RANGEOBJECT.

TYPES:
      ZARCH_S_IOBJ_RANGE TYPE ZARCH_IOBJ_RANGEOBJECT,
      ZARCH_T_IOBJ_RANGE TYPE ZARCH_S_IOBJ_RANGE OCCURS 0.
      
data:
      L_range_object_line  type  ZARCH_RANGE_LINE.
      l_wa_archived_ranges type  ZARCH_S_IOBJ_RANGE,
      l_t_archived_ranges  type  ZARCH_T_IOBJ_RANGE,
      
L_range_object_line-sign = 'BT'.
L_range_object_line-opt  = 'I'.
L_range_object_line-low  = '20110101'
L_range_object_line-high = '20110131'      

l_wa_archived_ranges-IOBJNM = 'CALDAY'.
l_wa_archived_ranges-ZARCH_RANGE_OBJECT = L_range_object_line.

append _wa_archived_ranges to l_t_archived_ranges.

L_range_object_line-sign = 'BT'.
L_range_object_line-opt  = 'I'.
L_range_object_line-low  = '20110201'
L_range_object_line-high = '20110228'      

l_wa_archived_ranges-IOBJNM = 'CALDAY'.
l_wa_archived_ranges-ZARCH_RANGE_OBJECT = L_range_object_line.

append _wa_archived_ranges to l_t_archived_ranges.

Now I need to find out if the date within a variable P_CALDAY is within the ranges of the data in ITAB l_t_archived_ranges.

If P_CALDAY = 20110201 then the result would be TRUE

If P_CALDAY = 20110301 then the result would be FALSE

Is there a relatively easy way to solve this???

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,357

Hi Martin

You can declare them as range objects. Here are the changes you need to make,


types : ty_rschavl type range of rschavl.
...
...
TYPES: BEGIN OF ZARCH_IOBJ_RANGEOBJECT,
         IOBJNM             TYPE RSIOBJNM,
         ZARCH_RANGE_OBJECT TYPE ty_rschavl,
       END OF ZARCH_IOBJ_RANGEOBJECT.
....
....
....
data:
      L_range_object_line  type line of ty_rschavl.
      l_wa_archived_ranges type  ZARCH_S_IOBJ_RANGE,
      l_t_archived_ranges  type  ZARCH_T_IOBJ_RANGE,
...
...

Regards

Ranganath

Edited by: Ranganath Ramesh on Mar 17, 2011 3:31 PM

Hello xperts,

despite searching thru SDN I still dont have been able to figure out if using RANGE is possible for our requirements.

I have defined the following as a start (pseudo-code):


TYPES: BEGIN OF ZARCH_RANGE_LINE,
         SIGN   TYPE RALDB_SIGN,
         OPT    TYPE RSZ_OPERATOR,
         LOW    TYPE RSCHAVL,
         HIGH   TYPE RSCHAVL,
       END OF ZARCH_RANGE_LINE.

TYPES: BEGIN OF ZARCH_IOBJ_RANGEOBJECT,
         IOBJNM             TYPE RSIOBJNM,
         ZARCH_RANGE_OBJECT TYPE ZARCH_RANGE_LINE,
       END OF ZARCH_IOBJ_RANGEOBJECT.

TYPES:
      ZARCH_S_IOBJ_RANGE TYPE ZARCH_IOBJ_RANGEOBJECT,
      ZARCH_T_IOBJ_RANGE TYPE ZARCH_S_IOBJ_RANGE OCCURS 0.
      
data:
      L_range_object_line  type  ZARCH_RANGE_LINE.
      l_wa_archived_ranges type  ZARCH_S_IOBJ_RANGE,
      l_t_archived_ranges  type  ZARCH_T_IOBJ_RANGE,
      
L_range_object_line-sign = 'BT'.
L_range_object_line-opt  = 'I'.
L_range_object_line-low  = '20110101'
L_range_object_line-high = '20110131'      

l_wa_archived_ranges-IOBJNM = 'CALDAY'.
l_wa_archived_ranges-ZARCH_RANGE_OBJECT = L_range_object_line.

append _wa_archived_ranges to l_t_archived_ranges.

L_range_object_line-sign = 'BT'.
L_range_object_line-opt  = 'I'.
L_range_object_line-low  = '20110201'
L_range_object_line-high = '20110228'      

l_wa_archived_ranges-IOBJNM = 'CALDAY'.
l_wa_archived_ranges-ZARCH_RANGE_OBJECT = L_range_object_line.

append _wa_archived_ranges to l_t_archived_ranges.

Now I need to find out if the date within a variable P_CALDAY is within the ranges of the data in ITAB l_t_archived_ranges.

If P_CALDAY = 20110201 then the result would be TRUE

If P_CALDAY = 20110301 then the result would be FALSE

Is there a relatively easy way to solve this???

10 REPLIES 10
Read only

Former Member
0 Likes
1,357

Hi

Try the code below.

ranges : ra_date FOR sy-datum.

ra_date-sign = 'I'.

ra_date-option = 'BT'.

ra_date-low = '20110101'.

ra_date-high = '20110131'.

APPEND ra_date.

CLEAR ra_date.

ra_date-sign = 'I'.

ra_date-option = 'BT'.

ra_date-low = '20110201'.

ra_date-high = '20110228'.

APPEND ra_date.

CLEAR ra_date.

IF p_calday IN ra_date.

WRITE : 'Date is in range'.

ELSE.

WRITE : 'Date is not in range'.

ENDIF.

Read only

0 Likes
1,357

Thanks for your answer Nikhil but the table also contains the field IOBJNM


l_wa_archived_ranges-IOBJNM = 'CALDAY'.

I just cannot do without that field since the table could contain other entries, for example:


l_wa_archived_ranges-IOBJNM = 'COMPCODE'.

and then with the corresponding range entries, for example:


L_range_object_line-sign = 'EQ'.
L_range_object_line-opt  = 'I'.
L_range_object_line-low  = '1010'
L_range_object_line-high = ''      

Your proposal does not accomodate for that, or?

Read only

Former Member
0 Likes
1,358

Hi Martin

You can declare them as range objects. Here are the changes you need to make,


types : ty_rschavl type range of rschavl.
...
...
TYPES: BEGIN OF ZARCH_IOBJ_RANGEOBJECT,
         IOBJNM             TYPE RSIOBJNM,
         ZARCH_RANGE_OBJECT TYPE ty_rschavl,
       END OF ZARCH_IOBJ_RANGEOBJECT.
....
....
....
data:
      L_range_object_line  type line of ty_rschavl.
      l_wa_archived_ranges type  ZARCH_S_IOBJ_RANGE,
      l_t_archived_ranges  type  ZARCH_T_IOBJ_RANGE,
...
...

Regards

Ranganath

Edited by: Ranganath Ramesh on Mar 17, 2011 3:31 PM

Read only

0 Likes
1,357

Thanx Ranganath pls see my answer to Alex above.

Read only

0 Likes
1,357

... and also: what - in general - is the difference between:


ZARCH_RANGE_OBJECT TYPE RANGE OF RSCHAVL

and


ranges: ZARCH_RANGE_OBJECT for RSCHAVL

if any???

I write "in genral" since in this case


ranges: ZARCH_RANGE_OBJECT for RSCHAVL

is not feasible, or?

Read only

0 Likes
1,357

Martin,

It looks like your question has two parts. (1) How to define the range table? (2) How to see if the value specified in the parameter is within the archival ranges?

See below code for the easy solution for your 1st question.


REPORT  Y_SK_TEST2.

parameters: p_calday type RSCHAVL DEFAULT '20110315',
            p_iobj   type RSIOBJNM DEFAULT 'CALDAY'.

data: t_io_range type STANDARD TABLE OF RSPLF_S_CHARSEL INITIAL SIZE 0,
      wa_io_range type RSPLF_S_CHARSEL.

wa_io_range-iobjnm = 'CALDAY'.
wa_io_range-sign   = 'I'.
wa_io_range-opt    = 'BT'.

wa_io_range-low    = '20110101'.
wa_io_range-high   = '20110131'.
append wa_io_range to t_io_range.

wa_io_range-low    = '20110201'.
wa_io_range-high   = '20110228'.
append wa_io_range to t_io_range.

* Now, how to determine if 3/15/2011 and CALDAY are in T_IO_RANGE?
* That is not easy to implement unless some restrictions are placed
* on how user can specify the parameters.

BREAK-POINT.

Now, there is no easy solution for the second question. It is even harder for the date field.

(1) Firstly you have to assume that the archival range is always SIGN = 'I' and OPT = 'BT'. Which is probably always true.

(2) For date fields, you will have to write your own code to see if the value specified in the parameter is between each of the high and low values.

(3) If you are checking for archival data, I don't think you will have non-date field to deal with. If you do, then it a bit tricky. You will have to check with the P table of the InfoObject in combination with the archival range.

Read only

0 Likes
1,357

Thanx for your answer Sudhi.

It is the reading out - listed by yourself as (2) - for which I am now looking for an easy solution.

Indeed there could also be other criteria for archiving than dates only. Data could have been archived for certain company codes, but not for others. Most likely it would then be 'EQ', but theoretically it could be 'BT' as well.

Read only

0 Likes
1,357

Martin,

I am not aware of a technique or function module to achieve what you are trying to do. You will have to develop tedious code.

Below is SAMPLE code that you can expand on.

Good luck!


REPORT  y_sk_test2.

PARAMETERS: p_calday TYPE rschavl DEFAULT '20110315',
            p_iobj   TYPE rsiobjnm DEFAULT 'CALDAY'.

DATA: t_io_range  TYPE STANDARD TABLE OF rsplf_s_charsel INITIAL SIZE 0,
      wa_io_range TYPE rsplf_s_charsel,

      l_archived  TYPE c.

wa_io_range-iobjnm = 'CALDAY'.
wa_io_range-sign   = 'I'.
wa_io_range-opt    = 'BT'.

wa_io_range-low    = '20110101'.
wa_io_range-high   = '20110131'.
APPEND wa_io_range TO t_io_range.

wa_io_range-low    = '20110201'.
wa_io_range-high   = '20110228'.
APPEND wa_io_range TO t_io_range.

LOOP AT t_io_range INTO wa_io_range WHERE iobjnm = p_iobj.
  CASE wa_io_range-sign.
    WHEN 'I'.
      CASE wa_io_range-opt.
        WHEN 'EQ'.
          IF wa_io_range-low = p_calday.
            l_archived = 'X'.
            EXIT.
          ENDIF.
        WHEN 'BT'.
          IF wa_io_range-low <= p_calday AND
             wa_io_range-high >= p_calday.
            l_archived = 'X'.
          ENDIF.
        WHEN 'LT'.
          IF wa_io_range-low < p_calday.
            l_archived = 'X'.
          ENDIF.
        WHEN 'GT'.
          IF wa_io_range-low > p_calday.
            l_archived = 'X'.
          ENDIF.
      ENDCASE.
    WHEN 'E'.
*&    fill up the code for exclusion
  ENDCASE.
ENDLOOP.

IF l_archived = 'X'.
  WRITE: / p_calday, 'is archived!'.
ELSE.
  WRITE: / p_calday, 'is NOT archived!'.
ENDIF.

Read only

AlexanderOv
Product and Topic Expert
Product and Topic Expert
0 Likes
1,357

Hi, Martin

I think you need following data definition

 
TYPES:
BEGIN OF ZARCH_IOBJ_RANGEOBJECT,
         IOBJNM             TYPE RSIOBJNM,
         ZARCH_RANGE_OBJECT TYPE RANGE OF RSCHAVL,
END OF ZARCH_IOBJ_RANGEOBJECT.

Pay attention to "TYPE RANGE OF" part.

Read only

0 Likes
1,357

Thanx for ur answer Alex, but pls could you indicate how I now read the results out of this.

I have tried this:


  loop at l_t_archived_ranges into l_wa_archived_ranges where
    IOBJNM = 'CALDAY'.

    MOVE-CORRESPONDING l_wa_archived_ranges TO L_range_object_line.

    if p_calday in L_range_object_line.
      p_bool = 'X'.
      exit.
    else.
      p_bool = ''.
    endif.
  endloop.

but get the syntax error:

"L_range_object_line" is not an internal table "OCCURS n" specification is missing"