Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Example 2: Command to output the contents of a file

&pagelevel(4)&pagelevel

A command to output the contents of a SAM or ISAM file on SYSOUT is to be defined and is to be implemented by means of a procedure. By default, the records in the file to be output are of variable length, but files with fixed-length records may also be output. When ISAM files are output, the ISAM key has a default length of eight bytes, but it may also be shorter. The command is to have the following format:

TYPE-FILE

NAME = <filename 1..54>

,ACCESS-METHOD = *ISAM(...) / *SAM

*ISAM(...)

  KEY-LENGTH = 8 / <integer 1..8>

,RECORD-SIZE = *VARIABLE / <integer 1..256>

The command is implemented by means of a procedure. The symbolic operands appear as positional operands in the operand list of the BEGIN-PROCEDURE command. The utility routine EDT is used within the procedure. The following procedure appears in the file $SDFUSR.TYPE.FILE.

/      BEGIN-PROCEDURE N,PARAM=YES(PROC-PARAM=(&FILE,&ACCESS,&KEY,&RECORD),- 
/      ESCAPE-CHARACTER='&') 
/      MODIFY-JOB-SWITCHES ON=(4,5) 
/      ASSIGN-SYSDTA TO-FILE=*SYSCMD 
/      CREATE-JV JV=RECORD-SIZE 
/      MODIFY-JV JV=RECORD-SIZE,VALUE='&RECORD' 
/      LOAD-PROGRAM FROM-FILE=$EDT 
/      SKIP-COMMAND TO-LABEL=&ACCESS   "ACCESS IST ISAM ODER SAM" 
/.SAM SKIP-COMMANDS TO-LABEL=SAM1,IF=JV(COND=(RECORD-SIZE='VARIABLE')) 
/      SET-FILE-LINK LINK-NAME=EDTSAM,FILE-NAME=&FILE,ACCES-METHOD=SAM,- 
/      RECORD-FORMAT=FIXED(REC-SIZE=&RECORD) 
/.SAM1 RESUME-PROGRAM 
@      READ '&FILE' 
/      HOLD-PROGRAM 
/      SKIP-COMMANDS TO-LABEL=COMMON,IF=JV(COND=(RECORD-SIZE='VARIABLE')) 
/      REMOVE-FILE-LINK LINK-NAME=EDTSAM 
/      SKIP-COMMANDS TO-LABEL=COMMON 
/.ISAM CREATE-JV JV=ISAM-KEY 
/      MODIFY-JV JV=ISAM-KEY,VALUE='&KEY' 
/      SKIP-COMMANDS TO-LABEL=ISAM3,IF=JV(COND=(ISAM-KEY='8' AND - 
/      RECORD-SIZE='VARIABLE')) 
/      SKIP-COMMANDS TO-LABEL=ISAM1,IF=JV(COND=(ISAM-KEY='8')) 
/      SKIP-COMMANDS TO-LABEL=ISAM2,IF=JV(COND=(RECORD-SIZE='VARIABLE')) 
/      SET-FILE-LINK LINK-NAME=EDTISAM,FILE-NAME=&FILE,ACCESS-METHOD=- 
/      ISAM(KEY-LEN=&KEY,KEY-POS=1),RECORD-FORMAT=FIXED(REC-SIZE=&RECORD) 
/      SKIP-COMMANDS TO-LABEL=ISAM3 
/.ISAM1 SET-FILE-LINK LINK-NAME=EDTISAM,FILE-NAME=&FILE,ACCES-METHOD=- 
/      ISAM(KEY-LEN=8,KEY-POS=1),RECORD-FORMAT=FIXED(REC-SIZE=&RECORD) 
/      SKIP-COMMANDS TO-LABEL=ISAM3 
/.ISAM2 SET-FILE-LINK LINK-NAME=EDTISAM,FILE-NAME=&FILE,ACCES-METHOD=- 
/      ISAM(KEY-LEN=&KEY) 
/.ISAM3 RESUME-PROGRAM 
@      GET '&FILE' 
/      HOLD-PROGRAM 
/      SKIP-COMMANDS TO-LABEL=ISAM4,IF=JV(COND=(ISAM-KEY='8' AND - 
/      RECORD-SIZE='VARIABLE')) 
/      REMOVE-FILE-LINK LINK-NAME=EDTISAM 
/.ISAM4 DELETE-JV JV=ISAM-KEY 
/.COMMON RESUME-PROGRAM 
@      PRINT %.-$N 
@      HALT 
/      SET-JOB-STEP 
/      DELETE-JV JV=RECORD-SIZE 
/      ASSIGN-SYSDTA TO-FILE=*PRIMARY 
/      MODIFY-JOB-SWITCHES OFF=(4,5) 
/      END-PROCEDURE 

The TYPE-FILE command is defined in the user syntax file SDF.USER.SYNTAX. It is subsequently tested.

/set-logon-parameters sdfusr,... ——————————————————————————————————————  (1)
 .
 .
/mod-sdf-opt synt-file=*remove(*std) ——————————————————————————————————  (2)
/start-sdf-a ——————————————————————————————————————————————————————————  (3)
%  BLS0517 MODULE 'SDAMAIN' LOADED
%  SDA0001 'SDF-A' VERSION '04.1E10' STARTED
%//open-syntax-file sdf.user.syntax ———————————————————————————————————  (4)
%//set-globals cont=*new ——————————————————————————————————————————————  (5)
%//add-cmd type-file,help=e('Outputs the contents of an ISAM or SAM -
%//file to SYSOUT.'),domain=user,impl=*proc('$sdfusr.type.file') ——————  (6)
%//add-oper name,help=e('Name of file to be output'),res-oper-nam=*pos(1) (7)
%//add-value *filename ————————————————————————————————————————————————  (8)
%//add-oper access-method,def='isam',res-oper-name=*pos(2) ————————————  (9)

                                                                                                

  1. A task is initiated under the user ID SDFUSR.

  2. The user syntax file SDF.USER.SYNTAX automatically activated during LOGON processing is deactivated.

  3. SDF-A is loaded and started.

  4. The existing user syntax file SDF.USER.SYNTAX is opened.

  5. The global information defines that the continuation character “-” for follow-on lines may be situated in any column between 2 and 72 when SYSCMD or SYSSTMT is input.

  6. The header of the TYPE-FILE command is defined. It contains an English help text and is assigned to the domain USER. It is implemented by means of the procedure appearing in the file $SDFUSR.TYPE.FILE.

  7. The first operand of the TYPE-FILE command is defined. Its name is NAME. It contains an English help text. It comes first in the string to be passed to the procedure.

  8. It is defined that the value of the operand NAME must be of the data type FILENAME.

  9. The second operand of the TYPE-FILE command is defined. Its name is ACCESS-METHOD. Its default value is ISAM. In the string to be passed to the procedure, it occupies the second position.

    %//add-value *keyw,struct=*y,value='isam' ————————————————————————————— (10)
    %//add-oper key-length,def='8',res-oper-name=*pos(3) —————————————————— (11)
    %//add-value *integ(1,8) —————————————————————————————————————————————— (12)
    %//close-struct ——————————————————————————————————————————————————————— (13)
    %//add-value *keyw,value='sam' ———————————————————————————————————————— (14)
    %//add-oper record-size,def='variable',res-oper-name=*pos(4) —————————— (15)
    %//add-value *keyw,value='variable' ——————————————————————————————————— (16)
    %//add-value *integ(1,256) ———————————————————————————————————————————— (17)
    %//close-cmd —————————————————————————————————————————————————————————— (18)

                                                                                                                                                                                                    

  10. It is defined that the keyword ISAM is a permissible value of the ACCESS-METHOD operand. ISAM introduces a structure.

  11. The first operand of the structure ISAM is defined. Its name is KEY-LENGTH. Its default value is the integer 8. It appears third in the string to be passed to the procedure.

  12. It is defined that the value of the KEY-LENGTH operand must be of the data type INTEGER. 1 is defined as its lower limit, 8 as its upper limit.

  13. The structure ISAM just edited is closed.

  14. It is defined that the keyword SAM is a permissible value of the ACCESS-METHOD operand.

  15. The third operand of the TYPE-FILE command is defined. Its name is RECORD-SIZE. Its default value is VARIABLE. It occupies the fourth position in the string to be passed to the procedure.

  16. It is defined that the keyword VARIABLE is a permissible value of the RECORD-SIZE operand.

  17. It is defined that the value of the RECORD-SIZE operand may be of the data type INTEGER. 1 is defined as its lower limit, 256 as its upper limit.

  18. The definition of the TYPE-FILE command is terminated.

    %//show *com(type-f),siz=*max ————————————————————————————————————————— (19)
    TYPE-FILE

         Outputs the contents of an ISAM or SAM file to SYSOUT.
         NAME =
              filename_1..54
              Name of file to be output
         ACCESS-METHOD = *ISAM
              *ISAM() or *SAM
              STRUCTURE: *ISAM
                   KEY-LENGTH = 8
                        integer_1..8
         RECORD-SIZE = *VARIABLE
              *VARIABLE or integer_1..256
    %//end
    /type-file demo.1 ————————————————————————————————————————————————————— (20)
    %  CMD0186 OPERATION NAME 'TYPE-FILE' UNKNOWN
    /mod-sdf-opt synt-file=*add(*std) ————————————————————————————————————— (21)
    /type-f demo.1 ———————————————————————————————————————————————————————— (22)
    Contents of ISAM file DEMO.1

     .
     .
    /type-f demo.2,rec-siz=52
    Contents of ISAM file DEMO.2

     .
     .
    /type-f demo.3,isam(6)
    Contents of ISAM file DEMO.3

     .
     .

                                                                                                                                                                                                    

  19. The definition of the TYPE-FILE command, generated in the user syntax file SDF.USER.SYNTAX, is displayed in its most detailed form. By default, SDF-A has defined a minimum length of 1 and a maximum length of 54 for FILENAME.

  20. SDF rejects the TYPE-FILE command, since it is not defined in an activated syntax file.

  21. The user syntax file SDF.USER.SYNTAX is activated.

  22. Various ISAM files are displayed with the TYPE-FILE command:

    DEMO.1: the ISAM key is 8 bytes long, the record length is variable DEMO.2: the ISAM key is 8 bytes long, the records length is 52 bytes DEMO.3: the ISAM key is 6 bytes long, the record length is variable

    /type-f demo.4,sam,rec-siz=60 ————————————————————————————————————————— (23)
    Contents of SAM file DEMO.4

     .
     .
    /type-f? —————————————————————————————————————————————————————————————— (24)

                                                                                                                                                                                                    

  23. The SAM file DEMO.4 is displayed with the TYPE-FILE command. This file has a fixed

    record length of 60 bytes.

  24. Guided dialog is temporarily introduced for the input of the TYPE-FILE command.

    Further information is requested via the operands NAME and RECORD-SIZE.

    Contents of ISAM file DEMO.5

     .
     .
    /exit-job

The name of the file to be output is specified here as demo.5, and the record size is given as a fixed length of 55 bytes. The access method *ISAM(KEY-LENGTH=8) is the default value and is therefore preset.

The command is then executed. After the command has been executed the task is terminated.