Requirement: I have a requirement to take a date(eg: 0CALDAY) and convert it to a number between 1 and 25 that represents the working day of the month. (compare it to the factory calendar, and then output the position in the factory calendar.)
Solution:
Note: This is an ABAP Program for understanding purposes only. Do not use the code as it is in BW Routines. Remove the code where it is not required. I think i have given some unnecessary information in the code for easy understanding .
CODE:
*&---------------------------------------------------------------------*
*& Report ZPVTEST *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZPVTEST .
parameters : p_date type sy-datum.
data : d1 like sy-datum, "first day of the month
d2 like sy-datum, "first working day date
d3 like sy-datum, "current working day date
d4 like sy-datum, "current working day of the month
v_nds type i.
data : facdate_from type facdate,
facdate_to type facdate.
write:/ 'input Date(eg:0CALDAY): = ', p_date.
write:/ ' ----------------------------------------------------'.
d4 = p_date.
p_date+6(2) = '01'.
d1 = p_date.
write:/ 'first day of the month :D1 =', d1.
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
* Here we find the first working day of month from Fact. Cal.
EXPORTING
CORRECT_OPTION = '+'
DATE = d1
FACTORY_CALENDAR_ID = 'AU' " factory calendar ID
IMPORTING
DATE = d2
FACTORYDATE = facdate_from
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
CORRECT_OPTION_INVALID = 2
DATE_AFTER_RANGE = 3
DATE_BEFORE_RANGE = 4
DATE_INVALID = 5
FACTORY_CALENDAR_NOT_FOUND = 6
OTHERS = 7.
IF SY-SUBRC = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write:/ 'first working(factory) date of the month: D2 = ', d2.
write:/ 'first working(factory) day of the month: = ', facdate_from.
write:/ ' ----------------------------------------------------'.
CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE'
* Here we find the current working day form Fact. Cal.
EXPORTING
CORRECT_OPTION = '-'
DATE = d4
FACTORY_CALENDAR_ID = 'AU' " factory calendar ID
IMPORTING
DATE = d3
FACTORYDATE = facdate_to
EXCEPTIONS
CALENDAR_BUFFER_NOT_LOADABLE = 1
CORRECT_OPTION_INVALID = 2
DATE_AFTER_RANGE = 3
DATE_BEFORE_RANGE = 4
DATE_INVALID = 5
FACTORY_CALENDAR_NOT_FOUND = 6
OTHERS = 7.
IF SY-SUBRC = 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
write:/ ' working(factory) date of the month: D3 = ', d3.
write:/ ' working(factory) day of the month: = ', facdate_to.
write:/ ' ----------------------------------------------------'.
if facdate_to ne facdate_from.
v_nds = facdate_to - facdate_from.
v_nds = v_nds + 1.
else.
v_nds = 1.
endif.
write :/ 'working day indicator ', v_nds.
OUTPUT:
----------------------------------------------------------
test program
input Date(eg:0CALDAY): = 15.08.2008
first day of the month :D1 = 01.08.2008
first working(factory) date of the month: D2 = 01.08.2008
first working(factory) day of the month: = 2,932
working(factory) date of the month: D3 = 15.08.2008
working(factory) day of the month: = 2,942
working day indicator 11
----------------------------------------------------------
No comments:
Post a Comment