Lesson 1 Understanding Variables [ Using the 900 Series HP 3000: Advanced Skills Module 6: Variables and Expression ] MPE/iX 5.0 Documentation
Using the 900 Series HP 3000: Advanced Skills Module 6: Variables and Expression
Lesson 1 Understanding Variables
Introduction
Lesson 1 covers the following topics dealing with variables and how to
define them:
* how to create user-defined variables
* how to modify user-defined and some system-defined variables
* SETVAR
* SHOWVAR
* DELETEVAR
As you become more experienced, you will probably find yourself creating
more and more specialized user commands. In doing so, you will probably
find the use of variables invaluable. Variables are similar to the
parameters that you have already used in the past lessons. Throughout
the lessons in this module, you will learn how to use both system-defined
and user-defined variables in
your user commands.
Command files in this lesson
In this lesson, you will execute command files that use variables. The
tasks performed by the command files could also be performed by UDCs;
however, this would involve constantly uncataloging and recataloging UDC
files to add or modify UDCs.
The LF and the STATS command files will be used to illustrate various
aspects of variables and expressions. Also, the contents of each file
serve as good review for system-defined formal files, file equations, and
backreferencing.
NOTE Each of these command files could become a UDC in a UDC file if you
wished.
Don't expect to understand everything about the LF and STATS command
files
immediately. You'll be looking at the pieces that make up the files as
you progress through the lesson.
STATS command file:.
This command file lets you check the number of jobs on the system and
compare them to the current job limit.
If the number of jobs has approached the limit (anything over three less
than the job limit), the command file tells you not to stream the job.
ECHO *** CURRENT JOBS = !HPJOBCOUNT
ECHO *** CURRENT JOB LIMIT = !HPJOBLIMIT
IF HPJOBCOUNT<=HPJOBLIMIT-3
ECHO *** NUMBER OF JOBS IS STILL REASONABLE --- STREAM JOB NOW ***
ELSE
ECHO *** APPROACHING JOB LIMIT --- STREAM JOB LATER ***
ENDIF
LF command file:.
This command file lets you list the names and characteristics of all
files in a specified group and account, using LISTFILE,1 or LISTFILE,2 or
LISTFILE,3 commands.
SETVAR FILENAME,"//"
SETVAR RESPONSE,"N"
SETVAR OPTION,"1"
INPUT RESPONSE;PROMPT="DO YOU WISH TO LIST ANY FILE(S)? (Y OR N): "
WHILE RESPONSE='Y' DO
INPUT FILENAME;PROMPT="ENTER FILE.GROUP.ACCT (@ ALLOWED,// TO END): "
IF FILENAME <> '//' THEN
INPUT OPTION;PROMPT="ENTER LISTFILE OPTION (1,2,3): "
LISTFILE !FILENAME,!OPTION
ELSE
SETVAR RESPONSE,'N'
ENDIF
ENDWHILE
DELETEVAR FILENAME,RESPONSE,OPTION
Assigning and displaying variable values
Now that you have had a chance to look at the command files, you'll be
examining the variables within them. An MPE/iX variable is just like a
programming variable. It is a placeholder that appears in command
syntax. When the actual command is entered, a value is specified to
replace the placeholder.
To define (create) a variable, only a
SETVAR statement is required:
SETVAR var_name,var_value
To display the variable value, all that is required is a SHOWVAR
statement:
SHOWVAR var_name
NOTE There are other ways to display a variable's value, but the SHOWVAR
command suffices for this lesson.
NOTE For Programmers
Unlike a programming variable, an MPE/iX variable is declared and
assigned a value in one step. No type statement is required, since
the variable type is automatically defined when the value is
assigned. An exception to this rule is that any variable used with
the INPUT command is considered type string, regardless of the
value that it contains.
To demonstrate the ease of assigning and displaying values, enter the
following statements:
x = your user number
SETVAR USER,"USERx"
SETVAR GROUP,"CLASS"
SETVAR ACCT,"ACCTx"
SHOWVAR USER,GROUP,ACCT
You should see the following:
USER = USERx
GROUP = CLASS
ACCT = ACCTx
NOTE Either single or double quotation marks may be used. In special
cases, you must use double quotes. For example, you may wish to
use a single quotation mark within a character string:
SETVAR WHEN,"The meeting's at 8:00"
Also, the variable name and value hmay be separated by a space or a
comma:
SETVAR WHEN,"The meeting's at 8:00"
or
SETVAR WHEN "The meeting's at 8:00"
Here are some simple examples of assigning variable values in the command
files:
The STATS command file makes reference to a variable called HPJOBLIMIT.
The value of this variable is the number of jobs (job limit) that can run
at one time. This is the same value that you see as JLIMIT when you do a
SHOWJOB. This is a system-defined variable which happens to be read only.
Its initial value is set by the LIMIT command.
This value can be changed only by the operator or system manager at the
system console.
The LF command file creates and references several variables, one of
which is RESPONSE. It is a user-defined variable that refers to an answer
that the user must make to a specific prompt. Near the end of the file,
it is automatically set to N (No):
SETVAR RESPONSE "N"
NOTE Notice also, that three of the variables are assigned initial
values at the beginning of the file, just in case the variables
already exist and have some other values. This is a good
programming practice.
Text values for variables require quotation marks around them;
integer values require that you do not use quotation marks.
Variable names
Regardless of how it is defined, a variable must have a name that follows
standard naming conventions:
* begin with an alpha character or an underscore (_)
* may contain 1 to 255 alphanumeric characters (including an
underscore)
Examples of valid names are:
PACIFIC_TIME
A
_007
NUM_array
employee1
HPSESLIMIT
HPJOBCOUNT
Examples of invalid names are:
#$%&
MAX#
ERROR_#
error flag
123
If you look in the two command files, you will see these variables:
STATS file: LF file:
HPJOBLIMIT RESPONSE
HPJOBCOUNT FILENAME
OPTION
--------------------------------------------------------------------------------------------
| |
| Q6-1 Which of the following are acceptable names for variables? |
| |
| |
| a. $DOLLARS |
| |
| b. CIERROR |
| |
| c. FRED_FLINTSTONE |
| |
| d. HPINPRI |
| |
| e. RINGO* |
| |
| f. _JAMES_BOND |
| |
| g. VARIABLE-1 |
| |
--------------------------------------------------------------------------------------------
Variable types
The value assigned to the variable determines the variable type, as
follows:
* string value is a sequence of characters or digits surrounded by
quotation marks.
Example:
SETVAR MOVIE "FANTASIA"
SETVAR DATE,"1988"
* integer value is a sequence of digits preceded by +, -, $, %, or
nothing.
Example:
SETVAR TEMP,-20
SETVAR STOCK_DIF,+30
SETVAR SALARY,100000
* hexadecimal integers are preceded by $.
Example:
SETVAR DEGREES_F,$D4
* octal integers are preceded by %.
Example:
SETVAR FLAVORS,%37
_________________________________________________________________
NOTE Variables cannot have real number values. For example,
100000 is an acceptable value for the SALARY variable
because it is an integer value. 100000.00 is not an
acceptable value for the SALARY variable because it is a
real value. Decimal points are not allowed in any numeric
variable value.
_________________________________________________________________
* boolean value is TRUE or FALSE.
Example:
SETVAR RESPONSE,TRUE
--------------------------------------------------------------------------------------------
| |
| Q6-2 According to the values assigned them (by the user or the system), what are |
| the types of the following variables? |
| |
| HPJOBLIMIT (number of jobs allowed to run): |
| |
| HPJOBCOUNT (number of jobs currently running): |
| |
| RESPONSE (user response - either Y or N): |
| |
| FILENAME (user-supplied file name): |
| |
--------------------------------------------------------------------------------------------
There are two classes of variables:
* System-defined variables are generally used to store
system-assigned information. (These are used in the STATS command
file. All but two of them begin with the letters "HP".)
* User-defined variables are generally used to store user-assigned
information. (These are used in the LF command file.)
The variables in both classes can be of any of the three types mentioned
earlier.
System-defined variables
System-defined variables are variables whose names are predefined by the
system, following the standard naming conventions. In general,
system-defined variables are "read only," having values that are assigned
and modified only by the system or system manager. Their initial values
are set during system configuration and can be changed only at the system
console, using special commands.
Values of a few system-defined variables can be modified by a user for
that user's session.
Some of the more useful system-defined variables are shown below. A
comprehensive list appears in appendix A of the MPE/iX Commands Reference
Manual Volumes 1 and 2 (32650-90003 and 32650-90364), indicating whether
such a variable is read only (not modifiable) or read/write (modifiable).
The same information is available in the online Help facility. Enter
HELP VARIABLESReturn to see the information on system-defined variables.
Variable Read only? Read/Write?
HPJOBLIMIT YES NO
HPSESLIMIT YES NO
HPPROMPT NO YES
HPPATH NO YES
HPVERSION YES NO
HPUSER YES NO
HPSESCOUNT YES NO
--------------------------------------------------------------------------------------------
| |
| Q6-3 Use the Help facility to look up each of these variables. What do each of |
| these variables do? What are their current values? |
| |
| Hint: Use SHOWVAR to display the value of each. |
| |
| |
| HPJOBLIMIT = |
| |
| HPSESLIMIT = |
| |
| HPPROMPT = |
| |
| HPPATH = |
| |
| HPVERSION = |
| |
| HPUSER = |
| |
| HPSESCOUNT = |
| |
| Q6-4 How could you list all of the system-defined and user-defined variables? |
| |
| Hint: Use a "wildcard" character in the same manner that you did when |
| listing files or users/accounts/groups. |
| |
--------------------------------------------------------------------------------------------
To illustrate the use of SETVAR with a modifiable,
system-defined variable, please enter the commands as shown in this
example:
Example:
Suppose that that you want to change the prompt to "Hi There: ".
You can change the value of the system-defined variable, HPPROMPT, by
entering:
SETVAR HPPROMPT,"Hi There: "
Do this now. Press RETURN. You should see the new prompt. The new
prompt remains in effect until you log off. You modify it later.
Use the SHOWVAR command to verify the value of the current prompt:
SHOWVAR HPPROMPT
Use the SHOWVAR command again to determine your current capabilities:
SHOWVAR HPUSERCAPF
Your capabilities should be AM, IA, BA, ND, SF, and PH.
--------------------------------------------------------------------------------------------
| |
| Q6-5 What are the system-defined variables in the STATS command file? |
| |
| Q6-6 Are those variables user-modifiable? |
| |
--------------------------------------------------------------------------------------------
User-defined variables
User-defined variables are variables with names and values that the user
specifies. Once again, names must follow standard conventions. You can
read, modify, or delete any user-defined variable. User-defined
variables are session dependent. They are good only for the one user
during that one session. They remain as long as the user who created
them does not log off. They remain even if the user changes groups using
the CHGROUP command.
Enter this command:
CHGROUP PUB
What prompt do you get? Yes, it remains the same even when you change
groups.
NOTE You can also use CG to perform a CHGROUP. It is a UDC works as long
as MYUDC3 is one of your cataloged UDC files.
Return to the CLASS group:
CG CLASS
--------------------------------------------------------------------------------------------
| |
| Q6-7 In the LF command file, what are the three user-defined variables? |
| |
--------------------------------------------------------------------------------------------
Deleting variables
To delete any user-defined variable and its value, you need only issue
the DELETEVAR command:
DELETEVAR variable_name
You cannot, however, delete any system-defined variable. Its value may
be changed, but its definition remains the same.
To illustrate this, delete the variables that you defined earlier:
DELETEVAR USER,GROUP,ACCT
Now use SHOWVAR to verify that they are gone.
SHOWVAR USER,GROUP,ACCT
You should get error messages indicating that the variables do not exist.
Now try to do the same with these system-defined variables:
DELETEVAR HPPROMPT,HPJOBLIMIT,HPSESLIMIT
What message do you get?
_______________________________________
| |
| |
| VARIABLE IS NOT DELETABLE |
| |
_______________________________________
Exercise 6-1: variables.
1. Define a variable called MYPROMPT and assign it the value
currently stored in HPPROMPT.
2. Display the value of MYPROMPT.
3. Delete MYPROMPT. Verify that it is gone. Try to delete HPPROMPT.
Why can you delete MYPROMPT, but not HPPROMPT?
********** End of Exercise 6-1 **********
Lesson summary
1. System-defined variables have system-assigned names and values.
Some of them have values that can be modified by the system
manager. A few of them can be modified by the user.
2. User-defined variables have user-defined names and values.
3. SHOWVAR and SETVAR are used to display and assign variable names
and values.
4. DELETEVAR deletes a specified user-defined variable and its value.
MPE/iX 5.0 Documentation