cobol

COBOL registry doesn't writing whole information


I'm learning COBOL and tried to do a little program that reads a file and then writes with format in another file but it doesn't writes whole information that is in the read file.

After writing WS-STATUS-EMP it stops writing in the output file.

.cbl code:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.                PROG01.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.

       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT EMPLEADOS ASSIGN TO "C:\COBOL\Archivos\EMPLEADOS.txt".
           SELECT REPORTE   ASSIGN TO "C:\COBOL\Archivos\REPORTE.txt".

       DATA DIVISION.
       FILE SECTION.
       FD EMPLEADOS
           LABEL RECORDS ARE STANDARD
           RECORD CONTAINS 50 CHARACTERS
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS REG-EMPLEADOS.
       01  REG-EMPLEADOS          PIC X(50).

       FD REPORTE
           LABEL RECORDS ARE STANDARD
           RECORD CONTAINS 50 CHARACTERS
           BLOCK CONTAINS 0 RECORDS
           DATA RECORD IS REG-REPORTE.
       01  REG-REPORTE            PIC X(50).

       WORKING-STORAGE SECTION.
       01  WS-AREAS-A-USAR.
           05 WS-REG-EMPLEADOS.
              10 WS-NUMERO-EMP    PIC 9(05).
              10 WS-NOMBRE-EMP    PIC X(30).
              10 WS-STATUS-EMP    PIC 9(01).
              10 WS-DEPTO-EMP     PIC 9(03).
              10 WS-PUESTO-EMP    PIC 9(02).
              10 WS-SALARIO-EMP   PIC 9(07)V99.
           05 WS-LEIDOS-EMP       PIC 9(05)    VALUE ZEROS.
           05 WS-IMPRESOS         PIC 9(05)    VALUE ZEROS.
           05 WS-TOTAL-SALARIOS   PIC 9(09)V99 VALUE ZEROS.

       01  WS-TITULO-1.
           05 FILLER              PIC X(27)    VALUE SPACES.
           05 WS-TIT-1            PIC X(25)
                                  VALUE "EMPLEADOS DE LA EMPRESA: ".
           05 FILLER              PIC X(28)    VALUE SPACES.

       01  WS-TITULO-2.
           05 FILLER              PIC X(01)    VALUE "/".

       01  WS-DETALLE.
           05 FILLER              PIC X(04)    VALUE SPACES.
           05 WS-DET-NUMERO       PIC ZZZZ9.
           05 FILLER              PIC X(04)    VALUE SPACES.
           05 WS-DET-NOMBRE       PIC X(30).
           05 FILLER              PIC X(04)    VALUE SPACES.
           05 WS-DET-STATUS       PIC 9(01).
           05 FILLER              PIC X(04)    VALUE SPACES.
           05 WS-DET-DEPTO        PIC 9(03).
           05 FILLER              PIC X(04)    VALUE SPACES.
           05 WS-DET-PUESTO       PIC 9(02).
           05 FILLER              PIC X(03)    VALUE SPACES.
           05 WS-DET-SALARIO      PIC Z,ZZZ,ZZ9.99.
           05 FILLER              PIC X(04)    VALUE SPACES.

       01  WS-DETALLE-LEIDOS.
           05 FILLER              PIC X(01).
           05 FILLER              PIC X(29)
                                  VALUE "TOTAL DE EMPLEADOS LEIDOS  : ".
           05 WS-TOT-LEIDOS       PIC 9(05).
           05 FILLER              PIC X(45)    VALUE SPACES.

       01  WS-DETALLE-IMPRESOS.
           05 FILLER              PIC X(01).
           05 FILLER              PIC X(29)
                                  VALUE "TOTAL DE EMPLEADOS IMPRESOS: ".
           05 WS-TOT-IMPRESOS     PIC 9(05).
           05 FILLER              PIC X(45)    VALUE SPACES.

       PROCEDURE DIVISION.
       010-INICIO.
           OPEN INPUT  EMPLEADOS
                OUTPUT REPORTE
           WRITE REG-REPORTE FROM WS-TITULO-1.
       020-LEE.
           READ EMPLEADOS INTO WS-REG-EMPLEADOS AT END
                GO TO 100-FIN.

           ADD 1 TO WS-TOT-LEIDOS
           MOVE WS-NUMERO-EMP     TO WS-DET-NUMERO
           MOVE WS-NOMBRE-EMP     TO WS-DET-NOMBRE
           MOVE WS-STATUS-EMP     TO WS-DET-STATUS
           MOVE WS-DEPTO-EMP      TO WS-DET-DEPTO
           MOVE WS-PUESTO-EMP     TO WS-DET-PUESTO
           MOVE WS-SALARIO-EMP    TO WS-DET-SALARIO
           WRITE REG-REPORTE FROM WS-DETALLE AFTER ADVANCING 1
           
           GO TO 020-LEE.
       100-FIN.
           WRITE REG-REPORTE FROM WS-DETALLE-LEIDOS AFTER ADVANCING 1
           CLOSE EMPLEADOS
                 REPORTE
           GOBACK.

Input file:

00100FERNANDOTOLEDO ESPEJEL 82003000320005000200JOSE MARIA MEDINA 51001000280006000300ROBERTO PEREZ GARCIA 80205000560007000400VENUSTIANO ESTRADA MENDEZ 76207000210000000500VALENTIN JIMENEZ OJEDA 810010001900080


Solution

  • REG-REPORTE is defined as PIC X(50) and therefore when you WRITE REG-REPORTE FROM WS-DETALLE AFTER ADVANCING 1 you only write out the first 50 bytes of WS-DETALLE.

    You probably want REG-REPORTE to be defined as PIC X(80).

    You also might want to think about restructuring your code to not use GO TO. The following is untested, but you can see the idea.

       01  END-OF-INPUT-SWITCH PIC X VALUE 'N'.
           88  END-OF-INPUT VALUE 'Y'.
    
       PROCEDURE DIVISION.
       010-INICIO.
           OPEN INPUT  EMPLEADOS
                OUTPUT REPORTE
           WRITE REG-REPORTE FROM WS-TITULO-1.
           READ EMPLEADOS INTO WS-REG-EMPLEADOS AT END
                SET END-OF-INPUT TO TRUE
           END-READ
           PERFORM 020-LEE UNTIL END-OF-INPUT
           CLOSE EMPLEADOS
                 REPORTE
           GOBACK.
       
       020-LEE.
           ADD 1 TO WS-TOT-LEIDOS
           MOVE WS-NUMERO-EMP     TO WS-DET-NUMERO
           MOVE WS-NOMBRE-EMP     TO WS-DET-NOMBRE
           MOVE WS-STATUS-EMP     TO WS-DET-STATUS
           MOVE WS-DEPTO-EMP      TO WS-DET-DEPTO
           MOVE WS-PUESTO-EMP     TO WS-DET-PUESTO
           MOVE WS-SALARIO-EMP    TO WS-DET-SALARIO
           WRITE REG-REPORTE FROM WS-DETALLE AFTER ADVANCING 1
           READ EMPLEADOS INTO WS-REG-EMPLEADOS AT END
                SET END-OF-INPUT TO TRUE
           END-READ
           .