Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 3: COBOL Program structure


COBOL LITERALS

  • The actual values specified in program known as Literals
  • For example,
            MOVE 800 TO AMOUNT.
  • In above example, value ‘800’ will be moved to data name or variable AMOUNT. The value ‘800’ used in above statement is a literal
  • A data name may have different values at various points of time, while Literal means the value that remains constant and unchanged throughout the execution of the program. For this reason, a literal is also referred as constant.
  • Literal does not have a name; it represents itself and does not have to be defined in the DATA DIVISION.
  • There are two type of literals:-
    1. Numeric
    2. Non-numeric

Numeric

  • A numeric literal is made up of digits only. It can have ( + , - or decimal point (.) ).
  • When no sign is specified, the numeric literal will be considered as positive.
  • Negative literals are indicated by (-) minus sign at leftmost end.
  • When no decimal point is specified, the literal is obviously an integer.
  • If the decimal point is used, it must be placed between the digits.
  • The maximum number of digits allowed in a numeric literal is compiler dependent
  • Examples:-
    Valid Numeric Literals Invalid Numeric literals and reason
    .4536 - 46 (Invalid as there is space after minus sign)
    18.5 “270” (Invalid as numeric literal but valid as Non numeric literal)
    -83.22

Non-numeric

  • A non-numeric literal is used in general output messages or headings.
  • Characters that are enclosed between “ “ constitute non-numeric literal
  • The maximum number of character allowed within two quotation marks is compiler dependent
  • Examples:-
    Valid Non-numeric literal Invalid Non-numeric literals and reason
    "MAINFRAME" 7 (Valid as numeric but Invalid as Non-numeric)
    “NEW EMPLOYEE” “One (invalid because there is no quotation mark on the right)
    “GRAND TOTAL”
    “PRICE/QUANTITY”
    “98.70”






© copyright mainframebug.com
Privacy Policy