Presentation is loading. Please wait.

Presentation is loading. Please wait.

Variables, Variables, Everywhere

Similar presentations


Presentation on theme: "Variables, Variables, Everywhere"— Presentation transcript:

1 Variables, Variables, Everywhere
Walter F. Blood Director of Product Management

2 Agenda Variables – A Quick Review Variables in Reports
Variables in Procedures Variables in Masters

3 A Quick Review

4 Two types of Variable Classes of variables The Basics
Local - &xxx - scope limited to procedure Named - &ABC Positional - &1 – passed in order from invocation Global - &&xxx - scope expanded to session Value retained from procedure to procedure Classes of variables System – value supplied by system Statistical – generated by WebFOCUS during processing Special -- variables for interactive use including &ECHO

5 Classes of Variables System Variables always available &APPROOT &DATE
&DATEfmt &DATXfmt &DMY/&DMYY &FOCCODEPAGE &FOCEXURL &FOCFEXNAME &FOCFOCEXEC &FOCINCLUDE &FOCMODE &FOCNEXTPAGE &FOCQUALCHAR &ECHO &FOCHTMLURL &FOCREL &TOD &YMD/YYMD &RETCODE &SETFILE &AUTOINDEX &MDY/&MDYY

6 Statistical variables follow activity
Classes of Variables Statistical variables follow activity &BASEIO &FOCDISORG &INDEXIO &FOCERRNUM &LINES &READS &RECORDS &SORTIO

7 Characteristics The Basics All variables are strings of characters
Data treated as Alphanumeric All numeric treated as Integer Use SET DMPRECISION to add decimal precision Maximum number of variables – 1024 active Maximum length of variable – 32K Variable Name characters A to Z, a to z, numbers, and ‘_’ Named must start with alpha Numeric only name treated as positional

8 Information About Variables
Existence Test the existence of a variable with &variable.EXIST Returns 0 if variable does not exist – test with EQ Returns non-zero if variable exists – test with NE Length of data Retrieve length of data value in variable with &variable.LENGTH Returns 0 if the variable is not present

9 Information About Variables
Variable Data Type Test character of content with &variable.TYPE Numeric – TYPE = N Can the contents be converted to a floating point number? Integer is the norm – no decimal points Add decimal places with SET DMPRECISION SET DMPRECISION = OFF/number Calculation requires conversion to double precision Calculation result truncated without DMPRECISION Alpha – TYPE = A Undefined – TYPE=U

10 Information About Variables
Evaluate Variable Immediately Evaluate variable on demand with &variable.EVAL Used when variable may not be fully resolved Complex expression Variable used within quotes Automatic Single Quote Handling Automatic adjustment to handle single quotes in data with &variable.QUOTEDSTRING Useful to accommodate single quotes which must be doubled in order to be passed

11 Setting the variable to a given value
Basic Actions Setting the variable to a given value -SET – creates variable and assigns value Requires terminator - ; Can be set to Literal value, including null, alpha in quotes Another variable Arithmetic, alphanumeric, logical, or compound expressions -READ <ddname &xxx.A5 &yyy.I3 Load variable by reading file physically – position DDNAME must be FILEDEFd or ALLOCATEd All space must be accounted for Use for Fixed or Comma-delimited files

12 Setting the variable to a given value
Basic Actions Setting the variable to a given value -DEFAULT and -DEFAULTH Creates default value for use if none is –SET -DEFAULTH hides value on AUTOPROMPT/PROMPT Cannot be set to expression -READFILE <filename> Uses Master file to read the file Assigns data values to &FIELDNAME

13 Working with variables
Basic Actions Working with variables EX procedure ABC= value1, value2, &DEF=value3 Key/value pair ABC assigned to &ABC &DEF assigned to &&DEF Value - assigned positionally - &2 Implicit prompting Unassigned variable forces prompting AUTOPROMPT with -WFDESCRIBE -PROMPT, -WINDOW, -CRTFORM Explicit methods to get value for variables from FOCUS

14 Prompting allows additional extensions
Basic Actions Prompting allows additional extensions &variable.format. – control format of data entered Type and length tested Incorrect entry – FOC291 error &variable.(text). – add text to display when prompting Use apostrophe if text contains parenthesis

15 Prompting allows additional extensions
Basic Actions Prompting allows additional extensions &variable.list. – list of acceptable values for prompt List - comma-delimited string Range of values – FROM a TO b Dynamic list – FIND field IN file &variable.VALIDATE Security – prevent injection Validate data received at runtime List, Range, FIND, REGEX

16 Variables in Reports

17 Self-service based upon user choice
Variables in Reports Self-service based upon user choice Create launch page to collect variable values Populate parameters passed with focexec Use values to generate report dynamically Allows you to add information Procedure information and variable description Headings and Footings Make use of default variable values

18 Variables in Reports- Auto-Prompting

19 Variables in Requests - Auto Prompting
All variables must have values before running Request scanned for variables Evaluated from –SET, -DEFAULT, -DEFAULTH Variables without values trigger prompting Variable ignored in prompting -SET variable Global variable - && -DEFAULTH variables (hidden) Special character handling ‘( ‘ - make sure there is space before it ‘&’ - to use this as a character use ‘&|’ -HTMLFORM BEGIN NOEVAL to suppress ‘&’ evaluation

20 Variables in Report - Selection
Static Single Select List of Values Dynamic Single Select List of Values WHERE STORENAME EQ ‘&STORENAME.(eMart,TV City, WebSales).’ WHERE STORENAME EQ ‘&STORENAME.(FIND STORENUM, STORENAME IN CENTORD). Store Name. ’

21 Variables in Selection
Static Multi-Select List of Values Dynamic Multi-Select List of Values WHERE STORENAME EQ ‘&STORENAME.(OR (eMart,TV City, WebSales).Store Name.’ WHERE STORENAME EQ ‘&STORENAME.(OR(FIND STORECODE, STORENAME IN CENTORD)). Store Name. ’

22 Variables in Selection
Special selection values FOC_ALL – Select All option WHERE -set to all values in multi-select list separated by OR /AND No selection _FOC_NULL – default value Can be reset in IBIF_describe_null variable Phrase or expression containing _FOC_NULL removed from request before run FOC_NONE – applies to non-DM line Line removed before request is run

23 Variables in Display or Sort – Static Single Select
Static Single Select List of Display fields Static Single Select List of BY fields Static Single Select List of ACROSS fields SUM &SumFlds.(<Sales,DOLLARS>,<Budget,BUDDOLLARS>, <Units,UNITS>).Sum. BY &SortBy.(<Category,GGSALES.SALES01.CATEGORY>, <PRODUCT>).By. ACROSS &Acrs.(<Area,REGION>,<State,ST>, <None,FOC_NONE>).Across.

24 Variables in Display or Sort – Static Multi-Select
Static Multi-Select list of display fields Static Multi-Select list of BY fields Static multi-select list of ACROSS fields SUM &SumFlds.(AND(<Sales,DOLLARS>,<Budget,BUDDOLLARS>, <Units,UNITS>)).Sum. BY &SortBy.(AND(<Category,GGSALES.SALES01.CATEGORY>, <PRODUCT>)).By. ACROSS &Acrs.(AND(<Area,REGION>,<State,ST>, <None,FOC_NONE>)).Across.

25 Variables in Display or Sort – Dynamic Single Select
Dynamic Single Select List of Display fields Dynamic Single Select List of BY fields Dynamic Single Select List of ACROSS fields SUM &SumFlds.(FIND NAME, FLDDESC IN GGDETFLD). Sum Field. BY &SortBy.(FIND NAME, FLDDESC IN GGBYFLD).By Field. ACROSS &Acrs.(FIND NAME, FLDDESC IN GGACRFLD).Across Field.

26 Variables in Display or Sort –Dynamic Multi-Select
Dynamic Multi- Select List of Display fields Dynamic Multi-Select List of BY fields Dynamic Multi-Select List of ACROSS fields SUM &SumFlds.(AND(FIND NAME, FLDDESC IN GGDETFLD)) .Sum Fields. BY &SortBy.(AND(FIND NAME, FLDDESC IN GGBYFLD)).By Fields. ACROSS &Acrs.(AND(FIND NAME, FLDDESC IN GGACRFLD)) .Across Fields.

27 Variables in Selection
Additional considerations What else can be parameterized in a report? Titles, Headings, SubHeads, SubFoots, Footings Calculations On retrieval with DEFINE On output with COMPUTE Variable values can also be created in HTML Javascript

28 Variables in Procedures

29 Variables in procedures
System Variables always available for testing or info &APPROOT &DATE &DATEfmt &DATXfmt &DMY/&DMYY &FOCCODEPAGE &FOCEXURL &FOCFEXNAME &FOCFOCEXEC &FOCINCLUDE &FOCMODE &FOCNEXTPAGE &FOCQUALCHAR &ECHO &FOCHTMLURL &FOCREL &TOD &YMD/YYMD &RETCODE &SETFILE &AUTOINDEX &MDY/&MDYY

30 Variables in procedures
Statistical variables available following activity &BASEIO &FOCDISORG &INDEXIO &FOCERRNUM &LINES &READS &RECORDS &SORTIO

31 Variables in procedures - Navigation
Calling other local procedures Use Global variables that last for the session EX <focexecname> <parm1> <parm2> Variables not evaluated in calling focexec Variables are passed as parameters Existing local variables are lost -INCLUDE <focexecname> Variables in –INCLUDE focexec are evaluated Existing local variables survive Code is added at parse time of calling focexec

32 Variables in procedures - Navigation
Calling other local procedures Use Global variables that last for the session EX <focexecname> <parm1> <parm2> Variables not evaluated in calling focexec Variables are passed as parameters Existing local variables are lost -INCLUDE <focexecname> Variables in –INCLUDE focexec are evaluated Existing local variables survive Code is added at parse time of calling focexec

33 Variables in procedures - Navigation
Calling procedures on other systems To send code to be run on another system surround code with -REMOTE BEGIN -REMOTE END To run a focexec on another system within remote block EXEC <focexecname> <parm1> <parm2> What to do with the output? ON TABLE HOLD leaves data and metadata on remote system ON TABLE PCHOLD retrieves data and metadata

34 Variables in procedures - navigation
Controlling the flow of the procedure Branch to perform an action – -GOTO – unconditional -- -IF ..GOTO ELSE …GOTO.. – conditional CREATE LOOKUP FILE LOOKUP FILE ? RUN REPORT NO YES -SET &A=‘ ‘; -READ LOOKUP &A.1. -IF &A NE ‘ ‘ THEN GOTO RUNREPORT ELSE GOTO CREATEREPORT ;

35 Variables in procedures - navigation
Controlling the flow of the procedure Storing multiple values for a single variable DONE LOOP MORE RECORDS? NO YES SET COUNTER READ RECORD -SET &A=‘ ‘; -SET &CTR=0; -LOOP -SET &CTR=&CTR + 1; -READ LOOKUP &A.&CTR.1. -IF &IORETURN NE 0 THEN GOTO DONE ELSE GOTO LOOP; -DONE

36 Variables in procedures - navigation
Controlling the flow of the procedure REPEAT process a variable number of times REPEAT label N TIMES REPEAT label FOR variable FROM x TO y STEP n DONE READ IORETURN NE 0? NO YES REPEAT WHILE WRITE -REPEAT DONE WHILE &IORETURN NE 0; -READ LOOKUP &A -WRITE OUTPUT NOCLOSE &A -DONE

37 Variables in procedures
Gathering data values Testing if variable value in file Using the master file to load field variables Place SET values in variables SET COUNTER -SET &A=&C IN FILE FILENAME; LOOP -READFILE CAR -TYPE COUNTRY IS &COUNTRY -TYPE CAR IS &CAR -CLOSE CAR MORE RECORDS? NO READ RECORD -? SET ASNAMES &ABC DONE YES

38 Variables in procedures
Displaying values in variables Local variables - list specific & variable Global variables – list all && variables SET COUNTER LOOP -? &ABC MORE RECORDS? NO ? && READ RECORD DONE YES

39 Variables in procedures -HTMLFORM
Passing information using HTMLFORM SET COUNTER -IF &OPTION.EXIST GOTO HRINFO ELSE GOTO CANTRUN; -HRINFO TABLE FILE CENTHR . . . END -EXIT LOOP -CANTRUN -HTMLFORM BEGIN <HTML> <BODY>TOTAL REPORT CAN'T BE RUN WITHOUT AN OPTION. TIME &TOD </BODY> </HTML> -HTMLFORM END -EXIT MORE RECORDS? NO READ RECORD DONE YES -READFILE CAR -TYPE COUNTRY IS &COUNTRY -TYPE CAR IS &CAR -TYPE MODEL IS &MODEL -CLOSE CAR

40 Variables in procedures
Variables in web pages Referring to variable value Referring to variable value length Variable in form input field Local variable !IBI.AMP.variablename; Global variable !IBI.GLB.variablename; Local variable !IBI.AML.variablename; Global variable !IBI.GLL.variablename; <INPUT TYPE=TEXT NAME=variable VALUE=“IBI.AMP.variable;”>

41 Variables in Master Files

42 Master File global variables
Global variables declared in Master files Global variables for use in requests based upon the Master Global variables for use in Master File profiles Global variables for attributes including TITLE DBA USERID and VALUE ACCESS file parameters – TABLENAME, CONNECTION VARIABLE NAME=[&&]var, USAGE=Aln, [DEFAULT=defvalue,] [QUOTED={OFF|ON},] $

43 Master File Profile MFD Profile opens new possibilities MFD Profile is standard focexec Run as soon as Master File is opened Contains any standard syntax Beware infinite loops – self referencing Possibilities Tailoring Field Titles by a condition Dynamic conditional creation of DBA or FILTER FILE Changing data location or allocation dynamically Dynamic alteration of request elements in Master Dynamic DECODE table generation FILE=name, SUFFIX=SQLMSS, MFD_PROFILE=profilename…,$

44 Master File – MFD Profile
MFD Profile characteristics Executed for commands TABLE, TABLEF, MATCH, GRAPH, CREATE, DEFINE, CHECK, ?F, and ?FF MATCH/MORE –executed in reverse order JOINed files – all MFD PROFILES are executed Variables will be subject to order of MFD PROFILES ! Ignored for MODIFY, MAINTAIN and READFILE Do not call the master the MFD PROFILE is in – infinite loop

45 Socialize to Win! Daily Prizes Awarded!
Tweet and tag #IBSummit during the event! in your #IBSummit pics! Check our Summit Facebook & LinkedIn pages for updates, photos, and announcements


Download ppt "Variables, Variables, Everywhere"

Similar presentations


Ads by Google