Cadet 1st Class
Cadet 1st Class
1574 views

Cobol Printing

Can anyone tell me how to print a file from within a cobol program.  I simply wish to write my data to a report and then print the report.  I tried using the PC_PRINT_FILE but I keep getting status code 05.  If anyone could share code examples that would be very helpful.  I tried also using the example given in prntfile.zip.  However, it keeps giving me an error about a missing .dll file and the prntfile.exe is missing.

Tags (1)
0 Likes
3 Replies
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

What operating system are you working in? We use Linux and have the Cobol programs write to a temp print file and use an environment statement to send the print request.  So Cobol writes to file prt01 and the environment has dd_prt01=>lp -dprt01 -s -oraw

0 Likes
Cadet 1st Class
Cadet 1st Class

I am using windows 10.  I actually got it to work.  I just needed to put the .dat file in the C:\ root folder.  But, if you wanted to share some other code I would not mind at all.

0 Likes
Micro Focus Expert
Micro Focus Expert

If you are using PC_PRINT_FILE on Windows then you do not need to place the file in the C:\ root directory in order to print it.

What is the name of the file that you were trying to write to?

If the filename contains a space character then you will need to enclose it within quotes when creating it but in PC_PRINT_FILE you would just leave it as is but set the filename-len parameter to the actual length of the filename. The docs for PC_PRINT_FILE specify that the name is space or NULL terminated but that is not true.

Example:

    select test-file assign to '"c:\my folder\printfile.txt"'.   *>double quotes enclose name surrounded by single quotes

params used in PC_PRINT_FILE

01 filename-param.

         03 filename-len          pic x(2) comp-5 value 26.

         03 filename              pic x(256)

         value 'c:\my folder\printfile.txt'.

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.