MainframeMaster

COBOL Tutorial

COBOL NATIONAL-EDITED Data Type - Quick Reference

Progress0 of 0 lessons

Overview

The NATIONAL-EDITED data type is used in COBOL for handling international character data (Unicode) with editing capabilities. It enables proper formatting, alignment, and display of text in various languages and writing systems while maintaining editing features.

Purpose and Usage

  • International support - Handle Unicode characters from various languages
  • Editing capabilities - Format and align international text
  • Multi-language display - Support different writing systems
  • Locale-specific formatting - Adapt to different cultural conventions
  • Character alignment - Handle right-to-left and complex scripts

International Character Support

English: "Hello World"
Chinese: "你好世界"
Japanese: "こんにちは世界"
Arabic: "مرحبا بالعالم"
Thai: "สวัสดีโลก"
All supported by NATIONAL-EDITED

NATIONAL-EDITED supports characters from virtually all writing systems.

Syntax and Usage

NATIONAL-EDITED fields are declared using the PIC G clause and can include editing characters for formatting international text data.

Basic Syntax

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* Basic NATIONAL-EDITED syntax level-number data-name PIC G(length) [editing-characters]. * Examples 01 INTERNATIONAL-NAME PIC G(30). 01 CURRENCY-AMOUNT PIC G(15) VALUE "1,234.56". 01 FORMATTED-DATE PIC G(10) VALUE "2024-01-15". 01 PHONE-NUMBER PIC G(15) VALUE "+1-555-123-4567". * Complete example 01 INTERNATIONAL-DATA. 05 CUSTOMER-NAME PIC G(50). 05 ADDRESS-LINE1 PIC G(60). 05 ADDRESS-LINE2 PIC G(60). 05 CITY-NAME PIC G(30). 05 COUNTRY-NAME PIC G(30). 05 CURRENCY-FIELD PIC G(20) VALUE "€1,234.56". 05 FORMATTED-PHONE PIC G(20) VALUE "+33 1 23 45 67 89".

NATIONAL-EDITED uses PIC G for Unicode character data with editing.

Complete Example

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
* Complete example using NATIONAL-EDITED IDENTIFICATION DIVISION. PROGRAM-ID. INTERNATIONAL-DEMO. DATA DIVISION. WORKING-STORAGE SECTION. 01 INTERNATIONAL-FORM. 05 FORM-HEADER PIC G(50) VALUE "International Customer Form". 05 CUSTOMER-INFO. 10 NAME-LABEL PIC G(20) VALUE "Customer Name:". 10 CUSTOMER-NAME PIC G(50). 10 ADDR-LABEL PIC G(20) VALUE "Address:". 10 ADDRESS-LINE PIC G(60). 10 CITY-LABEL PIC G(20) VALUE "City:". 10 CITY-NAME PIC G(30). 10 COUNTRY-LABEL PIC G(20) VALUE "Country:". 10 COUNTRY-NAME PIC G(30). 05 FINANCIAL-INFO. 10 AMOUNT-LABEL PIC G(20) VALUE "Amount:". 10 CURRENCY-AMOUNT PIC G(20). 10 CURRENCY-SYMBOL PIC G(5). 01 SAMPLE-DATA. 05 ENGLISH-NAME PIC G(50) VALUE "John Smith". 05 CHINESE-NAME PIC G(50) VALUE "张三". 05 JAPANESE-NAME PIC G(50) VALUE "田中太郎". 05 ARABIC-NAME PIC G(50) VALUE "أحمد محمد". 05 THAI-NAME PIC G(50) VALUE "สมชาย ใจดี". PROCEDURE DIVISION. MAIN-LOGIC. * Display international form DISPLAY FORM-HEADER DISPLAY NAME-LABEL CUSTOMER-NAME DISPLAY ADDR-LABEL ADDRESS-LINE DISPLAY CITY-LABEL CITY-NAME DISPLAY COUNTRY-LABEL COUNTRY-NAME * Display sample international names DISPLAY "Sample Names:" DISPLAY ENGLISH-NAME DISPLAY CHINESE-NAME DISPLAY JAPANESE-NAME DISPLAY ARABIC-NAME DISPLAY THAI-NAME STOP RUN.

This example shows how to use NATIONAL-EDITED for international data.

Editing Characters

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
* NATIONAL-EDITED with editing characters 01 FORMATTED-FIELDS. 05 CURRENCY-DISPLAY PIC G(15) VALUE "€1,234.56". 05 PHONE-DISPLAY PIC G(20) VALUE "+1-555-123-4567". 05 DATE-DISPLAY PIC G(10) VALUE "2024-01-15". 05 TIME-DISPLAY PIC G(8) VALUE "14:30:25". 05 PERCENTAGE-DISPLAY PIC G(10) VALUE "25.5%". 05 SCIENTIFIC-NUMBER PIC G(15) VALUE "1.23E+04". * Editing character examples 01 EDITING-EXAMPLES. 05 BLANK-INSERTION PIC G(10) VALUE "Hello World". 05 ZERO-INSERTION PIC G(10) VALUE "000123456". 05 SLASH-INSERTION PIC G(10) VALUE "2024/01/15". 05 MINUS-SIGN PIC G(10) VALUE "-123.45". 05 PLUS-SIGN PIC G(10) VALUE "+123.45". 05 CREDIT-INDICATOR PIC G(10) VALUE "123.45CR". 05 DEBIT-INDICATOR PIC G(10) VALUE "123.45DB".

Editing characters provide formatting capabilities for international text.

Common Use Cases

NATIONAL-EDITED is essential in various scenarios where international character support and formatting are required for global applications.

International User Interfaces

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
* International user interface with NATIONAL-EDITED IDENTIFICATION DIVISION. PROGRAM-ID. INTERNATIONAL-UI. DATA DIVISION. WORKING-STORAGE SECTION. 01 UI-ELEMENTS. 05 MENU-HEADER PIC G(50) VALUE "International Banking System". 05 MENU-OPTIONS. 10 OPTION-1 PIC G(30) VALUE "1. 查看账户 (View Account)". 10 OPTION-2 PIC G(30) VALUE "2. 转账 (Transfer)". 10 OPTION-3 PIC G(30) VALUE "3. 支付账单 (Pay Bills)". 10 OPTION-4 PIC G(30) VALUE "4. 退出 (Exit)". 05 PROMPT-MESSAGE PIC G(50) VALUE "请选择选项 (Please select option):". 05 ERROR-MESSAGE PIC G(60) VALUE "无效选择,请重试 (Invalid choice, please try again)". 01 USER-INPUT PIC X(1). 01 SELECTED-OPTION PIC 9(1). PROCEDURE DIVISION. MAIN-LOGIC. * Display international menu DISPLAY MENU-HEADER DISPLAY MENU-OPTIONS DISPLAY PROMPT-MESSAGE * Get user input ACCEPT USER-INPUT MOVE USER-INPUT TO SELECTED-OPTION * Process selection EVALUATE SELECTED-OPTION WHEN 1 PERFORM VIEW-ACCOUNT WHEN 2 PERFORM TRANSFER-FUNDS WHEN 3 PERFORM PAY-BILLS WHEN 4 STOP RUN WHEN OTHER DISPLAY ERROR-MESSAGE END-EVALUATE. VIEW-ACCOUNT. DISPLAY "查看账户功能 (View Account Function)". TRANSFER-FUNDS. DISPLAY "转账功能 (Transfer Function)". PAY-BILLS. DISPLAY "支付账单功能 (Pay Bills Function)".

International UIs use NATIONAL-EDITED for multi-language display.

International Reports

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
* International reports with NATIONAL-EDITED IDENTIFICATION DIVISION. PROGRAM-ID. INTERNATIONAL-REPORT. DATA DIVISION. WORKING-STORAGE SECTION. 01 REPORT-HEADER. 05 REPORT-TITLE PIC G(60) VALUE "International Sales Report". 05 REPORT-DATE PIC G(20) VALUE "2024年1月15日". 05 REPORT-TIME PIC G(20) VALUE "14:30:25". 01 REPORT-DATA. 05 REGION-HEADER PIC G(40) VALUE "Region (地区)". 05 SALES-HEADER PIC G(30) VALUE "Sales (销售额)". 05 CURRENCY-HEADER PIC G(20) VALUE "Currency (货币)". 01 SALES-RECORDS. 05 ASIA-RECORD. 10 ASIA-REGION PIC G(20) VALUE "Asia (亚洲)". 10 ASIA-SALES PIC G(15) VALUE "¥1,234,567". 10 ASIA-CURR PIC G(10) VALUE "CNY". 05 EUROPE-RECORD. 10 EUR-REGION PIC G(20) VALUE "Europe (欧洲)". 10 EUR-SALES PIC G(15) VALUE "€987,654". 10 EUR-CURR PIC G(10) VALUE "EUR". 05 AMERICA-RECORD. 10 AMR-REGION PIC G(20) VALUE "America (美洲)". 10 AMR-SALES PIC G(15) VALUE "$2,345,678". 10 AMR-CURR PIC G(10) VALUE "USD". PROCEDURE DIVISION. MAIN-LOGIC. * Display report header DISPLAY REPORT-HEADER DISPLAY REPORT-DATE DISPLAY REPORT-TIME * Display report data DISPLAY REGION-HEADER SALES-HEADER CURRENCY-HEADER DISPLAY ASIA-RECORD DISPLAY EUROPE-RECORD DISPLAY AMERICA-RECORD STOP RUN.

International reports use NATIONAL-EDITED for multi-language content.

Data Validation

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
* Data validation with NATIONAL-EDITED IDENTIFICATION DIVISION. PROGRAM-ID. INTERNATIONAL-VALIDATION. DATA DIVISION. WORKING-STORAGE SECTION. 01 VALIDATION-MESSAGES. 05 SUCCESS-MSG PIC G(50) VALUE "数据验证成功 (Validation successful)". 05 ERROR-MSG PIC G(50) VALUE "数据验证失败 (Validation failed)". 05 NAME-ERROR PIC G(60) VALUE "姓名不能为空 (Name cannot be empty)". 05 EMAIL-ERROR PIC G(60) VALUE "邮箱格式不正确 (Invalid email format)". 01 INPUT-DATA. 05 CUSTOMER-NAME PIC G(50). 05 EMAIL-ADDRESS PIC G(50). 05 PHONE-NUMBER PIC G(20). 01 VALIDATION-FLAGS. 05 NAME-VALID PIC X(1) VALUE "N". 05 EMAIL-VALID PIC X(1) VALUE "N". 05 PHONE-VALID PIC X(1) VALUE "N". PROCEDURE DIVISION. MAIN-LOGIC. * Get input data DISPLAY "请输入客户姓名 (Enter customer name):" ACCEPT CUSTOMER-NAME DISPLAY "请输入邮箱地址 (Enter email address):" ACCEPT EMAIL-ADDRESS DISPLAY "请输入电话号码 (Enter phone number):" ACCEPT PHONE-NUMBER * Validate data PERFORM VALIDATE-NAME PERFORM VALIDATE-EMAIL PERFORM VALIDATE-PHONE * Display results IF NAME-VALID = "Y" AND EMAIL-VALID = "Y" AND PHONE-VALID = "Y" DISPLAY SUCCESS-MSG ELSE DISPLAY ERROR-MSG END-IF STOP RUN. VALIDATE-NAME. IF CUSTOMER-NAME = SPACES DISPLAY NAME-ERROR ELSE MOVE "Y" TO NAME-VALID END-IF. VALIDATE-EMAIL. * Email validation logic here MOVE "Y" TO EMAIL-VALID. VALIDATE-PHONE. * Phone validation logic here MOVE "Y" TO PHONE-VALID.

Data validation uses NATIONAL-EDITED for international error messages.

Best Practices and Tips

Following these best practices ensures effective use of NATIONAL-EDITED in international COBOL applications.

NATIONAL-EDITED Best Practices

  • Use appropriate field lengths - Account for variable character widths
  • Consider text direction - Handle right-to-left languages properly
  • Test with multiple languages - Verify display with various scripts
  • Use consistent encoding - Ensure consistent Unicode handling
  • Plan for sorting - Consider collation rules for different languages
  • Document language support - Document which languages are supported

Language Support Considerations

Language TypeConsiderationsExample
Left-to-RightStandard alignmentEnglish, Spanish, French
Right-to-LeftReverse alignment neededArabic, Hebrew
Complex ScriptsCharacter combination rulesThai, Hindi, Korean
IdeographicVariable character widthChinese, Japanese
Mixed ScriptsBidirectional text handlingArabic with Latin numbers

Performance Considerations

  • Unicode processing overhead - More complex than single-byte characters
  • Storage requirements - Typically 2 bytes per character
  • Sorting complexity - Language-specific collation rules
  • Display performance - Rendering complex scripts
  • Memory usage - Larger memory footprint
  • I/O operations - Unicode-aware file handling

When to Use NATIONAL-EDITED

Use CaseNATIONAL-EDITED SuitabilityReasoning
International applicationsExcellentEssential for global support
Multi-language UIsExcellentProper display of various scripts
International reportsExcellentFormatted multi-language output
English-only applicationsPoorUse ALPHANUMERIC-EDITED instead
Numeric dataPoorUse numeric data types

NATIONAL-EDITED Quick Reference

UsageSyntaxExample
Basic declaration01 data-name PIC G(length)01 NAME PIC G(50)
With editing01 data-name PIC G(length) editing-chars01 AMOUNT PIC G(15) VALUE "€1,234.56"
International text01 text-field PIC G(length) VALUE "text"01 CHINESE-NAME PIC G(20) VALUE "张三"
Formatted display01 display-field PIC G(length) VALUE "formatted"01 PHONE PIC G(20) VALUE "+1-555-123-4567"
Multi-language01 multi-lang PIC G(length) VALUE "text"01 MESSAGE PIC G(50) VALUE "Hello 你好"

Test Your Knowledge

1. What is the primary purpose of the NATIONAL-EDITED data type in COBOL?

  • To perform arithmetic operations
  • To handle international character data with editing capabilities
  • To control file operations
  • To manage memory allocation

2. What character encoding does NATIONAL-EDITED typically use?

  • ASCII encoding
  • Unicode encoding (UTF-16)
  • EBCDIC encoding
  • Binary encoding

3. How is NATIONAL-EDITED different from ALPHANUMERIC-EDITED?

  • They are exactly the same
  • NATIONAL-EDITED supports Unicode while ALPHANUMERIC-EDITED supports ASCII/EBCDIC
  • NATIONAL-EDITED is for numbers only
  • ALPHANUMERIC-EDITED is for international data

4. Which of the following is a common use case for NATIONAL-EDITED?

  • Simple arithmetic calculations
  • International text display and formatting
  • File I/O operations
  • Data validation

5. How do you declare a NATIONAL-EDITED field in COBOL?

  • Using PIC N
  • Using PIC G
  • Using PIC X
  • Using PIC 9

Frequently Asked Questions