-
Occurs
- 01 ANNUAL-SALES-DATA.
- 05 SALES OCCURS 12 TIMES PIC 9(6)
- Cannot use OCCURS clause on an 01 data item.
- OCCURS clause cause definition of field or group to be repeated in memory
-
Subscripts can be a calculated
- ( using + or- only) numeric integer expression
- 01 W01-SUB PIC 99.
- MOVE 5 TO W01-SUB
- MOVE 0 TO SALES(W01-SUB + 4)
-
Syntax of perform verb to create a subscript “ITERATOR”
- PERFORM procedure-1
- VARYING identifier-1
- FROM initial-value
- BY increment-value
- UNTIL condition-1
- -----------------------------
- PERFORM VARYING identifier-1
- FROM initial-value
- BY increment-value
- UNTIL condition-1
- some step (procedure-1)
- END-PERFORM
-
PERFORMING A PARAGRAPH
VS
PERFORMING AN INLINE PARAGRAPH
- MOVE ZERO TO W10-ANNUAL-TOTAL
- PERFORM A300-ACCUM-ANNUAL-TOTAL
- VARYING W03-SALES-SUB
- FROM 1 BY 1
- UNTIL W03-SALES-SUB > 12
- A300-ACCUM-ANNUAL-TOTAL.
- ADD W02-SALES(W03-SALES-SUB)
- TO W10-ANNUAL-TOTAL
- --------------------------------------------------
- MOVE ZERO TO W10-ANNUAL-TOTAL
- PERFORM VARYING W03-SALES-SUB
- FROM 1 BY 1
- UNTIL W03- SALES-SUB > 12
- ADD SALES(W03- SALES-SUB)
- TO W10-ANNUAL-TOTAL
- END-PERFORM
-
Fixed data in table
- Many tables are used to hold constant data ( or data that rarely changes )
- The table can then be used to “look up” to see if the constant exists.
- In order to define this fixed data, it can be “hard- coded” into the program in working storage.
- Need to use a REDEFINE to overlay the table definition on top of the data values.
-
-
Accept Verb
Accept verb is used to get data such as date, time, and day from the operating system or directly the from user. If a program is accepting data from the user, then it needs to be passed through JCL. While getting data from the operating system FROM option is included as shown in the following below example:
- ACCEPT W01-STUDENT-NAME.
- ACCEPT W01-DATE FROM SYSTEM-DATE.
-
Create a table from
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
- 01 RT-REGION-TABLE
- REDEFINES RT-REGION-DATA.
- 05 RT-REGION-ROW OCCURS 5 TIMES.
- 10 RT-REGION-ABBR PIC X(2).
- 10 RT-REGION-NAME PIC X(12).
-
Initialize a table with fixed data
- 01 DAY-TABLE VALUE
- “SUNMONTUEWEDTHUFRISAT”.
- 05 DAY-CODE OCCURS 7 PIC XXX.
-
all elements in the table have to be initialized with the same value
- 01 SALARY-TABLE.
- 05 SALARY-ROW OCCURS 10 TIMES.
- 10 SALARY PIC 9(6) VALUE 0.
- 10 YEAR PIC 9(4) VALUE 0.
- 10 TITLE PIC X(5) VALUE “NONE “.
- 01 SAL-MAX-OCCUR PIC 99 VALUE 10.
-
A table can be reset by using the ____________ command
INITIALIZE
- Default is to set all
- pic 9 variables to zero and
- pic x to spaces
- Must reference the entire table ( field name
- that has higher level number than the field
- with the OCCURS clause )
- INITIALIZE SALARY-TABLE
-
If you want special values in the table
- create a loop to step through the table and reset each element.
- PERFORM VARYING SUB FROM 1 BY 1
- UNTIL SUB > SAL-MAX-OCCUR
- MOVE 0 TO SALARY(SUB)
- MOVE 2014 TO YEAR(SUB)
- MOVE “NONE” TO TITLE(SUB)
- END-PERFORM
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
MOVE RT-REGION-ROW TO HOLD-AREA
IGYPS2028-E "RT-REGION-ROW" was a table-item but was not subscripted or indexed. The first occurrence of the table was assumed.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0035 MOVE RT-REGION-NAME TO HOLD-AREA
IGYPS2028-E "RT-REGION-NAME" was a table-item but was not subscripted or indexed. The first occurrence of the table was assumed.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0036 MOVE "NEW VIEW" TO RT-REGION-NAME (5)
No Error
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0037 MOVE RT-REGION-DATA TO HOLD-AREA
No Error , truncation does occur. What is resulting value of HOLD-AREA?
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0038 MOVE RT-REGION-NAME ( RT-REGION-ABBR)
TO HOLD-AREA
- 38 IGYPS2082-S "RT-REGION-ABBR" was used as a subscript but required subscripts itself. The statement was discarded.
- 38 IGYPS2013-E Not enough subscripts or indices were specified for "RT-REGION-NAME". A subscript or index value of 1 was assumed for each missing subscript or index.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0039 MOVE RT-REGION-NAME (HIGH-VALUES) TO HOLD-AREA
39 IGYPS2157-S Expected a numeric literal or an indexname in the "MOVE” statement, but found "HIGH-VALUES". The statement was discarded.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0040 MOVE RT-REGION-NAME( "HI") TO HOLD-AREA
40 IGYPS2157-S Expected a numeric literal or an indexname in the "MOVE” statement, but found ""HI"". The statement was discarded.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0041 MOVE RT-REGION-NAME (6) TO HOLD-AREA
41 IGYPS2073-E Subscript or index literal "6" exceeded the maximum occurrence value "5" for the table. The maximum occurrence value was assumed.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0042 MOVE RT-REGION-NAME (ITEM) TO HOLD-AREA
No error, the compiler does not know what the value of variable ITEM will be at execution time. Compile option SSRANGE will restrict to valid value.
-
WORKING-STORAGE SECTION.
01 RT-REGION-DATA.
10 PIC X(14) VALUE 'GSGREAT SMOKEY'.
10 PIC X(14) VALUE 'RVRIM VIEW '.
10 PIC X(14) VALUE 'MEMETROPOLITAN'.
10 PIC X(14) VALUE 'HIHINTERLAND'.
10 PIC X(14) VALUE 'LVLAKE VIEW '.
01 RT-REGION-TABLE REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
01 HOLD-AREA PIC X(14).
01 ITEM PIC 99.
0043 ADD 6 TO ITEM
0044 MOVE RT-REGION-NAME (ITEM) TO HOLD-AREA
No error, the compiler does not know what the value of variable ITEM will be at execution time even though it appears that an execution error will occur.
-
One data record used to store Student id, name, term and course grades for each student
Each student can take anywhere from one to eight courses in a term
- 01 F01-STU-RECORD.
- 05 F01-STU-ID PIC X(6).
- 05 F01-STU-NAME PIC X(10).
- 05 F01-STU-TERM PIC X(3).
- 05 F01-STU-CNT PIC 9.
- 05 F01-STU-GRADES
- OCCURS 1 TO 8 TIMES
- DEPENDING ON F01-STU-CNT.
- 10 F01-STU-COURSE PIC X(4).
- 10 F01-STU-GRADE PIC X(2).
-
Variable Length Tables Record Layout
- Fixed part: The beginning of the record must have the FIXED size information
- Variable part: The grades are the variable portion that follow the fixed portion
- Must specify a MAXIMUM possible value following the OCCURS keyword.
- DEPENDING variable will tell ACTUAL number
-
FD for Variable records
- Some compilers need to be told the variations in the record size when the FD is defined
- Give the minimum and max size in bytes
- FD F01-STU-FILE
- RECORD CONTAINS min TO max.
- Minimum is fixed portion plus minimum of variable
- Max is fixed portion plus max of variable
-
01 F01-STU-RECORD.
05 F01-STU-ID PIC X(6).
05 F01-STU-NAME PIC X(10).
05 F01-STU-TERM PIC X(3).
05 F01-STU-CNT PIC 9.
05 F01-STU-GRADES
OCCURS 1 TO 8 TIMES
DEPENDING ON F01-STU-CNT.
10 F01-STU-COURSE PIC X(4).
10 F01-STU-GRADE PIC X(2).
What is FD?
- FD F01-STU-FILE
- RECORD CONTAINS 26 TO 68.
- 26 = 6+10+3+1+1(4+2)
- 68 = 6+10+3+1+8(4+2)
-
01 F01-STU-RECORD.
05 F01-STU-ID PIC X(6).
05 F01-STU-NAME PIC X(10).
05 F01-STU-TERM PIC X(3).
05 F01-STU-CNT PIC 9.
05 F01-STU-GRADES
OCCURS 1 TO 8 TIMES
DEPENDING ON F01-STU-CNT.
10 F01-STU-COURSE PIC X(4).
10 F01-STU-GRADE PIC X(2).
what is print report detail line?
- 01 W01-RPT-DETAIL.
- 05 W01-ID PIC BBX(6).
- 05 W01-NAME PIC BBX(10).
- 05 W01-TERM PIC BBX(3).
- 05 W01-GRADES OCCURS 8 TIMES.
- 10 W01-COURSE PIC BBX(4).
- 10 W01-GRADE PIC BX(2).
- Always print a full 8 grades
- Must make sure unused print grades are blank
-
01 F01-STU-RECORD.
05 F01-STU-ID PIC X(6).
05 F01-STU-NAME PIC X(10).
05 F01-STU-TERM PIC X(3).
05 F01-STU-CNT PIC 9.
05 F01-STU-GRADES
OCCURS 1 TO 8 TIMES
DEPENDING ON F01-STU-CNT.
10 F01-STU-COURSE PIC X(4).
10 F01-STU-GRADE PIC X(2).
01 W01-RPT-DETAIL.
05 W01-ID PIC BBX(6).
05 W01-NAME PIC BBX(10).
05 W01-TERM PIC BBX(3).
05 W01-GRADES OCCURS 8 TIMES.
10 W01-COURSE PIC BBX(4).
10 W01-GRADE PIC BX(2).
move values from FD to detail for printing
- *** clear entire record first
- INITIALIZE W01-RPT-DETAIL
- MOVE F01-STU-ID TO W01-ID
- MOVE F01-STU-NAME TO W01-NAME
- MOVE F01-STU-TERM TO W01-TERM
- PERFORM VARYING W02-SUB FROM 1 BY 1
- UNTIL W02-SUB > F01-STU-CNT
- MOVE F01-STU-COURSE (W02-SUB) TO
- W01-COURSE (W02-SUB)
- MOVE F01-STU-GRADE (W02-SUB) TO
- W01-GRADE (W02-SUB)
- END-PERFORM
-
A store identifies every product they sell by a UPC code and each product has a description and price.
The number of products changes often.
The prices change often.
- Cannot “hard code” the data inside a COBOL program
- Store the data in a text file, easy to change.
- We need a table to hold all the records in memory.
- Put data in memory to allow for fast reference ( often repeated ) to the data.
-
a file contains product info. Each record is
6 char UPC
10 char description
99.99 price
Write table working storage that can hold max 500 products.
- 01 W03-PROD-COUNT PIC 999 VALUE 0.
- 01 W03-PROD-MAX PIC 999 VALUE 500.
- 01 W03-PROD-TABLE.
- 05 W03-PRODUCTS
- OCCURS 1 TO 500 TIMES
- DEPENDING ON W03-PROD-COUNT.
- 10 W03-UPC PIC X(6).
- 10 W03-DESC PIC X(10).
- 10 W03-PRICE PIC 99V99.
-
a file contains product info. Each record is
6 char UPC
10 char description
99.99 price
Write file definition.
- SELECT F01-PRD-FILE ASSIGN TO
- F01PROD.
- FD F01-PRD-FILE.
- 01 F01-PRD-RECORD PIC X(20).
-
Load variable length table from file.
- INITIALIZE W03-PROD-TABLE
- OPEN INPUT F01-PRD-FILE
- MOVE 'N' TO W01-EOF-SW
- MOVE 0 TO W03-PROD-COUNT
- PERFORM UNTIL W01-EOF-SW = 'Y'
- READ F01-PRD-FILE
- AT END
- MOVE 'Y' TO W01-EOF-SW
- NOT AT END
- IF W03-PROD-COUNT < W03-PROD-MAX
- ADD 1 TO W03-PROD-COUNT
- MOVE F01-PRD-RECORD TO
- W03-PRODUCTS (W03-PROD-COUNT)
- ELSE
- DISPLAY “OVERFLOW – CANNOT LOAD “
- F01-PRD-RECORD
- END-IF
- END-READ
- END-PERFORM
- CLOSE F01-PRD-FILE
- .
-
Find the subscript of the max price product in the table
- MOVE 1 TO W04-MAX
- PERFORM VARYING
- W04-LOOK FROM 2 BY 1
- UNTIL W04-LOOK > W03-PROD-COUNT
- IF W03-PRICE(W04-MAX) <
- W03-PRICE(W04-LOOK)
- MOVE W04-LOOK TO W04-MAX
- END-IF
- END-PERFORM
- DISPLAY “THE MAX PRICE IS “
- W03-PRICE(W04-MAX)
-
Table INDEX
- The biggest use of tables is searching them to look-up codes.
- COBOL implements a SEARCH verb ( command ) t
- more efficient than iteration.
- SEARCH requires the use of an INDEX ,
- not a subscript
- INDEX is another form of identifying which element to reference in a table.
- designed for speed and efficiency.
- you do not create an index as a separate variable,
- provide name to use as index when you specify the OCCURS clause:
- OCCURS n TIMES INDEXED BY wnn-index.
-
Define a table with an index. Show fast and slow code.
- 01 W01-AGENT-TABLE.
- 05 W01-AGENT-NAME PIC X(10)
- OCCURS 20 INDEXED BY W01-IDX.
- *** FAST CODE
- SET W01-IDX TO 2
- MOVE “JACK” TO W01-AGENT-NAME(W01-IDX)
- *** SLOW CODE, BUT IT ALSO WORKS
- MOVE “JANE” TO W01-AGENT-NAME(4)
-
SUBSCRIPT VS INDEX
- SUBSCRIPT: number equal to the “element occurrence number”
- INDEX: value of the address offset
- (number of bytes from the start of the table)
- Actual value = ( element-occurrence# - 1 ) * ( length of one occurrence)
- cannot use MOVE or regular arithmetic verbs to modify an INDEX
- Can only modify an INDEX by using SET, PERFORM-VARYING or SEARCH
- there is an automatic conversion of an index to “element occurrence number” when used in a relational expression
- IF W01-IDX = 1 is valid
-
index values
- The SET command can do assignment ( both ways ) and add or subtract.
- SET W01-INDEX TO 5 calculates the offset address of 5th element and save it in W01-INDEX
- SET W01-INDEX TO W02-SUB uses value in W02-SUB and converts that occurrence number to the offset address and save it in W01-INDEX
- SET W02-SUB TO W01-INDEX converts the current offset address stored in W01-INDEX to an occurrence value and saves it in W02-SUB.
- SET W01-INDEX UP BY 1 adds element length to offset address held in W01-INDEX
- SET W01-INDEX DOWN BY W02-SUB increase or
- decrease index
- SET W01-INDEX TO W02-INDEX converts w02-index from offset in table2 to an occurrence number, then calculates the offset address of that occurrence in table1 and stores into w01-index.
-
Serial SEARCH
- SEARCH table-row:
- the field with OCCURS & INDEX
- AT END
- do the not found logic
- WHEN condition1
- do found the condition1 logic
- WHEN condition2
- do found the condition2 logic
- WHEN . . .
- END-SEARCH
- the table-row is where the OCCURS clause is specified, and it must have an INDEXED BY clause
- you should initialize the index value before the SEARCH, normally set to 1 to search entire table
- If you do not set the index, the current value is used
- The AT END occurs when the index reaches the OCCURS limit.
- Increment and test for end is automatic
-
Serial SEARCH will do
- check all WHEN clauses in order they appear
- if a WHEN is true, then it’s logic is executed and go to END-SEARCH
- If no WHEN is true, the INDEX is incremented by 1 and start the WHEN’s again ( set index up by 1 )
- if the index equivalent occurrence number is greater
- than the table row OCCURS value, then the AT END is true, statements execute and go to END-SEARCH.
- After the end of the SEARCH, the INDEX retains the value that the SEARCH left it at.
-
01 W01-AGENT-TABLE.
05 W01-AGENT-NAME PIC X(10)
OCCURS 20 INDEXED BY W01-IDX.
Search agent table for match to name in
F01-AGENT-NAME.
- SET W01-IDX TO 1
- SEARCH W01-AGENT-NAME
- AT END DISPLAY “AGENT NOT FOUND”
- WHEN W01-AGENT-NAME(W01-IDX) =
- F01-AGENT-NAME
- DISPLAY “FOUND AGENT “
- W01-AGENT-NAME(W01-IDX)
- END-SEARCH
-
01 RT-REGION-TABLE
REDEFINES RT-REGION-DATA.
05 RT-REGION-ROW OCCURS 5 TIMES
INDEXED BY RT-IDX.
10 RT-REGION-ABBR PIC X(2).
10 RT-REGION-NAME PIC X(12).
Serial SEARCH
Example using abbreviation lookup
- ACCEPT IN-ABBR
- SET RT-IDX TO 1
- SEARCH RT-REGION-ROW
- AT END DISPLAY “CODE NOT IN TABLE”
- WHEN RT-REGION-ABBR(RT-IDX) =
- IN-ABBR
- DISPLAY “THAT IS REGION “
- RT-REGION-NAME(RT-IDX)
- END-SEARCH
-
-
- 01 SALARY-VALUES.
- 05 FILLER PIC X(25) VALUE '2600027000280002900030000'.
- 05 FILLER PIC X(25) VALUE '2700028000290003000031000'.
- ...
- 05 FILLER PIC X(25) VALUE '4600050000540005800062000'.
- 01 SALARY-TABLE REDEFINES SALARY-VALUES.
- 05 RESPONSIBILITY OCCURS 10 TIMES.
- 10 EXPERIENCE OCCURS 5 TIMES.
- 15 SALARY PIC 9(5).
-
80/20
- The 80/20 rule states that 80% of the matches will come from 20% of the codes.
- Example, if Toronto is the busiest airport in Canada, then put YYZ in the first row of the table
-
WHEN clause
- The condition of the WHEN clause must have the table key field first,example
- WHEN TABLE-KEY-CODE(IDX) = INPUT-CODE
- is valid, but
- WHEN INPUT-CODE = TABLE-KEY-CODE(IDX)
- is not valid
- The condition can ONLY use the “EQUALS” operator
- Can have compound “AND” condition
-
01 W01-PROV-TABLE.
05 W01-PROV-DATA.
10 PIC X(20) VALUE ‘ABAlberta’.
10 PIC X(20) VALUE ‘BCBritish Columbia’.
...
05 REDEFINES W01-PROV-DATA.
10 W01-PROV-ROW OCCURS 13 TIMES
ASCENDING KEY IS W01-PROV-CODE
INDEXED BY W01-PROV-IDX.
15 W01-PROV-CODE PIC X(2).
15 W01-PROV-NAME PIC X(18).
Search All
- SEARCH ALL W01-PROV-ROW
- AT END
- DISPLAY "Province not found"
- MOVE SPACES TO W05-PRINT-PROV-NAME
- WHEN W01-PROV-CODE(W01-PROV-IDX)
- = IN-PROV-CODE
- MOVE W01-PROV-NAME(W01-PROV-IDX) TO
- W05-PRINT-PROV-NAME
- END-SEARCH.
-
define benefits summary table that has 11 offices and 5 benefit types
- 01 W02-BEN-SUMRY-TBL.
- 05 W02-OFFICE OCCURS 11 TIMES.
- 10 W02-BEN-CODE OCCURS 5 TIMES.
- 15 W02-MONTH-TOTAL
- PIC 9(5)V99 VALUE 0.
-
Put the following in a table for easy searching.
01 W04-BENEFIT-CODES.
05 PIC X(11) VALUE '1LIFE '.
05 PIC X(11) VALUE '2DENTAL '.
05 PIC X(11) VALUE '3HOSP '.
05 PIC X(11) VALUE '4RRSP '.
05 PIC X(11) VALUE '5PENSION '.
- 01 W04-BENEFIT-TABLE REDEFINES
- W04-BENEFIT-CODES.
- 05 W04-BENEFIT-ROW OCCURS 5 TIMES
- ASCENDING KEY IS W04-BEN-CODE
- INDEXED BY W04-BEN-INDX.
- 10 W04-BEN-CODE PIC 9.
- 10 W04-BEN-NAME PIC X(10).
- 01 W04-BEN-FOUND PIC 99 VALUE 0.
-
01 W04-BENEFIT-TABLE REDEFINES
W04-BENEFIT-CODES.
05 W04-BENEFIT-ROW OCCURS 5 TIMES
ASCENDING KEY IS W04-BEN-CODE
INDEXED BY W04-BEN-INDX.
10 W04-BEN-CODE PIC 9.
10 W04-BEN-NAME PIC X(10)
01 W04-BEN-FOUND PIC 99 VALUE 0.
Search the table for the benefit code.
- (wrong INITIALIZE W04-BEN-INDX)
- SET W04-BEN-INDX TO 1
- SEARCH ALL W04-BENEFIT-ROW
- AT END
- DISPLAY 'not found'
- WHEN W04-BEN-CODE(W04-BEN-INDX) =
- W05-EMP-BEN-CODE(W02-BEN-SUB)
- SET W04-BEN-FOUND TO W04-BEN-INDX
- do something
- END-SEARCH
- .
-
process record in Assign2
READ
PERFORM A200-PROCESS-RECORD
UNTIL W01-AT-EOF
- perform office-search
- PERFORM B200-SEARCH-OFFICE
- PERFORM VARYING W02-BEN-SUB
- FROM 1 BY 1
- UNTIL W02-BEN-SUB >5
- IF W05-BEN-CODE(W02-BEN-SUB)
- IS NOT = SPACES
- PERFORM B300-BEN-SEARCH-BENEFIT
- ADD W05-EMP-BEN-COST(W02-BEN-SUB)
- TO W02-MONTH-TOTAL(OFF-FOUND,
- BEN-FOUND)
- END-IF
- END-PERFORM
- PERFORM B100-READ-EMP-BEN-FILE
- .
-
write office monthly benefits table to detail line and print
- PERFORM VARYING W2-OFF-SUB
- FROM 1 BY 1
- UNTIL W02-OFF-SUB>11
- INITIALIZE W02-OFFICE-TOTAL
- MOVE W03-CITY-NAME(W02-OFF-SUB)
- TO W09-OFF-NAME-OUT
- PERFORM VARYING W02-BEN-SUB
- FROM 1 BY 1
- UNTIL W02-BEN-SUB > 5
- MOVE TOTAL(OFF-SUB,BEN-SUB)
- TO BEN-MONTH-OUT(BEN-SUB)
- ADD TOTAL(OFF-SUB,BEN-SUB)
- TO OFF-TOTAL
- END-PERFORM
- MOVE OFF-TOTAL TO OFF-TOT-OUT
- WRITE OUTPUT-REC FROM DET-LINE
- ADD OFF-TOTAL TO COMP-TOTAL
- END-PERFORM
-
Packed Decimal
- Primarily used for monetary figures
- Allows up to maximum of 15 decimal digits
- 01 MY-CREDIT-LIMIT
- PIC S9(13)V99 COMP-3.
- Thus, I could be up to
- $9,999,999,999,999.99 in debt, or 10 trillion
- dollars minus a cent.
-
- VERTICAL HEX: The EBCDIC character, the first HEX nibble, the second HEX nibble
- The first byte contains the character “M”, which is actually composed of the hex nibble x'D' followed by nibble x'4'.
- The EBCDIC code for “M” is x'D4'.
-
- The first amount is in column 11 through 14.
- By shifting each nibble from vertical to horizontal, we get the full hex value of x'0032165C' . Using the field definition of PIC S99999V99 COMP-3, = decimal number 00321.65+
-
The fourth quarter budget amount is:
Note that the x'80' happens to be the EBCDIC code for ___
- x'0280000C' = 2800.00+
- Note that the x'80' happens to be the EBCDIC
- code for “~” , just a random happening.
-
Value 123 = in binary and hex
- binary value '0111 1011'
- To view the binary number, it is easier to
- show as two hexadecimal characters.
- B'0111' = X'7', B'1011' = X'B'
- B'0111 1011' = X'7B'
- Thus PIC 9(3) COMP VALUE 123. will have
- memory value of X'007B'
-
COMP-3
Value 123 in binary
PIC 9(3) COMP-3 VALUE 123. will have memory value _____
- – keeps the numeric value of a number as individual decimal digits, but each decimal digit is stored as it's equalivent binary value.
- Value 123
- = digits binary value '0001 0010 0011'
- • Again, instead of viewing binary, we show
- the hex equal.
- Thus PIC 9(3) COMP-3 VALUE 123. will have memory value of X'123C'
-
Find the tax rate given the salary
- 01 TAXRATES.
- 05 PIC 9(6)V99 VALUE '25000025'.
- 05 PIC 9(6)V99 VALUE '10000017'.
- 05 PIC 9(6)V99 VALUE '01000015'.
- 01 TAXRATE-TBL REDEFINES TAXRATES
- 05 TAX-ROW OCCURS 3 TIMES
- DESCENDING KEY IS SAL
- INDEXED BY TAX-INDX.
- 10 LOW-SAL PIC 9(5).
- 10 TX-RATE PIC 9V99.
- SET TAX-INDX TO 1.
- SEARCH TAX-ROW
- AT-END
- MOVE 0 TO EMP-TAX-RATE
- WHEN EMP-SAL>=LOW-SAL(TAX-INDX)
- MOVE TX-RATE(TAX-INDX)
- TO EMP-TAX-RATE
- END-SEARCH
-
01 W01-AGENT-TABLE.
05 W01-AGENT-ROW OCCURS 1 TO 2000
DEPENDING ON W01-AGENT-NUM
INDEXED BY W01-AIX.
10 W01-AG-CODE PIC X(4) VALUE LOW-VALUES.
10 W01-AG-TOT PIC 9(7) VALUE 0.
01 W01-AGENT-NUM PIC 9999 VALUE 0.
How do you find the max, mean, sum?
- COMPUTE W01-MAX-TOTAL = FUNCTION MAX(W01-AG-TOT(ALL))
- DISPLAY 'TOP SALE TOTAL IS ' W01-MAX-TOTAL
- also FUNCTION MEAN(...
- FUNCTION SUM(....
|
|