Hi Experts,
This is the function module.
for "R3001" contract type (specified as WHEN 'R3001'),
the extended termination date should be end of the month ,for this we are aading 29 days to agent starting date, but in the case of february if we add 29 days it is going to the next month,(every year the problem appearing in the month of FEB only) for leap year also its creating problem in the month of february only,if it is moving to next month the checks are paying unnecessarily. My requirement is whatever the "ZAGENT_START" ,the extended termination should be last day of the month only.
How can we modify this ? Please suggest me ASAP.
****************************************
FUNCTION zepc_get_extended_trm_dt_new.
*"----
""Local interface:
*" IMPORTING
*" REFERENCE(INSOBJECT) TYPE INSOBJECT_MD
*" REFERENCE(ZAGENT) TYPE ZAGENT_NO
*" REFERENCE(SUB_CHANNEL) TYPE ZSUB_CHANNEL
*" REFERENCE(ZCONT_CODE) TYPE ZCONTR_CODE
*" REFERENCE(ZAGENT_START) TYPE ZAGENTNUMSTDATE
*" REFERENCE(ZAGENT_REF) LIKE ZEPC_IO_AGENT STRUCTURE
*" ZEPC_IO_AGENT OPTIONAL
*" REFERENCE(ZAGENT_NEW) LIKE ZEPC_IO_AGENT STRUCTURE
*" ZEPC_IO_AGENT OPTIONAL
*" EXPORTING
*" REFERENCE(EXTENDED_TRM_DATE) TYPE ZAGENTNUMSTDATE
*"----
************************************************************************
02/10/06 TMARVIN DV2K908222 TD #3181
08/09/06 APOT5 DV2K910117 Include status reason code
************************************************************************
DATA: l_day TYPE p,
t_agent LIKE zepc_io_agent OCCURS 0 WITH HEADER LINE,
l_enddate LIKE sy-datum,
f_extend TYPE c.
CLEAR l_enddate.
IF zagent_ref IS INITIAL AND
zagent_new IS INITIAL.
Then derive the from DB.
SELECT * FROM zepc_io_agent INTO TABLE t_agent
WHERE insobject = insobject AND
zagent_no = zagent.
SORT t_agent BY zintrl_agt_no DESCENDING.
READ TABLE t_agent INDEX 2.
IF t_agent-zagent_stat = 'ACT' AND
( t_agent-zstat_reas = '010'
or t_agent-zstat_reas = '028' ) .
f_extend = 'X'.
ENDIF.
ELSE. "Compare structures.
Still to do.
ENDIF.
Processing Logic
IF f_extend IS INITIAL.
extended_trm_date = zagent_start - 1.
ELSE.
CASE zcont_code+0(5).
WHEN 'R3001'.
extended_trm_date = zagent_start + 29.
Set the comparison date to the end date of the active record
l_enddate = zagent_start - 1.
WHILE zagent_start4(2) = extended_trm_date4(2).
WHILE l_enddate4(2) = extended_trm_date4(2).
ADD 1 TO extended_trm_date.
ENDWHILE.
WHEN 'L2000' OR 'NYFS '.
extended_trm_date = zagent_start + 6.
CLEAR l_day.
CALL FUNCTION 'DAY_IN_WEEK'
EXPORTING
datum = extended_trm_date
IMPORTING
wotnr = l_day.
CALL FUNCTION 'DATE_CHECK_WORKINGDAY'
EXPORTING
date = extended_trm_date
factory_calendar_id = 'ZD'
message_type = 'I'
EXCEPTIONS
date_after_range = 1
date_before_range = 2
date_invalid = 3
date_no_workingday = 4
factory_calendar_not_found = 5
message_type_invalid = 6
OTHERS = 7.
If not a working day and it is Thursday, make it Friday.
IF sy-subrc = 4 AND
l_day = 4.
extended_trm_date = extended_trm_date + 1.
ENDIF.
WHEN OTHERS.
extended_trm_date = zagent_start - 1.
ENDCASE.
ENDIF.
ENDFUNCTION.
Regards,
Sam.