lecture 31 numeric edited alphabetic (a) alphanumeric (x) numeric (9, v, s) numeric edited (9, z,...

24
lecture 3 1 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) Z = zero suppressed digit Value PIC Stored 0 Z(4) (spaces ) 0 ZZZ9 0 87 ZZZ9 87 +2,319 ZZ,ZZZ- 2,319 -338 ZZ,ZZZ- 338- +5,933 Z,ZZZ.9 9- 5,933.0 0 -.05 Z,ZZZ.9 .05-

Upload: esther-weaver

Post on 01-Jan-2016

229 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 1

Numeric Edited

• Alphabetic (A)• AlphaNumeric (X)• Numeric (9, V, S)

• Numeric Edited (9, Z, comma, decimal point, minus sign)– Z = zero suppressed

digit

Value PIC Stored

0 Z(4) (spaces)

0 ZZZ9 0

87 ZZZ9 87

+2,319 ZZ,ZZZ- 2,319

-338 ZZ,ZZZ- 338-

+5,933 Z,ZZZ.99- 5,933.00

-.05 Z,ZZZ.99- .05-

Page 2: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 2

PROCEDURE DIVISION

• Contains instructions to read, process, and output data

• I/O operations (OPEN, CLOSE, READ, WRITE), MOVE, DISPLAY, ACCEPT, Arithmetic (ADD, SUBSTRACT, MULTIPLY, DIVIDE), STOP RUN, …

Page 3: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 3

Coding the Procedure Division

• Divide into paragraphs

• Each paragraph represents one procedure

• The first procedure should represent the function of the entire program

• The procedures called by the first procedure should represent the functions performed by those procedures

Page 4: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 4

PERFORM/PERFORM UNTIL

PERFORM procedure-name.• Skips to the named procedure, executes it, and returns to the

statement after the PERFORM.

PERFORM procedure-name UNTIL condition.• Execute the procedure until the condition is true.

• It’s a loop statement

• The condition is tested first

• Execution continues after PERFORM when condition is true.

Page 5: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 5

STOP RUN statement

STOP RUN.

• Terminates the program

• Should appear only once in your program

• All files should be closed prior to executing this statement

Page 6: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 6

MOVE - Assignment MOVE {data-name | literal } TO data-name-2 … .

Copies data from a sending field to one or more receiving fields

MOVE NUMBER-ENTERED TO PAY-RATE.MOVE “Y” TO END-OF-SESSION-SWITCH.MOVE 1 TO PAGE-NUMBER.

Move data to multiple locationsMOVE 15 TO NUM-1 NUM-2 NUM-3

Page 7: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 7

MOVE

• The original data is retained in the sending field (only a copy operation)

• If the sending field is numeric and the receiving field is numeric edited, the MOVE converts from one form to the other

• If (receiving field size > sending field size) then– filled out with trailing blanks in an alphanumeric move,

or– leading zeros in a numeric move

• If (receiving field size < sending field size) then moved data is truncated

Page 8: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 8

SENDING FIELD RECEIVING FIELD

Alphabetic

Alphanumeric

Numeric

Numeric Edited

ALPHABETIC ALPHANUMERIC NUMERIC NUMERIC EDITED

Valid

Invalid

Invalid

Invalid

Valid

Valid

Integer

Valid

Invalid

Integer

Valid

Valid

Invalid

Integer

Valid

Invalid

MOVE Rules

Page 9: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 9

ExamplesAlphanumeric Alphanumeric

PIC Sending Contents PIC Rec. Contents

X(5) ‘ABCDE’ X(5) ‘ABCDE’

X(5) ‘ABCDE’ X(4) ‘ABCD’

X(5) ‘ABCDE’ X(6) ‘ABCDE ‘

• Data is copied from left to right with space filling or truncation on the right

• The contents of the receiving item are completely replaced

Page 10: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 10

ExamplesNumeric Numeric

PIC Sending Contents PIC Rec. Contents

9(5) 12345 9(5) 12345

9(5) 12345 9(4) 2345

9(5) 12345 9(6) 012345

9(3)V99 123^45 9(3) 123

9(3)V99 123^45 9V99 3^45

9(3) 123 9(3)V99 123^00

• Data is aligned at the decimal point with zero filling or truncation as necessary

• When the decimal point is not explicitly specified, an assumed decimal point is implied immediately after its rightmost character

Page 11: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 11

OPEN Read/Write Close

• OPEN– Only the files you declared in a SELECT

and corresponding FD statements• CLOSE

– You should close a file when either :

• it will not be read/written anymore

• before the program ends

File I/O

Page 12: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 12

OPEN and CLOSE

OPEN INPUT filename-1 ...

OUTPUT filename-2 …CLOSE filename …

• INPUT is a file you read into the program• OUTPUT is a file the program writes into• OPEN/CLOSE many files on the same line• Call OPEN before any READ/WRITE• After CLOSE you cannot READ/WRITE.

If you OPEN an input file again, you can read the records starting from the first record

Page 13: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 13

READ

READ filenameAT END statement

END-READ.

• The filename is defined with FD• Reads a single record• Each successive call reads the next record• AT END (optional) executes the statement if

the EOF has been reached• END-READ is optional (don’t forget period).

Page 14: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 14

Priming Read

• Pseudocode

Read input record Priming Read

Loop if not EOF

Calculate information

Read input next record

End-loop

Page 15: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 15

Priming Read…MOVE ‘N’ TO INPUT-EOF.READ INPUT-FILE

AT END MOVE ‘Y’ TO INPUT-EOF.…PERFORM PROCESS-RECORDS

UNTIL INPUT-EOF = ‘Y’.…PROCESS RECORDS…

READ INPUT-FILE AT-END MOVE ‘Y’ TO INPUT-EOF.

Page 16: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 16

WRITE

WRITE record-nameAFTER/BEFORE ADVANCING more.

more is PAGE integer [LINE | LINES] data-name [LINE | LINES]

• One record is written to the file• AFTER/BEFORE ADVANCING (optional)

– Printer usage to advance to the top of the next page or advance a number of lines

Page 17: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 17

DISPLAYDISPLAY (data-name-1 | literal-1) … WITH NO ADVANCING.

• Display literals or data values on the screen

• A single DISPLAY can display several items (separated by spaces) and then a carriage return

• The WITH NO ADVANCING clause (optional) suppresses the carriage return

• Handy tool to debug your program

Page 18: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 18

Examples

DISPLAY “ “.

DISPLAY 15000.

DISPLAY “----------------------------------------------------------”

DISPLAY “End of Session.”.

DISPLAY SALES-AMOUNT.

DISPLAY “THE SALES AMOUNT IS “ SALES-AMOUNT “.”.

Page 19: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 19

ACCEPTACCEPT data-name FROM reserve-word.

• Waits for input from the user• Input is stored in the variable data-name and the cursor

moves to the next line• Input should be consistent with the PIC of the data-name. If

not, it may be truncated or adjusted.• FROM reserve word (optional) :

DATE PIC 9(6) YYMMDDDAY PIC 9(5) YYDDDDAY-OF-WEEK PIC 9 1 = MondayTIME PIC 9(8) HHMMSSss

ss = S/100military time

Page 20: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 20

ADD

DATA NAME A B C

Value before execution 5 10 30

Value after execution of:

ADD A TO C 5 10 35

ADD A B TO C 5 10 45

ADD A TO B GIVING C 5 10 15

ADD A 18 B GIVING C 5 10 33

ADD A 18 B TO C 5 10 63

ADD 1 TO B C 5 11 31

Page 21: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 21

DATA NAME A B C D

Value before execution 5 10 30 100

Value after execution of:

SUBTRACT A FROM C 5 10 25 100

SUBTRACT A B FROM C 5 10 15 100

SUBTRACT A B FROM C GIVING D 5 10 30 15

SUBTRACT 10 FROM C D 5 10 20 90

SUBTRACT

Page 22: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 22

DATA NAME A B C

Value before execution 5 10 30

Value after execution of:

MULTIPLY B BY A GIVING C 5 10 50

MULTIPLY A BY B GIVING C 5 10 50

MULTIPLY A BY B 5 50 15

MULTIPLY B BY A 50 10 30

MULTIPLY A BY 3 GIVING B C 5 15 15

MULTIPLY

Page 23: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 23

DATA NAME A B C

Value before execution 5 10 30

Value after execution of:

DIVIDE 2 INTO B. 5 5 30

DIVIDE 2 INTO B GIVING C. 5 10 5

DIVIDE B BY 5 GIVING A 2 10 30

DIVIDE A INTO B C 5 2 6

DIVIDE A INTO B GIVING C 5 10 2

DIVIDE 3 INTO A GIVING B REMAINDER C 5 1 2

DIVIDE

Page 24: Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed

lecture 3 24

Conditions

Format : {variable|literal|reserve-const} symbol {variable|literal|reserve-const}

• Symbol

= < > >= <=

• Reserve-const

ZERO, ZEROS, SPACE, SPACES