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

quarters

Former Member
0 Likes
412

hi,

if the user enters 2 dates n selection screen and if i get the quarter of in which the selct-option-low and select-option-high lies how can i get the mioddle qaurter??

eg..from: 20/02/2007 to 29/09/2007

20/02/2007 lies in 1st quarter and 29/09/2007 lies in 3rd qaurter how can i get the middle quarters start and end date??its urgent!!

1 REPLY 1
Read only

Former Member
0 Likes
362

Hi,

Try this..



 TYPES: BEGIN OF type_date,
                 low TYPE sydatum,
                 high TYPE sydatum,
              END OF type_date. 

DATA: t_date     type standard table of type_date.
DATA: s_date     type type_date.
DATA: t_final     type standard table of type_date.
DATA: v_low_found.
DATA: v_high_found.
RANGES: r_date for sy-datum.


** have the four quarters in an internal table.
*" First quarter.
  s_date-low(4) = sy-datum(4).      " Store the current year.
  s_date-low+4(4) = '0101'.           " date and month.
  s_date-high(4) = sy-datum(4)     " Store the current year.
  s_date-high+4(4) = '0331'.          " date and month.
  APPEND s_date to T_DATE.

*" second quarter.
  s_date-low(4) = sy-datum(4).      " Store the current year.
  s_date-low+4(4) = '0401'.           " date and month.
  s_date-high(4) = sy-datum(4)     " Store the current year.
  s_date-high+4(4) = '0630'.          " date and month.
  APPEND s_date to T_DATE.

*" third quarter.
  s_date-low(4) = sy-datum(4).      " Store the current year.
  s_date-low+4(4) = '0701'.           " date and month.
  s_date-high(4) = sy-datum(4)     " Store the current year.
  s_date-high+4(4) = '0930'.          " date and month.
  APPEND s_date to T_DATE.

*" fourth quarter.
  s_date-low(4) = sy-datum(4).      " Store the current year.
  s_date-low+4(4) = '1001'.           " date and month.
  s_date-high(4) = sy-datum(4)     " Store the current year.
  s_date-high+4(4) = '1231'.          " date and month.
  APPEND s_date to T_DATE.

*"Read the select-option internal table.
  READ TABLE so_date INDEX 1.

  LOOP AT t_date INTO s_date.

*" Build the range.
   refresh: r_date.
   r_date-sign = 'I'.
   r_date-option = 'BT'.
   r_date-low = s_date-low.
   r_date-high = s_date-high.
   append r_date.

**" Check if the selection scren date so-date-low and high is in which quarters     
     IF s_date-low IN r_date AND s_date-high IN r_date.

*** Found..low and high is within the same quarter.
       APPEND s_date to t_final.
       EXIT.

     ENDIF.


***" Check if the selection screen date low is with in the range.
     IF s_date-low IN r_date.

*" Set the v_low_found flag.
         V_LOW_found = 'X'.
         CONTINUE.          " Process the next record.
        
     ENDIF.

***" Check if the selection screen date high is with in the range.
    IF s_date-high IN r_date.
      EXIT.         " Exit the loop.
    ENDIF.

     IF v_low_found = 'X'.
**" append the final internal table.
       append s_date TO t_final.

    ENDIF.


  ENDLOOP.

**" Now the t_final internal table will have the middle quarters start and end date.
  LOOP AT t_final INTO s_date.
    WRITE: / s_date.
  ENDLOOP.


Thanks

Naren