New Ranks & Badges For The Community!
Notice something different? The ranks and associated badges have gone "Star Fleet". See what they all mean HERE
Highlighted
Absent Member.
Absent Member.
3993 views

Printing

Jump to solution

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.

Tags (2)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

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...

View solution in original post

0 Likes
10 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

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,

0 Likes
Highlighted
Absent Member.
Absent Member.

Can that file be an external file that is created during the select assign to statement?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

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...

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

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'?

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

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.

0 Likes
Highlighted
Absent Member.
Absent Member.

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.

0 Likes
Highlighted
Absent Member.
Absent Member.

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!

0 Likes
Highlighted
Absent Member.
Absent Member.

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.

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

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#.

0 Likes
Highlighted
Absent Member.
Absent Member.

Thanks, I'll look into that.

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.