Jamir Dea Junior -Code

Jamir Dea Junior -Code

1. Environment

 
CRTLIB LIB(CMDDFN) TEXT('Command definition')   

CRTLIB LIB(LIBCONTROL) TEXT('Libraries Control')   

CREATE TABLE LIBCONTROL/LIBCONTROL (
	LIB CHAR (10 ) NOT NULL WITH DEFAULT, 
	OWNER CHAR (10 ) NOT NULL WITH DEFAULT, 
	TEXT CHAR (50 ) NOT NULL WITH DEFAULT, 
	CRDATE NUMERIC (8 ) NOT NULL WITH DEFAULT,  
	CRTIME NUMERIC (8 ) NOT NULL WITH DEFAULT, 
	DATEMTN NUMERIC (8 ) NOT NULL WITH DEFAULT,
	DAYSMTN NUMERIC (5 ) NOT NULL WITH DEFAULT)     

CRTMSGF MSGF(CMDDFN/CMDMSG) TEXT('Commands messages') 

ADDMSGD MSGID(CMD0001) MSGF(CMDDFN/CMDMSG)                                 
        MSG('Is not allowed to specify both parameters DATEMTN and DAYSMTN')                             

ADDMSGD MSGID(CMD0002) MSGF(CMDDFN/CMDMSG)                                 
        MSG('Specify DATEMTN or DAYSMTN parameter')                             

ADDMSGD MSGID(CMD0003) MSGF(CMDDFN/CMDMSG)                                 
        MSG('TEXT is a required parameter')                             

CRTSRCPF FILE(CMDDFN/SOURCES)

2. Command and Programs Sources

 Sources:
- SCRTLIB (CMD)
             CMD        PROMPT('Create Library')                            
             PARM       KWD(LIB) TYPE(*CHAR) LEN(10) MIN(1) +               
                          CHOICE('Name') PROMPT('Library')                  
             PARM       KWD(TYPE) TYPE(*CHAR) LEN(5) RSTD(*YES) +           
                          DFT(*PROD) VALUES(*PROD *TEST) +                  
                          CHOICE('*PROD, *TEST') PROMPT('Library type')     
             PARM       KWD(TEXT) TYPE(*CHAR) LEN(50) MIN(1) +              
                          PROMPT('Text ''description''')                    
             PARM       KWD(DATEMTN) TYPE(*DATE) CHOICE('Date (ddmmyyyy)') +
                          PROMPT('Don''t eliminate before')                 
             PARM       KWD(DAYSMTN) TYPE(*DEC) LEN(3) DFT(0) +             
                          CHOICE('Number of days') PROMPT('or, +            
                          number of days to maintain')                      
             PARM       KWD(AUT) TYPE(*CHAR) LEN(10) RSTD(*YES) +           
                          DFT(*LIBCRTAUT) VALUES(*LIBCRTAUT *CHANGE +       
                          *ALL *USE *EXCLUDE) CHOICE('Name, +               
                          *LIBCRTAUT, *CHANGE...') PMTCTL(*PMTRQS) +        
                          PROMPT('Authority')                               
             PARM       KWD(ASP) TYPE(*DEC) LEN(2) RSTD(*NO) DFT(1) +       
                          RANGE(1 16) CHOICE('1-16') +                      
                          PMTCTL(*PMTRQS) PROMPT('Auxiliary storage +       
                          pool ID')                                         
             PARM       KWD(CRTAUT) TYPE(*CHAR) LEN(10) RSTD(*YES) +  
                          DFT(*SYSVAL) VALUES(*SYSVAL *CHANGE *ALL +  
                          *USE *EXCLUDE) CHOICE('Name, *SYSVAL, +     
                          *CHANGE...') PMTCTL(*PMTRQS) +              
                          PROMPT('Create authority')                  
             PARM       KWD(CRTOBJAUD) TYPE(*CHAR) LEN(10) +         
                          RSTD(*YES) DFT(*SYSVAL) VALUES(*SYSVAL +   
                          *NONE *USRPRF *CHANGE *ALL) +              
                          CHOICE('Character value, *SYSVAL...') +    
                          PMTCTL(*PMTRQS) PROMPT('Create object +    
                          auditing')                                 
             DEP        CTL(DATEMTN) PARM((&DAYSMTN *EQ 0)) +        
                          MSGID(CMD0001)                             
             DEP        CTL(*ALWAYS) PARM((DATEMTN) (DAYSMTN)) +     
                          NBRTRUE(*EQ 1) MSGID(CMD0002)              
             DEP        CTL(*ALWAYS) PARM((TEXT)) NBRTRUE(*EQ 1) +   
                          MSGID(CMD0003)                             
- CCRTLIB (CLP)
             PGM        PARM(&LIB &TYPE &TEXT &DATEMTN &DAYSMTN &AUT + 
                          &ASP &CRTAUT &CRTOBJAUT)                     
             DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)                  
             DCL        VAR(&TYPE) TYPE(*CHAR) LEN(5)                  
             DCL        VAR(&TEXT) TYPE(*CHAR) LEN(50)                 
             DCL        VAR(&DATEMTN) TYPE(*CHAR) LEN(7)               
             DCL        VAR(&DAYSMTN) TYPE(*DEC) LEN(3 0)              
             DCL        VAR(&AUT) TYPE(*CHAR) LEN(10)                  
             DCL        VAR(&ASP) TYPE(*DEC) LEN(2)                    
             DCL        VAR(&CRTAUT) TYPE(*CHAR) LEN(10)               
             DCL        VAR(&CRTOBJAUT) TYPE(*CHAR) LEN(10)            
             DCL        VAR(&DAY) TYPE(*CHAR) LEN(2)                   
             DCL        VAR(&MONTH) TYPE(*CHAR) LEN(2)                 
             DCL        VAR(&YEAR) TYPE(*CHAR) LEN(4)                  
             DCL        VAR(&YEAR2) TYPE(*CHAR) LEN(2)                 
             DCL        VAR(&DATE) TYPE(*CHAR) LEN(8)                  
             DCL        VAR(&CLIB) TYPE(*CHAR) LEN(16)                 
             DCL        VAR(&COWNER) TYPE(*CHAR) LEN(16)               
             DCL        VAR(&CTYPE) TYPE(*CHAR) LEN(11)                
             DCL        VAR(&CTEXT) TYPE(*CHAR) LEN(56)                
             DCL        VAR(&CRTIME) TYPE(*CHAR) LEN(6)                
             DCL        VAR(&CRDATE) TYPE(*CHAR) LEN(8)                
             DCL        VAR(&DAYS) TYPE(*CHAR) LEN(3)                   
             DCL        VAR(&CASP) TYPE(*CHAR) LEN(15)                  
             DCL        VAR(&MSG) TYPE(*CHAR) LEN(100)                  
             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)                  
             DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)                  
             DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)               
             DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(132)              
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))         
             RTVJOBA    USER(&COWNER)                                   
             RTVSYSVAL  SYSVAL(QYEAR) RTNVAR(&YEAR2)                    
             RTVSYSVAL  SYSVAL(QMONTH) RTNVAR(&MONTH)                   
             RTVSYSVAL  SYSVAL(QDAY) RTNVAR(&DAY)                       
             RTVSYSVAL  SYSVAL(QTIME) RTNVAR(&CRTIME)                   
             CHGVAR     VAR(&YEAR) VALUE('20' *TCAT &YEAR2)             
             CHGVAR     VAR(&CRDATE) VALUE(&YEAR *CAT &MONTH *CAT &DAY) 
             CHGVAR     VAR(&CLIB) VALUE('''' *CAT &LIB *TCAT '''')     
             CHGVAR     VAR(&CTEXT) VALUE('''' *CAT &TEXT *TCAT '''')   
             CHGVAR     VAR(&COWNER) VALUE('''' *CAT &COWNER *TCAT '''')
             IF         COND(&DATEMTN *NE '0000000') THEN(DO)           
             CHGVAR     VAR(&YEAR) VALUE('20' *TCAT %SST(&DATEMTN 2 2)) 
             CHGVAR     VAR(&MONTH) VALUE(%SST(&DATEMTN 4 2))           
             CHGVAR     VAR(&DAY) VALUE(%SST(&DATEMTN 6 2))             
             CHGVAR     VAR(&DATE) VALUE(&YEAR *CAT &MONTH *CAT &DAY)   
             ENDDO                                                      
             ELSE       CMD(CHGVAR VAR(&DATE) VALUE('0'))               
             CHGVAR     VAR(&DAYS) VALUE(&DAYSMTN)                      
             CHGVAR     VAR(&CASP) VALUE(&CASP)                         
             QSYS/CRTLIB LIB(&LIB) TYPE(&TYPE) TEXT(&TEXT) AUT(&AUT) +  
                          ASP(&ASP) CRTAUT(&CRTAUT) +                   
                          CRTOBJAUD(&CRTOBJAUT)                         
             SNDPGMMSG  MSGID(CPC2102) MSGF(*LIBL/QCPFMSG) +            
                          MSGDTA(&LIB) TOPGMQ(*PRV (*)) MSGTYPE(*COMP)  
             STRQMQRY   QMQRY(CMDDFN/CRTLIBSQL) SETVAR((LIB &CLIB) +    
                          (OWNER &COWNER) (TEXT &CTEXT) (CRDATE +       
                          &CRDATE) (CRTIME &CRTIME) (DATE &DATE) +      
                          (DAYS &DAYS))                                 
             GOTO       CMDLBL(END)                                     
 ERROR:                                                                 
             RCVMSG     MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) +  
                          MSGF(&MSGF) MSGFLIB(&MSGFLIB)                 
             IF         COND(&MSGID *NE '       ') THEN(DO)             
             SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +            
                          MSGDTA(&MSGDTA) TOPGMQ(*PRV (*)) +            
                          MSGTYPE(*ESCAPE)                              
             MONMSG     MSGID(CPF0000)                                  
             GOTO       CMDLBL(ERROR)                                   
             ENDDO  
END:         ENDPGM 

- SDLTLIB (CMD)
             CMD        PROMPT('Delete library')              
             PARM       KWD(LIB) TYPE(*CHAR) LEN(10) MIN(1) + 
                          CHOICE('Name') PROMPT('Library')    

- CDLTLIB (CLP)
             PGM        PARM(&LIB)                                      
             DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)                   
             DCL        VAR(&CLIB) TYPE(*CHAR) LEN(16)                  
             DCL        VAR(&MSG) TYPE(*CHAR) LEN(100)                  
             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)                  
             DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)                  
             DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)               
             DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(132)               
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))         
             CHGVAR     VAR(&CLIB) VALUE('''' *CAT &LIB *TCAT '''')     
             QSYS/DLTLIB LIB(&LIB)                                      
             SNDPGMMSG  MSGID(CPC2194) MSGF(*LIBL/QCPFMSG) +            
                          MSGDTA(&LIB) TOPGMQ(*PRV (*)) MSGTYPE(*COMP)  
             STRQMQRY   QMQRY(CMDDFN/DLTLIBSQL) SETVAR((LIB &CLIB))     
             GOTO       CMDLBL(END)                                     
 ERROR:                                                                 
             RCVMSG     MSGTYPE(*EXCP) MSGDTA(&MSGDTA) MSGID(&MSGID) +  
                          MSGF(&MSGF) MSGFLIB(&MSGFLIB)                 
             IF         COND(&MSGID *NE '       ') THEN(DO)             
             SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) +            
                          MSGDTA(&MSGDTA) TOPGMQ(*PRV (*)) +            
                          MSGTYPE(*ESCAPE)     
             MONMSG     MSGID(CPF0000)         
             GOTO       CMDLBL(ERROR)          
             ENDDO                             
END:         ENDPGM                            

- CRTLIBSQL (SQL)
INSERT INTO LIBCONTROL/LIBCONTROL VALUES(                  
&LIB , &OWNER , &TEXT , &CRDATE , &CRTIME , &DATE , &DAYS )

- DLTLIBSQL (SQL)
DELETE FROM LIBCONTROL/LIBCONTROL WHERE LIB=&LIB 

3. Create programs, commands and others

 CRTQMQRY QMQRY(CMDDFN/CRTLIBSQL) SRCFILE(CMDDFN/SOURCES) 
CRTQMQRY QMQRY(CMDDFN/DLTLIBSQL) SRCFILE(CMDDFN/SOURCES) 

CRTCMD CMD(CMDDFN/SCRTLIB)     
       PGM(CMDDFN/CCRTLIB)           
       SRCFILE(CMDDFN/SOURCES)
       MSGF(CMDDFN/CMDMSG)         

CRTCMD CMD(CMDDFN/SDLTLIB)     
       PGM(CMDDFN/CDLTLIB)           
       SRCFILE(CMDDFN/SOURCES)
       MSGF(CMDDFN/CMDMSG)    

Problem: What happens with libraries created with RSTLIB, CPYLIB and CRTDUPOBJ?

1. You can also create alternate commands for these commands.

2. You can make a report with libraries created without command CRTLIB : DSPOBJD OBJ(*ALLUSR) OBJTYPE(*LIB) OUTPUT(*OUTFILE) OUTFILE(CMDDFN/LIB) SELECT ODOBNM FROM LIB WHERE ODOBNM NOT IN (SELECT LIB FROM LIBCONROL/LIBCONTROL)

3. Implementation 1 - Compile commands as new commands
WRKSYSVAL QSYSLIBL
Include library CMDDFN

Just create the new commands and assume that libraries created without new commands, will have just 1 or 2 days of life. Optionally, you can change the commands CRTLIB and DLTLIB:

 CHGCMD CMD(CRTLIB) ALLOW(*IMOD *BMOD *IREXX *BREXX *BPGM *IPGM) 
	CHGCMD CMD(DLTLIB) ALLOW(*IMOD *BMOD *IREXX *BREXX *BPGM *IPGM)  
After this, the commands CRTLIB and DLTLIB are not allowed in BATCH and INTERACT modes external to a CL program. CL programs can use CRTLIB and DLTLIB but these commands are not allowed in the command line in a SBMJOB command.

4. Implementation 2 - Compile commands with same name

In this case, you can create new CRTLIB and DLTLIB commands to substitute the actual ones.

Problem: What happens with programs that use CRTLIB and DLTLIB without new parameters?

1. You can change the programs to use the QSYS/CRTLIB instead of CRTLIB.

2. For applications that use this programs, you can change the system library list (CHGSYSLIBL) before you call the application.

3. Make the new parameters not required parameters.

WRKSYSVAL QSYSLIBL
Include library CMDDFN as first library

Compile new commands not as SCRTLIB and SDLTLIB, but as CRTLIB and DLTLIB. Optionally, you can remove authority from commands CRTLIB and DLTLIB in library QSYS to avoid users from using QSYS/CRTLIB or QSYS/DLTLIB (EDTOBJAUT OBJ(QSYS/CRTLIB) OBJTYPE(*CMD).

5. And my old libraries?

You can manually include it in LIBCONTROL file or make a report:

 DSPOBJD OBJ(*ALLUSR) OBJTYPE(*LIB) OUTPUT(*OUTFILE) OUTFILE(CMDDFN/LIB) 
SELECT ODOBNM FROM LIB WHERE ODOBNM NOT IN (SELECT LIB FROM LIBCONTROL/LIBCONTROL)
AND ODCDAT>DDMMYY (ODCDAT is creation date)

Dig deeper on iSeries programming commands

0 comments

Oldest 

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:

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close