Modify COBOL Source

Modify the COBOL source code in the TemperatureConverter project with new code to access your SQL Server database.

Here you replace the COBOL source in the TemperatureConverter.cbl file with COBOL source that accesses the SQL Server database.

  1. In the Project Explorer under TemperatureConverter > src > com.microfocus.converter, double-click TemperatureConverter.cbl to open it in the file editor.
  2. Replace the entire contents of the file with the following:
    $set sql(dbman=jdbc)      
      class-id com.microfocus.converter.TemperatureConverter public.
      01 text1 pic x(10). *> to force implements IObjectControl
      exec sql include sqlca end-exec.
      method-id toCelsius.
      procedure division using by value fahrenheit as float-short returning celsius as float-short.
      exec sql connect to pubs end-exec.
          exec sql
               select (:fahrenheit - 32) * 5 / 9 into :celsius
          end-exec.
          exec sql disconnect pubs end-exec.
          goback.
     end method.
     method-id toFahrenheit.
     procedure division using by value celsius as float-short returning fahrenheit as float-short.
          exec sql connect to pubs end-exec.             
          exec sql
               select (:celsius * 9 / 5) + 32 into :fahrenheit
          end-exec.
          exec sql disconnect pubs end-exec.
          goback
     end method.       
     end class.
  3. Click File > Save to save your changes.