Skip to main content

Problem:

When you need the option of being able to change the order and count of directories/paths where Shared Objects of COBOL programs are located, you might expect that this should be tunable inside the running process with setenv.

But changing the COBPATH environment variable in the running process with setenv has no effect to the Cobol run time. It seems that COBPATH is only once read at the process start.

How can one change the directories/paths, where the run time searches for the shared object that was called at realtime?

Resolution:

       id division.

       program-id. TEST1.

       data division.

       working-storage section.

       procedure division.

       DISPLAY "CALLING SETPATH"

       CALL "SETPATH".

       DISPLAY "CALLING TEST2".

       CALL "TEST2".

       ENDPGM.

           goback.

       End Program TEST1.

TEST2.CBL:

       id division.

       program-id. TEST2.

       data division.

       working-storage section.

       procedure division.

       DISPLAY "TEST2 IS CALLED".

       ENDPGM.

           goback.

       End Program TEST2.

SETPATH.c:

#include <stdio.h>

void SETPATH(void)

{

  setenv("COBPATH","/../../testprog1:/../../testprog2",1);

fprintf(stderr,"THE CONTENT OF THE ENV COBPATH IS >%s<\\n", getenv("COBPATH"));

}

int main()

{

  SETPATH();

  return 0;

}

Compiled the programs TEST1.CBL and TEST2.CBL with

cob32 -zUg TEST1.CBL -o ./TEST1.so

cob32 -zUg TEST2.CBL -o ./TEST2.so

SETPATH.c

cc -g -shared SETPATH.c -o SETPATH.so

The solution is to use in SETPATH.c cobrescanenv():

#include <stdio.h>

#include "cobenv.h"

int cobrescanenv(void);

void SETPATH(void)

{

  setenv("COBPATH","/../../testprog1:/../../testprog2",1);

  printf("Rescaning COBOL env ....");

  cobrescanenv();

fprintf(stderr,"THE CONTENT OF THE ENV COBPATH IS >%s<\\n", getenv("COBPATH"));

}

int main()

{

  SETPATH();

  return 0;

}

Old KB# 2311