Application Development 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: 

Factory Time function module

former_member302630
Participant
0 Kudos

Is there a Func module like DATE_CONVERT_TO_FACTORYDATE but for factory times instead of dates?

Input : Factcal_id, date.

Output should be next working Date, working start time , working end time (or factory begin and end timestamps for a working day for a factcal_id).

OR

Output: work start time and

duration of working seconds on a particular factory date.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Assuming you have retrieved the start and end times somewhere from your system, your function would resemble this:

function working_seconds_between_timestamps( date1, time1, date2, time2, 
                           plant_factory_calendar, plant_start_time, plant_end_time)
{
if date1 = date2 then working_seconds = time2 - time1
else if date1 < date2 then
  {
  number_of_working_days calculated from DATE_CONVERT_TO_FACTORYDATE (date1, date2, plant_factory_calendar)
  seconds_first_day = plant_end_time - time1
  seconds_full_days = plant_end_time - plant_start_time
  seconds_last_day = time2 - plant_start_time
  working_seconds = seconds_first_day + ( number_of_working_days - 1 ) * seconds_full_days + seconds_last_day
  }
}

Of course, you need to adjust many parts of the raw algorithm based on the context and on your exact requirement.

3 REPLIES 3

Sandra_Rossi
Active Contributor

The Factory Calendar is only for dates. If you're looking for hours, then this "function module" exists only if there is such a feature in your system, so it's a functional question to ask to an ECC (or SRM, APO, ...?) forum rather than ABAP. When you know the name of this feature, then you can ask how to get it from ABAP.

former_member302630
Participant
0 Kudos

or another way , given 2 timestamps, can the number of factory hours be derived between those 2 timestamps?

Basically the need is

1. for a given UTC start date-time of a task ,

is that UTC start time within factory working time of plant? If no, replace with next nearest factory working time.

2. For a given UTC end date-time of a task,

taking derived factory working start time from point 1 above, what is the time in factory hours passed (duration) between working start time and working end time.

So we have to derive working start and end date-time and then derive factory hours passed between them.

Sandra_Rossi
Active Contributor

Assuming you have retrieved the start and end times somewhere from your system, your function would resemble this:

function working_seconds_between_timestamps( date1, time1, date2, time2, 
                           plant_factory_calendar, plant_start_time, plant_end_time)
{
if date1 = date2 then working_seconds = time2 - time1
else if date1 < date2 then
  {
  number_of_working_days calculated from DATE_CONVERT_TO_FACTORYDATE (date1, date2, plant_factory_calendar)
  seconds_first_day = plant_end_time - time1
  seconds_full_days = plant_end_time - plant_start_time
  seconds_last_day = time2 - plant_start_time
  working_seconds = seconds_first_day + ( number_of_working_days - 1 ) * seconds_full_days + seconds_last_day
  }
}

Of course, you need to adjust many parts of the raw algorithm based on the context and on your exact requirement.