Focal Point
[CLOSED] Reusable code: X months ago

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/6307066916

May 01, 2012, 09:51 AM
Ublguy
[CLOSED] Reusable code: X months ago
Good Morning,

I currently use this code:
&YYMD = 05/01/2012

-SET &MYYEAR = DATECVT(DATEADD(DATECVT (&YYMD, 'I8YYMD', 'YYMD'),'M', -5 ), 'YYMD','YY');
-SET &MYMONTH = DATECVT(DATEADD(DATECVT (&YYMD, 'I8YYMD', 'YYMD'),'M', -5 ), 'YYMD','M');

MYYEAR --> returns the year from 5 months ago = 2011
MYMONTH --> returns the month from 5 months ago = 12

We do this a lot. I would LOVE to make this simpiler by building a DEFINE FUNCTION that will calculate the year by passing in 2 variables (aDate, aMonthsAgo). I gave it a try but I keep getting the following error. Can someone point me in the correct direction?

My code:
DEFINE FUNCTION GETYEAR(myDate/I8YYMD, pastMonths/I2)
GETYEAR/YY = DATECVT(DATEADD(DATECVT (myDate, 'I8YYMD', 'YYMD'),'M', pastMonths ), 'YYMD','YY');;
END

-SET &MYYEAR = GETYEAR(&YYMD, -4, 'YY');
-RUN
-TYPE &MYYEAR
-EXIT

My Error:
(FOC263) EXTERNAL FUNCTION OR LOAD MODULE NOT FOUND: GETYEAR

Thank you for taking the time to read and help.

Nick

This message has been edited. Last edited by: Kerry,
May 01, 2012, 10:49 AM
Danny-SRL
  
DEFINE FUNCTION GETYEAR(myDate/I8YYMD, pastMonths/I2)
GETYEAR/YY = DATECVT(DATEADD(DATECVT (myDate, 'I8YYMD', 'YYMD'),'M', pastMonths ), 'YYMD','YY');
END
-RUN
-SET &MYYEAR = GETYEAR(&YYMD, -4);
-RUN
-TYPE &MYYEAR
-EXIT

This works.


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

May 01, 2012, 12:16 PM
Ublguy
Daniel, that works great.

To Recap: The difference between my code (not working) and your code (working):
1) Add the RUN statement after the DEFINE FUNCTION
2) Remove the extra ; (wish Dev Studio could tell me I did this :-)
3) Remove the data type in the calling of GETYEAR()

Thank you.
May 01, 2012, 12:19 PM
susannah
you know about the AYMD and AYM functions?




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
May 01, 2012, 12:32 PM
Doug
Ahich one's "extra"?
quote:
2) Remove the extra ;





   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206
May 01, 2012, 03:50 PM
Ublguy
quote:
Originally posted by susannah:
you know about the AYMD and AYM functions?


Agreed WF offers a lot of options for working with dates. The reason why I didn't choose to use AYM is because of the required date format of (Year/Month). I like working with full dates. Even if the end game is just using the Month or Year format. AYMD I see no need for :-), but that is because my apps are mostly months at a time, and not X # of days.
May 01, 2012, 03:51 PM
Ublguy
quote:
Originally posted by Doug:
Ahich one's "extra"?
quote:
2) Remove the extra ;


Sorry I wasn't more clear, the "fixes" were based on the original post code. Just wanted to offer readers the ability to see what was wrong with the original, and how the second one fixed it. I guess I just added more confusion.
May 01, 2012, 05:35 PM
Waz
Nick, the most important thing here is the -RUN.

Dialog Manager is always parsed first, so when the -SET with GETYEAR is parsed, the DEFINE FUNCTION has not yet been processed.

The -RUN forces WebFOCUS to process up to the -RUN, then continue the parsing.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!