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

function Modules for time subtraction.

Former Member
0 Likes
9,660

Hello abapers..

I want two function modules...

1) to subtract 1 hour from time and date.

for eg if the date entered is 23.3.08 and time is 00:00:00

then the function module should give the result as

22.3.08 and 23:00:00.

or if the date is 21.03.08 and time is 12:00:00.

The result should be 21.03.08 and time 11:00:00.

2) the second one is for validation..i am not sure if there is

a function module for that.

I want to validate whether the date entered by the user

in the select option for type sy-datum is in the correct format.

I mean the user should not enter anything except a date.

For eg:

If the user enters 97898jjjj then it should also invalidate this

as well as if the user enters 34.07.08 then also the FM should invalidate this..

Points will be rewarded for helpful answer.

15 REPLIES 15
Read only

matt
Active Contributor
0 Likes
5,193

1)

DATA: dat TYPE d,
      tim TYPE t.

IF tim LT '01000'.
  SUBTRACT 1 FROM dat.
ENDIF.

SUBTRACT 3600 FROM tim.

2)

If you define your select options as type sy-datum, the user cannot enter an implausible/invalid date.

matt

Read only

Former Member
0 Likes
5,193

use fm



RP_CALC_DATE_IN_INTERVAL
 Add/subtract years/months/days from a date

Read only

0 Likes
5,193

hi,

Use the below FM ..


IF pa_older = 'X'.
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
 EXPORTING
   date = pa_end
    days = '00'
    months = '06'
    signum = '-'
    years = '00'
 IMPORTING
    calc_date = pa_end.
ENDIF.
   

Read only

Former Member
0 Likes
5,193

I am sorry but my select option is not of type sy-datum.

But of the type ITSEGDIAE-TIME_TST01 .

and it is a combination of date and time.

This structure is linked to the table TSEGE and the field for the

date and time is TSEGE-even_tstfr.

It is displayed in numeric format like 20.071.026.100.000.

But internally date and time is stored as 26.10.2007 10:00:00.

So i want to validate whether the date and time is in the correct format.

Also i want to subtract 1 hour from the actual date and time entered by the user.

Read only

Former Member
0 Likes
5,193

Hi,

Try the FM.

SCOV_TIME_DIFF.

example.

Import parameters Value

IM_DATE1 31.03.2008

IM_DATE2 31.03.2008

IM_TIME1 10:00:00

IM_TIME2 11:00:00

Export parameters Value

EX_DAYS 0

EX_TIME 01:00:00

Regards,

Morris Bond.

Reward Points if Helpful.

Read only

0 Likes
5,193

hi,

I have input as date and time and constant subtraction of 1 hour

.

The output should be new date and time with 1 hour subtraction.

Read only

Former Member
0 Likes
5,193

Try the FM LEINT_TIMECALC_DIFF / TIMECALC_DIFF.

This will find the difference b/w 2 time stamps in seconds.

Hope this helps.

Thanks

Balaji

Read only

0 Likes
5,193

Hi,

i also had one requirment of adding 1hour tp date and time.

i used the FM dimp_add_time. But i m not finding a suitable FM for subtracting 1 hour.I have still not got a apt FM like that.

Read only

0 Likes
5,193

Try this


DATA : diff TYPE i.

PARAMETERS :

       iv_stime TYPE  t,

       iv_sdate TYPE  d,

       iv_atime TYPE  t.

ev_endtime = iv_stime - iv_atime.

diff = ev_endtime - iv_stime.

IF diff > 0.

   ev_enddate = iv_sdate - 1.

ELSE.

   ev_enddate = iv_sdate.

ENDIF.

WRITE : ev_endtime.

WRITE : ev_enddate.

Read only

Former Member
0 Likes
5,193

Try the below FM CONV_UTIL_ADD_DATE_AND_TIME .

This will help you to add days and time to a timestamp. It will give you result in datestamp too.

Hope this helps.

Thanks

Balaji

Read only

0 Likes
5,193

Hi,

I do have a FM to add time i want a FM to subtract time!!!!

Is it that in SAP there is FM to add time but no FM to subtract

time!!!!!

Read only

SantoshKallem
Active Contributor
0 Likes
5,193

try this function module

LTRM_TIME_GAP_CALC

i searched it in www.se37.com

regards.

santhosh reddy

Read only

Former Member
0 Likes
5,193

Hi,

Try FM IGN_TIMESTAMP_PLUSMINUS

The Flag BACKWARD if to subtract.

Reward Points if useful.

Neelav

Read only

Former Member
0 Likes
5,193

Try this


DATA : diff TYPE i.

PARAMETERS :

       iv_stime TYPE  t,

       iv_sdate TYPE  d,

       iv_atime TYPE  t.

ev_endtime = iv_stime - iv_atime.

diff = ev_endtime - iv_stime.

IF diff > 0.

   ev_enddate = iv_sdate - 1.

ELSE.

   ev_enddate = iv_sdate.

ENDIF.

WRITE : ev_endtime.

WRITE : ev_enddate.

Read only

5,193

Try these two function module

IGN_TIMESTAMP_PLUSMINUS

CATT_ADD_TO_TIME