0

I'm studying Cobol, but I have a problem when reading a file, cobol is returning the status of the file as 35... I checked on the internet what it is this status, and from what I understand is that the system does not find the file, but I created the file in the same directory as the executable, with the columns that the system should identify...

How I can solve this ?

   IDENTIFICATION DIVISION.
   PROGRAM-ID.    EXCLI.

   ENVIRONMENT DIVISION.
   CONFIGURATION SECTION.
   SPECIAL-NAMES.
      DECIMAL-POINT IS COMMA.

   INPUT-OUTPUT SECTION.
   FILE-CONTROL.
        SELECT ARQCLI ASSIGN TO DISK
        ORGANIZATION            INDEXED
        ACCESS MODE             DYNAMIC
        RECORD KEY              FD-CODIGO
        FILE STATUS             FS.

   DATA DIVISION.
   FILE SECTION.
   FD ARQCLI LABEL RECORD STANDARD
         VALUE OF FILE-ID IS "ARQCLI.DAT".

   01 REG-ARQCLI.
      02 FD-CODIGO.
          03 CODIGO       PIC 9(04).
      02 FD-NOME          PIC X(30).
      02 FD-END           PIC X(30).
      02 FD-BAIRRO        PIC X(20).
      02 FD-CIDADE        PIC X(20).
      02 FD-CEP           PIC 9(05).

   WORKING-STORAGE SECTION.
   77 WS-SPACE            PIC X(40) VALUE SPACES.
   77 FS                  PIC X(02) VALUE SPACES.
   77 WS-FUNC             PIC 9     VALUE ZERO.
   77 MSG                 PIC X(09) VALUE SPACES.
   77 WS-CONF             PIC X     VALUE SPACE.
   01 WS-DATA-SIS.
      02 AA               PIC 9(02) VALUE ZEROS.
      02 MM               PIC 9(02) VALUE ZEROS.
      02 DD               PIC 9(02) VALUE ZEROS.
   01 WS-MENSAGENS.
      02 MENSA1           PIC X(30) VALUE "FUNÇÃO ERRADA - REDIGITE".
      02 MENSA2           PIC X(30) VALUE "CAMPO INVALIDO".
      02 MENSA3           PIC X(30) VALUE "CLIENTE JÁ CADASTRADO".
      02 MENSA4           PIC X(30) VALUE "CLIENTE NÃO CADASTRADO".

   SCREEN SECTION.
   01 TELA1.
      02 BLANK SCREEN.
      02 LINE 01 COLUMN 01 VALUE "EM:".
      02 LINE 01 COLUMN 26 VALUE "CADASTRO DE CLIENTES" REVERSE-VIDEO.
      02 LINE 03 COLUMN 19 VALUE "AUTOR: ALEXANDRE SAVELLI BENCZ".
      02 LINE 06 COLUMN 29 VALUE "FUNÇÃO DESEJADA: < >".
      02 LINE 08 COLUMN 29 VALUE "< 1 > INCLUSÃO".
      02 LINE 10 COLUMN 29 VALUE "< 2 > ALTERAÇÃO".
      02 LINE 12 COLUMN 29 VALUE "< 3 > EXCLUSÃO".
      02 LINE 14 COLUMN 29 VALUE "< 4 > CONSULTA".
      02 LINE 16 COLUMN 29 VALUE "< 5 > FIM".
      05 LINE 21 COLUMN 29 VALUE "MENSAGEM:".

   01 TELA-OPCAO.
      02 LINE 06 COLUMN 39 PIC X(09) USING MSG REVERSE-VIDEO.

   PROCEDURE DIVISION.
   INICIO.          
      OPEN I-O ARQCLI.
      IF FS NOT = "00"
         IF FS = "30"
            CLOSE ARQCLI OPEN OUTPUT ARQCLI CLOSE ARQCLI
            GO TO INICIO
         ELSE
            DISPLAY "FILE STATUS --->" LINE 24 COLUMN 35
            DISPLAY FS LINE 24 COLUMN 52
            STOP RUN
         ELSE
            NEXT SENTENCE.
            ACCEPT WS-DATA-SIS FROM DATE.

   TELA.
      DISPLAY TELA1.

   FIM.   
      STOP RUN.
Alexandre
  • 1,985
  • 5
  • 30
  • 55
  • 1
    One trick I find handy (on GNU/Linux at least) is `strace`. strace will show you exactly what search paths are used for file access. Not that easy to grok through but look for lines like `access("ARQCLI.DAT", F_OK) = -1 ENOENT (No such file or directory)` – Brian Tiffin Aug 07 '13 at 18:06
  • When the system (whatever that is) tells you something, I believe it. Uppercase/lowercase, 1 instead of I. A script changing the current directory/path. What is all the close/open about? If you get a 30 again after all that, you get a BIG FAT LOOP. Use CONTINUE instead of NEXT SENTENCE. Why ELSE NEXT SENTENCE anyway? I always think it nice to CLOSE a file when you finish with it. Good work on actually using the FILE STATUS, doesn't happen often enough. – Bill Woodger Aug 08 '13 at 01:04
  • It will be much better to ensure that your file is in a usable state before running your program. What you have "looks unclear" so is unclear to anyone looking. If you insist on doing it like that, document it, including comments in the program. – Bill Woodger Aug 22 '13 at 08:25

3 Answers3

4

A little late, and tangential, but here is a list of OpenCOBOL FILE STATUS codes as a copy book file, and slightly more mnemonic than the numbers. Edit to taste.

http://opencobol.add1tocobol.com/#isam

   01  status-code           pic x(2) value spaces.
       88  SUCCESS                    value '00'.
       88  SUCCESS_DUPLICATE          value '02'.
       88  SUCCESS_INCOMPLETE         value '04'.
       88  SUCCESS_OPTIONAL           value '05'.
       88  SUCCESS_NO_UNIT            value '07'.
       88  END_OF_FILE                value '10'.
       88  OUT_OF_KEY_RANGE           value '14'.
       88  KEY_INVALID                value '21'.
       88  KEY_EXISTS                 value '22'.
       88  KEY_NOT_EXISTS             value '23'.
       88  PERMANENT_ERROR            value '30'.
       88  INCONSISTENT_FILENAME      value '31'.
       88  BOUNDARY_VIOLATION         value '34'.
       88  NOT_EXISTS                 value '35'.
       88  PERMISSION_DENIED          value '37'.
       88  CLOSED_WITH_LOCK           value '38'.
       88  CONFLICT_ATTRIBUTE         value '39'.
       88  ALREADY_OPEN               value '41'.
       88  NOT_OPEN                   value '42'.
       88  READ_NOT_DONE              value '43'.
       88  RECORD_OVERFLOW            value '44'.
       88  READ_ERROR                 value '46'.
       88  INPUT_DENIED               value '47'.
       88  OUTPUT_DENIED              value '48'.
       88  I_O_DENIED                 value '49'.
       88  RECORD_LOCKED              value '51'.
       88  END_OF_PAGE                value '52'.
       88  I_O_LINAGE                 value '57'.
       88  FILE_SHARING               value '61'.
       88  NOT_AVAILABLE              value '91'.
Brian Tiffin
  • 3,978
  • 1
  • 24
  • 34
  • Actually, that copybook could be changed, and will be in the OpenCOBOL FAQ. `01 status-code. 05 stat-byte-one pic 9. 88 successful-io value 0. 05 stat-byte-two pic 9.` x's would still work, VALUE '0' for the conditional. The leading zero of the status field being the success codes. If the code at hand doesn't have to worry about why an IO verb succeeded, there is less need to test for the specific numbers, ummm, until you need to. – Brian Tiffin Aug 27 '13 at 03:49
1

You might want to check your IF statement. It is in a wrong format. Try using the IF ... END-IF format to make it clear, instead of using full-stops.

I think this is what you meant to do:

  OPEN I-O ARQCLI.
  IF FS NOT = "00"
     IF FS = "30"
        CLOSE ARQCLI OPEN OUTPUT ARQCLI CLOSE ARQCLI
        GO TO INICIO
     ELSE
        DISPLAY "FILE STATUS --->" LINE 24 COLUMN 35
        DISPLAY FS LINE 24 COLUMN 52
        STOP RUN
     END-IF
  ELSE
        ACCEPT WS-DATA-SIS FROM DATE
  END-IF.
JunYoung Gwak
  • 2,967
  • 3
  • 21
  • 35
Molusco
  • 59
  • 6
  • Very good advice concerning using END-whatever to delimit statement scope and avoidance of full stops. However, I don't think that will solve the OPs problem. – NealB Aug 07 '13 at 19:35
1

The correction is very simple... I just have chenged the IF...

         IF FS = "35"
            CLOSE ARQCLI OPEN OUTPUT ARQCLI CLOSE ARQCLI
            GO TO INICIO
         ELSE
Alexandre
  • 1,985
  • 5
  • 30
  • 55