Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using same pipe file for input/output from call prgm

Status
Not open for further replies.

SiouxCityElvis

Programmer
Jun 6, 2003
228
US
I have a COBOL program that acts as a server in which it reads a pipe file for requests.
It calls other programs depending on what type of request it is.
I'm working on handling the request, kicking off another cobol program to process the request.

What I need to do, is
OPEN INPUT PIPE-FILE ASSIGN TO "NAMEDPIPE"
ORGANIZATION IS LINE SEQUENTIAL.

Later in my procedure code I have a loop that handles the requests.

PERFORM UNTIL
...
OPEN INPUT PIPE-FILE
READ PIPE-FILE-REC NEXT RECORD
AT END
....Go to end subroutine ...
NOT AT END
IF REQUEST-TYPE = "O"
CLOSE PIPE-FILE
CALL "OTHERPGM.COB" USING .....
...
...
DISPLAY "ARE WE BACK YET FROM CALLED PGM??"
LINE 10 POSITION 1
END-IF

END-PERFORM

Then, in my OTHERPGM.COB

I try to Open the Pipe file for OUTPUT! For some reason, it does not like it. Here's what happens...

PROCEDURE DIVISION.
...
...
..processing code for query request form calling program

DISPLAY "HERE YET???" LINE 10 POSITION 1.
ACCEPT WS-PROMPT LINE 11 POSITION 1.
OPEN OUTPUT PIPE-FILE.

DISPLAY "WRITING TO PIPE-FILE" LINE 12 POSITION 1.

ACCEPT WS-PROMPT LINE 13 POSITION 1.
WRITE OUT-REC FROM WS-OUT-REC.
CLOSE PIPE-FILE.

The "WRITING TO PIPE-FILE" never gets displayed, as all my other DISPLAY statements do.
For some reason, it hangs on the OPEN OUTPUT PIPE-FILE statement and does not proceed past that. I have proven this by debugging in both the calling program and the called program.

Is there a reason why I wouldn't be able to use the same pipefile(named pipe) in my Called program that I am already using in my Calling program? The Server program opens it for read(since named pipes are like sequential files and can not be opened in I-O like index files, right?). The called program, OTHERPGM.COB opens the pipe file for output. I make sure to close the pipe file in the server program, before calling OTHERPGM and opening it again, so I have no conflicts there that I am aware of.

Please help if you have any suggestions. This makes no since to me. The only guess I have at it based on my little experience with Pipe files opened for INPUT, is that my OPEN OUTPUT PIPE-FILE statement is actually behaving as if it were opened for INPUT, and since there is nothing in the pipe file at that point, it hangs and waits on that statement until something is put in there. That happened to me before with OPEN INPUT PIPE-FILE before and that makes sense. But since I am doing an OPEN OUTPUT, it makes no sense. I want to write to that file-it shouldn't hang there!

Thanks.
-David
 
Hi

I am not sure which is ur platform, but mere closing a file will not dissotiate it from program. In unisys Cobol If I want to dissociate a file I use CLOSE RELEASE. There shud be same or some equivalent syntax in your dialet. Try that !!!

Devesh
 
I am using RMCOBOL - 85 release 8 on a Linux platform.
the RELEASE keyword in RMCOBOL does not regard closing of a file.
 
I tried something else and it doesn't work. Now I'm just trying to see if I can access my named pipe file "pipefile" first in INPUT mode, close that, then open in OUTPUT mode. But it still hangs at the OPEN OUTPUT OUT-FILE as if it were opened in INPUT mode and is waiting there for the named pipe to be fed before continuing on.

I'm wanting to see if I can write to the same file that I'm reading from.

What I have done is to declare my SELECT statements one with
SELECT IN-FILE
ASSIGN TO INPUT, "pipefile"
ORGANIZATION IS LINE SEQUENTIAL
ACCESS IS SEQUENTIAL.

the other

SELECT OUT-FILE
ASSIGN TO OUTPUT, "pipefile"
ORGANIZATION IS LINE SEQUENTIAL
ACCESS IS SEQUENTIAL.

PROCEDURE DIVISION.
...
...

A.
OPEN INPUT IN-FILE.

B.
READ IN-FILE NEXT RECORD
AT END
CLOSE IN-FILE
OPEN INPUT IN-FILE
NOT AT END
do some processing code here
CLOSE IN-FILE
DISPLAY "TRY TO OPEN FOR OUTPUT" LINE 8 POSITION 1
ACCEPT MENU-PROMPT LINE 9 POSITION 1
OPEN OUTPUT OUT-FILE
DISPLAY "HERE" LINE 10 POSITION 1
ACCEPT MENU-PROMPT LINE 11 POSITION 1
WRITE OUT-REC FROM WS-OUT-REC
CLOSE OUT-FILE

OPEN INPUT IN-FILE
GO TO B.
END-READ

The problem is at OPEN OUTPUT OUT-FILE. I never get the DISPLAY "HERE" to show up. I have "TRY TO OPEN FOR OUTPUT" showing up.

This really confusing. Basically, I've heard that named pipe files are used in a SELECT statement as mentioned above much like a SEQUENTIAL file is.

Can't we open a sequential file in INPUT/read mode, close it, and then open the same sequential file in OUTPUT mode and write to it???

Is that not possible?

Thanks.
-David
 
David,

I believe you have to have a process reading the other end of the pipe when you open it output. I have duplicated your behavior with RM/COBOL, MicroFocus COBOL, a C program and with UNIX shell commands.

For example, create a named pipe,

mknod pipefile p

Send something to it, this command will appear to hang,

echo "Hello World" > pipefile

From another telnet session enter the command,

cat pipefile

The "Hello World" will be displayed.

The behavior you are seeing has nothing to do with the pipe file being opened input during the run unit. Change your program to only do an open output and you will see the same behaviour. While it is waiting on the open output, cat the file from another user and the COBOL program will continue.

Hope this helps.


-Rob

 
Rob. You're exactly right!
Thanks! This came down the fundamentals of named pipe files.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top