Advanced File Techniques - i400Tech

15
Presentation © Copyright 2008, Bryan Meyers, www.bmeyers.net Part 17 Advanced File Techniques Advanced File Techniques

Transcript of Advanced File Techniques - i400Tech

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

Part 17

Advanced File TechniquesAdvanced File Techniques

Using File OverridesUsing 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 CommandOVRDBF Command

• OVRDBF (Override with Database File) command affects database file– Redirects program to another file– Changes attributes of file used by programOVRDBF 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 CommandOVRDBF 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 CommandDLTOVR 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 ExampleOVRDBF Example

PGM PARM(&fromlib &tolib) DCL &fromlib *CHAR 10 DCL &tolib *CHAR 10 DCL &eof *LGL DCLF QSYS/QADSPOBJ

DSPOBJD OBJ(&fromlib/*ALL) OBJTYPE(*ALL) + OUTPUT(*OUTFILE) OUTFILE(QTEMP/OBJECTS) OVRDBF QADSPOBJ TOFILE(QTEMP/OBJECTS)

DOUNTIL &eof RCVF MONMSG CPF0864 EXEC(DO) CHGVAR &eof '1' LEAVE ENDDO IF (&odobtp = '*FILE') DO MOVOBJ OBJ(&fromlib/&odobnm) OBJTYPE(&odobtp) TOLIB(&tolib) ENDDO ENDDO DLTOVR QADSPOBJ RETURNENDPGM

Compiler uses QSYS/QADSPOBJ(Model outfile for DSPOBJD)

Program processes QTEMP/OBJECTSinstead of QSYS/QADSPOBJ

Delete override when finished

Read outfile record(OBJECTS)

End of file

OVRPRTF CommandOVRPRTF 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 FilesPositioning Database Files

• File is normally positioned at beginning of file at opened– OVRDBF command may allow file open at another

recordOVRDBF Myfile POSITION(*START)OVRDBF Myfile POSITION(*END)OVRDBF Myfile POSITION(*RRN 501)

Positioning Database FilesPositioning 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 FilesPreopening 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 RETURNENDPGM

OPNQRYF CommandOPNQRYF 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 CommandOPNQRYF Command

• QRYSLT parameter selects records from file– Syntax resembles SQL

• KEYFLD parameter sets order of recordsOPNQRYF 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 CommandOPNQRYF 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) RETURNENDPGM

CPYFRMQRYF CommandCPYFRMQRYF 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 SQLCL 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 memberRUNSQLSTM SRCFILE(Mylib/Myfile) SRCMBR(Myscript)