1 / 20

Computation & Display Data

Computation & Display Data. DT266/2 Information System COBOL. Used to inform the program of its environment files special devices special characters Configuration Section configures the program to its hardware Special-names - paragraph name. Environment Division.

norah
Download Presentation

Computation & Display Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computation & Display Data DT266/2 Information System COBOL

  2. Used to inform the program of its environment files special devices special characters Configuration Section configures the program to its hardware Special-names - paragraph name Environment Division. Configuration Section. Special-names. Currency sign is “£”. This allows the program to use a “£” as a currency symbol - otherwise, a $ is used. Environment Division

  3. Data Division • Pictures • 9 => digit at the position in the picture • A => alphabetic character at the position in the picture • X => alpha numeric at the position in the picture • Decimals points => v and . • Signs s, -, +, CR, DB.

  4. Pictures 01 YOUR-NAME PIC A(10). 01 AGE PIC 999. • A picture describes the number of characters in a data item and the type of characters allowed • Character / alphabetic values are surrounded by “”. 01 message-string pic x(6) value “Hello!”.

  5. Computational vs Display • Numeric pictures are divided into:- • Computational data types • Display data types • Display Data Types • Floating leading characters “-”, “£”, “$”, “z” • Commas and currency symbols.

  6. Computational data types • Can be packed using the COMPUTATIONAL suffix. • Can only include 9, v and s. • v is a VIRTUAL decimal point - it takes up no space • s is an unprintable sign - usually superimposed on the first or last numeric digit. • Computation can be done on these fields (I.e. add, subtract, multiply, divide). • Example s9(7)v99 or s9(7)v99 comp.

  7. Numeric move • Integer • Movement is left justified • Non-filled high-order positions are replaced with zeros • Truncation of high-order digits occurs if the receiving field is not large enough to hold the results • Non-Integer • Decimal alignment is maintained • Movement is from left to right, beginning at the decimal point • Non-filled low-order positions are replaced with zeros

  8. Move • When data is moved into a data item its contents are completely replaced • If source data is too small to fill the item, the remainder is zero or space filled • E.g. • Data Item person-name pic x(15) • Move “Jacinta” to person-name. • Move “Supercalifragalistic” to person-name. • First assignment will leave spaces to right • Second will be truncated on right

  9. Moving Computational Data Types • Example #1 • AMOUNT-A PIC 9999 VALUE 1000. • AMOUNT-B PIC 999 VALUE 999. • After command • MOVE AMOUNT-A TO AMOUNT-B • AMOUNTB=000 (Lost leftmost digit)

  10. Moving Computational Data Types • Example #2 • AMOUNT-A PIC 99v99 VALUE 1234. • AMOUNT-B PIC 99v999 VALUE 56789. • (Implied decimal point 56.789) • After command • MOVE AMOUNT-A TO AMOUNT-B • AMOUNTB=12340 • (Implied decimal point 12.340)

  11. Display data types Each character takes up 1 byte Each character must be defined decimal point sign punctuation (e.g. “£”, “$”, “,”) Any data items with extra display symbols cannot be used in computation

  12. Sample display types • 01 Display-amount pic ££,£££,££9.99CR • This will display any positive or negative number, between +9,999,999.99 and -9,999,999.99 • If the number is negative, CR will be shown • If the number is positive, two blanks will replace CR • The £ is floating - a £ will precede the most significant digit. It will be preceded by blanks to fill the area. • The comma will be displayed only if there is a significant digit preceding it.

  13. Pic ---,---.99 12.34 -1,234.56 More display types Z shows blanks for leading zeros pic zzz,zzz.zz. 1,234.56 23.44 123,456.70 pic zzz,999.99+ 012.34+ 1,234.56- pic zzz,999.99- 012.34 1,234.56-

  14. Moredata.cbl Identification Division. Program-Id. moredata initial. *Introducing the Environment Division, more data types and conditions. Environment Division. Configuration Section. Special-names. Currency sign is "£".

  15. Moredata.cbl Data Division. Working-Storage Section. 01 Item-cost pic 99v99 value 0. 01 No-of-items pic 99 value 0. 88 valid-no value 8 through 15. 01 Amount-proferred pic 9(4)v99 value 0. 01 Amount-of-change pic s9(4)v99 value 0. 01 total-cost pic 9(4)v99 value 0. 01 Display-cost pic ££9.99. 01 Display-total-cost pic £(4)9.99. 01 Display-change pic £(4)9.99-.

  16. Moredata.cbl Procedure Division. Perform Transaction-item-info until valid-no. Perform calculate-and-display-change. Stop Run. Transaction-item-info. Display "Item purchase transaction". Display " ". Display "Enter item cost (99.99 format):" with no advancing. Accept item-cost. Display "Enter number of items (08 to 15):” with no advancing. Accept No-of-items.

  17. Moredata.cbl If valid-no Display "Enter amount proferred (9999.99 format):" with no advancing Accept Amount-proferred else Display "Number of items 08 to 15 - try again!" end-if.

  18. Moredata.cbl Calculate-and-display-change. Multiply Item-cost by No-of-items giving total-cost. Move total-cost to display-total-cost. Display "Total cost of transaction is", display-total-cost. Subtract total-cost from amount-proferred giving display-change. Display "Change to be given is:", Display-change.

  19. Permissible move operations

  20. Group items • A 01 item can contain subordinate items • An item subordinate to a 01 item • has a higher level number than its owning level • gives the picture (alphanumeric) to the owning level 01 Person-details. What picture? 02 Person-name pic x(20). 02 Person-address. What picture? 03 Address-road pic x(30). 03 Address-area pic x(15). 03 Address-county pic x(20). 03 Address-zip pic x(15).

More Related