cobol - usage clause

Upload: rammurthy

Post on 07-Aug-2018

212 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/21/2019 Cobol - Usage Clause

    1/3

    Computational Data Representation (USAGE Clause)

    Control how the computer internally stores your numeric data items by coding the USAGE clausein your data description entries. The numeric data you use in your program will be one of theformats available with COO!"

    • E#ternal decimal $ %USAGE &'S(!A)*

    • E#ternal floating+point $ %USAGE &'S(!A)*

    • 'nternal decimal $ %USAGE (AC,E&+&EC'-A!*

    • inary $ %USAGE 'A/)*

    • 'nternal floating+point $ %USAGE CO-(+01 USAGE CO-(+2*

    CO-( and CO-(+3 are synonymous with 'A/)CO-(+4 is synonymous with (AC,E&+&EC'-A!./egardless of what USAGE clause you use to control the computer5s internal representation ofthe value1 you use the same ('CTU/E clause conventions and decimal value in the 6A!UEclause e#cept for floating point data.

    1. External Decimal (USAGE DISPLAY) Items

    7hen you code USAGE &'S(!A) or omit the USAGE clause1 each position %or byte* of storagecontains one decimal digit. This corresponds to the format used for printing or displaying output1meaning the items are stored in displayable form.

    !"at USAGE DISPLAY Items Are #or$E#ternal decimal items are primarily intended for receiving and sending numbers between

    your program and files1 terminals1 and printers. 8owever1 it is also acceptable to use e#ternaldecimal items as operands and receivers in your program5s arithmetic processing1 and it is oftenconvenient to program this way.

    %. External #loatin&'Point (USAGE DISPLAY) Items

    &isplayable numbers coded in a floating+point format are called external   floating-point  items.!i9e e#ternal decimal items1 you define e#ternal floating+point items e#plicitly with USAGE&'S(!A) or implicitly by omitting the USAGE clause.'n the following e#ample1 Compute-Result is implicitly defined as an e#ternal floating+point item.

    Each byte of storage contains one character %e#cept for 6*.05 Compute-Result Pic -9v9(9)E-99.

    The 6A!UE clause is not allowed in the data description for e#ternal floating+point items. Also1the minus signs %+* do not mean that the mantissa and e#ponent will always be negative numbers1

     but that when displayed the sign will appear as a blan9 for positive and a minus sign for negative.'f a plus sign %:* were used1 positive would be displayed as a plus sign and negative as a minussign.;ust as with e#ternal decimal numbers1 e#ternal floating+point numbers have to be converted%automatically by the compiler* to an internal representation of the numeric value before they can be operated on. E#ternal floating+point numbers are always converted to internal long floating+ point format.

    .inar* (I+ARY, C-P, or C-P'/) Items

    'A/)1 CO-( and CO-(+3 are synonyms on all platforms.

  • 8/21/2019 Cobol - Usage Clause

    2/3

    inary format occupies 21 31 or < bytes of storage and is handled for arithmetic purposes as afi#ed+point number with the leftmost bit being the operational sign. =or byte+reversed binary data1the sign bit is the leftmost bit of the rightmost byte.

    0o uc" Stora&e I+ARY -ccupiesA ('CTU/E description with 3 or fewer decimal digits occupies 2 bytes> with ? to @ decimal digits1 3 bytes>

    with 0 to 0< decimal digits1 < bytes.inary items with @ or more digits reBuire more handling by the compiler. Testing them for theS'E E//O/ condition and rounding is more cumbersome than with other types.

    !"at to Use I+ARY #or$

    inary items are well suited for containing subscripts1 switches1 and arithmetic operands orresults.8owever1 you might want to use pac9ed decimal format instead of binary because"

    • inary format is not as well suited for decimal alignment as pac9ed decimal format.

    • inary format is not converted to and from &'S(!A) format as easily as pac9ed decimal

    format.

    /. Pac2e3 Decimal (PAC4ED'DECIAL or C-P') Items

    (ac9ed decimal format occupies 0 byte of storage for every two decimal digits you code in the('CTU/E description1 e#cept that the right+most byte contains only 0 digit and the sign. Thisformat is most efficiently used when you code an odd number of digits in the ('CTU/Edescription1 so that the left+most byte is fully used. (ac9ed decimal format is handled as a fi#ed+ point number for arithmetic purposes.

    !"* Use Pac2e3 Decimal $

    • (ac9ed decimal format reBuires less storage per digit than &'S(!A) format reBuires.

    • (ac9ed decimal format is better suited for decimal alignment than binary format.

    • (ac9ed decimal format is converted to and from &'S(!A) format more easily than binary

    format.

    • (ac9ed decimal format is well suited for containing arithmetic operands or results.

    5. #loatin&'Point (C-P'1 an3 C-P'%) Items

    CO-(+0 refers to short %single+precision* floating+point format1 and CO-(+2 refers to long%double+precision* floating+point format1 which occupy 3 and < bytes of storage1 respectively. Theleftmost bit contains the sign> the ne#t seven bits contain the e#ponent> the remaining 4 or D bytescontain the mantissa.On -6S 6-1 CO-(+0 and CO-(+2 data items are stored in SF4D he#adecimal format.A ('CTU/E clause is not allowed in the data description of floating+point data items1 but you can provide an initial value using a floating+point literal in the 6A!UE clause"

    05 Compute-result Usage Comp-1 Value 06.2E-2!.

    =loating+point format is well suited for containing arithmetic operands and results and formaintaining the highest level of accuracy in arithmetic.

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    # $%ter%al Represe%tatio% o& 'umeric $tems #

  • 8/21/2019 Cobol - Usage Clause

    3/3

      #"""""""""" """""""""""""""""""""""""" """""""" """"""""""""""""""#

    # 'umeric # P$CURE a% U*+,E a% # # #

    # pe # ptio%al *$,' Clause # Value # $%ter%al Represt.#

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # E/ter%al # P$C *9999 $*P+ # 3 12! # 41 42 4 C! #

    # ecimal # # - 12! # 41 42 4 ! #

    # # # 12! # 41 42 4 C! #

    # """""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # # P$C 9999 $*P+ # 12! # 41 42 4 4! #

    # #""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # # P$C *9999 $*P+ # 3 12! # C1 42 4 4! #

    # # *$,' E+$', # - 12! # 1 42 4 4! #

    # #""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # # P$C *9999 $*P+ # - 12! # !E 41 42 4 4! #

    # # *$,' E+$', *EP+R+E # - 12! # 60 41 42 4 4! #

    # # P$C *9999 $*P+ # 3 12! # 41 42 4 4! !E #

    # # *$,' R+$$', *EP+R+E # 3 12! # 41 42 4 4! 60 #

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # i%ar # P$C *9999 $'+R # 3 12! # 0! 2 #

    # # CP # - 12! # 4 2E #

    # # CP-! # # #

    # #""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # # P$C 9999 $'+R # 3 12! # 0! 2 ## # CP # - 12! # 0! 2 #

    # # CP-! # # #

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # $%ter%al # P$C *9999 P+C7E-EC$+ # 3 12! # 01 2 !C #

    # ecimal # CP- # - 12! # 01 2 ! #

    # #""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # # P$C 9999 P+C7E-EC$+ # 3 12! # 01 2 !4 #

    # # CP- # - 12! # 01 2 !4 #

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""#

    # $%ter%al # CP-1 # 3 12! # ! ! 20 00 #

    # 4loati%g # # - 12! # C ! 20 00 #

    # Poi%t # # # #

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""## $%ter%al # CP-2 # 3 12! #! ! 20 00 00 00 00 00 #

    # 4loati%g # # - 12! #C ! 20 00 00 00 00 00 #

    # Poi%t # # # #

    #""""""""""#""""""""""""""""""""#""""""""#""""""""""""""""""""""""#

    # E/ter%al # P$C 39(2)9(2)E399 $*P+# 3 12! # ! 41 42 ! 4 #

    # 4loati%g # # # 4! C5 !E 40 42#

    # Poi%t # #""""""""#""""""""""""""""""#

    # # # - 12! # 60 41 42 ! 4 #

    # # # # 4! C5 !E 40 42#

    #""""""""""#""""""""""""""""""""""""""#""""""""#""""""""""""""""""#