In some situations it may be necessary that you want the Intervals to dynamically change each time you execute a Diffuser program. This is an alternate method of Interval Generation to the more commonly used Interval Object method. Diffuser uses the concept of an Interval Generator to do this. An Interval Generator allows you to write ABAP code to do this dynamic interval creation. A custom Interval Generator can be implemented using the subroutine mdr_interval_generator in the Main program of the MDR program.

The impact on the selection screen is that the interval size and interval count options are displayed on the “Technical Setting” screen, see the Technical Settings section for details on this.

The subroutine mdr_interval_generator is called at the beginning of the Diffuser program. This subroutine is used to define the intervals that will be processed. The subroutine provides a single input structure that contains both an interval count and an interval size. These are values that are set at run-time, and provide information to the program on how it should break up the processing. The CHANGING parameter is a list of Intervals to be processed. The developer writing the Diffuser program needs to implement logic to populate the LOW and HIGH interval values of yt_intervals.

*----------------------------------------------------------------*
* FORM mdr_interval_generation
*----------------------------------------------------------------*
* This form is called by Diffuser to generate        * 
* interval ranges that can be coded as per your own requirements *  
*----------------------------------------------------------------*  
FORM mdr_interval_generation 
  USING    x_input       TYPE /btr/st_intgen_input 
  CHANGING yt_intervals  TYPE /btr/tt_mdr_interval_values. 


  DATA :
   lv_interval       LIKE LINE OF yt_intervals.

  DATA:
    lv_interval_size         TYPE i,
    lv_interval_index        TYPE i,
    lv_interval_index_l      TYPE i,
    lv_remainder             TYPE i,
    lv_count                 TYPE i,
    lv_count_numc            TYPE numc10,
    lv_count_intervals       TYPE i,
    lv_index                 TYPE syindex,
    lv_low_index             TYPE syindex,
    lv_flag                  TYPE c.

  DATA: lt_sbook TYPE sbook,
        ls_sbook TYPE sbook.

* Select bookings
  SELECT *
    FROM sbook
    INTO TABLE lt_sbook
   WHERE customid in s_custid

  SORT lt_sbook.

  DELETE ADJACENT DUPLICATES FROM lt_sbook.

  DESCRIBE TABLE lt_sbook LINES lv_count.

  IF x_input-interval_size IS INITIAL.

*   Determine the size of each interval
    lv_interval_size = lv_count DIV x_input-interval_count.
    lv_remainder     = lv_count MOD x_input-interval_count.

    IF NOT lv_remainder IS INITIAL.

      ADD 1 TO lv_interval_size.
    ENDIF.

  ELSE.

    lv_interval_size = x_input-interval_size.

  ENDIF.

  lv_interval_index = lv_interval_size.

*  Find the first low for the interval
  CLEAR ls_sbook.
  READ TABLE lt_sbook INTO ls_sbook INDEX 1.

  lv_interval-low = ls_sbook-custid.

  DO.

* Get the last number in this package of data
    CLEAR ls_sbook.
    READ TABLE lt_sbook INTO ls_sbook INDEX lv_interval_index.

    IF sy-subrc EQ 0.

*    Provided something was found store this in the high
      lv_interval-high = ls_sbook-custid.

      APPEND lv_interval TO yt_intervals.
      CLEAR  lv_interval.

*    Add one to the interval index to find the new low for the next interval
      lv_interval_index_l = lv_interval_index + 1.

      CLEAR ls_sbook.
      READ TABLE lt_sbook INTO ls_sbook INDEX lv_interval_index_l.
      IF sy-subrc = 0.
*      If a record is found we have a new interval to create so create the low
*      else interval creation is complete so exit
        lv_interval-low = ls_sbook-custid.
      ELSE.
        EXIT.
      ENDIF.
      lv_interval_index = lv_interval_index + lv_interval_size.

    ELSE.

*     Fill the last entry of the intervals with the last entry
      CLEAR ls_sbook.
      READ TABLE lt_sbook INTO ls_sbook INDEX lv_count.

      IF ls_sbook-custid >= lv_interval-low .
        lv_interval-high = ls_sbook-custid.
        APPEND lv_interval TO yt_intervals.
      ENDIF.
      EXIT.

    ENDIF.

  ENDDO.

ENDFORM. 
 

Feedback

Was this helpful?

Yes No
You indicated this topic was not helpful to you ...
Could you please leave a comment telling us why? Thank you!
Thanks for your feedback.

Post your comment on this topic.

Post Comment