Question

iSeries: Capture RPG printer output as a string

Asked by: MGothelf

I have an iSeries RPG program that writes a report using a printer file that has a dozen different record formats.  I need a way to repeat the printing of each page, without having to read through the data files a second or third time, and my solution is to capture the printer output and write to a file as a string of 132 characters.  I would like to avoid having to write a dozen routines to parse each record format as it is written and just save the 132 character buffer.  Is there a way to do this?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-06-23 at 07:28:56ID24514746
Topics

Programming for iSeries / AS400

,

RPG Programming Language

,

AS / 400

Participating Experts
3
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Need help for IBM certification :: i5 iSeries RPG ILE Progr…
    Hi All, I am planning to take i5 iSeries RPG ILE Programmer (IBM Test - 268) exam since last few days. But I am not sure whether it will help me into my career and what type of question I need to prepare for, as there is no assesment test from IBM. Can any one please guide ...
  2. Why use RPG?
    I work with .net/sql server and new to AS400... Trying to understand if RPG is object-oriented or is it considered a procedural language. Read the entry in wikipedia and looked at an example but still not clear... Given the choice...why would one use RPG over .net/iSeries P...
  3. Used Iseries server
    I want to buy a used Iseries box from ebay I am new on how to buy a Iseries box ; I have always used one which was provided to me and was logging in thru 5250 terminal. I saw many listing on ebay IBM AS400, iSeries, AS/400 9406-550-0915-7463 3300 CPW ($120,000) IBM AS...
  4. How can I copy Source RPG programs & CL to a PC using I…
    I have did this before but have forgot. I need to transfer some RPG & CL programs to a PC in .txt format. How can I accomplish this? I believe I have used Iseries Navigator before to do this.
  5. How Do I Call An RPG Program From An iSeries Stored Proc…
    I need to be able to call an RPG program from an iSeries Stored Procedure. The program that we have is that when the procedure is called an error is returned that the program cannot be found in the library. We are calling the procedure from a .NET application. We are able ...
  6. What is the easiest and quickest way to get XML file data in…
    I need to find out the quickest and easiest way to import XML file data for update into iSeries files using ILE-RPG programs. Thanks, Phil

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: daveslaterPosted on 2009-06-24 at 00:43:10ID: 24698983

Hi
you could use a Multi Occurance Data structure

the basic code is.



D ExtDs           ds                                                          
D  fld1                         10                                            
D  fld2                         10                                            
D**......                                                                      
D  fldx                         10                                            
                                                                               
D MODS            ds                  Occurs(12) Likeds(ExrDs)                
  /Free                                                                        
       Idx = 0 ;                                                              
       Dow '1' = '1' ;                                                        
          read Myfile ;                                                        
          if %eof ;                                                            
             leave ;                                                          
          endif ;                                                              
           fld1 = FileField1 ;                                                
           fld2 = FileField2 ;                                                
           fldx = FileField3 ;                                                
           idx+=1 ;                                                            
           %occur(Mods) = Idx;                                                
          Mods = ExtDs ;      
    enddo ;                


for idx1 = 1 to Idx ;
           %occur(Mods) = Idx1;                                                
          // move MOds to print file
          write format ;
endFor/


<<--------------------->>
 
Dave

 

by: MGothelfPosted on 2009-06-24 at 04:56:25ID: 24700146

I am already doing this with data structures in a slightly different way.  

It will not work for me to capture the INPUT fields because I need a solution that is easy to replicate withou having to recreate the data structures and input output logic each time.  The program logic does not allow for your solution because there are over a dozen record formats and different processing logic for each, so I would have to rewrite huge chunks of code.  (Where you say 'write format' would essentially be duplicating the entire program logic).

I need to capture the OUTPUT, that is the 132 character string that is being sent to the printer, so that I could then simply loop through the saved lines and write them out.

 

by: daveslaterPosted on 2009-06-24 at 05:26:16ID: 24700324

Can you post an example!

 

by: stevebowdoinPosted on 2009-06-24 at 08:24:26ID: 24702031

Are you wanting to duplicate pages in the same SPOOL file or will duplicateing the SPOOL file work?

 

by: tliottaPosted on 2009-06-24 at 18:10:00ID: 24707336

MGothelf:

It sounds like you have an existing program that had no design that allowed this to happen. And now you're asking for a way to get it done without changing the design.

Do you have the source code? It sounds like you do, because you discuss some of the program elements. So, we can probably assume that source code isn't an issue.

Are you allowed to make changes and re-compile? Again, it sounds like you do; but the question has to be asked.

Finally, are you an experienced developer in this language? There _might_ be a technique or two that you could use, but they'll be much easier to describe if we're fully informed of your level of comfort.

Can you please attach the output from DSPFD yourlib/yourfile TYPE(*RCDFMT) here?

Tom

 

by: MGothelfPosted on 2009-06-24 at 19:03:19ID: 24707547

I have an existing program.  It writes headers and detail lines.  It is now writing to a dot matrix printer that prints a 4-part form.  The user wants to replace with a laser printer, so that I would now have to print page 1 four times followed by page 2 four times etc.

What I have developed is a solution based on a series of 132-byte data structures, each of which stores the data fields that make up a record format in the Printer File.  As each record format is written, I copy the data fields to the appropriate data structure, then store the entire 132-byte data structure in an array of the print lines.

At the end of the normal printing of page 1, then go through the array and print the lines 1 by 1.  I do this 3 times (for page2, page3, page4).

This works OK, but if the layout changes, its a lot of code to maintain in each data structure.  Also, to duplicate this in another program is a bunch of work.

The PRTF is a normal printer file with a standard record length of 132 bytes. What I am hoping to find is a way to grab the 132-bytes that are sent to the printer buffer each time I do a WRITE.

 

by: stevebowdoinPosted on 2009-06-24 at 20:48:21ID: 24707897

The biggest problem you will have is forms control.
Let the system do that for you.

Here is some code for you.
Call the CL right after the RPG that creates the SPOOL file.  Give it a parm of the printer file name.
This process will be very flexable for you.

I am sure many newbies to RPG will find this code quaint.

Steve

             PGM        PARM(&FILE)
             DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)
             CRTPF      FILE(QTEMP/IN) RCDLEN(133)
             MONMSG     MSGID(CPF0000)
             CRTPF      FILE(QTEMP/OUT) RCDLEN(133)
             MONMSG     MSGID(CPF0000)
             CPYSPLF    FILE(&FILE) TOFILE(QTEMP/IN) SPLNBR(*LAST) +
                          CTLCHAR(*FCFC)
             CLRPFM     FILE(QTEMP/OUT)
             CALL       PGM(QUADRPG)
             OVRPRTF    FILE(QSYSPRT) CTLCHAR(*FCFC)
             CPYF       FROMFILE(QTEMP/OUT) TOFILE(QSYSPRT)
             ENDPGM
 
 
     Fin        ip   f  133        disk
     Fout       o  a f  133        disk
     D a               s            133    dim(100)
     d x               s              3  0
     d max             s              3  0
     d copies          s              3  0 inz(4)
     Iin        jn
     I                                  1    1  fcfc
     I                                  1  133  rec
     C     fcfc          ifeq      '1'
     C                   exsr      writeloop
     C                   endif
     C                   add       1             max
     C                   move      rec           a(max)
     Clr                 exsr      writeloop
     C     writeloop     begsr
     C     max           ifne      0
     C     1             do        copies
     C     1             do        max           x
     C                   except    record
     C                   enddo
     C                   enddo
     C                   clear                   max
     C                   endif
     C                   endsr
     Oout       eadd         record
     O                       a(x)

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:

Select allOpen in new window

 

by: tliottaPosted on 2009-06-26 at 16:53:12ID: 24725663

>  As each record format is written, I copy the data fields to the appropriate data structure, then store the entire 132-byte data structure in an array of the print lines.

Note that you should be able to overlay any number of formats with a single 132-byte field. If all that is done is capturing the bytes, then it's not necessary to keep track of individual fields. You might only need to keep track of an identifier value -- 'A' thru 'Z' is enough to identify 26 different data structures. A single-byte identifier would add one byte to make it a 133-byte area.

An array of 133-byte fields could be looped through. The chosen output "format" would be determined by the identifier.

It doesn't sound, though, as if you actually have different 'record formats'. It sounds like you have a single format of 132 bytes that you populate by executing different output specs. This would be something like a case where QPRINT, QSYSPRT or some similar generic "printer file" is used.

Many(!) years ago, I had a similar requirement. I had to convert an app that printed multi-part forms to print multiple copies on a laser printer. (A State government-issued certification app.) That was my introduction to designing and implementing true printer files.

It was quite a challenge re-engineering the RPG. But once finished, it was absolutely trivial to print multiple copies of pages. Where each page previously required a dozen or more different WRITE or EXCPT instructions and the O-specs were almost as numerous as the rest of the program, the end result was a single WRITE statement per document page and O-specs of perhaps a half-dozen lines to accommodate some specific details. I could print three copies simply by issuing the WRITE in a loop. If six copies were needed, the loop control variable was increased.

I suspect that that isn't the best direction for you to go right now, though.

Maybe what you should consider is changing your PRINTER file to a SPECIAL file.

Your main program could _mostly_ stay the same as it is now. You'd format your print lines as you do now. You'd issue a WRITE or EXCPT, and the formatted line would get passed to your SPECIAL handler program as a string of characters.

You might add a couple parms to the PLIST() in order to signal NEW_PAGE or other details. Your SPECIAL handler would do very little except store lines in an array and send the array to the printer (twice) when NEW_PAGE was signaled.

The RPG Programmer's Guide (not the Reference) has a simple example of a SPECIAL file with basic handler.

Tom

 

by: MGothelfPosted on 2009-09-02 at 07:06:32ID: 31595513

Thanks Tom.
This solution is very clean and easy to understand. I have not worked with SPECIAL files, but that sounds like the way to go.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...