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

DATE VALIDATION

Former Member
0 Likes
2,005

1) My requirment is to validate

current date of system(sy-datum) and past date in selection screen.

If difference between these

two dates more than six months than one error must display.

for example assume

current date = 02/21/2008 &

past date =

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,401

Hi,

Use the below code.

parameters: p_date type sy-datum.

data: v_date type sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

DATE = sy-datum

DAYS = 0

MONTHS = '06'

SIGNUM = '-'

YEARS = 0

IMPORTING

CALC_DATE = v_date.

if p_date lt v_date.

write:/ 'Invalid date'.

else.

write:/ 'Valid date'.

endif.

9 REPLIES 9
Read only

rainer_hbenthal
Active Contributor
0 Likes
1,401

sy-datum is always valid

Read only

Former Member
0 Likes
1,401

Hi,

You can make use of Function module 'HR_AUPBS_MONTH_DAY' to get the number of months b/w the current date and the end date.

<REMOVED BY MODERATOR>

Thanks,

Asha

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 5:34 PM

Read only

0 Likes
1,401

hi asha,

thanks for your replay.Kindly once read below query and send reply.

regards,

saritha.

1) My requirement is to validate

current date of system(sy-datum) and past date in selection screen.

If difference between these

two dates more than six months than one error must display.

for example assume

current date = 21/02/2008 &

past date = 19/08/2007 ,

difference between these two dates is 6 month 3 days.

Then error must display

" difference between current date & past date should not be more than six months"

2)Please explain me how to validate these two dates?

Read only

0 Likes
1,401

Hi,

try this:

PARAMETERS: P_DATE LIKE SY-DATUM.

*

DATA CH_DATE LIKE SY-DATUM.

*

CALL FUNCTION 'CALCULATE_DATE'

EXPORTING

MONTHS = '-6'

START_DATE = SY-DATUM

IMPORTING

RESULT_DATE = CH_DATE.

*

IF P_DATE < CH_DATE.

WRITE: 'ERROR', P_DATE.

ELSE.

WRITE: 'OK', P_DATE.

ENDIF.

Regards, Dieter

Read only

Former Member
0 Likes
1,402

Hi,

Use the below code.

parameters: p_date type sy-datum.

data: v_date type sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'

EXPORTING

DATE = sy-datum

DAYS = 0

MONTHS = '06'

SIGNUM = '-'

YEARS = 0

IMPORTING

CALC_DATE = v_date.

if p_date lt v_date.

write:/ 'Invalid date'.

else.

write:/ 'Valid date'.

endif.

Read only

0 Likes
1,401

THIS IS VIGNESh CODE...BUT FOR VALIDATION PURPOSES U NEED TO use at selection-screen .

Use the below code.



select-options: p_date type sy-datum.
*at selection-screen .*
data: v_date type sy-datum.

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
DATE = sy-datum
DAYS = 0
MONTHS = '06'
SIGNUM = '-'
YEARS = 0
IMPORTING
CALC_DATE = v_date.

if p_date lt v_date.
write:/ 'Invalid date'.
else.
write:/ 'Valid date'.
endif.

Edited by: saslove sap on Apr 11, 2008 10:52 AM

Read only

Former Member
0 Likes
1,401

HI,

Use the FM:

MONTH_PLUS_DETERMINE – add or subtract month from a date

Hope this helps.

<REMOVED BY MODERATOR>

Regards,

Sipra

Edited by: Alvaro Tejada Galindo on Apr 11, 2008 5:35 PM

Read only

Former Member
0 Likes
1,401

Hi,

Now, in your case the current date = 02/21/2008 ( mm/dd/yyyy)

and Past date = 08/19/2007.

1. Use the FM ' HR_AUPBS_MONTH_DAY' to get the number of months b/w these two dates.

2. You will get the no. of months in the parameter NO_MONTH.

3. Take it into a variable V_MONTH and then check if V_MONTH GE '6'.

4. If so, give the error message otherwise sucessfully carry out the your rest processing.

Please reward points if useful.

If you have any query revert back to me.

thanks,

Asha

Read only

Former Member
0 Likes
1,401

Hi,

Please refer the code below :


tables : bsis.

data : month like VTBBEWE-ATAGE.

parameters : sp_date like sy-datum.


at selection-screen.

CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
  EXPORTING
    i_date_from          = sp_date
*   I_KEY_DAY_FROM       = I_KEY_DAY_FROM
    i_date_to            = sy-datum
*   I_KEY_DAY_TO         = I_KEY_DAY_TO
*   I_FLG_SEPARATE       = ' '
 IMPORTING
*   E_DAYS               = E_DAYS
   E_MONTHS             = month
*   E_YEARS              = E_YEARS
          .

if month GT '6'.
message 'Invalid date' type 'E'.
endif.

OR

Try using FM MONTHS_BETWEEN_TWO_DATES.

Thanks,

Sriram Ponna.