Skip to main content
Question

access data base and occurs

  • May 22, 2026
  • 2 replies
  • 16 views

Ignacio

I have a relational database with a one-to-many table. When reading it in COBOL, I believe it's necessary to read the record key from the main table and the related records from the secondary table; I believe a read should be performed from the main table record key, and the related records from the secondary table would be stored in an "occurs" of that record.

The  code  FD : 

 FD ARCHIVO-NUEVO.

01 REG-NUEVO-FISICO.

05 Fis-RecNumber PIC 9(6).

05 Fis-Nombre PIC X(30).

05 Fis-Tabla-Pagos.

10 Fis-Nuevo PIC 9(8) OCCURS 100 TIMES.

 

Is correct???

Thanks

2 replies

Chris Glazier
Forum|alt.badge.img+4

Hi Ignacio,

I am not really sure what you are asking here. Are you using Database Connectors to access your database or are you referring to standard COBOL indexed data files when you refer to a database? 

Can you provide a bit more detail on what it is you are trying to read from the database. How do you read the data in the database? Can you show me a select statement you are using?

Thanks


Dennis Strahan

Hi Ignacio,

If you’re referring to a SQL based database like DB2, you can iterate through a cursor and store the rows in an array by using a multi row fetch cursor:

01  ws-dept-table.

    05  ws-dept-array       occurs 10 times.

        10  ws-dept-number  pic x(10).

        10  ws-dept-name    pic x(30).

  exec sql

     declare deptcurs  cursor for

        select dept-number, dept-name

          from depts 

         where dept-type = “acct”

  end-exec.

  exec sql

     fetch deptcurs for 10 rows 

      into :ws-dept-array

  end-exec.