|
VisualPQL | VisualPQL Programs and Routines |
RETRIEVAL
, PROGRAM
,
SUBROUTINE
, or
FORM
.
Retrievals and programs are main routines and a retrieval is allowed to access SIR/XS databases whereas a program is not.
Subroutines are independently compiled VisualPQL routines that are invoked with the EXECUTE SUBROUTINE
command from other routines including other subroutines. Subroutines can RETURN
to higher level routines.
PQLForms have a different structure because they contain predefined logic see PQLForms
.
VisualPQL procedures can only be included in a main routine. Retrievals, programs and sub-routines use the
PERFORM PROCS
command to
put data into the procedure table.
The general structure of main routines is:
RETRIEVAL or PROGRAM command .....pql commands .....pql commands EXECUTE SUBROUTINE ......pql commands PERFORM PROCS ......pql commands PROCEDURE ..... PROCEDURE ..... ...... END RETRIEVALThe general structure for a subroutine is:
SUBROUTINE .....pql commands .....pql commands EXECUTE SUBROUTINE ......pql commands ......pql commands RETURN END SUBROUTINE
{RETRIEVAL | PROGRAM | SUBROUTINE name [(input_list)] } [ CIRLOCK [=] lock_value] [ CRWARN | NOCRWARN] [ DEBUG [= name]] [ ENDMSG | NOENDMSG] [ EXECUTE | NOEXECUTE] [ GET = memb_name:E] [ LIBRARY = (family list)] [ LOADING = num_lt_one] [ LOADMAP] [ LOCK [=] lock_value] [ MISSCHAR = char] [ NOARRAYMSG] [ NOTFCHK ] [ NOAUTOCASE] [ PROGRESS] [ RECLOCK [=] lock_value ] [ RETURNING (list)] [ SAVE = memb_name:E [REPLACE][PUBLIC][ PROCS | NOPROCS ]] [ SEED = num ] [ SHOWMISS ] [ STATIC | DYNAMIC ] [ SUMFILE = fileid ] [ TABFILE = tabfile_name] [ TUPDATE [(list of tabfiles)]] [ UPDATE ] [ UPSTAT | NOUPSTAT ] [ NODATABASE] [ NOTUPDLOG] [ VARMAP | NOVARMAP]There are no required options on
RETRIEVAL
or PROGRAM
.
The subroutine name is required on SUBROUTINE
and is the name of the compiled subroutine. The name of the subroutine can be qualified with procedure file and family prefixes and passwords.
RETRIEVAL
specifies the beginning of a main routine that accesses the default database. A retrieval opens the database files for read operations unless the UPDATE
option is specified to open the database for write operations. All commands and procedures may be used in a retrieval. A retrieval is terminated with the END RETRIEVAL
command.
PROGRAM
specifies the beginning of a main routine that does not access database data. A program can use exactly the same features as a retrieval, except for the commands that access database data. A program can access data in tabfiles and in external files. A program is terminated with the END PROGRAM
command.
SUBROUTINE
specifies the beginning of a subroutine that is invoked by other routines. All of the commands may be used in a subroutine but VisualPQL procedures cannot be specified. A subroutine can access data in databases, tabfiles and in external files. The code in a subroutine is logically separate from any other routine. A subroutine is terminated with the END SUBROUTINE
command. The RETURN
command explicitly returns control from a subroutine to the higher level routine. If a subroutine does not explicitly RETURN
, control is passed back at the end of the routine. Subroutines may invoke other subroutines and may invoke themselves recursively.
(input list)
|
A subroutine may have input parameters. These are positional parameters corresponding to the EXECUTE SUBROUTINE list of parameters. The parameters are read-only and are local variables in the subroutine. These variables must be defined explicitly within the subroutine.
|
CIRLOCK
|
Sets the default lock type for concurrent operations for un-nested PROCESS CASE and CASE IS statements that do not explicitly specify locks. Nested CASE blocks inherit the lock type of the outer CASE block. The default lock type is exclusive (CIRLOCK = 6 ). (See Accessing the Database.)
|
CRWARN | NOCRWARN
|
Causes a warning message for any variable that is created implicitly. The default is NOCRWARN .
|
DEBUG
|
Stores information needed for the VisualPQL Debuggers with the compiled code. This includes the text of the program, pointers from the compiled code to the text line and the variable name table. The debug information is stored as a member subroutine with a default name of SYSTEM.DEBUG:O .
This information can be stored elsewhere by specifying a member name on the DEBUG clause:DEBUG [=membername]
|
ENDMSG | NOENDMSG
|
The default ENDMSG specifies that an 'END ASSUMED' warning message is issued for any implicit 'end of block' conditions. (See Block Structures.) NOENDMSG keyword suppresses warning message. You are advised NOT to specify NOENDMSG , as it can mask other problems in your program.
|
EXECUTE | NOEXECUTE
|
The default is EXECUTE , the routine begins execution when compilation is completed. NOEXECUTE compiles but does not execute the routine.
|
GET |
Loads and executes the executable member. Additional VisualPQL procedures can be specified for executable routines. For Example:
RETRIEVAL GET = WEEKLY.SALES REPORT FILENAME = 'SALES.REP' / PRINT = NAME REGION NUMSALES TOTSALES END REPORT |
LIBRARY
|
Specifies a list of families that are searched when loading subroutines when the family name is not specified. The search for subroutines with unspecified family names begins in the default directory and proceeds through the list in the specified order. If the named member exists in more than one family, the first one found is used. For example:
RETRIEVAL LIBRARY=(STATSUBS PRNTSUBS TESTSUBS ) |
LOADING
|
Specifies the loading factor used during a database update. The number is a percentage, expressed as a decimal number (e.g., .15 is 15%).
|
LOADMAP
|
Specifies that a description (map) of routines loaded prior to execution is produced.
|
LOCK
|
Defines the lock value for both CIR and records for concurrent operations. Use in place of defining both CIRLOCK and RECLOCK when these have the same value.
|
MISSCHAR
|
Specifies the character used when printing missing values. The default is asterisk (*). For example, to specify that a question mark is printed when the value of a variable is missing.
RETRIEVAL MISSCHAR = ?To specify that a blank is used, specify: RETRIEVAL MISSCHAR = /Note: that the slash is necessary here to indicate a blank. |
NOARRAYMSG
|
Suppresses the output of warning messages normally produced at compile time by references to array subscripts that do not correspond to the array definition. Specify when using REDEFINE ARRAY and references are expected that do not match the initial definition.
|
NOTFCHK
|
Changes the run time error 726 'Mismatch between tabfile used at execution & compile time' from a serious error which stops execution to a warning which allows execution to continue. This error occurs when the date/time on a tabfile used for compilation does not match the date/time on the tabfile opened at execution time.
|
NOAUTOCASE
|
In RETRIEVAL routines, this suppresses the generation of a PROCESS CASE command. If this is not specified, a PROCESS CASE is generated before the first executable command in the retrieval. If another case block is found later, the automatic one is removed. The compiler interprets all commands between the automatic PROCESS CASE and the first real case block as if they happened inside a case block.NOAUTOCASE suppresses generation of an automatic PROCESS CASE command in a retrieval.
|
NODATABASE
|
When compiling a subroutine, the compiler assumes that the database is accessed and the subroutine is referenced from a RETRIEVAL . The NODATABASE keyword specifies subroutines that may be used by a PROGRAM .
|
PROGRESS |
When a retrieval is running, gives a visual indication of progress so far through the database. The system keeps track of progress by any PROCESS command. It takes the total number of cases or record type and increments a percentage as appropriate. This means that the displayed percentage may fluctuate when these commands are nested but a general indication of progress still applies.
|
RECLOCK
|
Sets the default lock type for PROCESS REC and RECORD IS statements that do not explicitly specify locks for concurrent operations. The default record lock is exclusive ( RECLOCK = 6 ).
|
RETURNING ( list )
|
A SUBROUTINE can return values to the EXECUTE SUBROUTINE command. At the time the subroutine returns control, these output variables are mapped positionally to the RETURNING ( list ) variables on the EXECUTE SUBROUTINE command. These variables must be defined explicitly within the subroutine and cannot be the same variables input to the subroutine.
|
SAVE
|
Saves an executable (compiled) version of the program as a member. Using stored executables saves the overhead of repeated compilations. The member saved with this keyword is given a ':E', for 'executable', suffix. For example:
RETRIEVAL SAVE = WEEKLY.SALES:E |
PROCS | NOPROCS
|
Used with SAVE . PROCS is the default and specifies that any procedures (e.g. REPORT, SAS SAVE FILE , etc.) are saved along with the executable program. SIR SAVE FILE and WRITE RECORDS procedures cannot be saved. NOPROCS specifies that the procedure specifications are not saved as part of the stored executable. This allows you to save an executable version of a program that builds a procedure table and to specify the procedures at run time. See the GET option. The following example stores an executable retrieval without the procedures.
RETRIEVAL SAVE = WEEKLY.SALES:E NOPROCS NOEXECUTE |
PUBLIC
|
Used with SAVE . Specifies that anyone may execute the saved member, but only those with family or member passwords may alter it. The following example saves an executable program as a member protected with passwords and makes it publicly available.
PROGRAM SAVE = APPLIC/MOON.MENUSYS:E/STARS PUBLIC |
REPLACE
|
Used with SAVE and with SUBROUTINES (that are saved by default). Specifies that the member being saved replaces a member of the same name if it exists.
PROGRAM SAVE = WEEKLY.SALES:E REPLACE |
SEED
|
SEED defines the seed value used by the random number generator for any sampling done by procedures, for any sampling done by PROCESS CASE or PROCESS ROW commands that do not specify a seed and for the RAND function if this does not reset the seed.This value is not saved on any saved executable. If you wish to use a non-standard seed, specify it on the command you use to execute the saved program or retrieval.
The random number generator is initialised at the start of the execution and any sampling that generates a call or calls to it by the |
SHOWMISS
|
SHOWMISS specifies that a variable's original missing values are used when printing missing values. The default is asterisk (*) or the character specified by MISSCHAR.
|
STATIC | DYNAMIC
|
STATIC is the default subroutine loading mode. If static, then subroutines are loaded when the main routine is first executed and remain in memory. If local variables are altered in a statically loaded subroutine, the values are preserved from one invocation to the next.DYNAMIC specifies that subroutines are loaded each time they are executed and are unloaded when their execution completes.
Note that this keyword applies to the default subroutine loading mode of the main routine. This can be overridden by the
|
SUMFILE
|
Specifies the file where any database and tabfile update logs are written. (Specify UPSTAT to produce update logs.) If SUMFILE is not specified, any update logs are written to the standard output. SUMFILE affects only the update logs, other output is not affected.
|
TABFILE
|
Specifies the default tabfile used on any SAVE TABLE procedures.
|
TUPDATE
|
Specifies tabfiles opened in WRITE mode for update by the program. If this parameter is specified without any tabfile names, all referenced tabfiles are available for write (update). If specific tabfiles are listed, only those tabfiles are made available for update and any tabfile not in this list is opened as read only. |
UPDATE
|
Specifies that the database is attached for write (update). This keyword must be used to add, modify or delete from the default database. If the routine uses multiple databases, the DATABASE IS command specifies the update status for each database.
|
UPSTAT
|
Specifies that an update log is produced for database or tabfiles that are updated. NOUPSTAT is the default. |
NOTUPDLOG
|
Suppresses the tabfile part of the update log produced when UPSTAT is specified.
|
NOUPDLOG
|
Suppresses the database part of the update log produced when UPSTAT is specified. |
VARMAP | NOVARMAP
|
VARMAP specifies that the program variables are listed after compilation. The listing includes the routine name (main, subroutine or variable block name), variable names and data type.Proc Var indicates that this variable is included in a summary table (see PERFORM PROCS ).The VARMAP listing indicates variables explicitly declared before the first executable command. These variables are not affected by the AUTOSET command.
|
END RETRIEVAL | END PROGRAM | END SUBROUTINEIndicates the end of a particular routine. These commands are synonyms so it is not strictly necessary to match the routine type and the type of
END
command, although it is good practice.
If the isn't an explicit END
command, the end of a routine is indicated by the end of the input source or an END TASK
or a new task indicated by a TASK NAME
command or the start of another retrieval, program or subroutine.
EXECUTE DBMS string_expSuspends execution of this program and executes the specified SIR/XS command. This may call sets of commands and execute other programs or retrievals. When the input has finished processing, control is returned to this program at the following command.
Cannot be used inside a block that is accessing a database or tabfile e.g. a CASE
, RECORD
or ROW
block but can be used in a PQLForms screen.
..... EXECUTE DBMS 'RUN MYPROGS.REPORT' COMPUTE COMSTR = 'RUN MYPROGS.REPORT' EXECUTE DBMS COMSTR FBUTTON ACTION (EXECUTE DBMS 'RUN MYPROGS.REPORT') PROMPT 'Run Report'
EXECUTE SUBROUTINE { member_name | mem_name_exp_in_brackets } [ ( list of expressions) ] [ RETURNING ( list of variables ) ] [ STATIC | DYNAMIC ]Executes the specified previously compiled subroutine, loading it if necessary. Specify either the explicit subroutine name or the name of a variable in square brackets that contains the subroutine name, for example:
EXECUTE SUBROUTINE [ SUBNAME ]Specify an optional list of values to pass to the subroutine. This list may contain constants and expressions including variables. Variables referenced in this list must be defined in the calling routine. While individual array elements may be referenced and passed in this manner, a whole array cannot be passed to a subroutine. To pass a whole array, declare it as an external variable.
A subroutine may be executed at any point within another routine. Recursive executions are allowed and each copy maintains separate local subroutine variables.
PERFORM PROCSThe
PERFORM PROCS
command builds a set of data for the VisualPQL Procedures. A VisualPQL program that specifies one or more VisualPQL Procedures consists of two parts. The first part of the program retrieves data and puts it into the Procedure Table using the PERFORM PROCS
command. The second part consists of the procedure specifications and executes after the first part has completed. Each procedure specifies how the data in the procedure table is output.
The procedure contains a set of data records. Each record in the table is made up of the procedure variables and contains a value for each variable. By default, the procedure variables are all the program variables in the main routine. The procedure variables can be specified with the DEFINE PROCEDURE VARIABLES
command.
Each time a PERFORM PROCS
command is executed a record with the current values of the procedure variables is added to the procedure table. A PERFORM PROCS
command can appear in both the main routine and in subroutines. If a VisualPQL Procedure is specified and the PERFORM PROCS
command is omitted from the main routine, a compilation error occurs.
PQL ESCAPE string_exp [WAIT num_exp] [MINIMISE|MINIMIZE num_exp] [RETURNING num_var]Stops execution of this program and creates a sub-process that executes the operating system command specified in the string expression. The string expression is required and must immediately follow the command.
Specify the WAIT
keyword followed by a numeric expression to control waiting for the sub-process to complete. If the expression is missing or resolves to a positive value, VisualPQL processing waits for the sub-process to complete; if the expression resolves to zero or a negative value, the VisualPQL processing continues without waiting.
Specify the keyword MINIMISE
(optionally MINIMIZE
) followed by a numeric expression to control visibility of the sub-process. If the expression resolves to a positive value, the sub-process runs minimised; If the expression is missing or resolves to zero or a negative value, the sub-process runs visibly. Note that if the sub-process is minimised and waits for completion, the SIR window is not refreshed until processing continues.
Specify the RETURNING
keyword followed by a numeric variable name to get a return code. If the sub-process runs without waiting, zero is returned; if the sub-process fails to start, -1 is returned. Otherwise the termination status of the sub-process is returned (normally zero equates to success).
By default (no keywords), the command runs visibly and waits for the sub-process to complete before returning.
PQL EXIT DBMSTerminates the SIR/XS session. Use this command to exit completely without requiring further action from the user.
RETURN [ NLEVELS n | TO subroutine_name]Exits the current subroutine and is only allowed within a subroutine. Execution control is passed to the first statement following the
EXECUTE SUBROUTINE
command that called the current subroutine.If execution reaches the end of the subroutine, control is returned automatically.
If NLEVELS
is specified, the return goes back through n levels of sub-routine calls; if TO
is specified the return goes back to the named subroutine. Warning: Using either the NLEVELS
or TO
options means that the subroutine is not independent and relies on knowledge as to how it is called and so these are not recommended practices.