Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Closed - Currently working another project]Working with DATES in a looping routine

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[Closed - Currently working another project]Working with DATES in a looping routine
 Login/Join
 
Gold member
posted
With the help of this forum I was able to come up with a report that would print out a daily count for a specific time period. The report has prompts for start & end dates.

As a test, I ran the report for the period 09/01/2009 - 09/07/2009 which producted the following output. The totals for Day 6 and Day 7 are correct:

DAILY STUDENT COUNT FOR THE PERIOD: 09/01/2009 - 09/07/2009

DAY 1 0
DAY 2 0
DAY 3 0
DAY 4 0
DAY 5 0
DAY 6 24
DAY 7 24

What I would like to be able to do is replace the text labels ie. DAY 1 .. Day 7 with dates so the output would look like the following:

DAILY STUDENT COUNT FOR THE PERIOD: 09/01/2009 - 09/07/2009

09/01/2009 0
09/02/2009 0
09/03/2009 0
09/04/2009 0
09/05/2009 0
09/06/2009 24
09/07/2009 24

The origional report code is displayed below. I was looking to work with the AYMD function but I find working dates and variable assignments can be confusing and frustrating sometimes.

If someone could point me in the right direction I could sure use your assistance.

-SET &ECHO=ALL;
-DEFAULT &SD='09/01/2009';
-DEFAULT &ED= '09/07/2009';
-SET &BEGINFMT=DATECVT(EDIT(&SD,'99$99$9999'),'A8MDYY','I8');
-SET &ENDFMT=DATECVT(EDIT(&ED,'99$99$9999'),'A8MDYY','I8');
-SET &NUMDAYS=DATEDIF(&BEGINFMT,&ENDFMT,'D')+1;
-TYPE &NUMDAYS;
-SET &DAY=0;
-SET &BEGDATE = DATECVT(&BEGINFMT,'I8','A8YYMD');
-TYPE &BEGDATE;
JOIN
T_STUDENTREGISTRATION.TRAININGCLASS_ID IN T_STUDENTREGISTRATION TO
T_TRAININGCLASS.ID IN T_TRAININGCLASS AS J0
END

DEFINE FILE T_STUDENTREGISTRATION
ADATE/MDYY=HDATE(T_STUDENTREGISTRATION.T_STUDENTREGISTRATION.ARRIVALDATE, 'YYMD');
DDATE/MDYY=HDATE(T_STUDENTREGISTRATION.T_STUDENTREGISTRATION.DEPARTUREDATE, 'YYMD');
-REPEAT THISLOOP &NUMDAYS TIMES
DAY&DAY/MDYY=DATEADD('&BEGDATE','D',&DAY);
DAYCNT&DAY/I9=IF AD LE DAY&DAY AND DD GT DAY&DAY THEN 1 ELSE 0;
-SET &DAY=&DAY+1;
-THISLOOP

END
TABLE FILE T_STUDENTREGISTRATION
PRINT
&NUMDAYS
&DAY
&BEGDATE
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON

END
TABLE FILE T_STUDENTREGISTRATION
SUM
-SET &DAY=0;
-SET &RAY=1;
-REPEAT PRINTLOOP &NUMDAYS TIMES
DAYCNT&DAY.EVAL AS 'DAY &RAY' OVER
-SET &DAY=&DAY+1;
-SET &RAY=&RAY+1;
-PRINTLOOP
ARRIVALDATE NOPRINT
WHERE ( ADATE LE '&ED' ) AND ( DDATE GT '&SD' );
HEADING
"DAILY STUDENT COUNT FOR THE PERIOD: <+0>&SD<+0> - <+0>&ED<+0> "
" "
END

This message has been edited. Last edited by: Jeff_Rowland,


7.7.02 Windows7
HTML/Excel/PDF
 
Posts: 66 | Registered: April 16, 2008Report This Post
Expert
posted Hide Post
This is way more code than you need but it might give you some ideas. I use a Dialogue Manager index loop to create the column headings for the data.
-DEFAULT &ENDYYM=200606;
-SET &BEGYYM=AYM(&ENDYYM,-12,'I6YYM');
-SET &PREVYR=EDIT(&BEGYYM,'9999');
-SET &CURRYR=EDIT(&ENDYYM,'9999');
-SET &ENDOFYR=&PREVYR||'12';
-SET &BEGOFYR=&CURRYR||'01';
-SET &PREVMOCNT=YM(&BEGYYM,&ENDOFYR,'I3')+1;
-SET &CURRMOCNT=YM(&BEGOFYR,&ENDYYM,'I3')+1;
-SET &BEGDT=&BEGYYM||'01';
-SET &NXTYYM=AYM(&ENDYYM,1,'I6YYM');
-SET &NXTDT=&NXTYYM||'01';
-SET &ENDDT=AYMD(&NXTDT,-1,'I8YYMD');
-TYPE &BEGYYM &BEGDT &NXTDT &ENDDT &PREVYR &CURRYR &PREVMOCNT &CURRMOCNT
-*-EXIT
DEFINE FILE CENTURYSALES
ROLLRTN/P8C=IF YYEARMONTH EQ &BEGYYM THEN 0 ELSE RETURN;
ROLLPRF/D20=IF YYEARMONTH EQ &BEGYYM THEN 0 ELSE PROFIT;
CURRAVGRTN/P8C=IF YEAR EQ &CURRYR THEN RETURN ELSE 0;
PREVAVGRTN/P8C=IF YEAR EQ &PREVYR THEN RETURN ELSE 0;
CURRAVGPRF/P20=IF YEAR EQ &CURRYR THEN PROFIT ELSE 0;
PREVAVGPRF/P20=IF YEAR EQ &PREVYR THEN PROFIT ELSE 0;
-SET &LOOPYYM=&BEGYYM;
-REPEAT ENDLOOP FOR &I FROM 1 TO 13 STEP 1
-*-TYPE &I
-* COMPUTE BUCKETS FOR EACH MONTH
RTN&I/P8C=IF YYEARMONTH EQ &LOOPYYM THEN RETURN ELSE 0;
PRF&I/P20=IF YYEARMONTH EQ &LOOPYYM THEN PROFIT ELSE 0;
-SET &LOOPYYM=AYM(&LOOPYYM,1,'I6YYM');
-ENDLOOP
END
-*-EXIT
TABLE FILE CENTURYSALES
SUM
-SET &LOOPYYM=&BEGYYM;
-REPEAT ENDPRNT FOR &I FROM 1 TO 13 STEP 1
-*-TYPE &I
-* PRINT BUCKETS FOR EACH MONTH
-SET &MONTH=EDIT(&LOOPYYM,'$$$$99');
COMPUTE LOOPMONTH&I/A2='&MONTH'; NOPRINT
COMPUTE COLHDR&I/A20=DECODE LOOPMONTH&I('01' 'January' '02' 'February' '03' 'March'
                                        '04' 'April'   '05' 'May'      '06' 'June'
                                        '07' 'July'    '08' 'August'   '09' 'September'
                                        '10' 'October' '11' 'November' '12' 'December');
RTN&I/P8C
PRF&I/P20
-SET &LOOPYYM=AYM(&LOOPYYM,1,'I6YYM');
-ENDPRNT
COMPUTE COLHDR14/A20='12 Mo. Rolling Avg';
ROLLRTN NOPRINT
COMPUTE RTNAVG/P8C=ROLLRTN/12;
ROLLPRF NOPRINT
COMPUTE PRFAVG/P20=ROLLPRF/12;
COMPUTE COLHDR15/A20='&CURRYR YTD Avg';
CURRAVGRTN NOPRINT
COMPUTE CURRRTNAVG/P8C=CURRAVGRTN/&CURRMOCNT;
CURRAVGPRF NOPRINT
COMPUTE CURRPRFAVG/P20=CURRAVGPRF/&CURRMOCNT;
COMPUTE COLHDR15/A20='&PREVYR Avg';
PREVAVGRTN NOPRINT
COMPUTE PREVRTNAVG/P8C=PREVAVGRTN/&PREVMOCNT;
PREVAVGPRF NOPRINT
COMPUTE PREVPRFAVG/P20=PREVAVGPRF/&PREVMOCNT;
BY PLANTNAME
WHERE ORDERDATE GE &BEGDT AND ORDERDATE LE &ENDDT;
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD FORMAT ALPHA
END
-*? HOLD HOLD
-*-EXIT
-RUN
APP FI ALTMAS DISK altmas.mas
-RUN
-WRITE ALTMAS FILENAME=HOLD,SUFFIX=FIX
-WRITE ALTMAS SEGNAME=PLANT,SEGTYPE=S0
-WRITE ALTMAS FIELDNAME=PLANTNAME,ALIAS=PLNTNM,FORMAT=A15,ACTUAL=A15,$
-WRITE ALTMAS SEGNAME=MEASURES,SEGTYPE=S0,PARENT=PLANT,OCCURS=16,$
-WRITE ALTMAS FIELDNAME=COLHDR,ALIAS=CH,FORMAT=A20,ACTUAL=A20,$
-WRITE ALTMAS FIELDNAME=RETURNS,ALIAS=RTN,FORMAT=P8C,ACTUAL=A8,$
-WRITE ALTMAS FIELDNAME=PROFIT,ALIAS=PRF,FORMAT=P20C,ACTUAL=A20,$
-WRITE ALTMAS FIELDNAME=COLCNTR,ALIAS=ORDER,FORMAT=I4,ACTUAL=I4,$
APP FI ALTMAS DISK hold.ftm
DEFINE FILE ALTMAS
BLANK/A5=' ';
END
TABLE FILE ALTMAS
SUM  RETURNS AS 'Returns'
OVER PCT.RETURNS/F5.1% AS '% of Total'
OVER PROFIT AS 'Profit'
OVER PCT.PROFIT/F5.1% AS '% of Total'
BY PLANTNAME NOPRINT
BY BLANK AS ''
ACROSS COLCNTR NOPRINT
ACROSS COLHDR AS ''
ON PLANTNAME SUBHEAD
"<PLANTNAME"
ON TABLE SET PAGE NOPAGE
END


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Expert
posted Hide Post
Using the FOR statement may also help.

-SET &SD = '06/28/1998' ;
-SET &ED = '07/04/1998' ;

-SET &BEGINFMT=DATECVT(EDIT(&SD,'99$99$9999'),'A8MDYY','I8');
-SET &ENDFMT=DATECVT(EDIT(&ED,'99$99$9999'),'A8MDYY','I8');
-SET &NUMDAYS=DATEDIF(&BEGINFMT,&ENDFMT,'D');
-TYPE &NUMDAYS

TABLE FILE TRADES
SUM   CNT.DATE_OF_TRADE AS NUM_OF_TRADES
FOR   DATE_OF_TRADE
-REPEAT DATELOOP FOR &CNTR FROM 0 TO &NUMDAYS ;
-SET &Over = IF &CNTR EQ 0 THEN ' ' ELSE 'OVER' ;
-SET &ONumb= &BEGINFMT + &CNTR;
-SET &ODate= EDIT(DATECVT(&ONumb,'I8','A8MDYY'),'99/99/9999');
 &Over &ODate
-DATELOOP

WHERE DATE_OF_TRADE GE '&SD'
WHERE DATE_OF_TRADE LE '&ED'
END


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!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Virtuoso
posted Hide Post
This approach avoids use of OVER. The code hasn't been tested so proceed accordingly.

-DEFAULT &SD = '09/01/2009';
-DEFAULT &ED = '09/07/2009';
-* Convert MM/DD/YYYY dates to YYYYMMDD for use with function AYMD.
-SET &START_DATE = EDIT(&SD,'$$$$$$9999') | EDIT(&SD,'99$$$$$$$$') | EDIT(&SD,'$$$99$$$$$');
-SET &END_DATE   = EDIT(&ED,'$$$$$$9999') | EDIT(&ED,'99$$$$$$$$') | EDIT(&ED,'$$$99$$$$$');
-*
JOIN T_STUDENTREGISTRATION.TRAININGCLASS_ID IN T_STUDENTREGISTRATION
  TO T_TRAININGCLASS.ID IN T_TRAININGCLASS AS J0
END
-*
DEFINE FILE T_STUDENTREGISTRATION
 ADATE/YYMD = HDATE(T_STUDENTREGISTRATION.T_STUDENTREGISTRATION.ARRIVALDATE,'YYMD');
 DDATE/YYMD = HDATE(T_STUDENTREGISTRATION.T_STUDENTREGISTRATION.DEPARTUREDATE,'YYMD');
END
-* Extract and hold data falling within date range.
TABLE FILE T_STUDENTREGISTRATION
 PRINT ADATE
       DDATE
    BY TRAININGCLASS_ID
 WHERE ( ADATE LE '&END_DATE' ) AND ( DDATE GT '&START_DATE' );
    ON TABLE HOLD AS DATAHOLD
END
-RUN
-* Use REPEAT loop to calculate DAYCNT for each date in date range.
-* (Increase TO limit if date range might exceed 100 days.)
-REPEAT ENDREPEAT1 FOR &I FROM 0 TO 100
-SET &DATEVAL = AYMD(&START_DATE,&I,'I8');
-*
DEFINE FILE DATAHOLD
 DATEVAL/YYMD WITH TRAININGCLASS_ID = '&DATEVAL';
 DAYCNT/I9 = IF ( ADATE LE '&DATEVAL' ) AND ( DDATE GT '&DATEVAL' ) THEN 1 ELSE 0 ;
END
-* Hold count results.
TABLE FILE DATAHOLD
 PRINT DATEVAL
       DAYCNT
    BY TRAININGCLASS_ID
    ON TABLE HOLD AS CNTHOLD
END
-* Issue command to append successive REPEAT loop processing to existing file.
APP FILEDEF CNTHOLD DISK cnthold.ftm (APPEND
-RUN
-* Exit REPEAT loop if end of date range has been reached.
-IF &DATEVAL EQ &END_DATE GOTO QUITREPEAT1 ;
-*
-ENDREPEAT1
-QUITREPEAT1
-RUN
-*
TABLE FILE CNTHOLD
 SUM DATEVAL/MDYY
     DAYCNT
  BY DATEVAL NOPRINT
END


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Report This Post
Gold member
posted Hide Post
Thanks to all who posted. Your input was very helpful and helps me to become more efficient working with WebFocus. Currently reworking my report to incorporate some of the logic that came for all the posts.


7.7.02 Windows7
HTML/Excel/PDF
 
Posts: 66 | Registered: April 16, 2008Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [Closed - Currently working another project]Working with DATES in a looping routine

Copyright © 1996-2020 Information Builders