Printing specific pages

Hi frnds ,
I have a query . I need to create a tool which prints a spool file with specific pages only..
As far as i know..this can be done using OVRDBF PAGERANGE option . I have read an article on Iseries network ( problem with remote queues )
So..if this true then what things/issues i need to take care in my program ??
Pls explain in detail.
Your answers would be greatly appreciated.
Thanks and waiting for replies..

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

raj28Author Commented:
i.e this is a problem when spoolfiles are sent to a network printer - the full file is printed rather than the start/end pages that you requested.

There are tools out there that will do this already.

But if you want to do your own,

You will need to create two physical files which are 1 character longer than the width of the spool file.

copy the spool file to first physical file...

*FCFC (help from command CPYSPLF)            
    Specifies that the first character of every record    
    contains one of the ANSI forms control codes listed in
    the CL Reference manual.                    

Code Action before Printing a Line   (extract from CL refereence manual- CPYSPLF command)
’ ’      Space one line (blank code)
0       Space two lines
-       Space three lines
+       Suppress space
1       Skip to next channel 1
2       Skip to next channel 2
3       Skip to next channel 3
4       Skip to next channel 4
5       Skip to next channel 5
6       Skip to next channel 6
7       Skip to next channel 7
8       Skip to next channel 8
9       Skip to next channel 9
A       Skip to next channel 10
B       Skip to next channel 11
C       Skip to next channel 12

Write your program to copy the appropriate pages of information from PFILE1 to PFILE2,
you can look for control character 1..9,A,B,C as these indicate a new page and keep an internal count of page numbers.

Then copy this file back to a spool file with EXACTLY THE SAME attributes as your original spool file after applying the override

This should produce a spool file with just the pages you specified.

An Alternative approach would be to use *PRTCTL instead of *FCFC
*PRTCTL   (help from command CPYSPLF)                                                          
    Specifies that the first four characters of every record contains
    skip- and space-before values useful in high-level language
    programs.  This code can be viewed as SSSL, where SSS is the
    skip-before line value and L is the space-before value.    

As this uses 4 characters you will need to create one physical files which is 4 characters longer than the width of the spool file.

copy the spool file to first physical file...

Your program would need to read this file (internally defined to separate skip- space- splf data) and select the pages you want then print these out to a spool file with EXACTLY THE SAME attributes as the original spool file.  Your program would need to apply the skip- and space- before values as required.

Made a mistake..... In copying the data back to a print file for *FCFC..  you need the following commands..

Then copy this file back to a spool file with EXACTLY THE SAME attributes as your original spool file after applying the override
OVRPRTF FILE(SPLFLIB/SPOOLF) CTLCHAR(*FCFC)    <<tells it use the *FCFC ctrl chars>>

nb. You could always amend the OVRPRTF to use QSYSPRT and override the attributes to match the original spool file + CTLCHAR(*FCFC), then CPYF FROMFILE(TEMPLIB/PFILE2) TOFILE(QSYSPRT)

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

raj28Author Commented:
Hi tony,
Thx for quick reply. I want to confirm one thing - Will PAGERANGE option works in LAN i.e it gives problem only to remote queues ?  and other thing is how can i retreive the spool file width in program i.e rcdlen ??

thanx in advance,

easy one first... I don't believe page range will work in LAN either.

I am afraid I am a dinosaur and haven't got into APIs yet, but there are print APIs which will help unfortunately I can only point you in their direction - I can't help you to use them.
The link    links into the IBM Info centre, choose the appropriate country, language and os release - then you need to look for APIs under the programming section.
I have a problem getting the left hand navigation pane to show (JAVA problems I think) - but use the "site map" link from there or use the link   which will take you to a list of downloadable PDFs - and the navigation pane is ok (for me) !!!

If you have the time - get into APIs to write commands for the 21st Century !!

My old fashioned approach would be long winded as you would have to work with splf attributes into "another" spool file [IBM won't allow an output file], which could be copied into "another" physical file and then read this file to identify the record length and any other attributes you want.


Extra info - in the API examples V5R2 there is a "Delete Old Spool Files" command that may give you some ideas.

raj28Author Commented:
Hi tony,
I copied the spool file to PF using *FCFC abut it appears '1' in PF as First character whenever new page starts . So how can i get specific pages  ?? Also one more thing - *FCFC doesn't work for externally described printer files .( CL reference manual ). any workaround for this ??

I am pretty sure the '1' is a skip to new page, line 1... some reports may start printing on line 2 or 3 - IBM go upto line 12 - probably to cater for special stationery (eg. invoices).

In the extract IBM say
          'n' skip to channel n
I think this translates to
           skip to next page, line n

As I said I think you will have to either
(a) pick up the Page Number from the data on first Line if you know the report you are dealing with
(b) if you want to be generic, then you will have to count the page numbers in the program, by looking for '1'..'9','A','B' or 'C' and incrementing page count.

You can't copy the new file back to an external printer file, which is why I said "Then copy this file back to a spool file with EXACTLY THE SAME attributes as your original spool file", it requires the same attributes but needs to be just an ordinary print file (sorry I didn't make that clear).
You could just use the over ride printer file to set up the right attributes after retrieving them from the spool file.

If you were making it a generic utility, you would need to identify the spool file, retreive the attributes incl record length. Create workfiles with rcdlen=spool len+1 and build an override print file command with the correct attributes then do all the copying about.

Maybe initially to get you up and running, create appropriate workfile(s) and print file(s) with the same attributes as the report(s) you are interested in at the moment and then work out later how to retrieve the attributes and make the utility more generic.

raj28Author Commented:
Hi tony..
U mean to say..i have to update PF wth page number ?


I am not explaining this very well... try this...

Lets say you have a 200 page report and you want to print pages 10 through 12.

After you have copied the 200 page report into file1, your program will need to read through data in file1 and "find" page 10, then start writing the data into file2 until you reach page 13 then exit; you can then copy file2 into a new spool file.  

Two ways you can "find" page 10
(a) manually count the codes which skip to new page (my recommended choice - see below)
(b) Page number is printed on the report and is therefore in the record somewhere - but this is not guaranteed to be on first line of each page because it depends on programmer and any programming standards.
line1:                                        COMPANY NAME
line2:   date  time                                                                 page xxxx
SO STICK WITH option (a) as described below....

NB. The printed page numbers in the new print will still show page 10, page 11 and page 12.  (Hope thats ok !!!)


Control program
- retrieve spool file attributes etc, create work files, copy spool file to File1
--- Call process program passing StartPage and EndPage
- Copy File2 to create new spool file

pseudo code for process program...

/* receive parameters for StartPage End Page */
StartPage = ParmStartPage
EndPage = ParmEndPage

PageCount = 0

/* Read Through File1 until reach Start Page */
Dou pagecount < StartPage
   Read    File1rcd
   Code = %substr(File1rcd,1,1)
   If Code in ('1','2','3','4','5','6','7','8','9','A','B','C') then
     PageCount=PageCount + 1

/* Now have first record of page 10 */
/* Copy File1 rcds to File 2 until reach page after EndPage */
Dou Pagecount > EndPage
   File2rcd = File1rcd
   Write File2 Rcd
   Read    File1rcd
   Code = %substr(File1rcd,1,1)
   If Code in ('1','2','3','4','5','6','7','8','9','A','B','C') then
     PageCount=PageCount + 1
/* Finished writing out File2 records */


Does this make it clearer ?


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

Page ranges can work fine with LAN printers as long as they're set up correctly in the first place. In general, page ranges are not easily supported by LPR/LPD. That's a problem with that protocol to begin with, but QUSRTOOL has a tool that helps. See it on your system as the tool named TSPRWPRI.

But for many systems, there's a far better way -- don't use LPR/LPD and remote outqs. Instead, create a remote printer device description and use it with a local outq.

E.g., create a printer device as a *LAN 3812 model 1. Assign LAN attachment as *IP and supply the proper IP address and port number. (For an HP LaserJet for PJL, the port is usually 9100.) The manufacturer type and model would be *HP4000 in our case. I usually use *HPPJLDRV as the system driver program. Other parms can be set as needed.

It'll have an outq when it's created and you'll handle the outq and its writer just like any direct-attached printer. The one in the next room over from me is attached to the LAN with an HP jetdirect printer server adapter in the back.

Hardly anything special about it.

I'm still unclear why any programming is needed at all. I just created a new LAN printer device description for an HP LaserJet 8150 that's plugged directly into our LAN over on the other side of our building. Took about 2 minutes. I now have full page range support from the AS/400.

In fact, the original question pointed to an article that described exactly how to do this. The question was "what things/issues i need to take care in my program ?"

The answer is "Nothing."

When you want to print, you simply specify the page range, e.g.:

 ==>  chgsplfa  pagerange( 5 10 ) print pages beginning at page 5 and ending at page 10. Release the spooled file and the page range prints. Simple.

Well, technically, I suppose the things to take care of in a program _could_ be making sure that the spooled file is created on HOLD or on an outq that doesn't have a writer active that will print the spooled file immediately; but that's standard stuff.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
IBM System i

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.