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     [SOLVED]Simple REPEAT Loop

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED]Simple REPEAT Loop
 Login/Join
 
Member
posted
Hi,
I need to produce a row for each day between ADATE and CDATE. The number of days difference is calculated in DATEDIFF. And then I'm trying to use DATEDIFF to run through the loop that many times, each time printing a row. But obviously somethings not right as I'm only getting the one row. Here is the code and I would really appreciate any help with this... loops always get me!

DEFINE FILE CAR
ADATE/A8 = '&YYMD';
BDATE/YYMD = DATECVT(ADATE, 'A8YYMD', 'YYMD');
CDATE/A8 = '20151123';
DDATE/YYMD = DATECVT(CDATE, 'A8YYMD', 'YYMD');
DATEDIFF/I3 = DDATE-BDATE;
END

-SET &REPEATTIMES = DATEDIFF;

-REPEAT LOOPEND WHILE &REPEATTIMES NE 0;

TABLE FILE CAR
PRINT
BDATE
DDATE
DATEDIFF
COUNTRY
WHERE COUNTRY EQ 'ENGLAND'
-RUN
-SET &REPEATTIMES = &REPEATTIMES - 1;
-SET BDATE = BDATE + 1;
-LOOPEND
END

This message has been edited. Last edited by: <Emily McAllister>,


Dev Studio 8.1.0.4, App Studio 8.1.5m, Reporting Server 8.1.4, InfoAssist, Active Technologies, Windows 2003 Server, Windows7
 
Posts: 20 | Location: Wheaton College | Registered: April 25, 2005Report This Post
Virtuoso
posted Hide Post
Hey djackson,

Here's a loop structure I thought up to grab every column value for the first 5 rows from the request to build a top 5 in sales custom HTML widget for dropping into a portal page panel. Maybe you could glean some ideas from it to help you figure out how to gather multiple records instead of just the one. The trick is using a counter along with defining your date range correctly. I've used a -SET to get the week end date 3 weeks previous to the one passed by a filter form. The request uses that along with the passed weekend date to only pull the range specified. It then loops through gathering each of the top 5 records' values storing them in their own amper variable for later use within my own custom HTML below the code I've shared (whether it be for tool-tip values or actual values to be shown within the widget itself).

Hope this helps!

-SET &THREEWKSPREV = AYMD(&WEEKENDING.QUOTEDSTRING, -21, 'YYMD');

DEFINE FILE SRPROD
WKEND_MDYY/MDYY=DATECVT(SRPROD.DIMDATE.WEEKENDING, 'YYMD', 'MDYY');
INT_CASHIERNO/I10 = EDIT(SRPROD.SRPROD.SRPDCASHIERNO);
INT_STORENO/I5 = IF INT_CASHIERNO GT 9999 THEN INT_CASHIERNO;
STORENO/A5 = EDIT(INT_STORENO);
END
-RUN
TABLE FILE SRPROD
SUM
     SRPROD.DIMSTORE.DSNAME/A50
     SRPROD.SRPROD.SRPDGROSSSALES
BY TOTAL HIGHEST 5 SRPROD.SRPROD.SRPDGROSSSALES NOPRINT
BY SRPROD.SRPROD.SRPDCASHIERNAME/A35
BY INT_CASHIERNO
&select.EVAL
WHERE ( SRPROD.DIMDATE.WEEKENDING GE '&THREEWKSPREV');
WHERE ( SRPROD.DIMDATE.WEEKENDING LE '&WEEKENDING');
WHERE SRPDCASHIERNO NE STORENO;
WHERE SRPDCASHIERNO NE '800';
WHERE SRPDCASHIERNO NE '997';
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE SAVE FORMAT ALPHA
END
-RUN

-SET &I = 0;
-LOOP
-SET &I = &I + 1;
-IF &I GT 5 GOTO OUT;
-READ SAVE &SRPDCASHIERNAME.&I.A35. &CASHIERNO.&I.I10. &SNAME.&I.A50. &SRPDGROSSSALES.&I.I10.
-SET &CNAME.&I = TRUNCATE(&SRPDCASHIERNAME.&I);
-SET &STRNAME.&I = TRUNCATE(&SNAME.&I);
-SET &STORE = &STRNAME.&I;
-SET &CNO = &CASHIERNO.&I;
-SET &TOOLTIP.&I = '#&CNO.EVAL from &STORE.EVAL';
-TYPE &CNAME.&I &CNO &STRNAME.&I &SRPDGROSSSALES.&I &TOOLTIP.&I
-GOTO LOOP
-OUT


8.2.02M (production), 8.2.02M (test), Windows 10, all outputs.
 
Posts: 1113 | Location: USA | Registered: January 27, 2015Report This Post
Master
posted Hide Post
The basics of looping, there are two ways.

If your needing to know what loop count your on, you would do the following:
-SET &REPEATTIMES = 20;
-REPEAT LOOPEND FOR &COUNTER FROM 1 TO &REPEATTIMES
-SET &INREVERSE = ((&REPEATTIMES-&COUNTER)+1);
-TYPE COUNTER = &COUNTER or Backwards: &INREVERSE
-LOOPEND
END


If you don't care about what loop your on, you can do this:
-SET &REPEATTIMES = 20;
-REPEAT LOOPEND2 &REPEATTIMES TIMES
-TYPE Looping
-LOOPEND2
END


Results:
COUNTER = 1 or Backwards: 20
 COUNTER = 2 or Backwards: 19
 COUNTER = 3 or Backwards: 18
 COUNTER = 4 or Backwards: 17
 COUNTER = 5 or Backwards: 16
 COUNTER = 6 or Backwards: 15
 COUNTER = 7 or Backwards: 14
 COUNTER = 8 or Backwards: 13
 COUNTER = 9 or Backwards: 12
 COUNTER = 10 or Backwards: 11
 COUNTER = 11 or Backwards: 10
 COUNTER = 12 or Backwards: 9
 COUNTER = 13 or Backwards: 8
 COUNTER = 14 or Backwards: 7
 COUNTER = 15 or Backwards: 6
 COUNTER = 16 or Backwards: 5
 COUNTER = 17 or Backwards: 4
 COUNTER = 18 or Backwards: 3
 COUNTER = 19 or Backwards: 2
 COUNTER = 20 or Backwards: 1
 .
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping
 Looping



- FOCUS Man, just FOCUS!
-----------------------------
Product: WebFOCUS
Version: 8.1.04
Server: Windows 2008 Server
 
Posts: 578 | Registered: October 01, 2014Report This Post
Master
posted Hide Post
You have a few things not going for you right at the start.

Someone will be happy to correct me if I'm wrong, but your
-SET &REPEATTIMES=DATEDIFF;
won't do anything, because the DEFINE isn't processed until after all the -SET commands.

If you want that sort of logic to work you need something similar to what you'll find here:

http://forums.informationbuild...5732/xsl/print_topic


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
 
Posts: 674 | Location: Guelph, Ontario, Canada ... In Focus since 1985 | Registered: September 28, 2010Report This Post
Silver Member
posted Hide Post
Does this help?

 
-DEFAULT &Start = '20151126';
-DEFAULT &End   = '20151225';
-DEFAULT &i     =  1        ;
-SET     &Date  = &Start;

 SQL CREATE TABLE CALENDAR (KEY INTEGER,DATEYYMD DATE);
 END

 MODIFY FILE CALENDAR
 MATCH KEY
 ON MATCH REJECT
 ON NOMATCH INCLUDE
 DATA
-REPEAT ENDREPEAT WHILE &End GE &Date;
 &i,'&Date',$
-SET &i = &i + 1;
-SET &Date = AYMD(&Date, 1, 'I8YYMD');
-ENDREPEAT
 END

 TABLE FILE CALENDAR
 PRINT KEY DATEYYMD
 END


WF 8.2.03
Win10 / IE11 / Chrome
HTML EXL2K PDF et. al.
 
Posts: 5 | Registered: October 15, 2012Report This Post
Gold member
posted Hide Post
Like George said, your DEFINE is not run until after the SET. Put in a -RUN after the DEFINE.

Also, not sure about this, but maybe the -RUN in the middle of the loop is also not needed.


Diptesh
WF 7.1.7 - AIX, MVS
 
Posts: 79 | Location: Warren, NJ, USA | Registered: October 25, 2006Report This Post
Member
posted Hide Post
Hi,
It's taking me a while to work through all the suggestions and I really appreciate the help! There is so much to know/learn about webfocus... always surprised by how much I really don't know or haven't been exposed to in webfocus! Will probably have more questions as I go along. thanks very much!


Dev Studio 8.1.0.4, App Studio 8.1.5m, Reporting Server 8.1.4, InfoAssist, Active Technologies, Windows 2003 Server, Windows7
 
Posts: 20 | Location: Wheaton College | Registered: April 25, 2005Report This Post
Virtuoso
posted Hide Post
Hi,
I think you are not attacking the problem with a FOCUS viewpoint.
Since you want a number of records in sequence between 2 dates, I would prefer the MacGuyver technique:
  
-* File djackson01.fex
-* McGuyver technique
-*
-* Courtesy of Jack Gross
-*
-DEFAULTH &FILE=FSEQ, &KEY=BLANK, &COUNTER=COUNTER, &FIRST=1, &LAST=100
 EX -LINES 7 EDAPUT MASTER, &FILE, CV, MEM
  FILE=&FILE, SUFFIX=FOC, $
    SEGNAME=FSEQ1, SEGTYPE=S1, $
      FIELD=&KEY, , A1, ACCEPT=' ', INDEX=I, $
    SEGNAME=FSEQ2, SEGTYPE=S1, PARENT=FSEQ1, $
      FIELD=&COUNTER, , I4, $
 END
 -RUN
 CREATE FILE &FILE
 MODIFY FILE &FILE
  FREEFORM &KEY &COUNTER
  MATCH &KEY &COUNTER
    ON NOMATCH INCLUDE
    ON MATCH REJECT
 DATA
-REPEAT #SEQ.LOOP FOR &I FROM &FIRST TO &LAST ;
 ' ', &I, $
-#SEQ.LOOP
 END
-RUN
-* Now that we have the MacGuyver file we can create the loop within the TABLE request
JOIN BLANK WITH COUNTRY IN CAR TO BLANK IN FSEQ AS M_
DEFINE FILE CAR
BLANK/A1 WITH COUNTRY = ' ';
BDATE/YYMD  = '&YYMD';
DDATE/YYMD = '20151130';
NDATE/YYMD = BDATE + COUNTER;
END
-RUN
-*
TABLE FILE CAR
PRINT
BDATE
DDATE
NDATE
COUNTRY
WHERE COUNTRY EQ 'ENGLAND';
WHERE NDATE LE DDATE;
END


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

 
Posts: 1980 | Location: Tel Aviv, Israel | Registered: March 23, 2006Report This Post
Master
posted Hide Post
I agree with Danny - McGuyver is the way to go.


WebFOCUS 7.7.05 Windows, Linux, DB2, IBM Lotus Notes, Firebird, Lotus Symphony/OpenOffice. Outputs PDF, Excel 2007 (for OpenOffice integration), WP
 
Posts: 674 | Location: Guelph, Ontario, Canada ... In Focus since 1985 | Registered: September 28, 2010Report 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     [SOLVED]Simple REPEAT Loop

Copyright © 1996-2020 Information Builders