Focal Point
[CLOSED] Global variables changes

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

October 26, 2018, 11:53 AM
Shingles
[CLOSED] Global variables changes
Hi Folks,

I would like to create a loop and exit when a global variable is a certain key value (or when we've reached a certain number of iterations, but I'm clear on that bit). I created some code that sort of works. If &&DEFDB is 'DW_IBI_PROD' when the procedure is initially run, then it exits the loop as desired. If &&DEFDB is not 'DW_IBI_PROD' then it stays in that loop until the counter reaches 36. However if &&DEFDB is changed sometime while I am in the loop (so when the procedure starts it is not 'DW_IBI_PROD' but while its in the loop it is changed to 'DW_IBI_PROD' in some other process), then webfocus is not picking up that change and it is not exiting the loop, which is not desired. I hope that is clear. Here is the code:

-SET &COUNTER=0;

-REPEAT :ENDLOOP WHILE &COUNTER LT 36;

-IF &&DEFDB EQ 'DW_IBI_PROD' GOTO :BYPASS;
-SET &COUNTER = &COUNTER+1;
-SET &DELAY = SLEEP(2,'I6');

-:ENDLOOP

-*Do stuff when &&DEFDB is not 'DW_IBI_PROD'
-*...
-EXIT

-:BYPASS
-*Do stuff when &&DEFDB is 'DW_IBI_PROD'
...



So... ya... how do I make it so that webfocus sees that &&DEFDB has changed while the procedure is running?

Thank you,

This message has been edited. Last edited by: FP Mod Chuck,


WebFOCUS 8201, SP 0.1, Windows 7, HTML
October 26, 2018, 12:04 PM
BabakNYC
quote:
changed while the procedure is running


By procedure do you mean a report or chart? If that's what you're talking about, I don't see how that's possible because by the time WebFOCUS sees TABLE FILE or GRAPH FILE, the &&VARIABLE has been resolved into the value at that moment.


WebFOCUS 8206, Unix, Windows
October 26, 2018, 02:36 PM
Shingles
So can I have the bit the looks at the global in a separate procedure/fex (it would check if DEFDB is a certain text string and returns the result), then my procedure above can call it and based on the results.

I dont know if that makes sense... basically if you are saying that the moment a procedure/fex file is run, then that is when the global variable is resolved and only then, then I will have to call the same fex file multiple times, and this fex needs to reutrn a value that will help me to determine if the loop should terminate (ie that &&DEFDB = 'DW_IBI_PROD'


WebFOCUS 8201, SP 0.1, Windows 7, HTML
October 26, 2018, 02:45 PM
BabakNYC
I'm not quite sure but the way variables work is that they have to have a value between TABLE FILE and END. If you add -SET &ECHO=ALL; to the very beginning of your code you'll see how variables are populated with the real value you've provided them.

If you clarify your use case a little more we might be able to suggest a different way you could accomplish it though.


WebFOCUS 8206, Unix, Windows
October 26, 2018, 03:09 PM
Shingles
Our ETL sets a global variable called &&DEFDB to 'DW_IBI_PROD' when it is done.

I have a scheduled report that runs each morning and it gets emailed out.

I want to delay this report if our ETL took a little longer to run. More specifically, if &&DEFDB is not 'DW_IBI_PROD' then wait ten minutes and check again. If after 6 hours of trying this &&DEFDB is still not 'DW_IBI_PROD' then just give up and kill the schedule by running this -SET &&KILL_RPC='Y';.

If however at any point &&DEFDB does become 'DW_IBI_PROD' then exit the loop and run the schedule.

This procedure (the fex) is run as a pre-processing procedure for the report that will run the actual guts of the report.

I hope I didn't lose you, I thought I kept it simple enough up there. Basicly I was hoping there was a setting that I could set that would allow me to not used a cached copy of the global variable (which is what I think is happening).


WebFOCUS 8201, SP 0.1, Windows 7, HTML
October 26, 2018, 03:10 PM
MartinY
Using below code it does what you want (I think)
-SET &TSTVAR = 'CONTINUE';
-REPEAT LOOP FOR &I FROM 2 TO 5
-IF &TSTVAR EQ 'END' THEN GOTO ENDLOOP;

TABLE FILE CAR
SUM RETAIL_COST
BY COUNTRY
BY SEATS
-*WHERE SEATS EQ &I;
ON TABLE HOLD
END
-RUN
-SET &TSTVAR = IF &LINES EQ 0 THEN 'END' ELSE 'CONTINUE';

-LOOP
-ENDLOOP

As above, it will loop 4 times (from 2 to 5) but if you "activate" the where clause it will only loop twice since there is no seats = 3.

I have not defined a global variable within my sample, but maybe you can try on your side.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
October 26, 2018, 03:12 PM
BabakNYC
This sounds a lot like a use case for Alerts. https://webfocusinfocenter.inf...4C99A2294C62878AF7E0


WebFOCUS 8206, Unix, Windows
October 30, 2018, 07:40 AM
dhagen
quote:
Our ETL sets a global variable called &&DEFDB to 'DW_IBI_PROD' when it is done.


I assume that this is done by writing the whole expression to a fex. If that is true, then you have to include that procedure into your loop.

-SET &COUNTER=0;

-REPEAT :ENDLOOP WHILE &COUNTER LT 36;

-* include the procedure that has the global set.
EX GETDEFDB
-RUN

-IF &&DEFDB EQ 'DW_IBI_PROD' GOTO :BYPASS;
-SET &COUNTER = &COUNTER+1;
-SET &DELAY = SLEEP(2,'I6');

-:ENDLOOP

-*Do stuff when &&DEFDB is not 'DW_IBI_PROD'
-*...
-EXIT

-:BYPASS
-*Do stuff when &&DEFDB is 'DW_IBI_PROD'
...
  



"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott