Getting Soc4 Abend in a Cobol File Program

I am writing COBOL pgm to sum 2 numbers, passing these 2 numbers from JCL in an input file and storing their sum in output file. But I am getting SOC4 (at MOVE). Below is my code. Please advise

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
             SELECT FILEIN ASSIGN TO INPFILE
             ORGANIZATION IS SEQUENTIAL
             ACCESS MODE IS SEQUENTIAL
             FILE STATUS IS WS-ST1.

             SELECT FILEOUT ASSIGN TO OUTFILE
             ORGANIZATION IS SEQUENTIAL
             ACCESS MODE IS SEQUENTIAL
             FILE STATUS IS WS-ST2.

       DATA DIVISION.
       FILE SECTION.
       FD FILEIN.
         01  FIN-REC.
                05 FIN-NUM1       PIC 9(2).
                05 FILLER         PIC X(1).
                05 FIN-NUM2       PIC 9(2).
                05 FILLER         PIC X(75).
       FD FILEOUT.
         01  FOUT-TOT             PIC 9(2).
         01  FILLER               PIC X(78).
       WORKING-STORAGE SECTION.
         01  WS-REC.
                05 WS-NUM1        PIC 9(2).
                05 WS-NUM2        PIC 9(2).
         01 WS-ST1                PIC X(2) VALUE SPACES.
         01 WS-ST2                PIC X(2) VALUE SPACES.
         01 WS-EOF                PIC X(1) VALUE SPACE.
         01 WS-SUM                PIC 9(2).
       PROCEDURE DIVISION.
       MAIN-PARA.
           PERFORM 100-INITIAL-PARA THRU 100-EXIT.
           PERFORM 200-PROCESS-PARA THRU 200-EXIT
                       UNTIL WS-EOF='Y'.
           PERFORM 300-COMPUTE-PARA THRU 300-EXIT.
           PERFORM 400-WRITE-PARA   THRU 400-EXIT.

           STOP RUN.

       100-INITIAL-PARA.
           MOVE 'N' TO WS-EOF

           OPEN INPUT FILEIN

           IF WS-ST1 NOT = '00'
              DISPLAY 'ERROR IN 100-INITIAL-PARA'
              DISPLAY 'INPUT FILE OPEN STATUS IS' WS-ST1
              DISPLAY 'OUTPUT FILE OPEN STATUS IS' WS-ST2
           END-IF.

       100-EXIT.
           EXIT.

       200-PROCESS-PARA.

           PERFORM UNTIL WS-EOF='Y'
              READ FILEIN INTO WS-REC
                   AT END MOVE 'Y' TO WS-EOF
                   NOT AT END DISPLAY WS-REC
              END-READ
           END-PERFORM
           CLOSE FILEIN.

       200-EXIT.
           EXIT.

       300-COMPUTE-PARA.

           COMPUTE WS-SUM= WS-NUM1 + WS-NUM2.
       300-EXIT.
           EXIT.

       400-WRITE-PARA.
           OPEN OUTPUT FILEOUT.
           MOVE WS-SUM TO FOUT-TOT.
      *>   SOC4 abend in MOVE above
           WRITE FOUT-TOT
           END-WRITE.
           CLOSE FILEOUT.
       400-EXIT.
           EXIT.

Below is the run JCL

//A102153J JOB  MSGCLASS=S,MSGLEVEL=(1,1),NOTIFY=&SYSUID,REGION=0M
//STEP001  EXEC PGM=EXER4
//STEPLIB  DD DISP=SHR,DSN=ADESH.LOADLIB
//INPFILE  DD DSN=ADESH.EXER4.INFILE,DISP=SHR
//OUTFILE  DD DSN=ADESH.EXER4.OUTFILE,UNIT=SYSDA,
//            DISP=(NEW,CATLG,DELETE),SPACE=(CYL,(1,1),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT   DD   SYSOUT=*
//SYSPRINT DD   SYSOUT=*
6

2 Answers

Problem could be the output declaration:

FD FILEOUT.
     01  FOUT-TOT             PIC 9(2).
     01  FILLER               PIC X(78).

Replace with

FD FILEOUT.
     01  out-record. 
         03  FOUT-TOT             PIC 9(2).
         03  FILLER               PIC X(78).

Also update the write to

  Write out-record. 

Reason for the problem is the 2 01 levels --> VB which is different to the FB definition in the JCL which will cause the open to fail

There are a couple of logic errors in you program.

Firstly, in

   100-INITIAL-PARA.
       MOVE 'N' TO WS-EOF

       OPEN INPUT FILEIN

       IF WS-ST1 NOT = '00'
          DISPLAY 'ERROR IN 100-INITIAL-PARA'
          DISPLAY 'INPUT FILE OPEN STATUS IS' WS-ST1
          DISPLAY 'OUTPUT FILE OPEN STATUS IS' WS-ST2
       END-IF.

You open the input file, only, but check (well display) the status of the output file, which is yet to be opened.

Secondly, in the main paragraph

   MAIN-PARA.
       ...
       PERFORM 200-PROCESS-PARA THRU 200-EXIT
                   UNTIL WS-EOF='Y'.

you code a repetitive loop to end at end of input. And the called section

   200-PROCESS-PARA.

       PERFORM UNTIL WS-EOF='Y'
          READ FILEIN INTO WS-REC
               AT END MOVE 'Y' TO WS-EOF
               NOT AT END DISPLAY WS-REC
          END-READ
       END-PERFORM
       CLOSE FILEIN.

   200-EXIT.
       EXIT.

is again a repetitive loop to end at end of input file. There is one loop to many here.

Thirdly, in the section to write the output, you open the output file but are missing to check the status thereafter.

   400-WRITE-PARA.
       OPEN OUTPUT FILEOUT.
       MOVE WS-SUM TO FOUT-TOT.
       WRITE FOUT-TOT
       END-WRITE.
       CLOSE FILEOUT.
   400-EXIT.
       EXIT.

Lastly, the sum of two two digit numbers may well become a three digit number. You sum fields are declared as 2 digit field, however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Chloe Bennett

Chloe Bennett

Culture, Media & Entertainment Columnist

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.

Share this article
Twitter Facebook Pinterest