Focal Point
[CLOSED] Array of & Variable Names?

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

December 03, 2013, 10:07 AM
StevenTCramer
[CLOSED] Array of & Variable Names?
-? & ;

Will list all of the current & variables and their values.

 
-* File DisplayVariable.fex
-DEFAULT &VariableName = 'TestVariable';
-DEFAULT &TestVariable = '123';

-SET &VariableName = '&' | &VariableName;
-SET &VariableType = &VariableName | '.TYPE';
-SET &VariableExists = &VariableName | '.EXISTS';
-SET &VariableLength = &VariableName | '.LENGTH';
-SET &VariableValue = &VariableName | '.EVAL';

-IF NOT (&VariableExists.EVAL) GOTO VariableDoesNotExist;
-TYPE Name: &VariableName Value: &VariableValue.EVAL  Type: &VariableType.EVAL Length: &VariableLength.EVAL
-GOTO Return
-VariableDoesNotExist
-TYPE Name: &VariableName Exists: &VariableExists.EVAL
-Return

 


So I would like to use this routine to list all the variables with their type and lengths. But how can I get an array of all the variable names?

This message has been edited. Last edited by: <Kathryn Henning>,


7.7.03, Windows
HTML, Excel, PDF,
December 03, 2013, 11:17 AM
Mighty Max
1. Store output of -? & into hold file
2. Read hold file and store variable names in array

Used these two posts for following code.
[SOLVED] Write run-time &Variables to a file
Output data from report into Array

  
-SET &ECHO='OFF';

-SET &TEMPDIR = TEMPPATH(60,'A60');
-SET &TRACEFILE = &TEMPDIR || 'trace.trc';

SET TRACEOFF = ALL
SET TRACEON = ALL
SET TRACESTAMP=OFF
SET TRACEUSER=&TRACEFILE
-RUN
-? &
SET TRACEOFF = ALL
-RUN
FILEDEF MASTER DISK trace.mas
FILEDEF TRACE DISK trace.trc
-RUN
-WRITE MASTER FILENAME=TRACE, SUFFIX=FIX
-WRITE MASTER SEGNAME=TRACE
-WRITE MASTER FIELDNAME=LINE, FORMAT=A200, ACTUAL=A200, $
-RUN
DEFINE FILE TRACE
RESULT/A155 = SUBSTR(200,LINE,45,200,155,RESULT);
AMPER/A1 = EDIT(RESULT,'9');
VAR1/A155 = GETTOK(RESULT,155,1,'=',155,VAR1);
VAR2/A155 = STRIP(155,VAR1,'&',VAR2);
END
TABLE FILE TRACE
PRINT VAR2
IF LINE CONTAINS 'ngput'
IF AMPER EQ '&'
ON TABLE HOLD AS H1 FORMAT ALPHA
END
-RUN
-SET &CNT = &LINES;


-* Store Variable Names in Array
-SET &I = 0;
-STRT_READ
-SET &I = &I + 1;
-READ H1 &VAR_ARR.&I.A155
-IF &I LT &CNT GOTO STRT_READ;

-? &VAR_ARR



WebFOCUS 8.1.05M Unix Self-Service/MRE/Report Caster - Outputs Excel, PDF, HTML, Flat Files
December 03, 2013, 01:13 PM
StevenTCramer
Thanks Mighty Max I will give it a try.


7.7.03, Windows
HTML, Excel, PDF,
December 03, 2013, 01:33 PM
Tom Flynn
Fixed it for 7.7.x...
Use VAR2 if you only want the names; I like to use the Name and RESULT:
  
-SET &ECHO='OFF';
-SET &TEMPDIR   = TEMPPATH(100,'A100');
-SET &TRACEFILE = &TEMPDIR || 'trace.trc';

SET TRACEOFF = ALL
SET TRACEON = ALL
SET TRACESTAMP=OFF
SET TRACEUSER=&TRACEFILE
-RUN
-? &
SET TRACEOFF = ALL
-RUN
FILEDEF MASTER DISK trace.mas
FILEDEF TRACE  DISK trace.trc
-RUN
-WRITE MASTER FILENAME=TRACE, SUFFIX=FIX
-WRITE MASTER SEGNAME=TRACE
-WRITE MASTER FIELDNAME=LINE, FORMAT=A200, ACTUAL=A200, $
-RUN
DEFINE FILE TRACE
RESULT/A153 = SUBSTR(200,LINE,48,200,153,RESULT);
AMPER/A1    = EDIT(RESULT,'9');
VAR1/A153   = GETTOK(RESULT,153,1,'=',153,VAR1);
VAR2/A153   = STRIP(153,VAR1,'&',VAR2);
END
TABLE FILE TRACE
PRINT 
    RESULT 
WHERE LINE CONTAINS 'ngput';
WHERE RESULT CONTAINS '&'
  AND RESULT OMITS    '-?'
  AND RESULT OMITS    'CURRENTLY';
 ON TABLE HOLD AS H1 FORMAT ALPHA
END
-RUN
-SET &CNT = &LINES;
-* Store Variable Names in Array
-SET &I = 0;
-STRT_READ
-SET &I = &I + 1;
-SET &I = IF &I LT 10 THEN '0' || &I ELSE &I;
-READ H1 &VAR_ARR.&I.A153
-IF &I LT &CNT GOTO STRT_READ;

-? &VAR_ARR
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 03, 2013, 02:28 PM
StevenTCramer
This only will get variable names if they are 9 char or less. I am trying to get people out of the habit of using terrible variable names that are short but confusing. So this won't work for me. Obviously WF has the list stored in memory somewhere. Anyone know of another option that will work for variable names of any length?


7.7.03, Windows
HTML, Excel, PDF,
December 03, 2013, 02:45 PM
StevenTCramer
But thanks Tom and Max as it does work for capturing what is dumped to the output in a "array".


7.7.03, Windows
HTML, Excel, PDF,
December 04, 2013, 10:44 AM
njsden
Try using the following when "capturing" the list of variables to see if it helps:

-? & SAVEPRINT


It will give you not only each &variable's full name and value, but also how they got their values (via a -SET or -DEFAULT for instance).



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
December 04, 2013, 10:56 AM
njsden
Running this sample code in my environment:

-DEFAULT &WFFMT = 'EXL2K';
-DEFAULT &P_PROCESSING_DATE = &YYMD.EVAL;
-DEFAULT &P_FREQUENCY = 1;

-SET &&I_USER = LOCASE(&IBIMR_user.LENGTH, &IBIMR_user, 'A&IBIMR_user.LENGTH');
-SET &I_PROCESSING_FLAG = DECODE &P_FREQUENCY (1 'DAILY' 2 'WEEKLY' 3 'QUARTERLY' 4 'YEARLY' ELSE 'CUMULATIVE');

-? & SAVEPRINT


Provides the following:

 -*CURRENTLY DEFINED VARIABLES:
 -SET     &&I_USER = 'justme';
 -DEFAULT &ECHO = 'OFF ';
 -SET     &FOCEXURL = '/ibi_apps/WFServlet?IBIF_webapp=/ibi_apps&|IBIC_server=EDASERVE&|IBIWF_msgviewer=OFF&|';
 -SET     &FOCHTMLURL = '/ibi_html';
 -SET     &GOOGLEMAPSAPIKEY = ' ';
 -SET     &IBIMR_user = 'JustMe';
 -SET     &I_PROCESSING_FLAG = 'DAILY';
 -DEFAULT &P_FREQUENCY = 1;
 -DEFAULT &P_PROCESSING_DATE = 20131204;
 -SET     &WFDESCRIBE = OFF;
 -DEFAULT &WFFMT = 'EXL2K';


Both & and && variables are listed with a non-truncated name and specifying how each of them got its value (-SET / -DEFAULT).

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



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
December 04, 2013, 11:02 AM
Tom Flynn
New one on me!
Thanks! Works great...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 04, 2013, 11:04 AM
njsden
One of the coolest tricks presented by Rob Palmer at Summit. Loved it! Smiler



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
December 04, 2013, 11:05 AM
Tom Flynn
Thanks for sharing!!! Appreciate it!


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
December 04, 2013, 11:07 AM
njsden
You're very welcome, Tom. Hopefully Steven will find this useful to solve his requirement.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
December 05, 2013, 03:39 PM
StevenTCramer
when I use -? & SAVEPRINT I get less variables than when I use -? &;

In one case I get 55 the other 22.

So I now can get the fullname I just dont' get all. Any ideas?


7.7.03, Windows
HTML, Excel, PDF,
December 06, 2013, 09:34 AM
njsden
Are you only interested in your application variables (the ones you control) or also internal ones such as &YYMD, &LINES, etc.?

I think SAVEPRINT excludes the latter from consideration so you'll have to pick which version (-? & vs. -? & SAVEPRINT) gives you the best bang for the buck given your reporting needs, or perhaps come up with your own technique to read both sets and merge the results somehow which is obviously not so straightforward due to truncated variables names.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.