MainframeMaster

COBOL Tutorial

COBOL SEND Statement - Quick Reference

Progress0 of 0 lessons

Overview

The SEND statement is used to transmit data or messages in communication-oriented COBOL programs. It is commonly used in CICS applications and other communication environments to send data to terminals, other programs, or systems.

Purpose and Usage

  • Message transmission - Send messages to terminals or other programs
  • Communication - Enable program-to-program communication
  • CICS support - Support CICS applications
  • Data flow - Control data flow between components
  • Interactive applications - Support interactive user interfaces

Syntax

The SEND statement is used in the PROCEDURE DIVISION for message transmission.

Basic Syntax

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
* Basic SEND syntax SEND data-item [FROM literal] [LENGTH data-name] [WITH identifier-1] [FROM identifier-2] [ERASE] [FREEKB] [FRSET] [ALARM] [BELL] [LIGHT] [PRINT] [WAIT] [NOHANDLE] [HANDLE CONDITION condition-name [command-statement]]. * Complete example IDENTIFICATION DIVISION. PROGRAM-ID. SEND-EXAMPLE. DATA DIVISION. WORKING-STORAGE SECTION. 01 MESSAGE-DATA. 05 MESSAGE-TEXT PIC X(80). 05 MESSAGE-LENGTH PIC 9(3). PROCEDURE DIVISION. MAIN-LOGIC. MOVE "Hello, World!" TO MESSAGE-TEXT MOVE 13 TO MESSAGE-LENGTH SEND MESSAGE-DATA STOP RUN.

SEND transmits data in communication programs.

Practical Examples

Examples of using the SEND statement in different scenarios.

Simple Message Sending

cobol
1
2
3
4
* Send a simple message SEND "Welcome to the application" ERASE FREEKB.

SEND with ERASE and FREEKB options.

Sending with Data Items

cobol
1
2
3
4
5
6
7
8
9
10
* Send using data items 01 OUTPUT-MESSAGE. 05 MSG-TEXT PIC X(40). 05 MSG-LENGTH PIC 9(3). MOVE "Processing completed successfully" TO MSG-TEXT MOVE 32 TO MSG-LENGTH SEND OUTPUT-MESSAGE LENGTH MSG-LENGTH WAIT.

SEND with LENGTH and WAIT options.

CICS SEND Example

cobol
1
2
3
4
5
6
7
* CICS SEND example EXEC CICS SEND FROM(OUTPUT-MESSAGE) LENGTH(MSG-LENGTH) ERASE FREEKB END-EXEC.

SEND in CICS environment.

Best Practices

Understanding best practices ensures effective use of the SEND statement.

Best Practices

  • Use appropriate options - Choose relevant SEND options
  • Handle errors - Include error handling for SEND operations
  • Specify length - Use LENGTH when sending variable-length data
  • Consider timing - Use WAIT when synchronization is needed
  • Test thoroughly - Test SEND operations in target environment

Test Your Knowledge

1. What is the primary purpose of the SEND statement in COBOL?

  • To send data to files
  • To send messages in communication programs
  • To send data to printers
  • To send data to databases

2. In which COBOL division is the SEND statement typically used?

  • IDENTIFICATION DIVISION
  • ENVIRONMENT DIVISION
  • DATA DIVISION
  • PROCEDURE DIVISION

3. What types of data can be sent using the SEND statement?

  • Only numeric data
  • Only character data
  • Any type of data including records and literals
  • Only file records

4. Is the SEND statement commonly used in modern COBOL applications?

  • Yes, in all applications
  • No, it is obsolete
  • Yes, in communication and CICS applications
  • Only in batch processing

5. What is the relationship between SEND and RECEIVE statements?

  • They are the same thing
  • SEND transmits data, RECEIVE accepts data
  • SEND is for files, RECEIVE is for communication
  • They cannot be used together

Frequently Asked Questions