Yes, that is because the first record of the packed output file must be
updated after the rest of the file has been written.  The problem and the
solution are documented (don't have the reference offhand).  Here is a stage
I wrote to use in place of the pack stage:

/* Purpose: Write a packed file in the correct format.                   
   Operands: fn ft fm|dir <Fixed <lrecl>>                                
      Fixed <lrecl>: optional format of input records if not V.          
   Looks like > to the caller except output is packed (F 1024).          
   Output: If the primary output is connected, it receives records passed
      through unchanged from the primary input.                          
   History:                                                              
   10/07/09 Alan Winson: first version                                   
   03/10/10 AW: propagate eof if no input                                
*/                                                                       
'peekto'                            /* any input? */                     
if rc /== 0 then signal error       /* no, get out now */                
'streamstate output 0'              /* output stage there? */            
signal on error                                                          
signal on novalue                                                        
if rc <= 8 then do                  /* output stage is there */          
   fanout_stage = '| out: fanout'   /* send copy of input */             
   write_stage = '? out: | *.output:'  /* pass it on out */              
   end                              /* output stage is there */          
else do                             /* no output stage */                
   fanout_stage =                   /* don't send if not there */        
   write_stage =                    /* don't write if not there */       
   end                              /* no output stage */                
parse arg fn ft fmdir recfm lrecl                                        
parse source . . myfn .                                                  
'callpipe (name' myfn 'endchar ?)',                                      
      '*.input:',                   /* read data from previous stage */  
   fanout_stage,                    /* to primary output if it's there */
   '| p: pack' recfm lrecl,         /* pack the data */                  
   '| w: >' fn ft fmdir 'fixed',    /* write packed data */              
   '?',                             /* start of second pipeline */       
   'p:',                            /* define 2nd output for PACK */     
   '| w:',                          /* send corrected length record */   
   ,                                /* as secondary input to > stage */  
   write_stage                      /* to primary output if it's there */
error: if rc /== 12 then exit rc                                         

I'm sure more experienced pipers will have lots of criticism of my stage. 
Let the comments fly!

Reply via email to