Tip

Reorganize a library

Command and CL to reorganize all files in a library that have deleted records. Date and time for job to end can also be controlled.

  Source for CMD --

        *************** Beginning of data ***************************** 
0001.00              CMD        PROMPT('Reorganize Library')                    
0002.00                                                                         
0003.00              PARM       KWD(LIBRARY) TYPE(*CHAR) LEN(10) +              
0004.00                           PROMPT('Library to Reorganize')               
0005.00                                                                         
0006.00              PARM       KWD(END_DATE) TYPE(*CHAR) LEN(6) DFT(000000) +  
0007.00                           PROMPT('Ending Date MM/DD/YY')                
0008.00                                                                         
0009.00              PARM       KWD(END_TIME) TYPE(*CHAR) LEN(6) DFT(000000) +  
0010.00                           PROMPT('Ending Time')                         
0011.00                                                                         
        ****************** End of data ******************************** 
Source for CL --

0001.00                                                                        
0002.00              PGM        PARM(&LIB &INDAT &INTIM)                       
0003.00                                                                        
0004.00              DCLF       FILE(QAFDMBR)                                  
0005.00              DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)                  
0006.00              DCL        VAR(&INTIM) TYPE(*CHAR) LEN(6)                 
0007.00              DCL        VAR(&TIME) TYPE(*CHAR) LEN(6)                  
0008.00              DCL        VAR(&DATE) TYPE(*CHAR) LEN(6) VALUE('000000')  
0009.00              DCL        VAR(&INDAT) TYPE(*CHAR) LEN(6)                 
0010.00              DCL        VAR(&ENDTIM) TYPE(*CHAR) LEN(6) VALUE('000000')
0011.00              DCL        VAR(&ENDDAT) TYPE(*CHAR) LEN(6) +              
0012.00                           VALUE('000000')                              
0013.00              DCL        VAR(&MSG) TYPE(*CHAR) LEN(80)                  
0014.00              DCL        VAR(&QYEAR) TYPE(*CHAR) LEN(2)                 
0015.00              DCL        VAR(&QMONTH) TYPE(*CHAR) LEN(2)                
0016.00              DCL        VAR(&QDAY) TYPE(*CHAR) LEN(2)                  
0017.00                                                                        
0018.00 /* MAKE SURE LIBRARY EXISTS */                                         
0019.00                                                                        
0020.00              CHKOBJ     OBJ(QSYS/&LIB) OBJTYPE(*LIB)                   
0021.00              MONMSG     MSGID(CPF0000) EXEC(DO)                       
0022.00              CHGVAR     VAR(&MSG) VALUE('''Library'' *bcat &lib +     
0023.00                           *bcat ''not found''')                       
0024.00              SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +   
0025.00                           MSGTYPE(*ESCAPE)                            
0026.00              GOTO       CMDLBL(EOF)                                   
0027.00              ENDDO                                                    
0028.00                                                                       
0029.00 /* CREATE A FILE CONTAINING ALL FILES FROM THE REQUESTED LIBRARY */   
0030.00              DLTF       FILE(QTEMP/DELREC)                            
0031.00              MONMSG     MSGID(CPF2105)                                
0032.00                                                                       
0033.00              DSPFD      FILE(&LIB/*ALL) TYPE(*MBR) OUTPUT(*OUTFILE) + 
0034.00                           FILEATR(*PF) OUTFILE(QTEMP/DELREC) +        
0035.00                           OUTMBR(*FIRST)                              
0036.00                                                                       
0037.00              CHGVAR     VAR(&ENDTIM) VALUE(&INTIM)                    
0038.00                                                                       
0039.00              IF         COND(&INDAT = '000000') THEN(DO)              
0040.00              RTVSYSVAL  SYSVAL(QYEAR) RTNVAR(&QYEAR)                  
0041.00              RTVSYSVAL  SYSVAL(QMONTH) RTNVAR(&QMONTH)                
0042.00              RTVSYSVAL  SYSVAL(QDAY) RTNVAR(&QDAY)                      
0043.00              CHGVAR     VAR(%SST(&ENDDAT 1 2)) VALUE(&QMONTH)           
0044.00              CHGVAR     VAR(%SST(&ENDDAT 3 2)) VALUE(&QDAY)             
0045.00              CHGVAR     VAR(%SST(&ENDDAT 5 2)) VALUE(&QYEAR)            
0046.00              ENDDO                                                      
0047.00              ELSE       CMD(CHGVAR VAR(&ENDDAT) VALUE(&INDAT))          
0048.00                                                                         
0049.00 /* IF NO END TIME WAS ENTERED - RUN TILL ALL FILES ARE REORGANIZED */   
0050.00              IF         COND(&INTIM = '000000') THEN(CHGVAR +           
0051.00                           VAR(&ENDTIM) VALUE('999999'))                 
0052.00              ELSE       CMD(DO)                                         
0053.00              CHGVAR     VAR(&MSG) VALUE('Job will end at' *BCAT +       
0054.00                           &INTIM *BCAT 'on' *BCAT &INDAT)               
0055.00              SNDPGMMSG  MSG(&MSG)                                       
0056.00              ENDDO                                                      
0057.00                                                                         
0058.00 /* USE OPNQRYF TO ONLY SELECT FILES WITH AT LEAST ONE DELETED RECORD */ 
0059.00 /* AND REORGANIZE BASED ON THE MOST DISK SPACE BEING CONSUMED        */ 
0060.00              OVRDBF     FILE(QAFDMBR) TOFILE(QTEMP/DELREC) SHARE(*YES)  
0061.00              OPNQRYF    FILE((DELREC)) QRYSLT('MBNDTR *NE 0') +         
0062.00                           KEYFLD((*MAPFLD/MBDSSZ *DESCEND)) +           
0063.00                           MAPFLD((MBDSSZ 'MBMXRL * MBNDTR'))          
0064.00                                                                       
0065.00 READ:                                                                 
0066.00 /* GET CURRENT SYSTEM TIME */                                         
0067.00              RTVSYSVAL  SYSVAL(QTIME) RTNVAR(&TIME)                   
0068.00              RTVSYSVAL  SYSVAL(QYEAR) RTNVAR(&QYEAR)                  
0069.00              RTVSYSVAL  SYSVAL(QMONTH) RTNVAR(&QMONTH)                
0070.00              RTVSYSVAL  SYSVAL(QDAY) RTNVAR(&QDAY)                    
0071.00                                                                       
0072.00 /* COMPARE CURRENT DATE/TIME TO TIME YOU WANT THE JOB TO END */       
0073.00              CHGVAR     VAR(%SST(&DATE 1 2)) VALUE(&QMONTH)           
0074.00              CHGVAR     VAR(%SST(&DATE 3 2)) VALUE(&QDAY)             
0075.00              CHGVAR     VAR(%SST(&DATE 5 2)) VALUE(&QYEAR)            
0076.00              IF         COND(&TIME *GT &ENDTIM *AND &DATE *GE +       
0077.00                           &ENDDAT) THEN(GOTO CMDLBL(EOF)) /* If +     
0078.00                           past End Time, end job */                   
0079.00                                                                       
0080.00 /* READ NEXT RECORD FROM OUTPUT FILE OF "DSPFD" */                    
0081.00              RCVF       RCDFMT(QWHFDMBR)                              
0082.00              MONMSG     MSGID(CPF0864) EXEC(GOTO CMDLBL(EOF)) /* if + 
0083.00                           End of File error, end program */           
0084.00                                                                         
0085.00              RGZPFM     FILE(&MBLIB/&MBFILE) MBR(&MBNAME) +             
0085.01                           KEYFILE(*FILE)                                
0086.00              MONMSG     MSGID(CPF0000) EXEC(DO) /* If the reorganize +  
0087.00                           failed, put an error message in the joblog */ 
0088.00                                                                         
0089.00              CHGVAR     VAR(&MSG) VALUE('File' *BCAT &MBFILE *BCAT +    
0090.00                           'could not be reorganized.')                  
0091.00              SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +     
0092.00                           MSGTYPE(*STATUS)                              
0093.00                                                                         
0094.00              ENDDO                                                      
0095.00                                                                         
0096.00              GOTO       CMDLBL(READ) /* Read next record */             
0097.00                                                                         
0098.00 EOF:                                                                    
0099.00                                                                         
0100.00              CLOF       OPNID(DELREC)                                   
0101.00                                                                         
0102.00              DLTOVR     FILE(QAFDMBR)                                   
0103.00                                                                         
0103.00                                                                        
0104.00              RCLRSC                                                    
0105.00                                                                        
0106.00              ENDPGM                                                    
        ****************** End of data *************************  

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: Tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Read this Search400 Featured Topic: Managing your iSeries.


This was first published in August 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

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.