mpe/ix command file tips and techniques by jack bailie
TRANSCRIPT
MPE/iX Command FileMPE/iX Command FileTips and TechniquesTips and Techniques
by Jack Bailieby Jack Bailie
MPE/iX Command File Tips MPE/iX Command File Tips and Techniquesand Techniques
• Style
• Techniques
• Examples
• Parameters
• Predefined variables
• Help
• Functions
• Errors
• Debugging
StyleStyle
PARM fileset=@LISTFILE !fileset, DISC
• Meaningful parameter names
• Keywords and Commands in Upper Case
• Variables in lower case
• Blank lines
DocumentationDocumentation
PARM fileset=@COMMENT Title: LISTFILE a file setCOMMENT File: L.CMDCOMMENT By: J.D. BailieCOMMENT Rev: 3/12/91LISTFILE !fileset, DISC
• Comments to document command files
• Save command files in a special group (CMD)
HPPATHHPPATH
SETVAR HPPATH “CMD.CAPS,CMDD.CAPS,PUB,!!hpgroup,PUB.SYS”
• HPPATH is a system predefined variable
• Change the HPPATH in a logon UDC
• Order for searching :– CMD.CAPS– CMDD.CAPS– Account PUB– Current group– PUB.SYS
ParametersParameters
PARM fileset=@PARM format=DISCLISTFILE !fileset, !format
• Put each parameter on a separate line
• Example use :
:L C@:L C@, 3:L FILESET=C@:L FORMAT=DETAIL, FILESET=@
ANYPARMANYPARM
PARM fileset=@ANYPARM format=DISC
LISTFILE !fileset, !format
• May only have one
• Must be the last parameter
• Reads everything else, including punctuation
• May have default value
:L C@, DETAIL;PASS
MPE HELPMPE HELP
:HELP L
USER DEFINED COMMAND FILE: L.CMD.CAPS
PARM fileset=@ANYPARM format=DISCLISTFILE !fileset, !format
• Shows the name of file
• Lists contents of file
• Can be very complex
• Not very useful to a user
USER DEFINED COMMAND FILE: L.CMD.CAPS
PARM fileset=@
ANYPARM format=DISC
LISTFILE !fileset, !format
MPE HELPMPE HELP
PARM fileset=@ANYPARM format=DISC
COMMENTCOMMENT L LISTFILE a filesetCOMMENTCOMMENT SyntaxCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT fileset The file[set] to LISTF; default @COMMENT format The LISTFILE format; default DISCCOMMENTLISTFILE !fileset,!format
• Use COMMENTs to describe command
MPE HELPMPE HELPUSER DEFINED COMMAND FILE: L.CMD.CAPS
PARM fileset=@ANYPARM format=DISCCOMMENTCOMMENT L LISTFILE a filesetCOMMENTCOMMENT SyntaxCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT fileset The file[set] to LISTF; default @COMMENT format The LISTFILE format; default DISCCOMMENTLISTFILE !fileset,!format
• Gives user information
• Still lists all commands
• Cluttered
USER DEFINED COMMAND FILE: L.CMD.CAPS
PARM fileset=@ANYPARM format=DISCCOMMENTCOMMENT L LISTFILE a filesetCOMMENTCOMMENT SyntaxCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT :L fileset [,format]COMMENTCOMMENT ParametersCOMMENT fileset The file[set] to LISTF; default @COMMENT format The LISTFILE format; default DISCCOMMENTLISTFILE !fileset,!format
ECHO HELPECHO HELP
PARM fileset=?ANYPARM format=DISCIF "!fileset" = "?" THENECHOECHO L LISTFILE a filesetECHOECHO SyntaxECHO :L fileset [,format]ECHOECHO ParametersECHO fileset The file[set] to LISTF; default @ECHO format The LISTFILE format; default DISCECHOELSELISTFILE !fileset, !formatENDIF Use
• ECHO command
• "?" default parameter
ECHO HELPECHO HELP
:L
L LISTFILE a filesetSyntax:L fileset [,format]Parametersfileset The file[set] to LISTF; default @format The LISTFILE format; default DISC
• Clearer yet
• Only information the user needs
L LISTFILE a fileset
Syntax:L fileset [,format]
Parametersfileset The file[set] to LISTF; default @format The LISTFILE format; default DISC
Fancier ECHO HELPFancier ECHO HELP
IF "!fileset" = "?" THENSETVAR S CHR(14)SETVAR B CHR(14)+':'+CHR(15)ECHOECHO ![S+'R,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,T']ECHO ![B+' L LISTFILE a fileset '+B]ECHO ![S+'@9999999999999999999999999999999999999999999999999[']ECHO ![B+' Syntax '+B]ECHO ![B+' :L fileset [,format] '+B]ECHO ![B+' '+B]ECHO ![B+' Parameters '+B]ECHO ![B+' fileset The file[set] name to LISTF, @ '+B]ECHO ![B+' format The LISTFILE format; DISC '+B]ECHO ![S+'F,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,G']DELETEVAR S,BELSELISTFILE !fileset,!formatENDIF
• Use line drawing characters
Fancier ECHO HELPFancier ECHO HELP
:L
L LISTFILE a filesetSyntax:L fileset [,format]Parametersfileset The file[set] name to LISTF; @format The LISTFILE format; DISC
• Help information is outlined
L LISTFILE a fileset
Syntax
:L fileset [,format]
Parameters
fileset The file[set] name to LISTF; @
format The LISTFILE format; DISC
VARIABLESVARIABLES
PARM file
SETVAR _find_creator FINFO('!file','CREATOR')
LISTFILE !file, QUALIFYECHO Creator is !_find_creator
DELETEVAR _find_@
• Set variables
• Use unique names for variables
• Delete variables when done
FINFOFINFO
PARM file
SETVAR _find_creator FINFO('!file','CREATOR')
LISTFILE !file, QUALIFYECHO Creator is !_find_creator
DELETEVAR _find_@
• FINFO - find out 44 different things about a file, ie. EOF, Exists, Creator, Various Dates, Size,
• 1st argument of FINFO is Command file parameter
• Use option names with FINFO not numbers
Prompt for ParametersPrompt for Parameters
PARM file=' '
IF '!file' = ' ' THEN INPUT _find_file;PROMPT='Enter a file name ';WAIT=60ELSE SETVAR _find_file '!file'ENDIF
SETVAR _find_creator FINFO(_find_file,'CREATOR')LISTFILE !_find_file, QUALIFYECHO Creator is !_find_creator
DELETEVAR _find_@
• Prompt if parameter is not entered
• Alternative or in addition to help
• INPUT with WAIT
• 1st argument of FINFO is variable
INPUT from a fileINPUT from a file
PARM file
SETVAR _find_creator FINFO('!file','CREATOR')
INPUT _find_line < !file
LISTFILE !file, QUALIFYECHO Creator is !_find_creatorECHO First line isECHO !_find_line
DELETEVAR _find_@
• INPUT Command reads only the first line of file
INPUT from message fileINPUT from message filePARM fileset
FILE FINDTEMP;MSGLISTFILE !fileset,QUALIFY > *FINDTEMPRESET FINDTEMP
WHILE (FINFO('FINDTEMP','EOF') > 0) DO INPUT _find_file < FINDTEMP SETVAR _find_file RTRIM(_find_file) SETVAR _find_creator FINFO(_find_file,'CREATOR') ECHO !_find_file !_find_creatorENDWHILE
DELETEVAR _find_@PURGE FINDTEMP,TEMP
• Write LISTF to a message file
• 1st argument of FINFO is the filename
• Read from message file, one line at a time
• Trim blanks from right end of input line
StyleStylePARM fileset
FILE FINDTEMP;MSGLISTFILE !fileset,QUALIFY > *FINDTEMPRESET FINDTEMP
WHILE (FINFO('FINDTEMP','EOF') > 0) DOINPUT _find_file < FINDTEMPSETVAR _find_file RTRIM(_find_file)SETVAR _find_creator FINFO(_find_file,'CREATOR')ECHO !_find_file !_find_creator
ENDWHILE
DELETEVAR _find_@PURGE FINDTEMP,TEMP
• Parenthesis around WHILE statement conditions
• Indent WHILE statement logic
• DO is optional
• Clean up after yourself
INPUT from a Flat FileINPUT from a Flat File
PARM fileset=@
LISTFILE !fileset,QUALIFY > FINDTEMP
XEQ FINDIT < FINDTEMP
PURGE FINDTEMP,TEMP
• LISTF to a flat file
• Execute another command file and give it the flat file as input
INPUT from a Flat FileINPUT from a Flat File
SETVAR _find_I 1SETVAR _find_eof FINFO('FINDTEMP','EOF')
WHILE (_find_i <= _find_eof) DOSETVAR _find_file INPUT()SETVAR _find_file RTRIM(_find_file)SETVAR _find_creator FINFO(_find_file,'CREATOR')ECHO !_find_file !_find_creatorSETVAR _find_i _find_i + 1
ENDWHILE
DELETEVAR _find_@
• Called from another command file
• No parameters
• Input from file created by the other command
• 3 times faster than message files
• Requires two command files
Entry PointsEntry PointsPARM fileset=@PARM entry=MAIN
IF ('!entry' = 'MAIN') THEN LISTFILE !fileset,QUALIFY > FINDTEMP XEQ FIND ENTRY='NOTMAIN' < FINDTEMP PURGE FINDTEMP,TEMPELSE SETVAR _find_i 1 SETVAR _find_eof FINFO('FINDTEMP','EOF') WHILE (_find_i <= _find_eof) DO SETVAR _find_file INPUT() SETVAR _find_file RTRIM(_find_file) SETVAR _find_creator FINFO(_find_file,'CREATOR') ECHO !_find_file !_find_creator SETVAR _find_i _find_i + 1 ENDWHILEENDIF
• Use an "ENTRY POINT" of the same file
• Do not need multiple command files
Handle Error ConditionsHandle Error Conditions
PARM fileset
LISTFILE !fileset,QUALIFY > FINDTEMPIF (FINFO('FINDTEMP','EXISTS')) THEN ... ...ELSE ECHO ECHO No files in the fileset !fileset ECHOENDIF
• Handle all possible conditions
• Test command files
Handle Error ConditionsHandle Error Conditions
PARM fileset
ERRCLEARLISTFILE !fileset,QUALIFY > FINDTEMP
IF (HPCIERR = 0) THEN......ELSE ECHO ECHO No files in the fileset !fileset ECHOENDIF
• Another way to handle errors
• ERRCLEAR zeros predefined error variables
Fancy Error MessagesFancy Error Messages
ECHOECHO ![CHR(27)+"&dB"] No files !fileset ![CHR(27)+"&d@"]ECHO
• ![CHR(27)+"&dB"] Turns on highlighting
• ![CHR(27)+"&d@"] Turns it off
Fancy Error MessagesFancy Error Messages
SETVAR ON CHR(27)+"&dB"SETVAR OFF CHR(27)+"&d@"
ECHOECHO !on No files in ![UPS("!fileset")] !offECHO
• SETVARs easier (shorter) to use and reuse
• ON Turns on highlighting
• OFF Turns off highlighting
• UPS upshifts the input
No files in [email protected]
Handle Error ConditionsHandle Error Conditions
DELETEVAR _find_@
• DELETEVAR with no VARS to delete
"NO MATCH FOUND FOR THIS VARIABLE SET"
Handle Error ConditionsHandle Error Conditions
DELETEVAR _find_@ > $NULL
• Redirect command output to $NULL
• No error message
Continuation LinesContinuation Lines
PARM what=" "
SETVAR _S_WHAT UPS("!what")
IF ("!_s_what" = " " & OR "!_s_what" = "S" & OR "!_s_what" = "J") THEN SHOWJOB JOB=@!_s_whatELSEIF ("!_s_what" = "M") THEN SHOWMEELSEIF ("!_s_what" = "O") THEN SPOOLF @;SHOWENDIF
• Continuation lines
• ELSEIF
• Multiple commands in a single command file
Purging FilesPurging Files
...PURGE !file...
• Error message if file does not exist
Purging FilesPurging Files
...SETVAR _find_savemsg HPMSGFENCESETVAR HPMSGFENCE 2
PURGE !file
SETVAR HPMSGFENCE _find_savmsg...
• No error message if file does not exist
• Suppresses all error messages
• If command is aborted it leaves messages off
Purging FilesPurging Files
...IF (FINFO("!file","EXISTS")) THEN PURGE !fileENDIF
• No error message if file does not exist
Purging FilesPurging Files
...PURGE !file > $NULL...
• Simpler
DebuggingDebugging
SETVAR HPCMDTRACE TRUE
• Can set it interactively
• Lists every command executed
• Be sure to turn it off
DebuggingDebugging
OPTION LIST
• Add to command file
• Lists commands executed
• Use LIST and NOLIST to list selected parts
DebuggingDebugging...PARM debug=0...
IF (!debug > 0) THEN SETVAR HPCMDTRACE TRUE SETVAR HPMSGFENCE 0ELSE...
IF !debug = 0 THEN PURGE FINDTEMP,TEMP > $NULLENDIF
• Add a debug parameter
• Reference it as a keyword parameter
:FIND C@, DEBUG=1
• Most users do not know it exists
• Skip file purge in debug mode
DocumentationDocumentation
• Command file to list descriptions of commands
• Keyword search feature
DESCR List files in a fileset with FSEDIT Descriptions
Syntax
:DESCR [fileset] [,find-string]
Parameters
fileset The HP fileset desired; default @.CMD
find-string A string to search for
DocumentationDocumentation:DESCR [email protected]
Files in the fileset [email protected] with FSEDIT Descriptions
A - ABORT Command fileACCTINFO - Formatted output of System Accounting StructureADDR - Print address labelsAJ - ABORTJOBAS - Alter spool file PRI to 12 so it will print...
• Descriptions are in the file User Label
• Enter descriptions with FSEDIT or GSCAN
The EndThe End
SETVAR Function in WHILESETVAR Function in WHILEPARM fileset=@PARM entry=MAIN
IF ('!entry' = 'MAIN') THEN LISTFILE !fileset,QUALIFY > FINDTEMP XEQ FIND ENTRY='NOTMAIN' < FINDTEMP PURGE FINDTEMP,TEMPELSE SETVAR _find_i 0 SETVAR _find_eof FINFO('FINDTEMP','EOF') WHILE (SETVAR(_find_i,_find_i+1) <= _find_eof) DO SETVAR _find_file INPUT() SETVAR _find_file RTRIM(_find_file) SETVAR _find_creator FINFO(_find_file,'CREATOR') ECHO !_find_file !_find_creator ENDWHILEENDIF
• Use SETVAR Function to increment index within the WHILE statement
FINFO Function in WHILEFINFO Function in WHILEPARM fileset=@PARM entry=MAINIF ('!entry' = 'MAIN') THENLISTFILE !fileset,QUALIFY > FINDTEMPXEQ FIND ENTRY='NOTMAIN' < FINDTEMPPURGE FINDTEMP,TEMPELSESETVAR _find_i 0WHILE SETVAR(_find_i,_find_i+1) <= FINFO('FINDTEMP','EOF')
SETVAR _find_file INPUT()SETVAR _find_file RTRIM(_find_file)SETVAR _find_creator FINFO(_find_file,'CREATOR')ECHO !_find_file !_find_creatorENDWHILEENDIF
• Use the FINFO in the WHILE statement too
• Shorter command files
• Not as easy to follow
• Has the command file name in it
Choose Your Own NameChoose Your Own Name
SETVAR _my_name "!-1"
• "! 1" gives the last command executed
• As 1st command in file it gives name of file
Choose Your Own NameChoose Your Own Name
SETVAR _my_name "!-1"SETVAR _my_name UPS(_my_name)IF POS("XEQ ",_my_name) > 0 THENSETVAR _my_name _my_name "XEQ "ENDIFSETVAR _my_name LTRIM(_my_name)IF POS(" ",_my_name) > 1 THENSETVAR _my_name LFT(_my_name,POS(" ",_my_name)-1)ENDIF
• Clean it up to use it
• Upshift
• Strip off "XEQ"
• Strip off leading blanks
• Strip off trailing parameters
Choose Your Own NameChoose Your Own Name
...IF ('!entry' = 'MAIN') THENLISTFILE !fileset,QUALIFY > FINDTEMPXEQ !_my_name, ENTRY="NOTMAIN" < FINDTEMPPURGE FINDTEMP,TEMPELSE...
• Substitute line in FIND command file
• Use it to call other entry point
• I'll call it FIND
• You can call it WHEREIS
Choose Your Own NameChoose Your Own Name
...ECHO !_my_name LISTF a fileset with Creators name...
• Can even use it in help
System Message SpacingSystem Message Spacing
CHKDAT.COMMAND.CSLXLSHOWDEV !ldev > CKTEMP...SETVAR _chkdat_avail STR(_chkdat_ckin,11,1)SETVAR _chkdat_vol STR(_chkdat_ckin,43,1)SETVAR _chkdat_den STR(_chkdat_ckin,57,1)IF _chkdat_avail = "A" AND _chkdat_vol ="(" AND &( _chkdat_den = "1" OR _chkdat_den = "6") THEN
• Depends on spacing in SHOWDEV command
• Changed from 3.1 to 4.0
• Expect changes with 5.0
DocumentationDocumentationPARM fileset="@.CMD", find =" ", entry=MAINIF "!fileset" = "?" thenSETVAR S,CHR(14)SETVAR B CHR(14)+':'+CHR(15)ECHO ![S+'R,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,T'],ECHO ![B+' DESCR List files in a fileset with FSEDIT Description'+B]ECHO ![S+'@9999999999999999999999999999999999999999999999999999999999[']ECHO ![B+' '+B]ECHO ![B+' Syntax '+B]ECHO ![B+' :DESCR fileset [,find_string] '+B]ECHO ![B+' '+B]ECHO ![B+' Parameters '+B]ECHO ![B+' fileset The fileset to look at; default @.CMD '+B]ECHO ![B+' find_string a string to search for '+B]ECHO ![B+' '+B]ECHO ![S+'F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;G']DELETEVAR S,BRETURNENDIFIF '!entry' = 'MAIN' THENERRCLEARSETVAR _descr_find '!find'LISTFILE !fileset,QUALIFY > DESCRTMPSETVAR _descr_i 0IF HPCIERR = 0 THENSETVAR _descr_eof FINFO('DESCRTMP','EOF')ECHO Files in the fileset !fileset with FSEDIT DescriptionsECHOXEQ DESCR ENTRY='NOTMAIN' < DESCRTMPELSEECHO File !fileset NOT foundENDIFPURGE DESCRTMP,TEMPDELETEVAR _descr_@ELSEDocumentationWHILE SETVAR(_descr_i,_descr_i+1) <=_descr_eof DOSETVAR _descr_file INPUT()COMMENT Does it have User Labels Written?IF FINFO(_descr_file,10) > 0 THENCOMMENT Yes, read the fisrt user labelSETVAR _descr_file_descr RHT(FINFO(_descr_file,25),64)IF LFT(_descr_file_descr,1) < " " OR &LFT(_descr_file_descr,1) >= "}" THENSETVAR _descr_file_descr RPT(".",64)ENDIFSETVAR _descr_len 9-POS(".",_descr_file)SETVAR _descr_file_descr RTRIM(_descr_file)+ &RPT(" ",_descr_len)+" "+_descr_file_descrIF _descr_find <> " " THENIF POS(UPS(_descr_find),UPS(_descr_file_descr)) <> 0 THENECHO !_descr_file_descrENDIFELSEECHO !_descr_file_descrENDIFENDIFENDWHILEENDIF
Further ResearchFurther Research
@.COMMAND.CSLXLAUTOPAT.PATCHXL.TELESUPTREELIST.PUBXL.TELESUPMKACCT.PUB.SYS
• Lots of examples
• Very complex
• AUTOPAT stores STREAM file data in bottom of file
• MKACCT uses MKMSGS.MPEXL for messages
ReferencesReferencesMPE XL Commands Reference Manual 32650-90003CI Access and Variables Programmers Guide 32650-90011
INTERACT Page Title / AuthorNov 88 44 New Features of MPE XL User Interface Thomas Shem & Jeff VanceSept 89 26 Life of an MPE XL Command Scott Cressler & Jeff VanceMar 90 96 Programming with MPE XL Heikki TsakinenFeb 91 83 Advanced CI Programming, The 2.1 Story Scott Cressler, Jeff Vance, Steve ElmerSept 91 86 MPE XL Command Files Fred Ochs, Jr.Nov 92 26 Creating Command Files Rene MartinezNov 92 78 What the Manuals Don't Say John Dunlop