<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
  PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Examples: Moving spooled files to and from optical storage" />
<meta name="abstract" content="This topic includes some basic optical programming examples using i5/OS control language (CL) commands." />
<meta name="description" content="This topic includes some basic optical programming examples using i5/OS control language (CL) commands." />
<meta name="DC.Relation" scheme="URI" content="tipsandtechniques.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 2000, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2000, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="clexamples" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Examples: Moving spooled files to and from optical storage</title>
</head>
<body id="clexamples"><a name="clexamples"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Examples: Moving spooled files to and from optical storage</h1>
<div><p>This topic includes some basic optical programming examples using i5/OS™ control
language (CL) commands.</p>
<div class="section"><div class="p">This topic includes examples of four CL commands that can be used
to move spooled files and database members to and from optical storage: <ul><li>Copy stream file</li>
<li>Copy database to optical</li>
<li>Copy spooled file to optical</li>
<li>Copy optical to database</li>
</ul>
</div>
</div>
<div class="example"><h4 class="sectiontitle">Copy Stream File: Command source</h4><div class="note"><span class="notetitle">Note:</span> By using the
following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre><samp class="codeph">/***************************************************************************/ 
/*																														*/ 
/* 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')</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy Stream File: CL program source</h4><div class="note"><span class="notetitle">Note:</span> By using
the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
This
CL sample can be used to copy stream files between file systems.<pre><samp class="codeph">/**********************************************************************/ 
/*																															*/ 
/*  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(&amp;SRCFILE &amp;TGFILE &amp;CPYINFO);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&amp;SRCFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&amp;TGTFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&amp;CPYINFO);     TYPE(*CHAR)   LEN(6)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&amp;SRCLEN);      TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&amp;TGTLEN);      TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&amp;ERRCODE);     TYPE(*CHAR)   LEN(4)                   +
                                      VALUE(X'00000000')
     DCL   VAR(&amp;COUNT);       TYPE(*DEC)    LEN(5 0)
     DCL   VAR(&amp;TBL);         TYPE(*CHAR)   LEN(10)                  +
                                      VALUE('QSYSTRNTBL')
     DCL   VAR(&amp;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(&amp;SRCLEN 3 2)) VALUE(%SST(&amp;SRCFILE 1 2))
     CHGVAR VAR(%SST(&amp;SRCFILE 1 300)) VALUE(%SST(&amp;SRCFILE 3 298))
 
     CHGVAR VAR(&amp;COUNT); VALUE(%BIN(&amp;SRCLEN 3 2))
     CALL  QDCXLATE (&amp;COUNT       +
                     &amp;SRCFILE     +
                     &amp;TBL         +
                     &amp;LIB)
 
     /****************************************************************/
     /* Separate target file length and file value.  Ensure target   */
     /* file is upper case.                                          */
     /****************************************************************/
     CHGVAR VAR(%SST(&amp;TGTLEN 3 2)) VALUE(%SST(&amp;TGTFILE 1 2))
     CHGVAR VAR(%SST(&amp;TGTFILE 1 300)) VALUE(%SST(&amp;TGTFILE 3 298))
 
     CHGVAR VAR(&amp;COUNT); VALUE(%BIN(&amp;TGTLEN 3 2))
     CALL  QDCXLATE (&amp;COUNT       +
                     &amp;TGTFILE     +
                     &amp;TBL         +
                     &amp;LIB)
 
     /****************************************************************/
     /* Call the copy stream file HFS API to copy the source file to */
     /* the target file.                                             */
     /****************************************************************/
     CALL  QHFCPYSF (&amp;SRCFILE     +
                     &amp;SRCLEN      +
                     &amp;CPYINFO     +
                     &amp;TGTFILE     +
                     &amp;TGTLEN      +
                     &amp;ERRCODE)
 
     SNDPGMMSG MSG('CPYSTRF completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)           +
                MSGDTA(CPYSTRF) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy database file to optical file: command source</h4><div class="note"><span class="notetitle">Note:</span> By
using the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre><samp class="codeph">/********************************************************************/ 
/*                                                                  */ 
/* 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')</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy database file to optical file: CL program source</h4><div class="note"><span class="notetitle">Note:</span> By
using the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
This
CL sample can be used to copy a member from a database file to optical storage.<pre><samp class="codeph">/**********************************************************************/ 
/*                                                                  	 */ 
/*  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(&amp;FROMFILE &amp;FROMMBR &amp;TGTFILE);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&amp;FROMFILE);    TYPE(*CHAR)   LEN(20)
     DCL   VAR(&amp;FROMMBAR);     TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;TGTFILE);     TYPE(*CHAR)   LEN(300)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&amp;FILE);        TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;LIB);         TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;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(&amp;FILE); VALUE(%SST(&amp;FROMFILE 1 10))
     CHGVAR VAR(&amp;LIB);  VALUE(%SST(&amp;FROMFILE 11 10))
 
     CPYTOPCD FROMFILE(&amp;LIB/&amp;FILE);                            +
              TOFLR(OPTICAL.FLR)                               +
              FROMMBR(&amp;FROMMBR);                               +
              TRNTBL(*NONE)
 
     /****************************************************************/
     /* Complete the source file path name with the member and copy  */
     /* the stream file from DLS to optical                          */
     /****************************************************************/
     CHGVAR VAR(%SST(&amp;SRCFILE 19 10)) VALUE(&amp;FROMMBR);
 
     CPYSTRF  SRCFILE(&amp;SRCFILE);                               +
              TGTFILE(&amp;TGTFILE);
 
     SNDPGMMSG MSG('CPYDBOPT completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG) +
                MSGDTA(CPYDBOPT) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy spooled file to optical: command source</h4><div class="note"><span class="notetitle">Note:</span> By
using the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre><samp class="codeph">/********************************************************************/ 
/*                                                                	  */ 
/* 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')</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy spooled file to optical: CL program source</h4><div class="note"><span class="notetitle">Note:</span> By
using the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
This
CL sample can be used to copy a spooled file to optical storage.<pre><samp class="codeph">/*********************************************************************/ 
/*                                                                  	*/ 
/*  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(&amp;FROMFILE &amp;TGTFILE &amp;JOB &amp;SPLNBR);
 
     /****************************************************************/
     /* Input parameters                                             */
     /****************************************************************/
     DCL   VAR(&amp;FROMFILE);    TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;TGTFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&amp;JOB);         TYPE(*CHAR)   LEN(26)
     DCL   VAR(&amp;SPLNBR);      TYPE(*CHAR)   LEN(5)
 
     /****************************************************************/
     /* Program variables                                            */
     /****************************************************************/
     DCL   VAR(&amp;JNAME);       TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;JUSER);       TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;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(&amp;JNAME); VALUE(%SST(&amp;JOB 1 10))
     CHGVAR VAR(&amp;JUSER); VALUE(%SST(&amp;JOB 11 10))
     CHGVAR VAR(&amp;JNUM);  VALUE(%SST(&amp;JOB 21 6))
 
     IF COND(&amp;JNAME *EQ '*') THEN(DO)
        CPYSPLF  FILE(&amp;FROMFILE);                              +
                 TOFILE(QUSRSYS/LISTINGS)                      +
                 TOMBR(&amp;FROMFILE);                             +
                 SPLNBR(&amp;SPLNBR);                              +
                 CTLCHAR(*FCFC)
        ENDDO
 
     ELSE DO
        CPYSPLF  FILE(&amp;FROMFILE);                              +
                 TOFILE(QUSRSYS/LISTINGS)                      +
                 TOMBR(&amp;FROMFILE);                             +
                 JOB(&amp;JNUM/&amp;JUSER/&amp;JNAME);                     +
                 SPLNBR(&amp;SPLNBR);                              +
                 CTLCHAR(*FCFC)
        ENDDO
 
     /****************************************************************/
     /* Copy the database file to optical storage                    */
     /****************************************************************/
     CPYDBOPT FRMFILE(QUSRSYS/LISTINGS)                        +
              FRMMBR(&amp;FROMFILE);                               +
              TGTFILE(&amp;TGTFILE);
 
     SNDPGMMSG MSG('CPYSPLFOPT completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)              +
                MSGDTA(CPYSPLFOPT) MSGTYPE(*ESCAPE)
 
     RETURN
 
ENDPGM</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy optical to database: command source</h4><div class="note"><span class="notetitle">Note:</span> By using
the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
<pre><samp class="codeph">/********************************************************************/ 
/*                                                                  */ 
/* 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')</samp></pre>
</div>
<div class="example"><h4 class="sectiontitle">Copy optical to database: CL program source</h4><div class="note"><span class="notetitle">Note:</span> By
using the following code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
This
CL sample can be used to copy a file from an optical volume to a member of
an existing file on a database.<pre><samp class="codeph">/**********************************************************************/ 
/*                                                                  	 */ 
/*  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(&amp;SRCFILE &amp;TOFILE &amp;TOMBR);
 
     /*****************************************************************/
     /* Input parameters                                              */
     /*****************************************************************/
     DCL   VAR(&amp;SRCFILE);     TYPE(*CHAR)   LEN(300)
     DCL   VAR(&amp;TOFILE);      TYPE(*CHAR)   LEN(20)
     DCL   VAR(&amp;TOMBR);       TYPE(*CHAR)   LEN(10)
 
     /*****************************************************************/
     /* Program variables                                             */
     /*****************************************************************/
     DCL   VAR(&amp;FILE);        TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;LIB);         TYPE(*CHAR)   LEN(10)
     DCL   VAR(&amp;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(&amp;TGTFILE 19 10)) VALUE(&amp;TOMBR);
 
     CPYSTRF  SRCFILE(&amp;SRCFILE);                               +
              TGTFILE(&amp;TGTFILE);
 
     /*****************************************************************/
     /* Separate the file and library names.  Copy the folder to DB.  */
     /*****************************************************************/
     CHGVAR VAR(&amp;FILE); VALUE(%SST(&amp;TOFILE 1 10))
     CHGVAR VAR(&amp;LIB);  VALUE(%SST(&amp;TOFILE 11 10))
 
     CPYFRMPCD FROMFLR(OPTICAL.FLR)                            +
               TOFILE(&amp;LIB/&amp;FILE);                             +
               FROMDOC(&amp;TOMBR);                                +
               TOMBR(&amp;TOMBR);                                  +
               TRNTBL(*NONE)
 
     SNDPGMMSG MSG('CPYOPTDB completed successfully')
     RETURN
 
DONE:
     SNDPGMMSG  MSGID(OPT0125) MSGF(QSYS/QCPFMSG)              +
                MSGDTA(CPYOPTDB) MSGTYPE(*ESCAPE)
     RETURN
 
ENDPGM</samp></pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="tipsandtechniques.htm" title="The following techniques are often helpful in designing custom optical programs for your business.">Tips: Optical programming</a></div>
</div>
</div>
</body>
</html>