Microsoft KB Archive/62272

COBOL 2.20 Example to WRITE and READ from COM1

PSS ID Number: Q62272 Article last modified on 06-14-1990

2.20 MS-DOS

Summary: The code example below demonstrates how to read and write to and from the communications port (COM1) in Microsoft COBOL version 2.20. When using the communications port to receive data in COBOL, the receive buffer must be filled with data before COBOL will read any data out of the port. Therefore, it is not recommended to READ data in from the communications port using COBOL, since the communications buffer must first be filled. When using COBOL to send data, there is no minimum number of characters COBOL must send before it actually transmits the data. This information applies to Microsoft COBOL version 2.20 for MS-DOS.

Code Example
IDENTIFICATION DIVISION. PROGRAM-ID. Cob1. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT out-file ASSIGN TO DISK ORGANIZATION is LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. Fd out-file LABEL records are standard VALUE of FILE-ID is &quot;com1&quot;. 01 Test-record. 05 The-name  pic x(20). WORKING-STORAGE SECTION. 01 TEST-Name pic x(20). PROCEDURE DIVISION. 100-Main. OPEN I-O out-file. DISPLAY &quot;Enter the line to send&quot;. ACCEPT test-name. MOVE test-name to the-name. WRITE test-record. READ nout-file RECORD INTO test-record. MOVE the-name TO test-name. DISPLAY &quot;This is the line received&quot;. DISPLAY test-name. CLOSE out-file. Copyright Microsoft Corporation 1990.