File Handler behavior in managed code

In native COBOL if you have "SELECT DATA-FILE ASSIGN TO DISK 'OLD\Data.dat'" and "OPEN INPUT DATA-FILE" then the File Handler will look for an environment variable named "dd_OLD" and replace the "OLD" in the SELECT clause literal with the contents of the environment variable (if found). But what happens in managed code? We are getting "File not found". Is the managed-code version of the File Handler looking for "dd_OLD" somewhere other than in the environment, or does this functionality not exist in managed code?
Parents
  • Actually for a C# ASP.NET application I don't believe that you can automatically set environment variables in web.config as the values you set are simply string pairs that can be read by your application.

    If you are calling a COBOL program from within a C# ASP.NET application then you should be using RunUnits to do this or else the program will not be thread safe. Environment variables that are set prior to the opening of the COBOL files, (in computer environment or in application) will be picked up in the COBOL program.

    Example: variable dd_NEW could be set in computer's environment also but here it is set by the calling C# program.

    protected void Button1_Click(object sender, EventArgs e)
            {
                System.Environment.SetEnvironmentVariable("dd_NEW", "C:\\temp");
                MicroFocus.COBOL.RuntimeServices.RunUnit myRunUnit =
                  new MicroFocus.COBOL.RuntimeServices.RunUnit();
                try
                {
                    // Call the COBOL program
                    COBPROG cp = new COBPROG();
                    myRunUnit.Add(cp);
                    
                    myRunUnit.Call("COBPROG", "11111111111111111111");
                }
                finally
                {
                    // Destroy the run unit
                    myRunUnit.StopRun();
                }
            }



    COBOL program:

           program-id. COBPROG.
           environment division.
               select test-file assign to "NEW\myfile.dat"
                                organization is line sequential
                                file status is file-status.
           data division.
           file section.
           fd test-file.
           01 test-record pic x(20).
           working-storage section.
           01 file-status  pic x(2) value spaces.
           01 myvar  string.
           linkage section.
           01 myparams pic x(20).
           procedure division using by value myparams.
           
               open output test-file
               move myparams to test-record
               write test-record
               close test-file
               goback.
               
    
Reply
  • Actually for a C# ASP.NET application I don't believe that you can automatically set environment variables in web.config as the values you set are simply string pairs that can be read by your application.

    If you are calling a COBOL program from within a C# ASP.NET application then you should be using RunUnits to do this or else the program will not be thread safe. Environment variables that are set prior to the opening of the COBOL files, (in computer environment or in application) will be picked up in the COBOL program.

    Example: variable dd_NEW could be set in computer's environment also but here it is set by the calling C# program.

    protected void Button1_Click(object sender, EventArgs e)
            {
                System.Environment.SetEnvironmentVariable("dd_NEW", "C:\\temp");
                MicroFocus.COBOL.RuntimeServices.RunUnit myRunUnit =
                  new MicroFocus.COBOL.RuntimeServices.RunUnit();
                try
                {
                    // Call the COBOL program
                    COBPROG cp = new COBPROG();
                    myRunUnit.Add(cp);
                    
                    myRunUnit.Call("COBPROG", "11111111111111111111");
                }
                finally
                {
                    // Destroy the run unit
                    myRunUnit.StopRun();
                }
            }



    COBOL program:

           program-id. COBPROG.
           environment division.
               select test-file assign to "NEW\myfile.dat"
                                organization is line sequential
                                file status is file-status.
           data division.
           file section.
           fd test-file.
           01 test-record pic x(20).
           working-storage section.
           01 file-status  pic x(2) value spaces.
           01 myvar  string.
           linkage section.
           01 myparams pic x(20).
           procedure division using by value myparams.
           
               open output test-file
               move myparams to test-record
               write test-record
               close test-file
               goback.
               
    
Children
No Data