Skip to Content
avatar image
Former Member

modification of function module

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 20, 2008 at 01:20 PM

    >

    My requirement is whatever the "ZAGENT_START" ,the extended termination should be last day of the month only.

    > Regards,

    > Sam.

    Hi sam,

    Only since you asked as above i gave the solution, but now you are confusing.

    What exactly you want?

    If Zagent_start is 12th january and you add 29 days it will also go to next month, right?

    Give some example zagent_start dates and what you expect in EXTENDED_TRM_DATE.

    Regards

    Karthik D

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Karthik,

      Your reply solved my problem .I am very thankful to you.

      The same I done it in different way i.e., I checked whether given year is a leap year, if yes added 28 days,if not 27 days I added.

      Once again very very Thanks for your due response.

      Regards,

      Sam.

  • avatar image
    Former Member
    Sep 20, 2008 at 11:59 AM

    Hi Sam,

    Use the Function Module RP_LAST_DAY_OF_MONTHS to get the last day of the month and assign it to EXTENDED_TRM_DATE.

    Use this as follows;

    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in                  = ZAGENT_START
     IMPORTING
       LAST_DAY_OF_MONTH       = EXTENDED_TRM_DATE.

    Revert back if u have any doubts.

    Regards

    Karthik D

    Edited by: Karthik D on Sep 20, 2008 5:30 PM

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Karthik,

      If I wants the lastday of the month means your reply very helpful almost solves the problem.

      If I want to add 29 days and It(extended temination date) should not goes to the next month. For every year we are getting the problem for the month of february only. Because February has 28 days only and 29 days in case of leap year.

      My requirement is to add 29 days to all months , modify in case o february.the result EXTENDED TERMINATION DATE should not enter into next month( I want to check seperately for leap year also).

      Please suggest me Karthik.If you don't mind with coding.

      Thanks&Regards,

      Sam.