Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *PROCESS MARGINS(1, 140);
- t1: proc options (main);
- dcl from char (8) date ('DDMMYYYY');
- dcl to char (8) date ('DDMMYYYY');
- dcl holidays (7) char (8) date ('DDMMYYYY')
- init ('01012012', '06012012', '01052012', '06122012', '24122012', '25122012', '26122012');
- from = '01122012';
- to = '31122012';
- put skip list ('Number of working days in december 2012: ' || trim(workdays(from, to, holidays)));
- (STRINGRANGE, SUBSCRIPTRANGE):
- workdays: proc (from, to, holiday_list) returns (fixed bin (31));
- dcl (from, to) char (8) date ('DDMMYYYY');
- dcl holiday_list (*) char (8) date ('DDMMYYYY') optional;
- dcl (days_from, days_to, day) fixed bin (31);
- dcl total_days fixed bin (31);
- dcl week_index fixed bin (31);
- dcl nworkdays fixed bin (31);
- dcl i fixed bin (31);
- dcl (result, holiday) bit (*) controlled;
- dcl weeks (7) bit (7) nonasgn init ('1000001'b, '0000011'b, '0000110'b, '0001100'b, '0011000'b, '0110000'b, '1100000'b);
- dcl (days, weekday, tally, substr, lbound, hbound, copy, omitted) builtin;
- days_from = days(from, 'DDMMYYYY');
- days_to = days(to, 'DDMMYYYY');
- total_days = days_to - days_from + 1;
- if total_days <= 0 then return (0);
- allocate result bit (total_days);
- week_index = weekday(days_from);
- result = copy(weeks(week_index), total_days / 7) || substr(weeks(week_index), 1, mod(total_days, 7));
- if ^omitted(holiday_list) then
- do;
- allocate holiday bit (total_days);
- do i = lbound(holiday_list) to hbound(holiday_list);
- day = days(holiday_list(i), 'DDMMYYYY');
- if (day >= days_from) & (day <= days_to) then
- do;
- holiday = copy('0'b, day - days_from ) || '1'b || copy('0'b, days_to - day);
- result = result | holiday;
- end;
- end;
- free holiday;
- end;
- nworkdays = tally(result, '0'b);
- free result;
- return (nworkdays);
- end workdays;
- end t1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement