I spent a fair bit of time today trying to turn a time range into a start and end date. I've come to the conclusion that this is slightly futile, or at the very least, not a best practice.
Using the TIME_RANGES_GET procedure will populate a series of variables with all the fields from the TIME_RANGES table, if you feed it an ID or an abbreviation. The most potentially useful fields are the START_TIME_LEVEL and START_RANGE. The first will tell you if your time range is yearly, quarterly or weekly and the second will tell you how many points in time back you need to go.
I figured I'd be able to reverse-engineer a time range with a combination of the current date range and the aforementioned two fields. The problem I ran into is when you get into negative numbers, such as if the current month is 02, and you need to subtract 3. You are really not dealing with a date value, so there are no helpful functions to do the math for you.
This made me take a step back and assess why I was trying to do what I was trying to do. There are certain instances in PMF where you can drill down without clicking on a date value, and get to the a_meas_detail01.fex report with only a time range for a variable. This will likely only happen on custom gadgets without a date axis visible, such as a summary-type report (IE. show me the total for a particular date range).
I have a series of operational reports that expect to receive a point in time, and fail with a '&TIME is not found' error if they only find a time range. I decided to provide a default point in time for this sort of circumstance, which is to give the user the current time period at the level of the time range they are using. So if it is January, Quarter 1, of 2009, and they have Last 4 Quarters as a time range, I will set &TIME to Quarter 1, 2009. If they have a monthly time range, I'll set &TIME to January, 2009. A yearly time range will result in 2009. This is a fair compromise to handling a rare situation.
This is the code, which checks for a valid &TIME value and if it doesn't find one, does what I just described:
-IF &TIME.EXIST EQ 1 THEN GOTO SKP_TR;
-SET &RPT_TIME_RANGE_ABBR = '5WW';
-*
-INCLUDE TIME_RANGES_GET
-SET &TIME = IF &START_TIME_LEVEL EQ 1 THEN &TLVL01_CUR ELSE IF &START_TIME_LEVEL EQ 2 THEN &TLVL01_CUR||'~'||&TLVL02_CUR ELSE IF &START_TIME_LEVEL EQ 3 THEN &TLVL01_CUR||'~'||&TLVL02_CUR||'~'||&TLVL03_CUR ELSE &TLVL01_CUR||'~'||&TLVL02_CUR||'~'||&TLVL03_CUR||'~'||&TLVL04_CUR;
-SKP_TR;
-SET &DIM_NAME = 'TIME';
-SET &DIM_VALUE = &TIME;
-INCLUDE gadg_dim_parms
It might be a useful function to provide in a future release of PMF to populate a set of variables that can be used for a start and end date in external op reports, based on a provided time abbreviation. There are already a set of variables called &TLVL0x_CURR, which contain the current point in time. You could take the current point in time, give it a 'Last 6 Weeks' time range, and get a point in time that is six weeks back, with all the years, quarters, and months nicely sorted out for you.
Cheers,
Joey
-WebFOCUS 8.2.01 on Windows