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: 

modification of function module

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

>

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

8 REPLIES 8

Former Member
0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

>

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

0 Kudos

Hi Karthik,

The Zagent_Start should be any date of the month it will be 3rd jan or 10th jan or 01st Feb or any date . After adding 29 days it should not goes to next month.

Anyway I am very very thakful to your earliest response.

Thanks&Regards,

Sam.

0 Kudos

Hi sam,

Really you are confused, tell me how we can add 29 days to 10th of a month without going to next month. If it should not go to next month then the date should be the last day of the month, right?

If your requirement is to get the last day of the month use my solution given above.

Regards

Karthik D

0 Kudos

Hi Karthik,

In the function module WHEN 'R3001' case

if the Zagent_start = 02/01 i.e., Feb 1st

the extended termination date should be last day of the month(by adding 27 days to the ZAGENT_START we get it,

If it is a leap year we have to add 28 days to the ZAGENT_START, then the extended termination should become last day of the month.

The modification should done only for "02/01" month and for "R3001" case, not for all months. this is my requirement.

Can you suggest me how to do this(With coding).

Can you reply ASAP.

Thanks&Regards,

Sam.

0 Kudos

Hi Sam,

The following Code satisfy your requirement;

WHEN 'R3001'.
IF zagent_start+4(4) EQ '0201'. " If its February 1st
  extended_trm_date = zagent_start + 28. " Add 28 days to it
  IF extended_trm_date+6(2) NE '29'. " If Date is not 29, ie Current year is not a leap Year
    extended_trm_date = zagent_start + 27. " Add only 27 days to it.
  ENDIF.
ENDIF.

Hope your problem is solved.

Regards

Karthik D

0 Kudos

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.