Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read STDIN (SYSIN) in COBOL

I want to read the lines out of STDIN (aka SYSIN) in COBOL. For now I just want to print them out so that I know I've got them. From everything I'm reading it looks like this should work:

IDENTIFICATION DIVISION.
PROGRAM-ID. APP.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

    SELECT SYSIN ASSIGN TO DA-S-SYSIN ORGANIZATION LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.

FD SYSIN.
01 ln PIC X(255).
    88 EOF VALUE HIGH-VALUES.
WORKING-STORAGE SECTION.

PROCEDURE DIVISION.
    OPEN INPUT SYSIN
    READ SYSIN
      AT END SET EOF TO TRUE
    END-READ
    PERFORM UNTIL EOF
        DISPLAY ln
        READ SYSIN
            AT END SET EOF TO TRUE
        END-READ
    END-PERFORM
    CLOSE SYSIN
    STOP RUN.

That compiles (using open-cobol and cobc -x), but running it I get:

libcob: File does not exist (STATUS = 35) File : ''

What am I doing wrong?

like image 708
singpolyma Avatar asked Jun 02 '09 10:06

singpolyma


People also ask

How to access current-time-Val from SYSIN in COBOL?

ACCEPT CURRENT-TIME-VAL FROM TIME. Here the value of CURRENT-TIME-VAL will be fetched from the system defined TIME. 1. SYSIN Parameter is used in JCL (JOB CONTROL LANGUAGE) to pass the data from JCL to COBOL Program. 2. ACCEPT Statement is coded in COBOL Program to receive the Data which is passed from the SYSIN of the JCL.

How to pass data from JCL to COBOL program using SYSIN?

SYSIN Parameter is used in JCL (JOB CONTROL LANGUAGE) to pass the data from JCL to COBOL Program. 2. ACCEPT Statement is coded in COBOL Program to receive the Data which is passed from the SYSIN of the JCL. a) //SYSIN DD * values…

What is accept statement in COBOL?

COBOL ACCEPT Statement: Accept statement in COBOL with examples – It is used to receive the data that has been sent from outside of that program. Data can be sent from any Terminal or from JCL or from system defined items like date functions. ACCEPTING multiple records from input is also possible.

How to accept multiple records from input in COBOL?

ACCEPTING multiple records from input is also possible. Input data should be given in SYSIN DD as an in-stream data and in the cobol program it should be accepted. WORKING-STORAGE SECTION. 01 WK-INPUT. 05 WK-INP-1 PIC X (10) VALUE SPACES. PROCEDURE DIVISION. ACCEPT WK-INPUT. DISPLAY 'WK-INPUT>'WK-INPUT STOP RUN.


1 Answers

The following was suggested to me on the OpenCOBOL forums.

SELECT SYSIN ASSIGN TO KEYBOARD ORGANIZATION LINE SEQUENTIAL.

It's the keyword KEYBOARD that makes it work.

Apparently DISPLAY is a similar word for STDOUT, but I have not tested that.

like image 126
singpolyma Avatar answered Nov 10 '22 17:11

singpolyma