Multiple table in Cobol


Could you help me to understand, how I can code this easy program;)

I don't understand, how are tables presented in Cobol?How can I declare a foreign key in Cobol? I have 2 tables. Is it 2 files or i have to use SQL EXEC SQL и ENDEXEC for this request?

Please< help me((( It's very important for me! 

Write a program in cobol. The department name (ABTEILUNG_NAME) is entered from the keyboard. Display a list of all employees (ARBEITER_ID, FAMILIE, NAME, SALARY) working in this department.


  • Suggested Answer

    You would use the EXEC SQL syntax to access database tables in Visual COBOL. There are several preprocessors available for your use depending on the database vendor that you are using. The preprocessor from Micro Focus is called OpenESQL and it accesses databases using either ODBC, ADO.NET or JBC drivers depending on how you compile your application. Please look in the product documentation that covers databases in COBOL which you can find here:

    If you are running on Windows there are also many samples available in the Samples Browser which can be found on the Windows Start menu under the Visual COBOL group->Samples. Choose SQL as the main category.


  • Example with other tables


    FROM t_artikel A with (nolock)
    left join t_artikel_owg B with (nolock) on A.owg_nr =
    left join t_artikel_wg C with (nolock) on A.wg_nr =
    WHERE A.sperre = 0
    and (A.owg_nr >= :link-owg-nr-von and
    A.owg_nr <= :link-owg-nr-bis)
    and (A.wg_nr >= :link-wg-nr-von and
    A.wg_nr <= :link-wg-nr-bis)
    and (A.ar_nr >= :link-artikel-nr-von and
    A.ar_nr <= :link-artikel-nr-bis)
    order by A.owg_nr, A.wg_nr, A.ar_nr


    you must "join" to join to tables

    i hope this example help you to code correctly, when not send me a message

  • Thanks!

    could you help me, please, how I can declare my tables in working-storage section? I don’t understand this moment.

    and should I use CURSOR FOR(open, fetch, close) in my exercise?

    Thank you in advance!

  • Please see the documentation covering Cursors which can be found here:

    The cursor just needs to be declared before it is referenced.