
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
I am having trouble using the printer_redirection code. My printer will act like it wants to start printing, but nothing comes out. I am testing with the testprintraw cobol project. My printer acts like it wants to start printing, but nothing happens. What I am looking to do is build a report, save it to a file with headers and data and then print those results to my windows printer. I am using the Micro Focus Cobol for Visual Studio 2012 version.
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Take a look at PC_PRINT_FILE routine in the docs under Library routines.
The first parameter that you pass in is a variable containing the filename to print.
This could be the same variable that you use to hold the file-name in the SELECT.
If you are assigning your file to an environment variable which is set outside of the program then you would have to read the contents of that environment variable in order to set the name.
something like the following:
select test-file assign to external MYENV
...
01 pn-name.
03 pn-name-len pic x(2) comp-5
03 pn-name pic x(256).
open output test-file
display "MYENV" upon environment-name
accept pn-name from environment-value
*>find the length of the file name
perform varying pn-name-len from length of pn-name by -1 until pn-name-len < 1
if pn-name(pn-name-len:1) not = " "
exit perform
end-if
end-perform
call "PC_PRINT_FILE using pn-name...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
If you are writing the file to disk first then perhaps you could try using PC_PRINT_FILE instead of the printer redirection shown in the example which is really for writing your print line directly to the printer.
The example uses esc codes that are for a specific printer that is used in the example. You would have to replace these with codes that are applicable to your own printer if they are indeed different.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Can that file be an external file that is created during the select assign to statement?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Take a look at PC_PRINT_FILE routine in the docs under Library routines.
The first parameter that you pass in is a variable containing the filename to print.
This could be the same variable that you use to hold the file-name in the SELECT.
If you are assigning your file to an environment variable which is set outside of the program then you would have to read the contents of that environment variable in order to set the name.
something like the following:
select test-file assign to external MYENV
...
01 pn-name.
03 pn-name-len pic x(2) comp-5
03 pn-name pic x(256).
open output test-file
display "MYENV" upon environment-name
accept pn-name from environment-value
*>find the length of the file name
perform varying pn-name-len from length of pn-name by -1 until pn-name-len < 1
if pn-name(pn-name-len:1) not = " "
exit perform
end-if
end-perform
call "PC_PRINT_FILE using pn-name...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Sorry for the back and forth questions. I am relearning COBOL. It is quite different from when I studied it in 1984. In reference to the code you sent to me, is this the exact code I use replacing the MYENV with my filename that is located on my C: drive? So it would read select test-file assign to external 'C:\users\....\salesrpt'?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
No, that was an example for assigning to an environment variable because you mentioned you were using an external name which uses an environment variable.
If your select statement is assigning directly to a file name then you do not specify EXTERNAL in the select and you do not need to do the display and accept of the environment variable either.
So it would read:
select test-file assign to 'C:\users\....\salesrpt'
and then this would be the name of the file that you set in the PC_PRINT_FILE call as well.
Question: is this a native code project or a managed code project that you are using?
The example in the knowledgbase is for a managed code project so I just wanted to make sure we were on the same page here and then I can send you a complete sample.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
This is for a school project that I am running on my pc at home. I wasn't sure if it were best for managed for native. I am assuming native since I am not uploading to a server or anything. So, could you send me the complete code. My email address if that would be easier is aadowns1@catamount.wcu.edu. Thanks for your help. Just to recap of what I want to do. When i execute my program to create a sales report, I want the option to send it to my local printer attached to my pc as well as store the sales report on my local disk.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
No need to send the file. It is working great using the PC_PRINT_FILE. I now want to look into the option of having the dialog box pop up to choose the printer name. Maybe another day however. Thanks for your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Has Micro Focus considered tacking advantage of Microsoft visual basic powerpacks 3.0?
I would like to be able to use the good old faction Line Printer.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
You should be able to use the assemblies from Visual Basic Powerpacks from within a managed code .NET COBOL project by simply adding a reference to its assemblies.
Then you can access the available classes and methods from COBOL just like you would from VB.NET or C#.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
Thanks, I'll look into that.