Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed."— Presentation transcript:

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 digit ValuePICStored 0Z(4)(spaces) 0ZZZ90 87ZZZ987 +2,319ZZ,ZZZ-2,319 -338ZZ,ZZZ-338- +5,933Z,ZZZ.99-5,933.00 -.05Z,ZZZ.99-.05-

2 lecture 32 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, …

3 lecture 33 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

4 lecture 34 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.

5 lecture 35 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

6 lecture 36 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 locations MOVE 15 TO NUM-1 NUM-2 NUM-3

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

8 lecture 38 SENDING FIELDRECEIVING FIELD Alphabetic Alphanumeric Numeric Numeric Edited ALPHABETIC ALPHANUMERIC NUMERIC NUMERIC EDITED Valid Invalid Valid Integer Valid Invalid Integer Valid Invalid Integer Valid Invalid MOVE Rules

9 lecture 39 Examples Alphanumeric  Alphanumeric PIC SendingContentsPIC 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

10 lecture 310 Examples Numeric  Numeric PIC SendingContentsPIC Rec.Contents 9(5)123459(5)12345 9(5)123459(4)2345 9(5)123459(6)012345 9(3)V99123^459(3)123 9(3)V99123^459V993^45 9(3)1239(3)V99123^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

11 lecture 311 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

12 lecture 312 OPEN and CLOSE OPENINPUT filename-1... OUTPUTfilename-2 … CLOSEfilename … 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

13 lecture 313 READ READ filename AT 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).

14 lecture 314 Priming Read Pseudocode Read input record  Priming Read Loop if not EOF Calculate information Read input next record End-loop

15 lecture 315 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.

16 lecture 316 WRITE WRITE record-name AFTER/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

17 lecture 317 DISPLAY DISPLAY (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

18 lecture 318 Examples DISPLAY “ “. DISPLAY 15000. DISPLAY “----------------------------------------------------------” DISPLAY “End of Session.”. DISPLAY SALES-AMOUNT. DISPLAY “THE SALES AMOUNT IS “ SALES-AMOUNT “.”.

19 lecture 319 ACCEPT ACCEPT 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) : DATEPIC 9(6)YYMMDD DAYPIC 9(5)YYDDD DAY-OF-WEEKPIC 91 = Monday TIMEPIC 9(8)HHMMSSss ss = S/100 military time

20 lecture 320 ADD DATA NAMEA BC 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

21 lecture 321 DATA NAMEA BCD 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

22 lecture 322 DATA NAMEA BC 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

23 lecture 323 DATA NAMEA BC 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

24 lecture 324 Conditions Format : {variable|literal|reserve-const} symbol {variable|literal|reserve-const} Symbol = <>>=<= Reserve-const ZERO, ZEROS, SPACE, SPACES


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

Similar presentations


Ads by Google