Examples: Moving spooled files to and from optical storage

This topic includes some basic optical programming examples using i5/OS™ control language (CL) commands.

This topic includes examples of four CL commands that can be used to move spooled files and database members to and from optical storage:
  • Copy stream file
  • Copy database to optical
  • Copy spooled file to optical
  • Copy optical to database

Copy Stream File: Command source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
/***************************************************************************/ 
/*																														*/ 
/* COMMAND NAME:   CPYSTRF                                          			*/ 
/*           																									*/ 
/* COMMAND TITLE: Copy stream file  			                               	*/ 
/*                  																						*/ 
/* COMMAND DESCRIPTION: Copy stream file between two file systems   			*/ 
/*                        																				*/ 
/***************************************************************************/
        	CMD  PROMPT('Copy Stream File')

          PARM      KWD(SRCFILE) TYPE(*CHAR) LEN(300) MIN(1) +  
								MAX(1) PROMPT('Source file name')        + 
	                 	VARY(*YES)           
				PARM      KWD(TGTFILE) TYPE(*CHAR) LEN(300) MIN(1) + 
 								MAX(1) PROMPT('Target file name')        +
                    VARY(*YES) 
				PARM   		KWD(RPLFILE)TYPE(*CHAR) LEN(6) DFT(*NO) +
                    SPCVAL((*NO '0     ') (*YES '1     '))   +
                    PROMPT('Replace existing file')

Copy Stream File: CL program source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
This CL sample can be used to copy stream files between file systems.
/**********************************************************************/ 
/*																															*/ 
/*  PROGRAM: CPYSTRF (Copy stream file)                             	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  DESCRIPTION:                                                    	*/ 
/*  This is the CL program for sample CL command CPYSTRF.  This      */ 
/*  program can be used to copy stream files between file            */ 
/*  systems.  The actual copy is done by making a call to            */ 
/*  the HFS API program QHFCPYSF (Copy stream file).                 */ 
/*                                                                  	*/ 
/*                                               	                  */ 
/*  INPUT PARAMETERS:                                               	*/ 
/*  - Complete source path                           	               	*/ 
/*    Example: /filesystem/directory1/directoryx/file  	            	*/ 
/*             /QDLS/DIRA/DIRB/FILE01                    		         */ 
/*                  - or -                   						         	*/ 
/*             /filesystem/volume/directory1/directoryx/file 	       */ 
/*             /QOPT/VOLN01/DIRA/DIRB/FILE01                   			*/	
/*  - Complete target path                                          	*/ 
/*    Note:  Except for the file the path must already exist.       	*/ 
/*    Example: /filesystem/directory1/directoryx/file                */
/*             /QDLS/DIRA/DIRB/FILE01                                */ 
/*                 - or -                                           	*/ 
/*            /filesystem/volume/directory1/directoryx/file         	*/ 
/*            /QOPT/VOLN01/DIRA/DIRB/FILE01                         	*/ 
/*  - Replace existing target file                                   */ 
/*    *YES - replace existing file                                   */ 
/*    *NO  - do not replace existing file                            */ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  LOGIC:                                                          	*/ 
/*  - Separate source file length and value                          */ 
/*  - Ensure source path is converted to upper case                  */ 
/*  - Separate target file length and value                         	*/ 
/*  - Ensure target path is converted to upper case                  */ 
/*  - Call copy stream file                                         	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  EXAMPLE:                                                        	*/ 
/*  The example will copy document THISWEEK from folder BILLS       	*/ 
/*  to optical volume YEAR1993.  The document will be put into      	*/ 
/*  directory /BILLS/DEC as file WEEK50.                            	*/ 
/*  Folders are stored in file system DLS (document library services)*/
/*                                                                   */ 
/*       CPYSTRF SRCFILE('/QDLS/BILLS/THISWEEK')                    	*/ 
/*       TGTFILE('/QOPT/YEAR1993/BILLS/DEC/WEEK50')         				*/ 
/*       RPLFILE(*NO)                                       				*/ 
/*                                                                  	*/ 
/**********************************************************************/
  PGM  PARM(&SRCFILE &TGFILE &CPYINFO);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&SRCFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&TGTFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&CPYINFO);     TYPE(*CHAR)   LEN(6)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&SRCLEN);      TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&TGTLEN);      TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&ERRCODE);     TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&COUNT);       TYPE(*DEC)    LEN(5 0)
     DCL   VAR(&TBL);         TYPE(*CHAR)   LEN(10)                  +
                                      VALUE('QSYSTRNTBL')
     DCL   VAR(&LIB);         TYPE(*CHAR)   LEN(10)                  +
                                      VALUE('QSYS      ')
 
     /****************************************************************/
     /* Monitor for any messages sent to this program                */
     /****************************************************************/
     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(OPT0000) EXEC(GOTO CMDLBL(DONE))
 
     /****************************************************************/
     /* The HFS API needs to be passed the file and the file length. */
     /* By coding the VARY(*YES) parameter on the command definition */
     /* for the source and target file we are passed the length of   */
     /* entered value as a 2 byte binary field which precedes the    */
     /* actual value entered.                                        */
     /****************************************************************/
 
     /****************************************************************/
     /* Separate source file length and file value.  Ensure source   */
     /* file is upper case.                                          */
     /****************************************************************/
     CHGVAR VAR(%SST(&SRCLEN 3 2)) VALUE(%SST(&SRCFILE 1 2))
     CHGVAR VAR(%SST(&SRCFILE 1 300)) VALUE(%SST(&SRCFILE 3 298))
 
     CHGVAR VAR(&COUNT); VALUE(%BIN(&SRCLEN 3 2))
     CALL  QDCXLATE (&COUNT       +
                     &SRCFILE     +
                     &TBL         +
                     &LIB)
 
     /****************************************************************/
     /* Separate target file length and file value.  Ensure target   */
     /* file is upper case.                                          */
     /****************************************************************/
     CHGVAR VAR(%SST(&TGTLEN 3 2)) VALUE(%SST(&TGTFILE 1 2))
     CHGVAR VAR(%SST(&TGTFILE 1 300)) VALUE(%SST(&TGTFILE 3 298))
 
     CHGVAR VAR(&COUNT); VALUE(%BIN(&TGTLEN 3 2))
     CALL  QDCXLATE (&COUNT       +
                     &TGTFILE     +
                     &TBL         +
                     &LIB)
 
     /****************************************************************/
     /* Call the copy stream file HFS API to copy the source file to */
     /* the target file.                                             */
     /****************************************************************/
     CALL  QHFCPYSF (&SRCFILE     +
                     &SRCLEN      +
                     &CPYINFO     +
                     &TGTFILE     +
                     &TGTLEN      +
                     &ERRCODE)
 
     SNDPGMMSG MSG('CPYSTRF completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)           +
                MSGDTA(CPYSTRF) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM

Copy database file to optical file: command source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
/********************************************************************/ 
/*                                                                  */ 
/* COMMAND NAME:   	CPYDBOPT                                        */ 
/*                                                                  */ 
/* COMMAND TITLE: 	Copy database to optical                        */ 
/*                                                                  */ 
/* DESCRIPTION:    	Copy database file to an optical file           */ 
/*                                                                	 */ 
/********************************************************************/ 
CPYDBOPT:   CMD        PROMPT('Copy DB to Optical')                    
				                                                              
					PARM      KWD(FRMFILE) TYPE(QUAL1) MIN(1)        +    
                    	PROMPT('From file')                              
				
					PARM      KWD(FRMMBR) TYPE(*NAME)  LEN(10)       +  
                    	SPCVAL((*FIRST)) EXPR(*YES) MIN(1)    +   
          					 PROMPT('From member')               
				
					PARM      KWD(TGTFILE) TYPE(*CHAR)  LEN(300)     +
                    	MIN(1)  EXPR(*YES)                    +
                   	 	PROMPT('Target file')   
QUAL1:     QUAL      TYPE(*NAME) LEN(10)             
					QUAL      TYPE(*NAME) LEN(10) DFT(*LIBL)         + 
                    	SPCVAL((*LIBL) (*CURLIB))             +  
                     	PROMPT('Library')

Copy database file to optical file: CL program source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
This CL sample can be used to copy a member from a database file to optical storage.
/**********************************************************************/ 
/*                                                                  	 */ 
/*  PROGRAM: CPYDBOPT (Copy database to Optical)                    	 */ 
/*                                                                  	 */ 
/*                                                                  	 */ 
/*  DESCRIPTION:                                                    	 */ 
/*  This is the CL program for sample CL command CPYDBOPT.  This      */ 
/*  program can be used to copy a member from a database file to      */ 
/*  optical storage.                                                	 */ 
/*                                                                 	 */ 
/*                                                                  	 */ 
/*  DEPENDENCIES:                                                   	 */ 
/*  - The sample command and program CPYSTRF exists.                  */ 
/*  - There is an existing folder named OPTICAL.FLR                 	 */ 
/*    This folder is used for temporary storage when copying        	 */ 
/*    from database to optical.  It is assumed that this folderis   	 */ 
/*    empty and that the user will delete anything which gets       	 */ 
/*    copied into it.                                               	 */ 
/*                                                                    */
/*                                                                    */ 
/* INPUT PARAMETERS:                                                	 */ 
/*  -From file                                                      	 */ 
/*  - From member                                                     */ 
/*  - Complete	target path                                      		 */ 
/*     Assumption: - Except for the file the complete path currently  */ 
/*                  exists.                                         	 */ 
/*                 - File does not currently exist.                   */ 
/*     Example: /filesystem/volume/directory1/directoryx/file         */ 
/*              /QOPT/VOLN01/DIRA/DIRB/FILE01                       	 */ 
/*                                                                  	 */ 
/*                                                                  	 */ 
/*  LOGIC:                                                            */
/*  - Separate file and library                                       */ 
/*  - Copy file to folder                                             */ 
/*  - Build source file                                             	 */ 
/*  - Copy file from Document Library Service (DLS) to OPT            */ 
/*                                                                    */ 
/*                                                                  	 */ 
/*  EXAMPLE:                                                        	 */ 
/*  The example will copy member MYMEMBER in file MYFILE in library   */ 
/*  MYLIB to optical storage. It will be stored as file             	 */ 
/*  MYFILE.MYMEMBER in directory /MYLIB on volume VOLN01.             */ 
/*                                                                  	 */ 
/*        CPYDBOPT FRMFILE(MYLIB/MYFILE)                              */ 
/*                 FRMMBR(MYMEMBER)                                 	 */ 
/*                 TGTFILE('/QOPT/VOLN01/MYLIB/MYFILE.MYMEMBER')      */ 
/*                                                                  	 */ 
/**********************************************************************/
  PGM  PARM(&FROMFILE &FROMMBR &TGTFILE);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&FROMFILE);    TYPE(*CHAR)   LEN(20)
     DCL   VAR(&FROMMBAR);     TYPE(*CHAR)   LEN(10)
     DCL   VAR(&TGTFILE);     TYPE(*CHAR)   LEN(300)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&FILE);        TYPE(*CHAR)   LEN(10)
     DCL   VAR(&LIB);         TYPE(*CHAR)   LEN(10)
     DCL   VAR(&SRCFILE);     TYPE(*CHAR)   LEN(28)             +
     VALUE('/QDLS/OPTICAL.FLR/xxxxxxxxxx')
 
     /****************************************************************/
     /* Monitor for all messages sent to this program                */
     /****************************************************************/
     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(IWS0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(OPT0000) EXEC(GOTO CMDLBL(DONE))
 
     /****************************************************************/
     /* Separate file and library names then copy the DB file to a   */
     /* PC folder.                                                   */
     /****************************************************************/
     CHGVAR VAR(&FILE); VALUE(%SST(&FROMFILE 1 10))
     CHGVAR VAR(&LIB);  VALUE(%SST(&FROMFILE 11 10))
 
     CPYTOPCD FROMFILE(&LIB/&FILE);                            +
              TOFLR(OPTICAL.FLR)                               +
              FROMMBR(&FROMMBR);                               +
              TRNTBL(*NONE)
 
     /****************************************************************/
     /* Complete the source file path name with the member and copy  */
     /* the stream file from DLS to optical                          */
     /****************************************************************/
     CHGVAR VAR(%SST(&SRCFILE 19 10)) VALUE(&FROMMBR);
 
     CPYSTRF  SRCFILE(&SRCFILE);                               +
              TGTFILE(&TGTFILE);
 
     SNDPGMMSG MSG('CPYDBOPT completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG) +
                MSGDTA(CPYDBOPT) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM

Copy spooled file to optical: command source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
/********************************************************************/ 
/*                                                                	  */ 
/* COMMAND NAME:   CPYSPLFOPT                                      	*/ 
/*                                                                 	*/ 
/* COMMAND TITLE: Copy spooled file to optical                     	*/ 
/*                                                                 	*/ 
/* DESCRIPTION:    Copy spooled file to an optical file            	*/ 
/*                                                                 	*/ 
/********************************************************************/
CPYSPLFO:    CMD        	PROMPT('Copy Spooled File to Optical')           
    
					PARM       	KWD(FRMFILE) TYPE(*NAME) LEN(10)      +
                       	MIN(1)                              + 
                        	PROMPT('From file')                

					PARM       	KWD(TGTFILE) TYPE(*CHAR)  LEN(300)    + 
                       	MIN(1)  EXPR(*YES)                  +             
           						PROMPT('Target file')                

					PARM       	KWD(JOB) TYPE(Q2)                      +
                         DFT(*) SNGVAL(*)                    +
                         MIN(0) MAX(1)                       +  
                      		PROMPT('Jobname')                

					PARM       	KWD(SPLNBR) TYPE(*CHAR) LEN(5)         +  
                       	SPCVAL((*ONLY) (*LAST)) DFT(*ONLY)   + 
                        	PROMPT('Spool number')   

Q2:       	QUAL       	TYPE(*NAME) LEN(10)                    +    
                    		MIN(1)                               +
                         EXPR(*YES)             

					QUAL       	TYPE(*NAME) LEN(10)                    +
                        	EXPR(*YES)                           + 
                       	PROMPT('User')              

					QUAL       	TYPE(*CHAR) LEN(6)                     +
                         RANGE(000000 999999)             	 +     
                   			EXPR(*YES) FULL(*YES)                +
                        	PROMPT('Number')

Copy spooled file to optical: CL program source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
This CL sample can be used to copy a spooled file to optical storage.
/*********************************************************************/ 
/*                                                                  	*/ 
/*  PROGRAM: CPYSPLFOPT (Copy Spooled File to Optical)              	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  DESCRIPTION:                                                    	*/ 
/*  This is the CL program for sample CL command CPYSPLFOPT.  This   */ 
/*  program can be used to copy a spooled file to optical storage.   */ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  DEPENDENCIES:                                                   	*/ 
/*  - The sample command and program CPYDBOPT exists.                */ 
/*  - The sample command and program CPYSTRF exists.                	*/ 
/*  - There is an existing folder named OPTICAL.FLR                 	*/ 
/*    This folder is used for temporary storage when copying        	*/ 
/*    from spooled files to optical.  It is assumed that this folder */ 
/*    is empty and that the user will delete anything which gets     */
/*    copied into it.                                                */ 
/* - This CL program uses the CL command CPYSPLF to copy the        	*/ 
/*   spooled files to a physical file before copying them to        	*/ 
/*    optical. When you use the CPYSPLF command to copy             	*/ 
/*    a spooled file to a physical file, certain information can     */ 
/*    be lost or changed. Before using this command please          	*/ 
/*    refer to the CL Reference Book for the limitations and         */ 
/*    restrictions of the CPYSPLF command.                           */ 
/*  - There is an existing file named LISTINGS in library QUSRSYS.   */ 
/*    It is assumed that this file contains no existing members      */ 
/*    and that any members that are created will be deleted by the   */ 
/*    user.  The record length of the file is 133.                  	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  INPUT PARAMETERS:                                               	*/ 
/*  - From file                                                     	*/ 
/*    Specify the name of the spooled file to be copied.            	*/ 
/*  - Target file                                                   	*/ 
/*    Assumption: Except for the file the path must already exist.		*/ 
/*    Example: /filesystem/volume/directory1/directoryx/file        	*/ 
/*             /QOPT/VOLN01/DIRA/DIRB/FILE01                         */
/*  - Job                                                            */ 
/*   Specify the name of the job that created the spooled file      	*/ 
/*   which is to be copied.  The possible values are:               	*/ 
/*     The job that issued this command is the job that    					*/ 
/*     created the spooled file.                           					*/ 
/*              - or -                                              	*/ 
/*    job-name  Specify the name of the job that created the        	*/ 
/*              spooled file.                                       	*/ 
/*    user-name  Specify the user name that identifies the user      */ 
/*               profile under which the job was run.                */ 
/*    job-number Specify the system assigned job number.             */ 
/*  - Spool number                                                  	*/ 
/*    If there are multiple files for a job specify the files        */ 
/*    spool number.                                                 	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  LOGIC:                                                          	*/ 
/*  - Separate job into its three parts: job name, user, job number  */ 
/*  - Copy spooled files to database                                	*/ 
/*  - Copy database to optical                                      	*/ 
/*                                                                  	*/ 
/*                                                                  	*/ 
/*  EXAMPLE:                                                        	*/ 
/*  The example will copy spooled file QSYSPRT spool number 2 which  */ 
/*  the current process has printed to optical storage.              */
/*  It will be stored on volume YEAR92 in directory                  */ 
/* 	/DEC/WEEK01/MONDAY as file INVOICES                              */ 
/*                                                                  	*/ 
/*      	CPYSPLFO SPLFILE(QSYSPRT)                                   */ 
/*       	TGTFILE('/QOPT/YEAR92/DEC/WEEK01/MONDAY/INVOICES') 				*/ 
/*        SPLNBR(2)                                          				*/ 
/*                                                                 	*/ 
/*********************************************************************/
  PGM  PARM(&FROMFILE &TGTFILE &JOB &SPLNBR);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&FROMFILE);    TYPE(*CHAR)   LEN(10)
     DCL   VAR(&TGTFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&JOB);         TYPE(*CHAR)   LEN(26)
     DCL   VAR(&SPLNBR);      TYPE(*CHAR)   LEN(5)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&JNAME);       TYPE(*CHAR)   LEN(10)
     DCL   VAR(&JUSER);       TYPE(*CHAR)   LEN(10)
     DCL   VAR(&JNUM);        TYPE(*CHAR)   LEN(6)
 
     /****************************************************************/
     /* Monitor for all messages that can be signalled               */
     /****************************************************************/
     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(OPT0000) EXEC(GOTO CMDLBL(DONE))
 
     /****************************************************************/
     /* Separate each part of the job name and call the copy spool   */
     /* file command using the current job or the specified name.    */
     /****************************************************************/
     CHGVAR VAR(&JNAME); VALUE(%SST(&JOB 1 10))
     CHGVAR VAR(&JUSER); VALUE(%SST(&JOB 11 10))
     CHGVAR VAR(&JNUM);  VALUE(%SST(&JOB 21 6))
 
     IF COND(&JNAME *EQ '*') THEN(DO)
        CPYSPLF  FILE(&FROMFILE);                              +
                 TOFILE(QUSRSYS/LISTINGS)                      +
                 TOMBR(&FROMFILE);                             +
                 SPLNBR(&SPLNBR);                              +
                 CTLCHAR(*FCFC)
        ENDDO
 
     ELSE DO
        CPYSPLF  FILE(&FROMFILE);                              +
                 TOFILE(QUSRSYS/LISTINGS)                      +
                 TOMBR(&FROMFILE);                             +
                 JOB(&JNUM/&JUSER/&JNAME);                     +
                 SPLNBR(&SPLNBR);                              +
                 CTLCHAR(*FCFC)
        ENDDO
 
     /****************************************************************/
     /* Copy the database file to optical storage                    */
     /****************************************************************/
     CPYDBOPT FRMFILE(QUSRSYS/LISTINGS)                        +
              FRMMBR(&FROMFILE);                               +
              TGTFILE(&TGTFILE);
 
     SNDPGMMSG MSG('CPYSPLFOPT completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)              +
                MSGDTA(CPYSPLFOPT) MSGTYPE(*ESCAPE)
 
     RETURN
 
ENDPGM

Copy optical to database: command source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
/********************************************************************/ 
/*                                                                  */ 
/* COMMAND NAME:   CPYOPTDB                                         */ 
/*                                                                  */ 
/* COMMAND TITLE: Copy optical to database                          */ 
/*                                                                  */ 
/* DESCRIPTION:    Copy optical file to database file               */ 
/*                                                                  */ 
/********************************************************************/
CPYOPTDB:   	CMD      	PROMPT('Copy Optical to DB ')             

					PARM     	KWD(SRCFILE) TYPE(*CHAR)  LEN(300)    + 
                      	MIN(1)  EXPR(*YES)                    +  
                      	PROMPT('Source file')              

					PARM     	KWD(TOFILE) TYPE(QUAL1) MIN(1)        +
                      	PROMPT('To file')               

					PARM     	KWD(TOMBR) TYPE(*NAME)  LEN(10)       + 
                     	SPCVAL((*FIRST)) EXPR(*YES) MIN(1)    +   
                    	PROMPT('To member')   

QUAL1:     	QUAL   		TYPE(*NAME) LEN(10)      
       
					QUAL     	TYPE(*NAME) LEN(10) DFT(*LIBL)        +   
                    	SPCVAL((*LIBL) (*CURLIB))             + 
                      	PROMPT('Library')

Copy optical to database: CL program source

Note: By using the following code examples, you agree to the terms of the Code license and disclaimer information.
This CL sample can be used to copy a file from an optical volume to a member of an existing file on a database.
/**********************************************************************/ 
/*                                                                  	 */ 
/*  PROGRAM: CPYOPTDB (Copy Optical to Database)                    	 */ 
/*                                                                    */ 
/*                                                                 	 */ 
/*  DESCRIPTION:                                                    	 */ 
/*  This is the CL program for sample CL command CPYOPTDB.  This      */ 
/*  program can be used to copy a file which is on optical            */ 
/*  storage to a member of an existing file.                          */ 
/*                                                                  	 */ 
/*                                                                  	 */ 
/*  DEPENDENCIES:                                                   	 */ 
/*  - The sample command and program CPYSTRF exist.                 	 */ 
/*  - There is an existing folder named OPTICAL.FLR                 	 */ 
/*    This folder is used for temporary storage when copying        	 */ 
/*    from optical to database.  It is assumed that this folder is    */ 
/*    empty and that the user will delete anything which gets       	 */ 
/*    copied into it.                                               	 */ 
/*                                                                    */
/*                                                                    */ 
/* INPUT PARAMETERS:                                                	 */ 	
/*  - Complete source path                                            */ 
/*     Example: /filesystem/volume/directory1/directoryx/file         */ 
/*              /QOPT/VOLN01/DIRA/DIRB/FILE01                         */ 
/*  - To file                                                       	 */ 
/*    Assumptions:                                                  	 */ 
/*    - Target library already exists.                              	 */ 
/*    - Target file already exists and has the same attributes      	 */ 
/*      as that which contained the original file.                  	 */ 
/*  - To member                                                     	 */ 
/*                                                                  	 */ 
/*                                                                    */
/*  LOGIC:                                                            */ 
/* - Build target file                                              	 */ 
/*  - Copy file from OPT to Document Library Services (DLS)           */ 
/*  - Separate file and library                                       */ 
/*  - Copy from folder to database file                               */ 
/*                                                                  	 */ 
/*                                                                 	 */ 
/*  EXAMPLE:                                                        	 */ 
/*  The example will copy file invoices which is in directory         */ 
/*  DEC on volume YEAR1992.  INVOICES was originally a spooled file   */ 
/*  which had a record length of 133.  It will be placed in file      */ 
/*  LISTINGS which is in library QUSRSYS as member INVOCDEC92.        */ 
/*                                                                    */ 
/*        CPYDBOPT TGTFILE('/QOPT/YEAR1992/DEC/INVOICES')           	 */ 
/*                 TOFILE(QUSRSYS/LISTINGS)                         	 */ 
/*                 TOMBR(INVOCDEC92)                                	 */ 
/*                                                                  	 */ 
/**********************************************************************/
  PGM  PARM(&SRCFILE &TOFILE &TOMBR);
 
     /*****************************************************************/
     /* Input parameters                                              */
     /*****************************************************************/
     DCL   VAR(&SRCFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&TOFILE);      TYPE(*CHAR)   LEN(20)
     DCL   VAR(&TOMBR);       TYPE(*CHAR)   LEN(10)
 
     /*****************************************************************/
     /* Program variables                                             */
     /*****************************************************************/
     DCL   VAR(&FILE);        TYPE(*CHAR)   LEN(10)
     DCL   VAR(&LIB);         TYPE(*CHAR)   LEN(10)
     DCL   VAR(&TGTFILE);     TYPE(*CHAR)   LEN(28)            +
                                   VALUE('/QDLS/OPTICAL.FLR/xxxxxxxxxx')
 
     /*****************************************************************/
     /* Monitor for all messages signalled                            */
     /*****************************************************************/
     MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(IWS0000) EXEC(GOTO CMDLBL(DONE))
     MONMSG     MSGID(OPT0000) EXEC(GOTO CMDLBL(DONE))
 
     /*****************************************************************/
     /* Build the target file name and copy the stream file from      */
     /* optical to DLS                                                */
     /*****************************************************************/
     CHGVAR VAR(%SST(&TGTFILE 19 10)) VALUE(&TOMBR);
 
     CPYSTRF  SRCFILE(&SRCFILE);                               +
              TGTFILE(&TGTFILE);
 
     /*****************************************************************/
     /* Separate the file and library names.  Copy the folder to DB.  */
     /*****************************************************************/
     CHGVAR VAR(&FILE); VALUE(%SST(&TOFILE 1 10))
     CHGVAR VAR(&LIB);  VALUE(%SST(&TOFILE 11 10))
 
     CPYFRMPCD FROMFLR(OPTICAL.FLR)                            +
               TOFILE(&LIB/&FILE);                             +
               FROMDOC(&TOMBR);                                +
               TOMBR(&TOMBR);                                  +
               TRNTBL(*NONE)
 
     SNDPGMMSG MSG('CPYOPTDB completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)              +
                MSGDTA(CPYOPTDB) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM