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.
NATIONAL-EDITED supports characters from virtually all writing systems.
NATIONAL-EDITED fields are declared using the PIC G clause and can include editing characters for formatting international text data.
123456789101112131415161718* 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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647* 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.
123456789101112131415161718* 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.
NATIONAL-EDITED is essential in various scenarios where international character support and formatting are required for global applications.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152* 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.
1234567891011121314151617181920212223242526272829303132333435363738394041424344* 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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960* 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.
Following these best practices ensures effective use of NATIONAL-EDITED in international COBOL applications.
Language Type | Considerations | Example |
---|---|---|
Left-to-Right | Standard alignment | English, Spanish, French |
Right-to-Left | Reverse alignment needed | Arabic, Hebrew |
Complex Scripts | Character combination rules | Thai, Hindi, Korean |
Ideographic | Variable character width | Chinese, Japanese |
Mixed Scripts | Bidirectional text handling | Arabic with Latin numbers |
Use Case | NATIONAL-EDITED Suitability | Reasoning |
---|---|---|
International applications | Excellent | Essential for global support |
Multi-language UIs | Excellent | Proper display of various scripts |
International reports | Excellent | Formatted multi-language output |
English-only applications | Poor | Use ALPHANUMERIC-EDITED instead |
Numeric data | Poor | Use numeric data types |
Usage | Syntax | Example |
---|---|---|
Basic declaration | 01 data-name PIC G(length) | 01 NAME PIC G(50) |
With editing | 01 data-name PIC G(length) editing-chars | 01 AMOUNT PIC G(15) VALUE "€1,234.56" |
International text | 01 text-field PIC G(length) VALUE "text" | 01 CHINESE-NAME PIC G(20) VALUE "张三" |
Formatted display | 01 display-field PIC G(length) VALUE "formatted" | 01 PHONE PIC G(20) VALUE "+1-555-123-4567" |
Multi-language | 01 multi-lang PIC G(length) VALUE "text" | 01 MESSAGE PIC G(50) VALUE "Hello 你好" |
1. What is the primary purpose of the NATIONAL-EDITED data type in COBOL?
2. What character encoding does NATIONAL-EDITED typically use?
3. How is NATIONAL-EDITED different from ALPHANUMERIC-EDITED?
4. Which of the following is a common use case for NATIONAL-EDITED?
5. How do you declare a NATIONAL-EDITED field in COBOL?
Understanding the NATIONAL data type for Unicode support.
Understanding ALPHANUMERIC-EDITED for traditional character editing.
Complete guide to internationalization in COBOL.
Understanding COBOL data types and their usage.
Understanding character encoding in COBOL.