title: RPGLE Increment Counter into Data Structure
body: <p>I'm trying to implement a counter in my program that will give a total at the end of the records. Currently I have a counter within a procedure called <code>TotalCalls += 1;</code> that counts the calls which is working fine, and I have a Totals field in my print file that I need to move that into. The problem is that I have a datastructure <code>Dcl-ds PrinterTotalDS likeRec(PrinterFile.Totals:*output);</code> that I need to move the counter data into and then write that to the print file. I'm currently using this as the write: <code>Write PrinterFile.Totals PrinterTotalDS;</code> but nothing shows up. When I debug the program the counter works but nothing is moved to the write for totals. Here is the code in it's entirety: Any help is greatly appreciated!</p>
  <pre><code>/Copy IMPWR126/QRPGLESRC,S071303CPY
  
  Dcl-F PrinterFile PRINTER Qualified Alias ExtFile(*extdesc) OfLind(EndOfPage) USROPN
                       ExtDesc('S071303P');
  
  Dcl-F S071303LF Keyed;
  
  Dcl-s EndofPage ind inz(*on);
  Dcl-s DateConv Date;
  Dcl-s TimeConv Time;
  Dcl-s Tempstring Char(25);
  Dcl-s DayofWk Char(15);
  Dcl-s InputDate Zoned(8:0);
  Dcl-s TotalCalls Zoned(5:0);
  
  Dcl-ds PrinterHeadDS likeRec(PrinterFile.Header:*output);
  Dcl-ds OutputDS likeRec(PrinterFile.Detail:*output);
  Dcl-ds InputDS likeRec(CALLREC);
  
  Dcl-Proc Driver;
    Dcl-Pi *N;
        CALDAT Zoned(8:0);
    END-PI;
  
    Dcl-ds PrinterTotalDS likeRec(PrinterFile.Totals:*output);
  
    Open PrinterFile;
  
    Clear InputDS;
    Read S071303LF InputDS;
    Clear OutputDS;
  
    DOW not %eof(S071303LF);
      TotalCalls += 1;
      MoveDS();
      Eval-Corr OutputDS = InputDS;
      IF EndofPage;
        EndOfPage = *off;
        Write PrinterFile.Header PrinterHeadDS;
      ENDIF;
      Write PrinterFile.Detail OutputDS;
      Read S071303LF InputDS;
      Clear OutputDS;
    Enddo;
    TotalCalls = %dec('0' + %trim(PrinterTotalDS):5:0);
    Write PrinterFile.Totals PrinterTotalDS;
    close S071303LF;
    close PrinterFile;
    return;
  END-PROC Driver;
  
  Dcl-Proc MoveDS;
      OutputDS.DateConv = CONVDATE(InputDS.CALDAT);
      OutputDS.TimeConv = CONVTIME(InputDS.CALTIM);
      TempString = InputDS.CFNAME;
      OutputDS.FirstName = PROPCASE(TempString);
      TempString = InputDS.CLNAME;
      OutputDS.LastName = PROPCASE(TempString);
      OutputDS.DayofWk = GetDayofWeek(InputDS.CalDat);
  End-Proc;
  </code></pre>