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

Splitting the date based on the selection screen input

Former Member
0 Likes
1,962

Hi all,

In the Selection screen of my report i had maintained two fields

SELECT-OPTIONS : S_DATE FOR TPCDATE-FROM_DATE.

PARAMETERS : P_NUMBER TYPE ZMMAREA-NUMBER.

I need to code such that

S_DATE should be splitted into P_NUMBER times

for example if P_NUMBER is 4 i need S_DATE should be splitted into 4 equal parts or near by equal parts

IF P_NUMBER is 2 i need S_DATE should be splitted into 2 equal parts or near by equal parts

Please suggest me the code of if any Function module exists fot this date splitting

Thanks in advance

Ajay.D

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,482

Hello

Try this logic:


SELECT-OPTIONS : S_DATE FOR TPCDATE-FROM_DATE.
PARAMETERS : P_NUMBER TYPE ZMMAREA-NUMBER.

DATA: DAYS TYPE I,
      COUNT TYPE I,
      XXX TYPE I.
DATA: BEGIN OF ITAB OCCURS 0,
      LDATE LIKE SY-DATUM,
      HDATE LIKE SY-DATUM,
      END OF ITAB.

DAYS = S_DATE-HIGH - S_DATE-LOW.
COUNT = TRUNC( DAYS / P_NUMBER ).
XXX = P_NUMBER - 1.
DO XXX TIMES.
  ITAB-LDATE = S_DATE-LOW.
  S_DATE-LOW = S_DATE-LOW + COUNT.
  ITAB-HDATE = S_DATE-LOW.
  APPEND ITAB.
  S_DATE-LOW = S_DATE-LOW + 1.
  CLEAR ITAB.
ENDDO.
ITAB-LDATE = S_DATE-LOW.
ITAB-HDATE = S_DATE-HIGH.
APPEND ITAB.

In table ITAB you will have date intervals.

9 REPLIES 9
Read only

vinod_vemuru2
Active Contributor
0 Likes
1,482

Hi,

your question seems to be not clear to me. Can you eloborate about the requirement.

Are you looking for splitting of date range? Please note that Select options can have ranges, exclusions and single values.

Thanks,

Vinod.

Read only

Former Member
0 Likes
1,483

Hello

Try this logic:


SELECT-OPTIONS : S_DATE FOR TPCDATE-FROM_DATE.
PARAMETERS : P_NUMBER TYPE ZMMAREA-NUMBER.

DATA: DAYS TYPE I,
      COUNT TYPE I,
      XXX TYPE I.
DATA: BEGIN OF ITAB OCCURS 0,
      LDATE LIKE SY-DATUM,
      HDATE LIKE SY-DATUM,
      END OF ITAB.

DAYS = S_DATE-HIGH - S_DATE-LOW.
COUNT = TRUNC( DAYS / P_NUMBER ).
XXX = P_NUMBER - 1.
DO XXX TIMES.
  ITAB-LDATE = S_DATE-LOW.
  S_DATE-LOW = S_DATE-LOW + COUNT.
  ITAB-HDATE = S_DATE-LOW.
  APPEND ITAB.
  S_DATE-LOW = S_DATE-LOW + 1.
  CLEAR ITAB.
ENDDO.
ITAB-LDATE = S_DATE-LOW.
ITAB-HDATE = S_DATE-HIGH.
APPEND ITAB.

In table ITAB you will have date intervals.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,482

What do you mean by splitting ? Any example .

Read only

Former Member
0 Likes
1,482

Hi Ajay,

1. Find the difference betweem low and high of the selction date (say value = x)

2. Divide x by P_number (say the resut = y)

3. add Y to low of selection data.. till it reaches High value..

Please consider point of vinod as well..


Are you looking for splitting of date range?  "Please note that Select options can have ranges, exclusions and single values.

Hope this helps,

Nag

Read only

Former Member
0 Likes
1,482

Yes u can do as u need i.e, first get the parameter value and then get the difference (in no.of years) between the given date range and divide it by value (given for paratmer) and update the select option accordingly. But your logic should cover all the cases i.e, if user gives single day for selecti option then how u will divide it based on the parameter value. So be clear about the requirement first and build logic accordingly.

Read only

Former Member
0 Likes
1,482

Hi,

Please be clear with your requirement then only we can suggest some solution.

Regards,

Amit

Read only

Former Member
0 Likes
1,482

though date question are not allowed, this requirement sounds little different.

you can take a difference between those days by: S_date-high - S_date-low.

then divide the difference by p_number. now you get the split positions.

now in a do enddo you can negate the dates by the split amount you got from the divisions.

like...

PARAMETERS: num type i.
select-OPTIONS: s_date for sy-datum.

data : gv_split type i, gv_temp type sy-datum.

gv_split = s_date-high - s_date-low.
gv_split = gv_split / num.

gv_temp = s_date-high.
do num times.
  gv_temp = gv_temp - gv_split.
  WRITE / gv_temp.
enddo.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,482

Kindly ignore .

Edited by: Keshav.T on Jan 12, 2010 2:17 PM

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,482

Check whether RHXPROVIDE_PERIODS is helpful