----------------------------------------------------------------------------------------------------------
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

• EBCDIC and ASCII codes are printable data.  If data is not in EBCDIC or ASCII code, then it has to be transformed to that format before it can be printed as standard characters.

• Each EBCDIC or ASCII character requires 1 byte of storage.
-------------------------------------------------------------------

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

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

• VALUE-1 and VALUE -2 are numeric if they contain numeric digits as EBCDIC or ASCII data.   What is the EBCDIC value of  '1'  '5'  '9' ?

• EBCDIC or ASCII codes are immediately printable but not immediately usable for computer math.  The computer must transformation them to an internal format suitable for computation.

• 1 storage location is needed for every digit in the picture clause.
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.

• VALUE-3 and VALUE-4 are numeric if they contain numeric digits as EBCDIC or ASCII data.

• 1 storage location is needed for every digit in the picture clause.

• The content in value-1 and value-2 is numeric if all digits contain numbers as character data or
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

• Signed external decimal numbers are immediately printable but not immediately usable for computer math.  The computer must transformation them to an internal format suitable for computation.
---------------------------------------------------------------------
USAGE COMP  -- Binary Numbers

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

• Binary numbers suit computer math but are not normally printed because they would be hard to read.
• Move to an external decimal or edited data field before printing.
• Computers are binary machines, so binary numbers are the most efficient for computer math.  Use binary for internal counters and subscripts.
• Do not use for numbers containing decimals.  There is a loss of decimal accuracy because binary numbers can only approximate decimal results.
• The number of digits used for the picture determines the amount of storage used.
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)

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.

• Use for saving space when storing numbers or for computer math but move to an external decimal or edited data field before printing.
• This form of storage can have up to 18 digits in the picture and is useful for decimal results (percentages, dollars and cents, etc).
• Stored 2 digits per byte, except for the last byte which contains a digit and the sign + as C, - as D, unsigned as F.
• The number of bytes required to store a comp-3 is determined by counting the number of digits in the picture, add 1 for the sign (if the total is not an even number, add another 1), then divide by 2.
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.

• Each digit and the sign occupies a half-byte of storage.  Four binary digits represent each digit.
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.
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.
DATA DIVISION.
FILE SECTION.
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).
10 GI-LETTER          PIC X.
10 GI-FILL            PIC X.
05  FILLER                PIC X(40).

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.

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.
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.
300-END-IT-ALL.
MOVE '*** E N D   O F   L I S T ***' TO GO-REC.
WRITE GO-REC.
STOP RUN.

----------------------------------------------------------------------------------------------------------
Program 4 (Review page 55 through page 72)
----------------------------------------------------------------------------------------------------------

VSAM records

• contain at least one unique key field -- the primary key.
• are stored in sequential order based on the primary key.
• could be read sequentially (no key reference) or randomly (explicit key given).

----------------------------------------------------------------------------------------------------------
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…..

----------------------------------------------------------------------------------------------------------
Always test for success of prior READ statement.
(method 1)

OPEN file-name
MOVE some-value TO primary-key-field
INVALID KEY
NOT INVALID KEY
Executed statements if key found

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

(method 2)

OPEN file-name
MOVE some-value TO primary-key-field