VS COBOL - RELATIVE FILE ACCESS AFTER SORTING.

ITEM: RTA000012997



                                                                                
Question:                                                                       
                                                                                
The vs cobol compiler doesn't seem to allow sorting a file defined              
as dynamic access. what is one to do to get around this?                        
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
A:   The VS COBOL compiler does give you compiler error 318-S when              
     you use a dynamically accessed file in the USING phrase of the             
     SORT command.  There is a workaround.  The main idea is to have            
     two select/fd groups pointing to the same file; one with dynamic           
     access for normal processing and one with sequential access for            
     the sort.  What follows is an example showing this technique:              
                                                                                
       IDENTIFICATION DIVISION.                                                
      *                                                                         
       PROGRAM-ID.  SORTTEST.                                                   
      *                                                                         
       ENVIRONMENT DIVISION.                                                    
      *                                                                         
       CONFIGURATION SECTION.                                                   
       SOURCE-COMPUTER.  VSCOBOL.                                               
       OBJECT-COMPUTER.  VSCOBOL.                                               
       SPECIAL-NAMES.    CONSOLE IS CRT                                         
                          CRT STATUS IS CRT-STATUS.                             
      *                                                                         
       INPUT-OUTPUT SECTION.                                                    
       FILE-CONTROL.                                                            
       SELECT SRTSTNEW  ASSIGN TO "sortfile"                                    
           ORGANIZATION IS RELATIVE                                            
           ACCESS MODE IS DYNAMIC                                               
           RELATIVE KEY IS REL-KEY                                              
           FILE STATUS IS FILE-STATUS.                                          
       SELECT SRTSTDMY  ASSIGN TO "sortfile"                                    
           ORGANIZATION IS RELATIVE                                             
           ACCESS MODE IS SEQUENTIAL                                            
           RELATIVE KEY IS REL-KEY                                              
           FILE STATUS IS FILE-STATUS.                                          
       SELECT SRTSTOLD  ASSIGN TO "sortout"                                     
           ORGANIZATION IS RELATIVE                                             
           ACCESS MODE IS SEQUENTIAL                                            
           RELATIVE KEY IS REL-KEY                                              
           FILE STATUS IS FILE-STATUS.                                          
       SELECT SRTSTWRK  ASSIGN TO "sortwork"                                    
           SORT STATUS IS SORT-STATUS.                                         
      *                                                                         
      *                                                                         
       DATA DIVISION.                                                           
       FILE SECTION.                                                            
       FD SRTSTNEW                                                              
           DATA RECORD IS SORTNEW.                                              
       01  SORTNEW.                                                             
           03  SN-REV-KEY PIC 9(4).                                             
           03  SN-FWD-KEY PIC 9(4).                                             
       FD SRTSTDMY                                                              
           DATA RECORD IS SORTDMY.                                              
       01  SORTDMY.                                                             
           03  SD-REV-KEY PIC 9(4).                                             
           03  SD-FWD-KEY PIC 9(4).                                             
       FD SRTSTOLD                                                             
           DATA RECORD IS SORTOLD.                                              
       01  SORTOLD.                                                             
           03  SO-REV-KEY PIC 9(4).                                             
           03  SO-FWD-KEY PIC 9(4).                                             
       SD SRTSTWRK                                                              
           DATA RECORD IS SORTWRK.                                              
       01  SORTWRK.                                                             
           03  SW-REV-KEY PIC 9(4).                                             
           03  SW-FWD-KEY PIC 9(4).                                             
      *                                                                         
       WORKING-STORAGE SECTION.                                                 
      *                                                                         
       01  SORT-STATUS PIC X(2).                                                
       01  FILE-STATUS PIC X(2).                                                
       01  REL-KEY     PIC 9(4).                                               
       01 CRT-STATUS  PIC X(3).                                                 
      *                                                                         
      /                                                                         
       PROCEDURE DIVISION.                                                      
      *                                                                         
       MAIN-SECT SECTION.                                                       
       OPEN-FILE.                                                               
           OPEN OUTPUT SRTSTNEW.                                                
       CREATE-FILE.                                                             
           MOVE 0 TO REL-KEY.                                                   
       WRITE-FILE.                                                              
           ADD 1 TO REL-KEY.                                                    
           IF REL-KEY > 1000 GO TO CLOSE-FILE.                                  
           MOVE REL-KEY TO SN-FWD-KEY.                                          
           COMPUTE SN-REV-KEY = 9999 - REL-KEY.                                
           WRITE SORTNEW INVALID KEY MOVE 1000 TO REL-KEY.                      
           GO TO WRITE-FILE.                                                    
       CLOSE-FILE.                                                              
           CLOSE SRTSTNEW.                                                      
       SORT-FILE.                                                               
           SORT SRTSTWRK                                                        
                ASCENDING KEY SW-REV-KEY                                        
                USING SRTSTDMY                                                  
                GIVING SRTSTOLD.                                                
       STOP-PARA.                                                               
           STOP RUN.                                                            
                                                                                
                                                                                
---------- ---------- ---------- --------- ---------- ----------                
                                                                               
                                                                                
This item was created from library item Q447817 1992 5QDCF                      
                                                                                
S e a r c h - k e y w o r d s:                                                  
ACC ACCESS ARTPC AUG89 COBOL CUSTORG FILE FILES IX LANGUAGE PC PCRT             
RELATIVE RT RTPC SORT STORAGE VIRTUAL VS 5QDCF                                  
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                                
                                                                               


WWQA: ITEM: RTA000012997 ITEM: RTA000012997
Dated: 07/1998 Category: RISCLANG
This HTML file was generated 99/06/24~12:43:07
Comments or suggestions? Contact us