You are on page 1of 15

Advanced File Techniques

Part 17

Presentation © Copyright 2008, Bryan Meyers, www.bmeyers.net


Using File Overrides

• Overrides enable minor runtime changes in


program function without recompiling
– Redirect file
• Specific library
• Different file name
• Specific member
– Change file attribute
• File open data path sharing
• Overrides are temporary
– Only affect job which issues override
OVRDBF Command

• OVRDBF (Override with Database File)


command affects database file
– Redirects program to another file
– Changes attributes of file used by program
OVRDBF FILE(overridden-file-name) +
TOFILE(library-name/database-file-name) +
MBR(member-name) +
POSITION(file-positioning-option) +
SECURE(secure-from-previous-overrides-option) +
SHARE(open-data-path-sharing-option) +
OVRSCOPE(override-scope)
OVRDBF Command
• OVRSCOPE parameter controls effective range of
override
– OVRSCOPE(*JOB) extends override to all programs
that will subsequently run in job
– OVRSCOPE(*CALLLVL) scopes override to current call
stack level and any new ones
– OVRSCOPE(*ACTGRPDFN) scopes override based on
program’s activation group
• Default
• ILE programs in ILE activation groups scope override to
activation group
• Others scope override to call stack level
DLTOVR Command

• DLTOVR (Delete Override) command removes


override(s)
– DLTOVR *ALL removes all overrides
– DLTOVR *PRTF removes printer file overrides
• LVL parameter controls scoping level to remove
– LVL(*) deletes override at current call stack level
– LVL(*JOB) delete job level override
– LVL(*ACTGRPDFN) is used with ILE programs
DLTOVR FILE(Myfile) LVL(*JOB)
OVRDBF Example
PGM PARM(&fromlib &tolib)
DCL &fromlib *CHAR 10
DCL &tolib *CHAR 10
DCL &eof *LGL Compiler uses QSYS/QADSPOBJ
DCLF QSYS/QADSPOBJ (Model outfile for DSPOBJD)
DSPOBJD OBJ(&fromlib/*ALL) OBJTYPE(*ALL) +
OUTPUT(*OUTFILE) OUTFILE(QTEMP/OBJECTS)
OVRDBF QADSPOBJ TOFILE(QTEMP/OBJECTS) Program processes QTEMP/OBJECTS
instead of QSYS/QADSPOBJ
DOUNTIL &eof
RCVF Read outfile record
MONMSG CPF0864 EXEC(DO) (OBJECTS)
CHGVAR &eof '1'
LEAVE End of file
ENDDO
IF (&odobtp = '*FILE') DO
MOVOBJ OBJ(&fromlib/&odobnm) OBJTYPE(&odobtp) TOLIB(&tolib)
ENDDO
ENDDO
Delete override when finished
DLTOVR QADSPOBJ
RETURN
ENDPGM
OVRPRTF Command

• OVRPRTF (Override with Printer File)


command adjusts printer file’s attributes
OVRPRTF FILE(file-override-name) +
TOFILE(library-name/printer-device-file-name) +
DEV(device-name) +
PAGESIZE(page-length +
page-width +
unit-of-measure) +
LPI(lines-per-inch) +
CPI(characters-per-inch) +
OVRFLW(overflow-line-number) +
OUTQ(library-name/output-queue-name) +
FORMTYPE(form-type) +
COPIES(number-of-copies) +
SCHEDULE(print-schedule) +
HOLD(hold-spooled-report) +
SAVE(save-spooled-report) +
SECURE(secure-from-previous-overrides-option) +
OVRSCOPE(override-scope)
Positioning Database Files

• File is normally positioned at beginning of file


at opened
– OVRDBF command may allow file open at another
record
OVRDBF Myfile POSITION(*START)
OVRDBF Myfile POSITION(*END)
OVRDBF Myfile POSITION(*RRN 501)
Positioning Database Files

• POSDBF (Position Database File) command


repositions already open file
– Previously opened with OPNDBF or OPNQRYF
POSDBF OPNID(Myfile) POSITION(*START)
POSDBF OPNID(Myfile) POSITION(*END)
Preopening Database Files

• Preopening files may improve application


performance
– All programs within same job can access
preopened files
– All programs share single open data path
PGM
OVRDBF FILE(MAILLIST) SHARE(*YES)
OPNDBF FILE(MAILLIST)
OVRDBF FILE(ZIPCODE) SHARE(*YES)
OPNDBF FILE(ZIPCODE)
CALL MAILMENU
CLOF OPNID(MAILLIST)
CLOF OPNID(ZIPCODE)
DLTOVR *ALL
RETURN
ENDPGM
OPNQRYF Command
• OPNQRYF (Open Query File) creates temporary
access path to a file
– Select subset of available records
– Reorder records
– Join records from different files into one data path
– Group records
– Calculate new fields
• CL cannot directly access OPNQRYF path
– Must be processed by high level language
– Requires shared open data path
OPNQRYF Command

• QRYSLT parameter selects records from file


– Syntax resembles SQL
• KEYFLD parameter sets order of records
OPNQRYF command:
OPNQRYF FILE(MAILLIST) +
QRYSLT('COUNTRY = "USA"') +
KEYFLD((ZIPCOD *DESCEND) (CARRTE))

SQL statement:
SELECT * FROM MAILLIST
WHERE COUNTRY = 'USA'
ORDER BY ZIPCOD DESCENDING, CARRTE
OPNQRYF Command
PGM PARM(&fromzip &tozip)
DCL &fromzip *CHAR 5
DCL &tozip *CHAR 5
DCL &qryslt *CHAR 2000

/* Build QRYSLT string: */


/* 'ZIPCOD = %RANGE("xxxxx" "xxxxx")' */
/* or: '*ALL' */
IF (&fromzip *NE '*ALL') DO
CHGVAR &qryslt ('ZIPCOD = %RANGE("' *CAT +
&fromzip *CAT '" "' *CAT &tozip *CAT '")')
ENDDO
ELSE CHGVAR &qryslt ('*ALL')

OVRDBF MAILLIST SHARE(*YES)

OPNQRYF FILE(MAILLIST) QRYSLT(&qryslt) KEYFLD((COUNTRY) (ZIPCOD))


CALL PRINTLABEL

CLOF OPNID(MAILLIST)
DLTOVR FILE(*ALL)
RETURN
ENDPGM
CPYFRMQRYF Command

• CPYFRMQRYF (Copy from Query File)


command copies records from OPNQRYF
temporary data path to database file
– Or prints records
• Allows other jobs to access copy of data path
– Allows CL to process file
OPNQRYF FILE(Maillist) +
QRYSLT('COUNTRY = "USA"') +
KEYFLD((ZIPCOD *DESCEND) (CARRTE))

CPYFRMQRYF FROMOPNID(MAILLIST) TOFILE(Mylib/Myfile)


CL and SQL

• CL can process tables and views created by


SQL
• CL cannot directly process SQL statements
• RUNSQLSTM (Run SQL Statements) command
runs SQL script stored in source member
RUNSQLSTM SRCFILE(Mylib/Myfile) SRCMBR(Myscript)

You might also like