Rational Developer for System z
Enterprise COBOL for z/OS, Version 4.1, Programming Guide


Calling UNIX/POSIX APIs

You can call standard UNIX/POSIX functions from z/OS UNIX programs and from traditional z/OS COBOL programs by using the CALL literal statement. These functions are part of Language Environment.

Because these are C functions, you must pass arguments BY VALUE. Pass character strings as BY VALUE pointers that point to null-terminated strings. You must use the compiler options NODYNAM and PGMNAME(LONGMIXED) when you compile programs that call these functions.

You can call the fork(), exec(), and spawn() functions from a COBOL program or from a non-COBOL program in the same process as COBOL programs. However, be aware of these restrictions:

The exec() and spawn() functions start a new Language Environment enclave in the new UNIX process. Therefore the target program of the exec() or spawn() function is a main program, and all COBOL programs in the process start in initial state with all files closed.

Sample code for calling some of the POSIX routines is provided in the SIGYSAMP data set.

Table 1. Samples with POSIX function calls
Purpose Sample Functions used
Shows how to use some of the file and directory routines IGYTFL1
  • getcwd()
  • mkdir()
  • rmdir()
  • access()
Shows how to use the iconv routines to convert data IGYTCNV
  • iconv_open()
  • iconv()
  • iconv_close()
Shows the use of the exec() routine to run a new program along with other process-related routines IGYTEXC, IGYTEXC1
  • fork()
  • getpid()
  • getppid()
  • execl()
  • perror()
  • wait()
Shows how to get the errno value IGYTERNO, IGYTGETE
  • perror()
  • fopen()
Shows the use of the interprocess communication message routines IGYTMSQ, IGYTMSQ2
  • ftok()
  • msgget()
  • msgsnd()
  • perror()
  • fopen()
  • fclose()
  • msgrcv()
  • msgctl()
  • perror()

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)