Highlighted
New Member.
1911 views

File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution

Here is my select statement for a file used as printer handling

 


SELECT PRINT-FILE
ASSIGN TO PRINTER "prt109"
FILE STATUS IS ERR-STATUS.


FD PRINT-FILE
RECORD CONTAINS 132 CHARACTERS
LABEL RECORDS ARE OMITTED.

01 PRT-BUFFER.
    10 PL PIC X(132).

I have an environment statement of 

dd_prt109=>lp -dprt109 -s -oraw

 

Writing out records to this file and then doing a close works just perfectly, however I need to add in contents from an existing file which happens to contain some binary data and is much larger than my print file definition.  As such I cannot just read one line at at time from the binary file and inset to the print file.

 

Any suggestions?

 

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution

As Michael.Wojcik says, it would be possible to modify the COBOL program to use byte-stream I-O. Here's a link to byte-stream I-O in the Visual COBOL documentation:

documentation.microfocus.com/.../HRCLRHCALL04.html

Here is sample COBOL source code using byte-stream I-O:

documentation.microfocus.com/.../HRCLRHCALL7C.html

But I speculate this would be more work than your alternative of using a script outside of COBOL to 'cat' the two types of output into the 'lp' command, and of invoking this script from COBOL using CALL "SYSTEM".

For others reading this discussion: the COBOL program could write the output file to disk (instead of writing directly to the "lp" command with dd_prt109=>lp -dprt109 -s -oraw). Then the COBOL program could invoke a shell script that would cat the binary data and the disk file together into the "lp" command. The COBOL program could invoke the script using CALL "SYSTEM" immediately after it finishes writing the file.

Here's a knowledgebase article about invoking shell scripts using CALL "SYSTEM". The article concentrates on retrieving the return code from the scripts, but the sample code shows the basic use of CALL "SYSTEM":


http://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/6537/invoke-a-unix-command-from-within-cobol-using-call-system-and-retrieve-return-code

View solution in original post

0 Likes
8 Replies
Highlighted
Absent Member.
Absent Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
Did you try to open your binary file as sequential (not line sequential). This way you can read your files data in blocks you define yourself and there will not be any CR LF hex characters at the and of your record definition. This way you can print the whole contents of your file in a loop.
0 Likes
Highlighted
New Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
Thank you for the suggestion, unfortunately the record length of the file containing the binary data is larger than the record length of my print file as I tired to describe in my post. I was hoping somehow I could "cat" the contents of the binary file into the Cobol file opened for output. I have an option in creating two different files and then doing a "cat" to combine, but I was hoping there might be a different option from the field.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
The record length depends on your definition and not the file itself. The creator of the file might define it as x bytes / record, you however can define it as y Bytes / record. This way you can read the creators records as chunks of the size you define and process it as you wish.
Maybe I do not understand you correctly. If you can make the file you are talking about available for me, I can be of further assistance.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
If the file you're reading is indeed a blob, and neither text (so LINE SEQUENTIAL is incorrect) nor any sort of COBOL record format (so COBOL records are incorrect), then you should be reading it as a byte stream. The MF COBOL mechanism for doing that is the library routines CBL_OPEN_FILE, CBL_READ_FILE, and CBL_CLOSE_FILE.

See documentation.microfocus.com:8080/.../HRCLRHCALL04.html.

Don't try to force record-oriented I/O on non-record data.
Highlighted
New Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
I am working inside a print macro that is use throughout our system and cannot be changed. I am going to fall back to the "cat" option.
0 Likes
Highlighted
New Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
The file I am trying to merge in with new print data is mostly text commands for a barcode printer with one line of binary that is very long. Thank you for your suggestion but I will go ahead and perform system commands to cat the files together before printing.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution

As Michael.Wojcik says, it would be possible to modify the COBOL program to use byte-stream I-O. Here's a link to byte-stream I-O in the Visual COBOL documentation:

documentation.microfocus.com/.../HRCLRHCALL04.html

Here is sample COBOL source code using byte-stream I-O:

documentation.microfocus.com/.../HRCLRHCALL7C.html

But I speculate this would be more work than your alternative of using a script outside of COBOL to 'cat' the two types of output into the 'lp' command, and of invoking this script from COBOL using CALL "SYSTEM".

For others reading this discussion: the COBOL program could write the output file to disk (instead of writing directly to the "lp" command with dd_prt109=>lp -dprt109 -s -oraw). Then the COBOL program could invoke a shell script that would cat the binary data and the disk file together into the "lp" command. The COBOL program could invoke the script using CALL "SYSTEM" immediately after it finishes writing the file.

Here's a knowledgebase article about invoking shell scripts using CALL "SYSTEM". The article concentrates on retrieving the return code from the scripts, but the sample code shows the basic use of CALL "SYSTEM":


http://community.microfocus.com/microfocus/cobol/net_express__server_express/w/knowledge_base/6537/invoke-a-unix-command-from-within-cobol-using-call-system-and-retrieve-return-code

View solution in original post

0 Likes
Highlighted
New Member.

RE: File open output and assign to printer works fine but need to add contents from a binary file running on Redhat

Jump to solution
Yes Dan, you are correct that the byte-stream I-O is more work than the alternative I already had in mind.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.