MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Close and re-open file

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
ldushkin
Beginner


Joined: 05 Apr 2006
Posts: 56
Topics: 20

PostPosted: Thu Mar 22, 2007 4:33 pm    Post subject: Close and re-open file Reply with quote

I have a program, it write only one record from para 0300- this record is the last in the file, not write records from para 0400- . When I split this pgm for two programs it works OK. Can somebody take a look
I appreciate all your help
Code:
 IDENTIFICATION DIVISION.                                       
 PROGRAM-ID. TESTKAS.                                           
 AUTHOR.     XXXXXXXXXXXX.                                       
 DATE-WRITTEN. 12/10/06.                                         
 DATE-COMPILED.                                                 
*                                                               
 ENVIRONMENT DIVISION.                                           
 CONFIGURATION SECTION.                                         
 SOURCE-COMPUTER. IBM-370.                                       
 OBJECT-COMPUTER. IBM-370.                                       
 INPUT-OUTPUT SECTION.                                           
 FILE-CONTROL.                                                   
     SELECT JRNL-IN                       ASSIGN TO JRNL.       
     SELECT JRNL-OUT-FILE                 ASSIGN TO JRNLOUT.     
                                                                 
 DATA DIVISION.                                                 
 FILE SECTION.                                                   
 FD  JRNL-IN                                                     
     LABEL RECORDS ARE STANDARD                                 
     RECORDING MODE IS V                                         
     BLOCK CONTAINS 0 RECORDS.                                   
 01  JRNL-IN-REC          PIC X(421).                           
                                                                 
 FD  JRNL-OUT-FILE                                               
     LABEL RECORDS ARE STANDARD                                 
     RECORDING MODE IS V                                         
     BLOCK CONTAINS 0 RECORDS.                                   
 01  JRNL-OUT-REC         PIC X(421).                           
*****************************************************************
 WORKING-STORAGE SECTION.                                       
*****************************************************************
 01  EOF-SW            PIC X             VALUE 'N'.             
     88 EOF                              VALUE 'Y'.             
*----------------------------------------------------------------
*                 COUNTERS                                       
*----------------------------------------------------------------
 01  RECIN-CTR               PIC S9(16) COMP-3 VALUE ZEROS.     
 01  RECOUT-CTR              PIC S9(16) COMP-3 VALUE ZEROS.     
*---------------------------------------------------------------*
* INPUT JOURNAL FILE                                            *
*---------------------------------------------------------------*
 COPY coopybook.                                                 
*                                                               
 PROCEDURE DIVISION.                                             
 MAINLINE SECTION.                                               
     PERFORM 0100-INITIALIZE       THRU 0100-EXIT.               
     PERFORM 0200-READ-JRNLIN      THRU 0200-EXIT.               
     PERFORM 0300-PROCESS-SEC-REC  THRU 0300-EXIT               
                   UNTIL EOF.                                   

     OPEN INPUT  JRNL-IN.                                       
     PERFORM 0200-READ-JRNLIN      THRU 0200-EXIT.               
     PERFORM 0400-PROCESS-ALL-REC  THRU 0400-EXIT               
                   UNTIL EOF.                                   

     PERFORM 9999-WRAP-UP THRU 9999-EXIT.                       

     DISPLAY ' RECORD INPUT  ' RECIN-CTR
     DISPLAY ' RECORD OUTPUT ' RECOUT-CTR

     STOP RUN.                                                   
                                                                 
 0100-INITIALIZE.                                               

      INITIALIZE DETAIL-STOCK-REC-BOOKKEEPING

      OPEN INPUT  JRNL-IN                                       
      OPEN OUTPUT JRNL-OUT-FILE.                                 
                                                                 
 0100-EXIT.                                                     
     EXIT.                                                       
 0200-READ-JRNLIN.                                               
       READ JRNL-IN       INTO DETAIL-STOCK-REC-BOOKKEEPING     
          AT END SET EOF       TO TRUE                           
            IF RECIN-CTR = 0
              DISPLAY '***********************************'
              DISPLAY '***     A T T E N T I O N !     ***'
              DISPLAY '***     INPUT FILE IS EMPTY     ***'
              DISPLAY '***********************************'
              GO TO 0200-EXIT
            END-IF
          NOT AT END
          ADD 1 TO RECIN-CTR                                     
       END-READ.

 0200-EXIT.                                                     
     EXIT.                                                       

 0300-PROCESS-SEC-REC.                                           
     IF NOT EOF
      IF D-SECURITY-NO NOT = '000000000'
         CONTINUE
      ELSE
         WRITE JRNL-OUT-REC FROM DETAIL-STOCK-REC-BOOKKEEPING   
         ADD 1 TO RECOUT-CTR
         MOVE 'N'             TO  EOF-SW
      END-IF
     END-IF

     IF EOF
         CLOSE JRNL-IN                                           
         GO TO 0300-EXIT
     END-IF

     IF NOT EOF
       PERFORM 0200-READ-JRNLIN  THRU 0200-EXIT                 
     END-IF.

 0300-EXIT.                                                     
     EXIT.                                                       
*                                                               
 0400-PROCESS-ALL-REC.                                           
     IF NOT EOF
      IF D-SECURITY-NO > '000000000'
         WRITE JRNL-OUT-REC FROM DETAIL-STOCK-REC-BOOKKEEPING   
         ADD 1 TO RECOUT-CTR
      ELSE
        CONTINUE
      END-IF
     END-IF

     IF NOT EOF
       PERFORM 0200-READ-JRNLIN  THRU 0200-EXIT                 
     END-IF.


 0400-EXIT.                                                     
     EXIT.                                                       
*
 9999-WRAP-UP.                                                   

     CLOSE JRNL-IN                                               
           JRNL-OUT-FILE.                                       

 9999-EXIT.                                                     
     EXIT.                                                       
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12367
Topics: 75
Location: San Jose

PostPosted: Fri Mar 23, 2007 8:44 am    Post subject: Reply with quote

ldushkin,


If you hit the EOF file you never excuete the process paragraph and your file is never closed. The reason it worked with 2 different programs is that OS closed the file upon the successful completion of the pgm. Also your pgm would fail for EMPTY file also

Kolusu
_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ldushkin
Beginner


Joined: 05 Apr 2006
Posts: 56
Topics: 20

PostPosted: Fri Mar 23, 2007 4:39 pm    Post subject: Reply with quote

Thank you Kolusu,
What should I do to close input file.
Back to top
View user's profile Send private message
jyoung
Beginner


Joined: 10 Nov 2005
Posts: 36
Topics: 2
Location: Flint, MI

PostPosted: Mon Mar 26, 2007 7:46 am    Post subject: Reply with quote

If you are trying to place the last record at the beginning of the file could you not sort the file in ascending order on D-SECURITY-NO? This might be easeir than writing a program to do it.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group