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

Future dates....

naveen_inuganti2
Active Contributor
0 Likes
320

Hi friends:

I am developing one report...which contains a date in the selection screen....

So now we are in may... , second quarter for this year... so if you enter the any date from may or april or june....

we have to get results for next five qurters...

means....

july-sep,

oct-dec..upto fiev qureters.

any body suggest me logic or if any function modules...

Thank you ,

naveen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
298

Do the following:


PARAMETERS p_date TYPE dats.

RANGES: lr_1 FOR p_date,
        lr_2 FOR p_date,
        lr_3 FOR p_date,
        lr_4 FOR p_date,
        lr_5 FOR p_date.

* get the start date of the current quarter
CASE p_date+4(2).
  WHEN '01' OR '02' OR '03'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0101'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0331'.
    APPEND lr_1.
  WHEN '04' OR '05' OR '06'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0401'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0630'.
    APPEND lr_1.
  WHEN '07' OR '08' OR '09'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0701'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0930'.
    APPEND lr_1.
  WHEN '10' OR '11' OR '12'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '1001'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '1231'.
    APPEND lr_1.
ENDCASE.
* now fill the remaining quarters
lr_2-sign      = 'I'.
lr_2-option    = 'BT'.
lr_2-low       = lr_1-high + 1.
* to get into the third month of the quarter
lr_2-high      = lr_1-high + 70.
* now set the last day of the quarter
CASE lr_2-high+4(2).
  WHEN '03' OR '12'.
    lr_2-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_2-high+6(2) = '30'.
ENDCASE.
APPEND lr_2.
* now fill the remaining quarters
lr_3-sign      = 'I'.
lr_3-option    = 'BT'.
lr_3-low       = lr_2-high + 1.
* to get into the third month of the quarter
lr_3-high      = lr_2-high + 70.
* now set the last day of the quarter
CASE lr_3-high+4(2).
  WHEN '03' OR '12'.
    lr_3-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_3-high+6(2) = '30'.
ENDCASE.
APPEND lr_3.
* now fill the remaining quarters
lr_4-sign      = 'I'.
lr_4-option    = 'BT'.
lr_4-low       = lr_3-high + 1.
* to get into the third month of the quarter
lr_4-high      = lr_3-high + 70.
* now set the last day of the quarter
CASE lr_4-high+4(2).
  WHEN '03' OR '12'.
    lr_4-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_4-high+6(2) = '30'.
ENDCASE.
APPEND lr_4.
* now fill the remaining quarters
lr_5-sign      = 'I'.
lr_5-option    = 'BT'.
lr_5-low       = lr_4-high + 1.
* to get into the third month of the quarter
lr_5-high      = lr_4-high + 70.
* now set the last day of the quarter
CASE lr_5-high+4(2).
  WHEN '03' OR '12'.
    lr_5-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_5-high+6(2) = '30'.
ENDCASE.
APPEND lr_5.

This will fill five ranges (one for each subsequent quarter) which you can use to select your data

select * from xxxxx

into table yyyy1

where date_field in lr_1.

select * from xxxxx

into table yyyy2

where date_field in lr_1.

etc.

Hope that helps,

Michael

1 REPLY 1
Read only

Former Member
0 Likes
299

Do the following:


PARAMETERS p_date TYPE dats.

RANGES: lr_1 FOR p_date,
        lr_2 FOR p_date,
        lr_3 FOR p_date,
        lr_4 FOR p_date,
        lr_5 FOR p_date.

* get the start date of the current quarter
CASE p_date+4(2).
  WHEN '01' OR '02' OR '03'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0101'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0331'.
    APPEND lr_1.
  WHEN '04' OR '05' OR '06'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0401'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0630'.
    APPEND lr_1.
  WHEN '07' OR '08' OR '09'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '0701'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '0930'.
    APPEND lr_1.
  WHEN '10' OR '11' OR '12'.
*   this is the first quarter
    lr_1-sign      = 'I'.
    lr_1-option    = 'BT'.
    lr_1-low       = p_date.
    lr_1-low+4(4)  = '1001'.
    lr_1-high      = p_date.
    lr_1-high+4(4) = '1231'.
    APPEND lr_1.
ENDCASE.
* now fill the remaining quarters
lr_2-sign      = 'I'.
lr_2-option    = 'BT'.
lr_2-low       = lr_1-high + 1.
* to get into the third month of the quarter
lr_2-high      = lr_1-high + 70.
* now set the last day of the quarter
CASE lr_2-high+4(2).
  WHEN '03' OR '12'.
    lr_2-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_2-high+6(2) = '30'.
ENDCASE.
APPEND lr_2.
* now fill the remaining quarters
lr_3-sign      = 'I'.
lr_3-option    = 'BT'.
lr_3-low       = lr_2-high + 1.
* to get into the third month of the quarter
lr_3-high      = lr_2-high + 70.
* now set the last day of the quarter
CASE lr_3-high+4(2).
  WHEN '03' OR '12'.
    lr_3-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_3-high+6(2) = '30'.
ENDCASE.
APPEND lr_3.
* now fill the remaining quarters
lr_4-sign      = 'I'.
lr_4-option    = 'BT'.
lr_4-low       = lr_3-high + 1.
* to get into the third month of the quarter
lr_4-high      = lr_3-high + 70.
* now set the last day of the quarter
CASE lr_4-high+4(2).
  WHEN '03' OR '12'.
    lr_4-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_4-high+6(2) = '30'.
ENDCASE.
APPEND lr_4.
* now fill the remaining quarters
lr_5-sign      = 'I'.
lr_5-option    = 'BT'.
lr_5-low       = lr_4-high + 1.
* to get into the third month of the quarter
lr_5-high      = lr_4-high + 70.
* now set the last day of the quarter
CASE lr_5-high+4(2).
  WHEN '03' OR '12'.
    lr_5-high+6(2) = '31'.
  WHEN '06' OR '09'.
    lr_5-high+6(2) = '30'.
ENDCASE.
APPEND lr_5.

This will fill five ranges (one for each subsequent quarter) which you can use to select your data

select * from xxxxx

into table yyyy1

where date_field in lr_1.

select * from xxxxx

into table yyyy2

where date_field in lr_1.

etc.

Hope that helps,

Michael