----------------------------------------------------------------------------------------------------------
Codes for representing data in a computer.

EBCDIC  (EXTENDED Binary Coded Decimal Interchange Code)
ASCII   (American Standard Code for Information Interchange)

Collating sequence -- The most common printable data is sorted according to its numeric representation.  The codes arranged from low to high (sort order) are:

  ASCII (PC/UNIX)           EBCDIC (IBM)

  space                     space
  0-9                       a-z
  A-Z                       A-Z
  a-z                       0-9
 

  -------------------------------------------------------------------

USAGE DISPLAY -- External Decimal Numbers.  (Zoned Decimal)

01 VALUE-1 PIC  99.
01 VALUE-2 PIC  99 USAGE DISPLAY.
 

    Is the following series legal in COBOL?

      MOVE '40' TO VALUE-1
      COMPUTE VALUE-2 = VALUE-1 + 59.

What is the content of VALUE-2 after the following?

    MOVE 40 TO VALUE-1
    COMPUTE VALUE-2 = VALUE-1 - 60.

--------------------------------------------------------------------
USAGE DISPLAY -- Signed External Decimal Numbers.

01 VALUE-3 PIC  S99.
01 VALUE-4 PIC  S99 USAGE DISPLAY.
 

            last digit contains          for values ending in

        'A' through 'I' , '{'          +1 through +9, +0
        'J' through 'R',  '}'          -1 through -9, -0

What is the numeric value of VALUE-4 if a '5L' is printed after
the program statement?

                DISPLAY VALUE-4
 

---------------------------------------------------------------------
USAGE COMP  -- Binary Numbers

 PIC S999 USAGE COMPUTATIONAL.
 PIC 9999 USAGE COMP.
 PIC 99 USAGE BINARY.
 

            Pictures of:           use                         
            9     to 9(4)          2 bytes of storage
            9(5)  to 9(9)          4 bytes (full word)
            9(10) to 9(18)         8 bytes (2 full words) 

 INTEGER BINARY   HEXADECIMAL EBCDIC ASCII
    0    00000000     0         FO     30
    1    00000001     1         F1     31
    2    00000010     2         F2     32
    3    00000011     3         F3     33
    4    00000100     4         F4     34
    5    00000101     5         F5     35
    6    00000110     6         F6     36
    7    00000111     7         F7     37
    8    00001000     8         F8     38
    9    00001001     9         F9     39
   10    00001010     A       F1F0   3130
   11    00001011     B       F1F1   3131
   12    00001100     C       F1F2   3132
   13    00001101     D       F1F3   3133
   14    00001110     E       F1F4   3134
   15    00001111     F       F1F5   3135
   16    00010000    10       F1F6   3136
 

---------------------------------------------------------------------

USAGE PACKED-DECIMAL

 PIC S999 USAGE COMPUTATIONAL-3.
 PIC S999 USAGE COMP-3.
 PIC S99V9 USAGE PACKED-DECIMAL.
 

        01 VALUE-5 PIC S99 USAGE COMP-3.
        01 VALUE-6 PIC S999 USAGE COMP-3.
 
      Both VALUE-5 and VALUE-6 require the same amount of storage space.
          Given a PIC S9 COMP-3

        If the Integer Value is,
        +1 it is stored as binary 00011100 or hex value 1C
        -1                   "    00011101     "        1D
         1                   "    00011111     "        1F

----------------------------------------------------------------------------------------------------------
 ----------------------------------------------------------------------------------------------------------

PARM - "PARAMETER" - a JCL value which can be input to a program.

Up to 100 bytes of information to a batch program through JCL PARM statement.

----------------------------------------------------------------------------------------------------------

How to use a JCL PARM?

Code the PARM statment directly when executing the program directly.

ie //STEP020  EXEC PGM=PARMCODE,PARM='401-999,OVERTIME'

To override a PARM statement on PROCs, use the pattern PARM.procstepname

ie. //STEP020 EXEC PROC=COB2J,PARM.GO='401-999,OVERTIME'

----------------------------------------------------------------------------------------------------------

  IDENTIFICATION DIVISION.
  PROGRAM-ID.  PARMCODE.
  ENVIRONMENT DIVISION.
  DATA DIVISION.
  WORKING-STORAGE SECTION.
  01  DISPLAY-NUMBER   PIC ZZZ9.
  LINKAGE SECTION.
  01  PARM-FIELDS.
   05  PARM-CHAR-COUNT  PIC S9(4) COMP.
   05  PARM-INPUT           PIC X(100).
  PROCEDURE DIVISION USING PARM-FIELDS.
  000-MAINLINE.
            MOVE PARM-CHAR-COUNT TO DISPLAY-NUMBER
            DISPLAY 'TOTAL CHARACTERS INPUT = ' DISPLAY-NUMBER
            DISPLAY 'PARM FIELD PUT INTO PROGRAM IS = ' PARM-INPUT
            MOVE PARM-CHAR-COUNT TO RETURN-CODE
       GOBACK.

-------------------------------------------------------------------
Why use a JCL PARM?

To pass explicit data to a program.  The program starts with the data passed data embedded in its linkage section.

Two other methods of passing data would be an ACCEPT statement or the OPEN FILE, READ statement within the program.

--------------------------------------------------------------------

IDENTIFICATION DIVISION.
PROGRAM-ID. PGMWPARM.
**************************************************************
*  PROGRAM RECEIVES INFO FROM JCL THRU PARM PARAMETER.  IF   *
*  NO PARM IS SPECIFIED, PROGRAM DEFAULTS AND WRITES ALL THE *
*  RECORDS.  IF PARM IS SPECIFIED, PROGRAM WRITES ONLY THOSE *
*  RECORDS THAT MATCH THE PARM.                              *
**************************************************************
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
 SELECT GRADESI ASSIGN TO DATAIN.
 SELECT GRADESO ASSIGN TO DATAOUT.
DATA DIVISION.
FILE SECTION.
FD  GRADESI
 BLOCK CONTAINS 0 RECORDS
 RECORD CONTAINS 80 CHARACTERS
 RECORDING MODE IS F
 LABEL RECORDS ARE STANDARD
 DATA RECORD IS GI-REC.
01  GI-REC.
 05  GI-SCHOOL             PIC X(3).
 05  GI-DEPT               PIC X(3).
 05  GI-STUNUM             PIC X(4).
 05  GI-NAME               PIC X(20).
 05  GI-GRADES OCCURS 5 TIMES.
  10 GI-LETTER          PIC X.
  10 GI-FILL            PIC X.
 05  FILLER                PIC X(40).

FD  GRADESO
 BLOCK CONTAINS 0 RECORDS
 RECORD CONTAINS 80 CHARACTERS
 RECORDING MODE IS F
 LABEL RECORDS ARE STANDARD
 DATA RECORD IS GO-REC.
01  GO-REC                    PIC X(80).

 WORKING-STORAGE SECTION.
 01  EOF-SW                    PIC X  VALUE ' '.
     88  EOF                          VALUE 'Y'.

 01  W-DISPLAY.
     05  FILLER                PIC X(31)  VALUE
   'RECORDS LISTED FROM JCLGRDS - '.
     05  W-SELECTION           PIC X(3).
     05  FILLER                PIC X(46)  VALUE SPACES.

LINKAGE SECTION.
01  PARMINFO.
 05  PARM-LENGTH           PIC S9(4) COMP.
 05  PARM-DATA.
         10  PARM-SCHOOL       PIC X(3).
         10  FILLER            PIC X(97).
PROCEDURE DIVISION USING PARMINFO.
 PERFORM 100-START.
 PERFORM 200-LOOP UNTIL EOF.
 PERFORM 300-END-IT-ALL.
100-START.
 IF PARM-LENGTH = 0
    MOVE 'ALL'  TO W-SELECTION
 ELSE
  IF PARM-LENGTH < 4
     MOVE PARM-SCHOOL TO W-SELECTION
  ELSE
     DISPLAY '==> INVALID JCL PARM, PROGRAM TERMINATED <=='
     MOVE 100  TO RETURN-CODE
     STOP RUN.
 OPEN  INPUT  GRADESI
  OUTPUT GRADESO.
 READ GRADESI AT END MOVE 'Y' TO EOF-SW.
 DISPLAY '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'.
 DISPLAY 'LIST 'W-DISPLAY 'SCHOOLS'.
 DISPLAY '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'.
200-LOOP.
 IF W-SELECTION = 'ALL'
    MOVE GI-REC TO GO-REC
    WRITE GO-REC
 ELSE
    IF GI-SCHOOL = W-SELECTION
    MOVE GI-REC TO GO-REC
    WRITE GO-REC.
 READ GRADESI AT END MOVE 'Y' TO EOF-SW.
300-END-IT-ALL.
 MOVE '*** E N D   O F   L I S T ***' TO GO-REC.
 WRITE GO-REC.
 CLOSE GRADESI GRADESO.
 STOP RUN.

----------------------------------------------------------------------------------------------------------
Program 4 (Review page 55 through page 72)
----------------------------------------------------------------------------------------------------------
Reading Indexed Files randomly

VSAM records
 

----------------------------------------------------------------------------------------------------------
Select statement for reading Indexed VSAM randomly.

 SELECT File-name ASSIGN TO ddname
      ORGANIZATION IS INDEXED
      ACCESS IS RANDOM
      RECORD KEY IS primary-key-field
      FILE STATUS IS ws-status-field.

File-name -- name used in FD, OPEN, READ, CLOSE statements

Ddname    -- //ddname JCL reference

Primary-key-field -- program name used for primary key

Ws-status-field -- 2 character field for file access codes indicating success or reason for failure.

----------------------------------------------------------------------
FD STATEMENT

FD   file-name
     RECORD CONTAINS length CHARACTERS
Or   RECORD VARYING FROM minimum to maximum CHARACTERS
Or   RECORD VARYING FROM minimum to maximum CHARACTERS
     DEPENDING ON count-field-within-record
01   record-description.
     05 fields-within-record         PIC X..
     05 primary-key-field            PIC X(??)
     05 fields-within-record         PIC X..

----------------------------------------------------------------------------------------------------------
READING RANDOMLY - program actions depend on success of the read
                   Always test for success of prior READ statement.
(method 1)

         OPEN file-name
         MOVE some-value TO primary-key-field
         READ file-name [INTO record-identifier]
              INVALID KEY
                  Executed statements if key not found
              NOT INVALID KEY
                  Executed statements if key found
         END-READ

----------------------------------------------------------------------------------------------------------
READING RANDOMLY

(method 2)

         OPEN file-name
         MOVE some-value TO primary-key-field
         READ file-name [INTO record-identifier]
         IF ws-file-status = '00'
              Executed statements if key found
         ELSE
              Executed statements if key NOT found
         END-IF

----------------------------------------------------------------------------------------------------------