Re-open a spool file

1,285 pts.
Tags:
IBM i 6.1
Spool file
Hi, I need to create reports from a sub-file where the user can select several lines. Each selection will call a program to print the requested data, but I need to combine the data into one spool file. Is it any way to re-open an already created spool-file and if yes, how? Thank you in advance. YuVa

Software/Hardware used:
OS 6.1 and 5.4 on IBM i
ASKED: March 3, 2013  10:44 AM
UPDATED: March 4, 2013  1:54 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 11  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    A printer file can have an override with SHARE(*YES) for the activation group or for the job. Programs that open the printer file while the override is in effect will write to the same file, and the output will be in the same spooled file.. Set the override in the subfile program so the lower-level programs run under it. -- Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    TomDoes that mean that those programs should not close the printer file or end with *INLR on?
    48,595 pointsBadges:
    report
  • TomLiotta
    Hard to say. It depends some on how the job stream goes. I'll try to post some test code to let anyone experiment on their own.   First, a test printer file, TSTPRTF:
        A           R HEADER
        A                                       SKIPB(6)
        A                                      3'My Test Report'
        A                                       SPACEA(2)
        A                                      3'Program'
        A                                     20'Description'
        A                                       SPACEA(2)
        A           R DETAIL
        A                                       SPACEA(1)
        A             PGMNAM        10         3
        A                                     20'This program'
        A           R FOOTER
        A                                       SPACEA(1)
        A                                     20'END OF REPORT'
      It's not much, but it has everything needed. (Assuming it posts okay.) Next is a simple CLLE that assigns an override and calls the three RPG programs:
    pgm
    
       ovrprtf     TSTPRTF +
                     ovrscope( *ACTGRPDFN ) +
                     share( *YES )          +
                     opnscope( *ACTGRPDFN )
    
          call        TSTSHRPRT1
          call        TSTSHRPRT2 ( '1' )
          call        TSTSHRPRT2 ( '0' )
          call        TSTSHRPRT3
    
    
       dltovr      TSTPRTF lvl( *ACTGRPDFN )
    
       return
    
    endpgm
      The call to the second program includes a parm that enables or disables *INLR. That can show any difference in spooled files from before and after those CALLs.   The first RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
    
         FTSTPRTF   O    E             PRINTER usropn
         f                                     infds( OPNFDBK )
    
         DOPNFDBK          DS
         d ODP_Shr               116    116
    
         C                   open      TSTPRTF
         C                   eval      PGMNAM = 'TSTSHRPRT1'
         C                   dump
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   if        *inLR = *on
         c                   eval      *inLR = *on
         c                   endif
         C                   return
      The second RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
    
         FTSTPRTF   O    E             PRINTER infds( OPNFDBK )
    
         DOPNFDBK          ds
         d ODP_Shr               116    116
    
         D TSTSHRPRT2      pr                  extpgm( 'TSTSHRPRT2' )
         D EndChk                         1
    
         D TSTSHRPRT2      pi
         D EndChk                         1
    
         C                   eval      PGMNAM = 'TSTSHRPRT2'
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   if        EndChk = '1'
         c                   eval      *inLR = *on
         c                   endif
         C                   dump
         C                   return
      The third RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
    
         FTSTPRTF   O    E             PRINTER usropn
         f                                     infds( OPNFDBK )
    
         DOPNFDBK          DS
         d ODP_Shr               116    116
    
         C                   open      TSTPRTF
         C                   eval      PGMNAM = 'TSTSHRPRT3'
         C                   dump
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   eval      *inLR = *on
         C                   return
      After the sequence runs once to see results, change the first RPG to disable the IF-test around *INLR by commenting the IF and ENDIF.   The open feedback and debug is there mostly to show if sharing is enabled for the file or not. Bit 2 of position 116 will be on if it's SHARE(*YES) enabled. By default, the file would be compiled as SHARE(*NO).   The CL should be compiled this way:
    CRTBNDCL PGM(mylib/TSTSHRPRT0)
             SRCFILE(mylib/QCLSRC)
             SRCMBR(TSTSHRPRT0)
             DFTACTGRP(*NO)
             ACTGRP(*NEW)
    Compiling it for a *NEW activation group will isolate just about everything from the rest of the job. The RPGs all compile for *CALLER, so they automatically slip in with the CL.   Run it with the initial code, change the IF-test in the first RPG, and run it again. Then tell me whether *INLR controls or not. Especially note the state of *INLR in RPG #2 in both sets of dumps.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Apparently, any blank line in a code-block causes code formatting to end. That's worth remembering, I suppose.
    pgm
      /* */
       ovrprtf     TSTPRTF +
                     ovrscope( *ACTGRPDFN ) +
                     share( *YES )          +
                     opnscope( *ACTGRPDFN )
      /* */
          call        TSTSHRPRT1
          call        TSTSHRPRT2 ( '1' )
          call        TSTSHRPRT2 ( '0' )
          call        TSTSHRPRT3
      /* */
       dltovr      TSTPRTF lvl( *ACTGRPDFN )
      /* */
       return
      /* */
    endpgm
    Let's see how bad that looks.   Tom  
    125,585 pointsBadges:
    report
  • TomLiotta
    Well, except for the stupid BR-tags, it's okay. Notepad can edit those out easily enough. So, first RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
          *
         FTSTPRTF   O    E             PRINTER usropn
         f                                     infds( OPNFDBK )
          *
         DOPNFDBK          DS
         d ODP_Shr               116    116
          *
         C                   open      TSTPRTF
         C                   eval      PGMNAM = 'TSTSHRPRT1'
         C                   dump
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   if        *inLR = *on
         c                   eval      *inLR = *on
         c                   endif
         C                   return
      Second RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
          *
         FTSTPRTF   O    E             PRINTER infds( OPNFDBK )
          *
         DOPNFDBK          ds
         d ODP_Shr               116    116
          *
         D TSTSHRPRT2      pr                  extpgm( 'TSTSHRPRT2' )
         D EndChk                         1
          *
         D TSTSHRPRT2      pi
         D EndChk                         1
          *
         C                   eval      PGMNAM = 'TSTSHRPRT2'
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   if        EndChk = '1'
         c                   eval      *inLR = *on
         c                   endif
         C                   dump
         C                   return
      Third RPG:
         H Debug( *yes )
         h dftactgrp( *NO )
         h     actgrp( *CALLER )
          *
         FTSTPRTF   O    E             PRINTER usropn
         f                                     infds( OPNFDBK )
          *
         DOPNFDBK          DS
         d ODP_Shr               116    116
          *
         C                   open      TSTPRTF
         C                   eval      PGMNAM = 'TSTSHRPRT3'
         C                   dump
         C                   write     HEADER
         C                   write     DETAIL
         C                   write     FOOTER
         C                   eval      *inLR = *on
         C                   return
      A little more readable, I hope.   Tom
    125,585 pointsBadges:
    report
  • TomLiotta
    Formatting is different in the full 'Discussions' list and in individual question threads. Weird. No BR-tags in the 'Discussions' list and no blank-line problem. Ah, well. "It's like a box o' chocolates..." -- Tom
    125,585 pointsBadges:
    report
  • YuVa47
    Thank you Tom,Actually I have only two programs, the first one is the selection sub-file program, which is calling the print program individually within a loop for each selected sub-file record. The calls for the printing program can be up to 100 times. Yehuda
    1,285 pointsBadges:
    report
  • YuVa47
    Tom,Your test example works perfect. Thanks a lot.Yehuda
    1,285 pointsBadges:
    report
  • TomLiotta
    Sorry about the code format attempts, but it should still be easy enough to use the samples for proof-of-concept. The override can be set in various ways depending on how activation groups are used or not used. At some point, the printer file will need to be closed and the override deleted. Ending an activation group makes both easy. -- Tom
    125,585 pointsBadges:
    report
  • YuVa47
    Tom, now I have tested with your suggestion to remove the IF statement in PGM1 for LR test. It doesn't works in the proper way. The first program creates a spool with TSTSHRPRT1, the second creates a new one with TSTSHRPRT2 and the third and fourth creates a new with TSTSHRTPRT2 and TSTSHRPRT3. Totally 3 spools, so your first suggestion if the good one.Thanks again - Yehuda 
    1,285 pointsBadges:
    report
  • TomLiotta
    That's right. There is a difference in what gets created depending on when the LR indicator is enabled. The second program sets it on and there's no break in the spooled files, but things work a little differently when it's set on in the first program. The point is that even though it works, you might need to do some testing before your programs get it right. You should be okay if you only have one print program. -- Tom
    125,585 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following