Question

Having trouble with RPG creating an output file on AS/400

Asked by: netwrked

Our programmer has left and I have a task that must be completed.  We currently have an RPG program that sends output directly to a printer.  Corporate wants to rollup the reports to a softcopy to save paper.   I am no RPG programmer.

I took the orginal file (attached) that output to two printers and added what I thought would be code to get it to output to a file.  When I run the program using the lines in the code section below, I still get the printed output, but no file is created.  I expected to see ADPFCH.

Not sure what I am doing wrong.  The second attachment is what I came up with.  I tried making it look like other reports that do rollup correctly, apparently I am missing something.  Would greatly appreciate any help.

Joe

0024.00              PGM                                                        
0025.00              OVRDBF     FILE(ADTRAN) TOFILE(MYLIB/ADTRAN1)
0026.00              OVRDBF     FILE(ADPCKFCH) TOFILE(MYLIB/ADPFCH)
0027.00              CALL         PGM  MYLIB/WELRPT)
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
 F3=Exit   F5=Refresh   F9=Retrieve   F10=Cursor   F11=Toggle   F12=Cancel      
 F16=Repeat find        F24=More keys

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:

Select allOpen in new window

  • MyVersion.txt
    • 3 KB

    Modified code - sends to one printer and ADPFCH file

  • Original.txt
    • 3 KB

    Original code - sends to two printers

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-07-21 at 11:44:40ID24588545
Tags

RPG

,

AS/400

Topics

RPG Programming Language

,

AS / 400

Participating Experts
2
Points
500
Comments
23

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. What is RPG, Lansa?
    Hi! May somebody tell me what RPG and Lansa are? (i found out that they are related to AS400) I need a short description of these, if it's possible. ...or some good links where I can find information about these. Many Thanks!
  2. RPG programming and AS/400
    Big points for this, so ya gotta do some thinking!! I want 30 questions that would most likely come up in an interview that programmers and managers ask potential new RPG programming employees. Here are the guidelines: 10 questions that are basic, designed to see if the ca...

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: tliottaPosted on 2009-07-21 at 13:52:02ID: 24909205

Joe:

One part isn't clear --

>  We currently have an RPG program that sends output directly to a printer.

Can you elaborate on that? Are you _sure_ that the job sends directly to the printer rather than routing through an output queue?

Normally, direct output to a printer would imply some very specific business need. For example, by communicating directly with a printer, you can bypass intermediate storage on a queue where the output _might_ be visible to some operators who shouldn't see it. Direct printing can thereby be highly secure.

But maybe the output simply routes through a queue automatically and simply _appears_ to go "direct". It's pretty rare to see direct printing.

Tom

 

by: Gary_The_IT_ProPosted on 2009-07-21 at 23:12:11ID: 24911880

Joe,

Usually when a client comes to me with a similar request, they really want to the report image in some PC compatible format (PDF, XLS, CSV, TIFF, TXT, etc.).

There really are lots of options:

1) Grab the spooled output and convert it to PDF, TIFF ot TXT, as appropriate.
2) Modify the underlying program to export a database file (or XLS, CSV, etc)

What exactly do you mean by "softcopy"?

- Gary Patterson

 

by: netwrkedPosted on 2009-07-22 at 03:07:15ID: 24912973

My bad, my inexperience knows no bounds!  On the first part, the job is sent to QSYSPRT and the operators release it to do the hardcopies

I have attached another program which is (I believe) to be the rollup program.  Essentially, there are other programs that write the reports to a disk file.  Those disk files get concatenated into two file and the attach program concatenates the two files into one and gives it a name of  X071709X01.MBR  (that is date of 7-17-09).  From i-series, I can see that is goes to a library called IMAGECMIP, then CSDTCI.FILE and then the MBR.  I believe it is the two CPYF commands that do this.

If I could just grab the spooled file and concatenate it with the rest, that would save me from trying to do the O records and I could leave the original program as it is.  I am not sure how I would modify the attached code to do that, would you be able to help?

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-23 at 11:05:01ID: 24928164

In RPG programs, I/O is performed through device-specific "files" that represent a particular device" Disk file, Tape file, Printer file.

You can use the OVRDBF (Override with Database File) in certain cases to override a Printer file to a Database file, without changing the underlying program that creates the printer file.

Assuming that the PRINTER file is called ADPCKFCH, then the database file MYLIB/ADPFCH needs to exist (OVRDBF will not create it), and you need to be redirecting the correct file from the RPG (the PRINTER file).

Post the WELRPT source code if you need more help.

- Gary Patterson

 

by: netwrkedPosted on 2009-07-23 at 12:04:28ID: 24928866

The original attachments are the welrpt source code.  The original version is the one that was sent to two printers, the second one was my modification which I had hoped would product output.

If there is not way for the O piece to work (I assume I coded it wrong), is there any way to modify the 3rd attachment (the rollup program) to include (concatenate) the spooler print file?

On the calling code piece, my understanding of the line:

OVRDBF     FILE(ADTRAN) TOFILE(MYLIB/ADTRAN1)

means that the database file MYLIB/ADTRAN1 (which does exist) will be used where referenced in the RPG program (where the I record calls it ADTRAN)

What I though would happen with this  part:

OVRDBF     FILE(ADPCKFCH) TOFILE(MYLIB/ADPFCH)

is the the O referenced in the RPG program ADPCKFCH would be written to an output file called MYLIB/ADPFCH.  If I understand your comment, in order for that to work, there has to already be a file called ADPFCH?  Would that be a CRTPF command?

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-23 at 13:08:40ID: 24929407

Yes, you can use the CRTPF command to create the file you need.  Ignore the "source file" parameter, and just specify the correct record length (should match the report width).

Sounds like you understand.

Depending on lots of complexities, it is possible that your override isn't in effect when the RPG program gets run.  Specify OVRSCOPE(*JOB) - that will make sure that the override applies to all programs in the job.  Also make sure you DLTOVR the override immediately after you are through with it:

OVRDBF
CALL
DLTOVR

Keep in mid that overrides do not survive the SBMJOB command.  If you put an override in place and then submit a job to batch, the override will not apply to the work performed inside the sublitted job.  It will continue to apply in the submittING job.

====================================================================================

Let's back up.  Apparently, I never looked at your original source.  This is old RPG II-styple cycle-driven code, and my RPG II is about 15 years rusty, so bear with me.

I do notice that you are missing a "D"etail specification in you "O" specs for ADPCKFC in MyVersion-1.txt.  Needs to be above the "TYPE    3" line:

  O        D        01

The "D" instructs RPG to output this block when it is doing "Detail time" output in the RPG cycle, and only when indicator 01 is on (valid record read that matches input criteria specified in you I specs.

Create the file, then fix the detail spec.  You will have some issues with repeating page headings, too. Remember that your "C" specs get executed each time a new record is read from your primary file.

The attached code should get you there.  I was too lazy to replicate the ADTRAN layout, so I just use two fields, but you should get the gist of it.

- Gary Patterson

     H        1                                                         
     FADTRAN  IP  F     100            DISK                             
     FADPCKFCHO   F     133            DISK                      A      
     FQSYSPRT O   F     132     OF     PRINTER                          
     F*                                                                 
     IADTRAN  AA  01   1 CC   2 CT                                      
     I                                        1   2 TYPE                
     I                                        3 100 REST                
     I        NS  02                                                    
     C* EXCEPT THE REPORT HEADERS                                       
     C   OF                EXCPTHDR                                     
     C*                                                                 
     C           *INZSR    BEGSR                                        
     C                     EXCPTHDR                                     
     C                     ENDSR                                        
     OADPCKFCHEADD             HDR                                      
     O                                    1 '1'                         
     O                                    9 'AURCTRPT'                  
     O                                   41 'C O M P A N Y C E   W E'   
     H        1                                                           
     FADTRAN  IP  F     100            DISK                               
     FADPCKFCHO   F     133            DISK                      A        
     FQSYSPRT O   F     132     OF     PRINTER                            
     F*                                                                   
     IADTRAN  AA  01   1 CC   2 CT                                        
     I                                        1   2 TYPE                  
     I                                        3 100 REST                  
     I        NS  02                                                      
     C* EXCEPT THE REPORT HEADERS                                         
     C   OF                EXCPTHDR                                       
     C*                                                                   
     C           *INZSR    BEGSR                                          
     C                     EXCPTHDR                                       
     C                     ENDSR                                          
     OADPCKFCHEADD             HDR                                        
     O                                    1 '1'                           
     O                                    9 'AURCTRPT'                    
     O                                   41 'C O M P A N Y C E   W E'     
     O                                   63 'L F A R E   B O A R D'       
     O                                   76 'PAGE-'                       
     O                         PAGE6 Z   80                               
     O        EADD             HDR                                        
     O                                   44 'UNEDITED CT TRANSACTIONS'    
     O                                   53 'REPORTED'                    
     O                         UDATE Y   62                               
     O                                    5 'TYPE'                        
     O                                   25 'REST'                        
     O        DADD     01                                                 
     O                         TYPE       3                               
     O                         REST     103                               
     C*                                                                   
     OQSYSPRT H  206   OF                                                 
...
                                              
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:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:

Select allOpen in new window

 

by: netwrkedPosted on 2009-07-24 at 11:49:14ID: 24937847

I think I am getting close.  On my system, it would not allow be to enter the "*" in front of INZSR.  It says "The Factor 1 entry is invalid".  I hit F4 to bring up the prompts.  Level is blank, N01N02N03 is blank, Factor 1 has INZSR, Operation has BEGSR and the rest are blank.  If I enter an * anywhere to the left of INZSR, I get the message above.

I did the CRTPF for the ADPFCH file and it created successfully.  However, when I call myversion of the RPG, I still get no output.  Is that due to the missing *'s.  I have attached myversion.txt to this post which incorporates the changes you suggested.  Can you do a wuick sanity check on it for me?

I truly appreciate the help, hopefully we can get a AS/400 expert hired that will stay more then 2 days!

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 12:13:05ID: 24938111

Joe,

I certainly understand your dilemma.  I see the same problem all the time, since my company frequently gets hired to provide ongoing support by organizations that are tired of dealing with AS/400 employee and/or contractor turnover.  We also get to clean up a lot of messes left by "short-timers".

What is the source type on your RPG program member?  RPG, or RPG36?  It must be RPG36: try changing the source type to RPG, then it should take *INZSR.  I'm not sure that the syntax is for INZSR in S/36 RPG II, and I don't have a manual handy.  RPG36 source type forces SEU and the RPG compiler to obey ancient System/36 RPG II syntax rules.  RPG will allow my *INZSR code.

Make sure the file that you created is in a library in the library list, and that no other file with the same name is higher in the library list.  You can test this using the WRKF command:

WRKF *LIBL/ADPFCH

If the program is not crashing, but not producing the output you expected, it probably means that it is writing to a file with the same name (or to an overridden file with a different name) someplace else.

Or just try switching output files to a completely new name that you know doesn't exist elsewhere ad is unlikely to be overridden (XMRWPQQY, or some other random name - then use WRKF to check).

Alternately, if you know how, you can run the program in debug, and look at the list of open files to see what files are being updated.

- Gary Patterson

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 12:20:41ID: 24938185

Joe,  

Drop the U8 switch on the F spec for ADPFCH, (or turn on job switch 8 before you call this program).  That is why you aren't getting output.

The U8 tells RPG to only use this file if job switch U8 is on.  I bet it isn't, especially in your testing.

This provides jobs a mechanism for turning file generation on or off, without much coding in each program.

IF your job stream uses switch 8 to control file generation, then you'll need to include the U8 switch, but turn it on when testing.  You can use the CHGJOB command's SWS paramter to turn these switches on or off:

SWS('00000001') turns on switch 8
SWS('00000000') turns off all switches
SWS('1010101010') turns on switches 1,3,5, and 7.

- Gary Patterson

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 12:23:22ID: 24938209

Got a little enthusiastic with my last SWS example.  Drop the extra "10" pair.  There are only 8 switches.

- Gary Patterson

 

by: netwrkedPosted on 2009-07-24 at 13:03:30ID: 31618574

Eureka!  That was it, I now have output.  Looks like I have some cleaning up to do, it it printing a header, then data, then another header, etc.  Many many thanks for the assist!

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 13:06:30ID: 24938609

Happy to help.

- Gary Patterson

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 13:07:51ID: 24938628

If you use my code, you will see that it does not have the repeating header problem.

- Gary Patterson

 

by: netwrkedPosted on 2009-07-24 at 13:55:04ID: 24939013

Hmmm...my codes matches yours but it still prints the header lines

AURCTPR       C O M P A N Y C E  W E L F A R E  B O A R D          PAGE 1
                           UNEDITED CT TRANSACTIONS REPORTED
TYPE          PURPOSE    AMOUNT    <...>
CT             <DATA>       <data>     <...>
AURCTPR       C O M P A N Y C E  W E L F A R E  B O A R D          PAGE 2
                           UNEDITED CT TRANSACTIONS REPORTED
TYPE          PURPOSE    AMOUNT    <...>
CT             <DATA>       <data>     <...>

It repeats, showing one line of data, then goes to a new page number.  I know this is closed, I can open a new question for this issue.

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-24 at 15:33:05ID: 24939697

That's OK - post your current code one last time for me to look at and see what I can see.

- Gary Patterson

 

by: netwrkedPosted on 2009-07-24 at 17:51:31ID: 24940248

File attached..essentially, it should look like:
AURCTPR       C O M P A N Y C E  W E L F A R E  B O A R D          PAGE 1
                           UNEDITED CT TRANSACTIONS REPORTED
TYPE          PURPOSE    AMOUNT    <...>
CT             <DATA>       <data>     <...>
CT             <DATA>       <data>     <...>
CT             <DATA>       <data>     <...>
CT             <DATA>       <data>     <...>
CT             <DATA>       <data>     <...>
CT             <DATA>       <data>     <...>
AURCTPR       C O M P A N Y C E  W E L F A R E  B O A R D          PAGE 2
                           UNEDITED CT TRANSACTIONS REPORTED
TYPE          PURPOSE    AMOUNT    <...>

I tried moving some things around, definitely made it worse.  I had copied most of  the lines from the original printed output thinking it would be the same...wrong again!

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-27 at 09:24:07ID: 24953194

Joe,

Your "C" specs aren't quite the same as mine, though if this is really the code you are running, you shouldn't see a new page generated with each row.

Does the repeating header problem happen in the file, the printed report, or both?  

- Gary Patterson

Mine:
     C   OF                EXCPTHDR     <-- Print headings on page overflow                                      
     C           *INZSR    BEGSR                                          
     C                     EXCPTHDR     <-- Print headings 1x during pgm initialization                                  
     C                     ENDSR         
 
Yours:
     C   OF                EXCPTHDR
     C           *INZSR    BEGSR
     C                     ENDSR

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:

Select allOpen in new window

 

by: netwrkedPosted on 2009-07-27 at 12:26:03ID: 24954979

The printed report is correct, but the disk copy was not.  I made the changes above, it is "almost" perfect.  What it is doing now is printing a page of data, then the header with Page 1, and then more data.  If there is an easy way to get the header above the first set of data, I believe that will do it!

Thanks!

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-27 at 12:36:21ID: 24955088

Joe,

Please post your current code...

*INZSR BEGSR
EXCEPTHDR
ENDSR

Is supposed to print the headings before the first set of data.  Are you sure you have the EXCEPT HDR inside the BEGSR-ENDSR block?

- Gary Patterson

 

by: netwrkedPosted on 2009-07-27 at 12:44:54ID: 24955205

I believe mine looks like yours, file is attached.

 

by: Gary_The_IT_ProPosted on 2009-07-27 at 14:00:02ID: 24955972

This should do it.  Are you clearing the output file between runs?  Also change the following line of code:




     O        TADD     01
     O                         TYPE       3
     O                         PURPOS    39
 
change to
 
     O        DADD     01
                                              
1:
2:
3:
4:
5:
6:
7:

Select allOpen in new window

 

by: netwrkedPosted on 2009-07-28 at 02:14:39ID: 24958936

That did it!!!!  Many many thanks!  I truly hope we can find someone with your experience to take over our system.  Getting someone in to take over undocumented 30 year old code is no easy task.

Joe

 

by: Gary_The_IT_ProPosted on 2009-07-28 at 09:37:53ID: 24962421

Happy to help.  

- Gary Patterson

Check out my EE profile:  http://www.experts-exchange.com/M_4382324.html


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