05-09-2006 10:17 PM
Is there a standard SAP function module that calculates a date using a specific number of hours?
For example:
The expected GR date is 4 days and 11 hours from the PGI date. So we would like to use the functionality to add 107 hours to the PGI date to recieve the Expected GR date.
thanks,
brian
05-10-2006 5:26 AM
Hi brian,
1. The logic is simple.
2. For this purpose, i have an independent
subroutine - FORM,
in which we pass the hours,
and we get back days, and hours.
107 hours = 4 days , 11 hours
3. just copy paste in new program
4.
report abc.
*----
DATA : DAYS TYPE I.
DATA : HRS TYPE I.
*----
parameters : h type i DEFAULT '107'.
perform getfigure using H CHANGING DAYS HRS.
WRITE : DAYS , HRS.
*----
FORM
*----
form getfigure using phours changing days hrs.
DATA : MYDAYS TYPE P DECIMALS 2.
MYdays = phours / 24.
DAYS = TRUNC( MYDAYS ).
hrs = phours mod 24.
endform.
regards,
amit m.
05-09-2006 10:35 PM
Hi Brian,
Please check this FM <b>C14Z_CALC_DATE_TIME</b>.
Hope this will help.
Regards,
Ferry Lianto
Please reward point if helpful.
05-09-2006 10:39 PM
Also check !
SD_CALC_DURATION_FROM_DATETIME
Hope thisll give you idea!!
<b>P.S award the points.</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise"
05-09-2006 11:12 PM
hi Brain,
Check FM <b>C14Z_CALC_DATE_TIME</b>...
Hope this helps,
Regards,
Santosh
05-09-2006 11:16 PM
I guess there is a bug in the function module. C14Z_CALC_DATE_TIME..See the results to corraborate.
_______________________________________________________
Import parameters Value
I_ADD_SECONDS 3.600
I_UZEIT 10:00:00
I_DATUM 2006/01/01
Export parameters Value
E_DATUM 2006/01/02
E_UZEIT 10:00:00
05-10-2006 5:26 AM
Hi brian,
1. The logic is simple.
2. For this purpose, i have an independent
subroutine - FORM,
in which we pass the hours,
and we get back days, and hours.
107 hours = 4 days , 11 hours
3. just copy paste in new program
4.
report abc.
*----
DATA : DAYS TYPE I.
DATA : HRS TYPE I.
*----
parameters : h type i DEFAULT '107'.
perform getfigure using H CHANGING DAYS HRS.
WRITE : DAYS , HRS.
*----
FORM
*----
form getfigure using phours changing days hrs.
DATA : MYDAYS TYPE P DECIMALS 2.
MYdays = phours / 24.
DAYS = TRUNC( MYDAYS ).
hrs = phours mod 24.
endform.
regards,
amit m.
06-06-2006 4:21 PM
Amit,
This is great code, however it just brings back the days and hours... how would i then apply that to the current date and time to get the expected date and time?
-brian
06-06-2006 4:23 PM
I haven't look at the code closely, but if it is bring back the days and hours, all you should need to do is add the days to the date, and the hours to the time. If date is typed as sy-datum and time is typed as sy-uzeit, then adding the values to them will work. The system will handle date and times for you.
Of course this won't work if the hours pushs you into the next day. So you would have to handle that by checking and adding one to the date.
Regards,
Rich Heilman
06-06-2006 4:41 PM
Here is the sample code a little modified. This will handle when the hours push to the next day.
report abc.
data : days type i.
data : hrs(2) type c.
data: t type sy-uzeit value '113500',
d type sy-datum value '20060606'.
data: test_time type sy-uzeit.
data: conv_hrs type sy-uzeit.
parameters : h type i default '110'.
perform getfigure using h changing days hrs.
write : days , hrs.
d = d + days.
conv_hrs+0(2) = hrs.
test_time = conv_hrs + t.
if test_time < t.
d = d + 1.
endif.
t = t + conv_hrs.
write:/ d, t.
*---------------------------------
* FORM
*---------------------------------
form getfigure using phours changing days hrs.
data : mydays type p decimals 2.
mydays = phours / 24.
days = trunc( mydays ).
hrs = phours mod 24.
endform.
Regards,
Rich Heilman
06-06-2006 6:28 PM
execellent, i was just coding your first post when i saw that you responded with your changes... thank you very much
any idea on how to relate to the factory calendar?
06-06-2006 4:37 PM
The best way is to use the FM ADD_TIME_TO_DATE
Sample Usage:
<b>
CALL FUNCTION 'ADD_TIME_TO_DATE'
EXPORTING
i_idate = wa_starting_date
i_time = wa_time
i_iprkz = wa_iprkz
I_RDMHD =
IMPORTING
o_idate = wa_return_date
EXCEPTIONS
invalid_period = 1
invalid_round_up_rule = 2
internal_error = 3
OTHERS = 4
.</b>
Regards,
Ravi