Home > AS/400 Tips > iSeries programmer tips > The secret to saving only source files
iSeries 400 Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ISERIES PROGRAMMER TIPS

The secret to saving only source files


Tim Granatir, Search400 expert
06.05.2002
Rating: -4.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



Tim Granatir

This tip is in response to a search400 member who wanted to save only source files.

While this program saves only source files, there are several interesting features of this program that also apply to other applications. The first is the use of the system file QADBXREF. This is an OS/400 file that contains all of the physical and logical files on the system. I use this file to quickly build the list of source files on the system. This file can be helpful in a lot of other ways, too. I've used this system file to locate files when I knew only a partial name of a file, to locate duplicate programmer copies of files, etc.

The second thing to point out is the use of the FROMRCD parameter on the CPYF command. The QADBXREF is a keyed physical file, and by using the FROMRCD parameter on the copy, the copy file ignores the keys and proceeds much faster.

This program is capable of running in an automated mode. As you can from the program, all this program requires is that a tape is in the tape drive before it starts.

This file uses a temporary file called QADBXTMP that would reside in the user's library list. I use a temporary file for a couple reasons, but the overriding reason is that you can't declare the QADBXREF file in your CL program. Since QADBXREF is a system file, you will have to make sure that the user profile running the backup has authority to use it or change this program to adopt authority of a profile that has sufficient authority. The SAVOBJ command has a limit of 300 objects that it can save per library. If you have more source files than that in a single library, you'll want to change this program to add a counter to limit the number of files saved in the SAVOBJ command.

A quick summary of what it does:

  • Initializes a tape
  • Builds list of source files
  • Reads the list and builds a QCMDEXC command string so that all source files in a library are saved in a single SAVOBJ command
  • Leaves the tape where it left off so that the next save won't have to waste time repositioning the tape head
  • Repeats the save process for each library and informs QSYSOPR of any errors encountered
  • At end of file, rewinds and unloads the tape.

Program:

QADBXTMP Command CL SOURCE 
     A          R QADBXFM
     	A            DBXLIB        10
     	A            DBXFIL        10
     	A          K DBXLIB
     	A          K DBXFIL

SAVSRC Command CL SOURCE 

PGM

DCLF       FILE(QADBXTMP)
DCL        VAR(&SENDMSG) TYPE(*CHAR) LEN(512)
DCL        VAR(&BLANKS) TYPE(*CHAR) LEN(3700)
DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)
DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(132)
DCL        VAR(&CURDATE) TYPE(*CHAR) LEN(6)
DCL        VAR(&OWNID) TYPE(*CHAR) LEN(7)
DCL        VAR(&USER) TYPE(*CHAR) LEN(10)
DCL        VAR(&ERRFLG) TYPE(*CHAR) LEN(1)
DCL        VAR(&CMD) TYPE(*CHAR) LEN(3700)
DCL        VAR(&FILES) TYPE(*CHAR) LEN(3300)
DCL        VAR(&HLDLIB) TYPE(*CHAR) LEN(10)
DCL        VAR(&ENDFLG) TYPE(*CHAR) LEN(1)

MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(FATALERR))
SNDPGMMSG  MSG('BACKUP PGM STARTED') TOUSR(QSYSOPR)

/*  MAKE SURE WE GET A JOB LOG                    */
             CHGJOB     LOG(*SAME *SAME *SECLVL)

             RTVSYSVAL  SYSVAL(QDATE) RTNVAR(&CURDATE)
             CHGVAR     VAR(&OWNID) VALUE('D' *CAT &CURDATE)
             RTVJOBA    USER(&USER)

INITIALIZE:

/*  INITIALIZE TAPE                                             */
             INZTAP     DEV(TAP02) NEWVOL(BACKUP) NEWOWNID(&OWNID) +
                          CHECK(*NO) DENSITY(*CTGTYPE)
             MONMSG     MSGID(CPF0000) EXEC(DO) /* tape not ready */
               SNDMSG     MSG('Tape was not ready.  Backup was not +
                            done.') TOMSGQ(QSYSOPR) MSGTYPE(*INFO)
               GOTO       CMDLBL(ENDPGM)
             ENDDO

/*  JUST IN CASE                                        */
             DLTF       FILE(QTEMP/QADBXTMP)
             MONMSG     MSGID(CPF0000)

/*  CREATE WORK FILE IN QTEMP                           */
             CPYF       FROMFILE(*LIBL/QADBXTMP) +
                          TOFILE(QTEMP/QADBXTMP) CRTFILE(*YES) +
                          NBRRCDS(1)
             CLRPFM     FILE(QADBXTMP)


/*  GET A LIST OF ALL SOURCE FILES ON THE SYSTEM */
             CPYF       FROMFILE(QSYS/QADBXREF) +
                          TOFILE(QTEMP/QADBXTMP) MBROPT(*REPLACE) +
                          CRTFILE(*YES) FROMRCD(1) INCREL((*IF +
                          DBXTYP *EQ 'S')) FMTOPT(*MAP *DROP)

             OVRDBF     FILE(QADBXTMP) TOFILE(QTEMP/QADBXTMP)

/*  READ FILES & DECIDE WHICH ONES TO SAVE */
RCVF:
             RCVF
             MONMSG     MSGID(CPF0864) EXEC(DO) /* At End */
               CHGVAR     VAR(&ENDFLG) VALUE('Y')
               GOTO       CMDLBL(SAVE)
             ENDDO
             IF         COND(&HLDLIB *EQ '          ') THEN(CHGVAR +
                          VAR(&HLDLIB) VALUE(&DBXLIB))

             IF         COND(&DBXLIB *NE &HLDLIB) THEN(GOTO +
                          CMDLBL(SAVE))
 RCVF2:
 /* BUILD QCMDEXC STRING */
             CHGVAR     VAR(&FILES) VALUE(&FILES *BCAT &DBXFIL)

             GOTO RCVF

SAVE:
/*  LEAVE TAPE AT END SO THAT NEXT SAVE GOES FASTER           */
             CHGVAR     VAR(&CMD) VALUE('SAVOBJ OBJ(' *TCAT &FILES +
                          *TCAT ') LIB(' *TCAT &HLDLIB *TCAT ') +
                          DEV(TAP02) ENDOPT(*LEAVE) SAVACT(*SYSDFN) +
                          DTACPR(*YES)')
             CALL       PGM(QCMDEXC) PARM(&CMD 3700)
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(SAVERR))

/*  CLEAR & SET VARIABLES                       */
             CHGVAR     VAR(&FILES) VALUE(&BLANKS)
             CHGVAR     VAR(&HLDLIB) VALUE(&DBXLIB)

             IF         COND(&ENDFLG *EQ 'Y') THEN(GOTO CMDLBL(ENDPGM))

             GOTO       CMDLBL(RCVF2)

SAVERR:
/*  PROCESS ALL SAVE ERRORS                                   */
             RCVMSG     MSGTYPE(*EXCP) MSGID(&MSGID)

             CHGVAR     VAR(&SENDMSG) VALUE(&BLANKS)
             CHGVAR     VAR(&SENDMSG) VALUE('Files in library' *BCAT +
                          &HLDLIB *BCAT 'not saved because of +
                          error' *BCAT &MSGID *TCAT '.' *BCAT +
                          'Please investigate.')
             SNDPGMMSG  MSG(&SENDMSG) TOMSGQ(QSYSOPR)

/*  GET THE REST OF THE FILES TO SAVE                        */
             GOTO       CMDLBL(RCVF)

FATALERR:
             RCVMSG     MSGTYPE(*EXCP) MSG(&MSGDTA) MSGID(&MSGID)
             MONMSG     MSGID(CPF0000)

             IF         COND(%SST(&MSGDTA 1 10) *EQ '          ') +
                          THEN(DO)
               CHGVAR     VAR(&MSGDTA) VALUE('Error Message text not +
                            available at this time')
             ENDDO

/*  CHECK ERROR FLAG TO ENSURE THAT WE DON'T GET STUCK IN AN */
/*  ENDLESS LOOP  */
             IF         COND(&ERRFLG *EQ 'Y') THEN(GOTO +
                          CMDLBL(ENDPGM2))

             CHGVAR     VAR(&ERRFLG) VALUE('Y')

             CHGVAR     VAR(&SENDMSG) VALUE(&BLANKS)
             CHGVAR     VAR(&SENDMSG) VALUE('Backup pgm ended +
                          abnormally because of error' *BCAT &MSGID +
                          *BCAT '-' *BCAT &MSGDTA *TCAT '.' *BCAT +
                          'Please investigate.')

             SNDPGMMSG  MSG(&SENDMSG) TOMSGQ(QSYSOPR)

ENDPGM:
             SNDPGMMSG  MSG('BACKUP PGM ENDED') TOUSR(QSYSOPR)
  /*  REWIND AND UNLOAD THE TAPE AFTER WE ARE DONE              */
             OVRPRTF    FILE(QPTAPDMP) HOLD(*YES)
             DMPTAP     DEV(TAP02) DTABLK(*FIRST *ONLY) VOLLBL(*NO) +
                          ENDOPT(*UNLOAD)
             DLTSPLF    FILE(QPTAPDMP) SPLNBR(*LAST)
ENDPGM2:     ENDPGM

---------------------------
About the author: Tim is vice president of Technical Services at Interlink Technologies in Maumee, Ohio, where he serves as chief architect for their warehouse management system. He has worked in the banking, insurance, healthcare and distribution industries in various positions, including programmer/analyst, systems analyst and DP manager. Tim has worked on IBM midrange platforms since 1983.

==================================
MORE INFORMATION
==================================


Rate this Tip
To rate tips, you must be a member of Search400.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Application Development
iSeries calling an .exe
Top 10 programmer tips
Formatted work job scheduler
Convert system date and time
Mixing free format code with embedded SQL
SQL update a field in one file from a field in another file
Webcasts for iSeries programmers
Programming advice from the pros
Easy code copying via the drag and drop method
Setting FTP time-outs

OS/400
Top 10 backup commands
Take control of your iSeries
How to save time using the CPYTOPCD and CPYFRMPCD commands
Top Q&A's on the OS/400
Top 10 security tips
Use caution when providing access to file shares
How to set up an autostart job
How does Sarbanes-Oxley affect you?
Automated disaster recovery revisited
Top 10 Administrator Tips

iSeries programmer tips
Enhancing RPG with external SQL stored procedures
Tracking data changes on IBM i with triggers
Introduction to SQLRPGLE on IBM i: Making a report
Implementing a browser interface in COBOL: Displaying database fields
Taking advantage of CL advancements, starting with V5R3
TAATOOL: Useful tools for programmers on IBM i
Implementing a browser interface in COBOL: Creating your graphic Web page
Implementing a browser interface in COBOL: Getting started
Making the most of RPG data handling on IBM i
Groovy programming on IBM i

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



iSeries Security - Security Tools, Physical Security and System Security
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts