MainframeMaster

COBOL Tutorial

COBOL UNIVERSAL (UCS) - Quick Reference

Progress0 of 0 lessons

Overview

UNIVERSAL refers to the Universal Character Set (UCS), the basis for Unicode (ISO/IEC 10646). In COBOL, NATIONAL data (PIC N) typically maps to UCS-2/UTF-16. Use conversion functions to interoperate with DISPLAY data.

Key Concepts

  • UCS - Universal repertoire for characters
  • NATIONAL - PIC N character storage using UCS encodings
  • Conversions - NATIONAL-OF, DISPLAY-OF for text interchange

Syntax and Usage

NATIONAL Conversions

cobol
1
2
3
4
5
6
* UNIVERSAL (UCS) conversions with NATIONAL data 01 WIDE-TEXT PIC N(40). 01 DISP-TEXT PIC X(120). MOVE FUNCTION NATIONAL-OF("Curaçao – 東京") TO WIDE-TEXT MOVE FUNCTION DISPLAY-OF(WIDE-TEXT) TO DISP-TEXT DISPLAY DISP-TEXT

Interoperability Notes

  • Verify code-set on files and databases
  • Consider byte order for UCS-2/UTF-16
  • Prefer UTF-8 for system boundaries when feasible

Best Practices

  • Documentation - Record encodings and conversions in design docs
  • Testing - Round-trip test text with diacritics and CJK
  • Portability - Avoid assumptions across compilers

UNIVERSAL Quick Reference

AspectDescriptionExample
UCSUniversal repertoireISO/IEC 10646
NATIONALPIC N mapped to UCS encodingPIC N(30)
ConversionsNATIONAL-OF, DISPLAY-OFDISPLAY-OF(WIDE-TEXT)

Test Your Knowledge

1. What does UNIVERSAL generally refer to in character encoding contexts?

  • Universal Arithmetic System
  • Universal Character Set (UCS)
  • Universal File System
  • Universal Screen Interface

2. Which COBOL feature typically maps to UCS-based encodings?

  • NATIONAL data items (PIC N)
  • COMP-3 fields
  • INDEX data
  • REPORT SECTION only

3. What is the relationship between UCS-2 and UTF-16?

  • They are identical in all cases
  • UCS-2 is fixed-width BMP only; UTF-16 supports surrogate pairs
  • UTF-16 is 8-bit
  • UCS-2 is variable-length

4. What is a best practice when handling UNIVERSAL encodings in COBOL?

  • Assume all runtimes are identical
  • Document code pages and conversion functions clearly
  • Hard-code byte order
  • Avoid NATIONAL data

5. Which COBOL functions help convert between DISPLAY and NATIONAL text?

  • NATIONAL-OF and DISPLAY-OF
  • NUMVAL and NUMVAL-C
  • INTEGER and DECIMAL
  • CURRENT-DATE and RANDOM

Frequently Asked Questions