MainframeMaster

COBOL Tutorial

COBOL VALUE - Quick Reference

Progress0 of 0 lessons

Overview

VALUE is a COBOL clause used in the DATA DIVISION to assign initial values to data items. It allows you to initialize variables, constants, and data structures with default values at compile time, ensuring data items have predictable starting values.

Key Features

  • Data initialization - Assign initial values to data items
  • Compile-time assignment - Values are set when program is compiled
  • Multiple data types - Works with numeric, alphanumeric, and edited fields
  • Figurative constants - Supports COBOL figurative constants

Syntax and Usage

VALUE clause syntax and usage patterns for different data types and scenarios.

Basic VALUE Usage

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
IDENTIFICATION DIVISION. PROGRAM-ID. VALUE-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 CUSTOMER-DATA. 05 CUSTOMER-ID PIC 9(6) VALUE 123456. 05 CUSTOMER-NAME PIC X(30) VALUE "JOHN DOE". 05 CUSTOMER-STATUS PIC X(1) VALUE "A". 05 CUSTOMER-BALANCE PIC 9(8)V99 VALUE 1000.50. PROCEDURE DIVISION. DISPLAY "Customer ID: " CUSTOMER-ID DISPLAY "Customer Name: " CUSTOMER-NAME DISPLAY "Customer Status: " CUSTOMER-STATUS DISPLAY "Customer Balance: " CUSTOMER-BALANCE STOP RUN.

Basic usage of VALUE to initialize data items with default values.

VALUE with Figurative Constants

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
IDENTIFICATION DIVISION. PROGRAM-ID. VALUE-FIGURATIVE. DATA DIVISION. WORKING-STORAGE SECTION. 01 INITIALIZATION-DATA. 05 EMPTY-STRING PIC X(10) VALUE SPACES. 05 ZERO-NUMBER PIC 9(5) VALUE ZEROS. 05 HIGH-VALUE-FIELD PIC X(5) VALUE HIGH-VALUES. 05 LOW-VALUE-FIELD PIC X(5) VALUE LOW-VALUES. 05 QUOTE-STRING PIC X(10) VALUE QUOTES. PROCEDURE DIVISION. DISPLAY "Empty String: '" EMPTY-STRING "'" DISPLAY "Zero Number: " ZERO-NUMBER DISPLAY "High Value Field: " HIGH-VALUE-FIELD DISPLAY "Low Value Field: " LOW-VALUE-FIELD DISPLAY "Quote String: " QUOTE-STRING STOP RUN.

Using VALUE with COBOL figurative constants for common initialization patterns.

VALUE with Group Items

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
IDENTIFICATION DIVISION. PROGRAM-ID. VALUE-GROUP. DATA DIVISION. WORKING-STORAGE SECTION. 01 TRANSACTION-RECORD. 05 TRANSACTION-ID PIC 9(8) VALUE 0. 05 TRANSACTION-DATE PIC 9(8) VALUE 20240101. 05 TRANSACTION-TYPE PIC X(2) VALUE "CR". 05 TRANSACTION-AMOUNT PIC 9(8)V99 VALUE 0.00. 05 TRANSACTION-STATUS PIC X(1) VALUE "P". PROCEDURE DIVISION. DISPLAY "Transaction Record:" DISPLAY " ID: " TRANSACTION-ID DISPLAY " Date: " TRANSACTION-DATE DISPLAY " Type: " TRANSACTION-TYPE DISPLAY " Amount: " TRANSACTION-AMOUNT DISPLAY " Status: " TRANSACTION-STATUS STOP RUN.

Using VALUE to initialize individual fields within a group item structure.

Value Types

Numeric Values

Initialize numeric data items.

cobol
1
2
01 NUMERIC-FIELD PIC 9(3) VALUE 123. 01 DECIMAL-FIELD PIC 9(5)V99 VALUE 123.45.

Alphanumeric Values

Initialize alphanumeric data items.

cobol
1
2
01 TEXT-FIELD PIC X(20) VALUE "Hello World". 01 CHAR-FIELD PIC X(1) VALUE "A".

Figurative Constants

Use predefined COBOL constants.

cobol
1
2
3
01 SPACE-FIELD PIC X(10) VALUE SPACES. 01 ZERO-FIELD PIC 9(5) VALUE ZEROS. 01 HIGH-FIELD PIC X(5) VALUE HIGH-VALUES.

Edited Values

Initialize edited numeric fields.

cobol
1
2
01 DOLLAR-FIELD PIC $9(6).99 VALUE $1234.56. 01 COMMA-FIELD PIC 9(3),9(3) VALUE 123,456.

Best Practices

  • Use meaningful defaults - Choose initial values that make sense for the data
  • Be consistent - Use consistent initialization patterns throughout your program
  • Consider data types - Ensure values are compatible with PICTURE clauses
  • Document values - Document why specific initial values were chosen
  • Use figurative constants - Use SPACES, ZEROS, etc. for common initialization patterns

VALUE Quick Reference

Data TypeSyntaxExample
NumericPIC 9(n) VALUE numberPIC 9(3) VALUE 123
AlphanumericPIC X(n) VALUE "text"PIC X(10) VALUE "HELLO"
FigurativePIC X(n) VALUE SPACESPIC X(5) VALUE ZEROS
DecimalPIC 9(n)V99 VALUE numberPIC 9(5)V99 VALUE 123.45

Test Your Knowledge

1. What is the primary purpose of VALUE in COBOL?

  • To assign initial values to data items
  • To perform arithmetic calculations
  • To control program flow
  • To define file structures

2. Where is VALUE typically used in a COBOL program?

  • In the PROCEDURE DIVISION for calculations
  • In the DATA DIVISION for data initialization
  • In the ENVIRONMENT DIVISION for configuration
  • In the IDENTIFICATION DIVISION

3. What types of values can be assigned using VALUE?

  • Only numeric values
  • Only alphanumeric values
  • Numeric, alphanumeric, and figurative constants
  • Only figurative constants

4. How does VALUE differ from MOVE?

  • VALUE is used at compile time, MOVE at runtime
  • VALUE is used at runtime, MOVE at compile time
  • They are identical in function
  • VALUE only works with files, MOVE with memory

5. What is a figurative constant in COBOL?

  • A mathematical expression
  • A predefined value like SPACES, ZEROS, or HIGH-VALUES
  • A variable name
  • A file name

Frequently Asked Questions