Same Easytrieve code in different installations gives different results

182 views Asked by At

I have the following Easytrieve Plus code:

*
FILE ENTRADA
    INPUT-REC1   1    132 A
*
*
FILE SALIDA
    C1-JOBNAME    1   16 A
    C1-FILLER     17   5 A
    C1-MENSAGEM   22  31 A
*
DEFINE WS-INREC1 W 132 A
*
DEFINE WS-INDIC1 WS-INREC1 1 A
*
DEFINE WS-INPUT1 WS-INREC1 16 A
*
*
DEFINE WS-INREC2 W 132 A
*
DEFINE WS-INDIC2 WS-INREC2 1 A
*
DEFINE WS-INPUT2 WS-INREC2 16 A
*
DEFINE WS-MSG1  W 31 A VALUE 'INSERIR PARAMETROS CA-VIEW.    '
*
DEFINE WS-MSG2  W 31 A VALUE 'PARÂMETROS CORRECTOS.          '
*
DEFINE WS-MSG3  W 31 A VALUE 'PARÂMETROS INCORRECTOS.        '
*
DEFINE WS-COUNT W 8 N VALUE 0
*
DEFINE WS-COUNT-VAL W 8 N VALUE 0
*
* PROCESO
*
JOB INPUT NULL
    DO WHILE NOT EOF ENTRADA

    IF WS-COUNT = 0
        GET ENTRADA
        MOVE INPUT-REC1             TO WS-INREC1
        WS-COUNT = WS-COUNT + 1
    END-IF

    IF WS-INDIC1 = 'J' AND NOT EOF ENTRADA

        GET ENTRADA
        WS-COUNT = WS-COUNT + 1
        WS-COUNT-VAL = WS-COUNT
        DISPLAY 'WS-COUNT: ' WS-COUNT
        MOVE INPUT-REC1              TO WS-INREC2

     IF WS-INDIC2 = 'J'
        MOVE WS-MSG1              TO C1-MENSAGEM
        MOVE WS-INPUT1            TO C1-JOBNAME
        DISPLAY 'CJ-JOBNAME:' C1-JOBNAME
        MOVE WS-INREC2            TO WS-INREC1
      ELSE
       IF WS-INPUT2 = 'F RF CNF CH    '
        MOVE WS-MSG3              TO C1-MENSAGEM
        MOVE WS-INPUT1            TO C1-JOBNAME
        DISPLAY 'CF3-JOBNAME:' C1-JOBNAME
         END-IF
         IF WS-INPUT2 = 'F RF CH        '
         MOVE WS-MSG2              TO C1-MENSAGEM
         MOVE WS-INPUT1            TO C1-JOBNAME
         DISPLAY 'CF2-JOBNAME:' C1-JOBNAME
         END-IF
        GET ENTRADA
        WS-COUNT = WS-COUNT + 1
        DISPLAY 'WS-COUNT2: ' WS-COUNT
        MOVE INPUT-REC1           TO WS-INREC1
    END-IF
   END-IF
   PUT SALIDA
  END-DO
  STOP

This code at one installation works without error and at another installation gives the message:

68 *******A010 INVALID FILE REFERENCE - ENTRADA

The input file looks like the following:

JOBNAME:ADJADP0        
F RF CH                
JOBNAME:ADJBDK1      
F RF CH                
JOBNAME:BMRPNN2      
JOBNAME:BMRP1N1         
F RF CNF CH             
JOBNAME:BMRP1N2        
F RF CNF CH            
JOBNAME:IU3A02J4       
F RF CH                
JOBNAME:IU3A02J5       
F RF CH                    

And the ouptut file:

JOBNAME:ADJADP0      PARÂMETROS CORRECTOS.        
JOBNAME:ADJBDK1      PARÂMETROS CORRECTOS.        
JOBNAME:BMRPNN2      INSERIR PARAMETROS CA-VIEW.  
JOBNAME:BMRP1N1      PARÂMETROS INCORRECTOS.      
JOBNAME:BMRP1N2      PARÂMETROS INCORRECTOS.      
JOBNAME:IU3A02J4     PARÂMETROS CORRECTOS.        
JOBNAME:IU3A02J5     PARÂMETROS CORRECTOS.              

At the installation where it doesn't work, the Easytrieve step ends with Condition Code 0016 but produces an output file (it just doesn't process the last record):

JOBNAME:ADJADP0      PARÂMETROS CORRECTOS.         
JOBNAME:ADJBDK1      PARÂMETROS CORRECTOS.         
JOBNAME:BMRPNN2      INSERIR PARAMETROS CA-VIEW.   
JOBNAME:BMRP1N1      PARÂMETROS INCORRECTOS.       
JOBNAME:BMRP1N2      PARÂMETROS INCORRECTOS.       
JOBNAME:IU3A02J4     PARÂMETROS CORRECTOS.  

The error that it gives is:

    68 *******A010 INVALID FILE REFERENCE - ENTRADA                             


FILE STATISTICS - E Z T  PLUS  5.2D- 3/07/17-19.42-JSN00036                     
ENTRADA              13    INPUT        SAM  FIX   BLK                  132    2
SALIDA                6   OUTPUT        SAM  FIX   BLK                  132    3
       *******A014 PREMATURE TERMINATION DUE TO PREVIOUS ERROR(S)               
1

There are 1 answers

0
Bill Woodger On

I don't have access to Easytrieve Plus, so apologies in advance if it doesn't compile around the edges.

A simplification of your program:

FILE ENTRADA
    INPUT-DATA-PART   1    16 A

FILE SALIDA
    C1-JOBNAME    1   16 A
    C1-MENSAGEM   22  31 A

W-INREC1 W 16 A
W-INDIC1 W-INREC1 1 A

W-INREC2 W 16 A
W-INDIC2 W-INREC2 1 A

W-MSG1  W 31 A VALUE 'INSERIR PARAMETROS CA-VIEW.    '
W-MSG2  W 31 A VALUE 'PARÂMETROS CORRECTOS.          '
W-MSG3  W 31 A VALUE 'PARÂMETROS INCORRECTOS.        '
W-COUNT W 8 N VALUE 0
W-COUNT-VAL W 8 N VALUE 0

    JOB INPUT NULL

        PERFORM                         READ-INPUT

        IF EOF ENTRADA
            DISPLAY "No input and some other useful text, like name"
            RETURN-CODE                 = 20
            STOP EXECUTE
        END-IF

        W-INREC1                        = INPUT-DATA-PART 
        DISPLAY "First record read"

        DO WHILE NOT EOF ENTRADA
            IF W-INDIC1 EQ 'J' 
                PERFORM READ-INPUT
                DISPLAY 'W-COUNT 1: ' W-COUNT
                W-INREC2                = INPUT-DATA-PART    
                IF W-INDIC2 EQ 'J'
                    PERFORM             NEXT-WAS-J-STORE-IT
                ELSE
                    PERFORM             NOT-J-PROCESS-AND-READ
                END-IF
            END-IF
            PUT SALIDA
        END-DO
    STOP

READ-INPUT. PROC
    GET ENTRADA
    W-COUNT                             = W-COUNT + 1
    W-COUNT-VAL                         = W-COUNT
END-PROC
NEXT-WAS-J-STORE-IT. PROC
    C1-MENSAGEM                         = W-MSG1  
    C1-JOBNAME                          = W-INREC1 
    DISPLAY 'CJ-JOBNAME:' C1-JOBNAME
    W-INREC1                            = W-INREC2             
END-PROC
NOT-J-PROCESS-AND-READ. PROC
    IF W-INREC2 EQ 'F RF CNF CH    '
        C1-MENSAGEM                     = W-MSG3              
        C1-JOBNAME                      = W-INREC1             
        DISPLAY 'CF3-JOBNAME:' C1-JOBNAME
    END-IF
    IF W-INREC2 EQ 'F RF CH        '
        C1-MENSAGEM                     = W-MSG2               
        C1-JOBNAME                      = W-INREC1             
        DISPLAY 'CF2-JOBNAME:' C1-JOBNAME
    END-IF
    PERFORM                             READ-INPUT
    DISPLAY 'W-COUNT 2: ' W-COUNT
    W-INREC1                            = INPUT-DATA-PART 
END-PROC

If you look at the simplified control-logic, you'll see that if the second of a pair of records is read with the first GET in the DO-loop, and that is the last record on the file (like with your sample data), then will will do another GET (giving you EOF) and then your program will then still attempt to access INPUT-DATA-PART from the record area, and Easytrieve Plus will give you the A0016, invalid file reference (and the name of the file).

With the data shown, the program will always fail. If the data instead ends with a lonely JOBNAME record, the program will "succeed".

And No, you shouldn't "fix" it by just banging in a test for EOF. You should restructure the logic.

Use indentation, consistently and correctly.

Inside the Library, you don't need to specify DEFINE. You only need DEFINE if defining data in a JOB or a SORT.

MOVE does not work like a COBOL MOVE. It'll trip you. Use assignments for most things (except files, or if you want a variable-length MOVE).

Since you already use assignments, I'd suggest using EQ in IFs, just to get some differentiation.

You only need to define the data you need.

Improve your names.

Don't go for massive nested structures, break things down with PERFORMs.

And don't use Tabs when posting code here. It can be a pain when someone else takes your code to look at.