Focal Point
[SOLVED]Simple REPEAT Loop

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

November 19, 2015, 05:24 PM
djackson
[SOLVED]Simple REPEAT Loop
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
November 19, 2015, 06:15 PM
CoolGuy
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.
November 20, 2015, 09:05 AM
GavinL
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
November 20, 2015, 09:54 AM
George Patton
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
November 20, 2015, 10:37 AM
David Beagan
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.
November 20, 2015, 11:16 AM
Diptesh Patel
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
November 20, 2015, 02:55 PM
djackson
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
November 22, 2015, 02:57 AM
Danny-SRL
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

November 22, 2015, 06:54 AM
George Patton
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