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.
The SEND statement is used in the PROCEDURE DIVISION for message transmission.
1234567891011121314151617181920212223242526272829303132* 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.
Examples of using the SEND statement in different scenarios.
1234* Send a simple message SEND "Welcome to the application" ERASE FREEKB.
SEND with ERASE and FREEKB options.
12345678910* 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.
1234567* CICS SEND example EXEC CICS SEND FROM(OUTPUT-MESSAGE) LENGTH(MSG-LENGTH) ERASE FREEKB END-EXEC.
SEND in CICS environment.
Understanding best practices ensures effective use of the SEND statement.
1. What is the primary purpose of the SEND statement in COBOL?
2. In which COBOL division is the SEND statement typically used?
3. What types of data can be sent using the SEND statement?
4. Is the SEND statement commonly used in modern COBOL applications?
5. What is the relationship between SEND and RECEIVE statements?