ECHO in COBOL

Learn about the ECHO feature in COBOL, including its usage in terminal interaction, input handling, and screen management.

Understanding ECHO

ECHO is a terminal interaction feature in COBOL that controls whether characters typed during ACCEPT operations are displayed on the screen. This feature is essential for creating secure input interfaces and managing how user input is handled visually.

Key Characteristics

  • Controls character display during input
  • Can be enabled or disabled per ACCEPT statement
  • Commonly used for password input
  • Part of COBOL's screen handling capabilities

Basic ECHO Usage

Standard Input with ECHO

cobol
1
2
3
4
5
6
7
WORKING-STORAGE SECTION. 01 USER-INPUT PIC X(20). PROCEDURE DIVISION. DISPLAY "Enter your name: " ACCEPT USER-INPUT DISPLAY "Hello, " USER-INPUT

Input without ECHO

cobol
1
2
3
4
5
6
7
WORKING-STORAGE SECTION. 01 PASSWORD PIC X(20). PROCEDURE DIVISION. DISPLAY "Enter password: " ACCEPT PASSWORD WITH NO ECHO DISPLAY "Password accepted"

Advanced ECHO Applications

Custom Input Masking

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
WORKING-STORAGE SECTION. 01 SECURE-INPUT PIC X(10). 01 DISPLAY-MASK PIC X(10). PROCEDURE DIVISION. INITIALIZE DISPLAY-MASK DISPLAY "Enter PIN: " ACCEPT SECURE-INPUT WITH NO ECHO PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > LENGTH OF SECURE-INPUT MOVE "*" TO DISPLAY-MASK(WS-I:1) END-PERFORM DISPLAY "Input received: " DISPLAY-MASK

Screen Section Implementation

ECHO can be used effectively with COBOL's SCREEN SECTION for more sophisticated input handling:

cobol
1
2
3
4
5
6
7
8
9
10
SCREEN SECTION. 01 LOGIN-SCREEN. 05 BLANK SCREEN. 05 LINE 5 COLUMN 10 VALUE "Username: ". 05 LINE 5 COLUMN 20 PIC X(20) USING WS-USERNAME. 05 LINE 6 COLUMN 10 VALUE "Password: ". 05 LINE 6 COLUMN 20 PIC X(20) USING WS-PASSWORD SECURE.

Handling Special Cases

Mixed ECHO States

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
WORKING-STORAGE SECTION. 01 PUBLIC-DATA PIC X(20). 01 PRIVATE-DATA PIC X(20). PROCEDURE DIVISION. DISPLAY "Enter public info: " ACCEPT PUBLIC-DATA DISPLAY "Enter private info: " ACCEPT PRIVATE-DATA WITH NO ECHO DISPLAY "Public: " PUBLIC-DATA DISPLAY "Private data received (hidden)"

Best Practices

  • Always use NO ECHO for sensitive data input
  • Provide clear user feedback when input is hidden
  • Consider platform-specific behavior
  • Test ECHO functionality thoroughly
  • Combine with other security measures

Common ECHO Patterns

Password Validation

cobol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
WORKING-STORAGE SECTION. 01 WS-PASSWORD PIC X(20). 01 WS-CONFIRM PIC X(20). 01 WS-MATCH PIC X VALUE 'N'. PROCEDURE DIVISION. PERFORM UNTIL WS-MATCH = 'Y' DISPLAY "Enter password: " ACCEPT WS-PASSWORD WITH NO ECHO DISPLAY "Confirm password: " ACCEPT WS-CONFIRM WITH NO ECHO IF WS-PASSWORD = WS-CONFIRM MOVE 'Y' TO WS-MATCH DISPLAY "Passwords match" ELSE DISPLAY "Passwords do not match, try again" END-IF END-PERFORM

Error Handling

  • Handle unexpected input gracefully
  • Provide clear error messages
  • Implement input validation
  • Consider timeout scenarios
  • Plan for system interrupts

Frequently Asked Questions

Related Pages