How to connect DB2 using Micro Focus Extension on VS Code?

I am using VS Code to code Visual COBOL. And one of my programs will require to connect to DB2 (MySQL Workbench).

As per my research, I need to have ODBC to apply the OpenESQL in microfocus. But as I was trying to compile my cobol program, I am hitting an error saying:

error COBCH0149 : No SQL directives have been set.

But on the upper part i have declared $SET SQL. 

I also tried updating the default directives to include sql, i am still getting COBCH0149 error.

  • 0  

    Hi Thea,

    What version of Visual COBOL do you have installed?
    What version of the VSCode extension are you using? (click on extensions from side menu and then click on Micro Focus COBOL.)

    This works fine for me when building if I add the SQL directive in a $SET statement in column 7 at the top of the program, or I add the SQL directive directly in the .bat file I am using as a custom build task.

    It also works for debugging if I add the directive to the default list of directives under Preferences.

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0 in reply to   

    Hi Chris,

    I am using extension version of 1.0.55.

    May I request what is inside the .bat file? Actually this is the first time that I am using Visual COBOL. All the $SET or directives are new to me.

    Is it ok for me to ask, a sample program you are using that has SQL? I would like to try on my machine and see if I am missing anything.

  • 0 in reply to 

    Also, how to determine what version of Visual COBOL I have?

    I am not sure, all of the support I am seeing, to determine what version of Visual COBOL is only applicable for Visual Studio and not for VSCode? Correct me if I am wrong Chris.

    I maybe lacking some setups on my machine to make a COBOL-DB2 work on my side.

  • Verified Answer

    +1   in reply to 

    cob -V

    Will tell you what version and patch update you have. cob is the cobol compiler

  • 0 in reply to   

    Thank you Micheal.

    Hi Chris,

    Currently my machine has:

    Micro Focus COBOL version 9

    Extension Version: 1.0.55

  • 0   in reply to 

    Under which operating system are you running? I have been assuming that you were running on Windows, but it sounds like it may be Linux. 

    The test program that I am using simply has a connect statement in it and it doesn't even have to connect to a real connection because this is a compile time error.

         $set sql(dbman=ODBC)
           id division.
           program-id.  VSCodeDB.
           working-storage section.
           exec sql include sqlca end-exec
           procedure division.

               exec sql connect to 'testodbc17' end-exec
               exec sql disconnect current end-exec
               display "done"
               goback.
               .

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0 in reply to   

    I am running on Windows 10.

    I tried your code and giving me "error COBCH0170 : Invalid argument in sql(dbman=ODBC)"

    I have put $SET sql(dbman=ODBC) at column 7.

    I also tried removing the default directive sql, leaving with only the following directives: int(), anim, nognt, errformat(3)

    Did you build yours using a .bat file? I am not an expert with the .bat file, can you please share with me if there is a set need there as well?

    I am running the code using these Run COBOL program button.

  • 0   in reply to 

    I created a file buildit.bat which contains the following line:

    cobol VSCodeDB.cbl/int() anim;

    Then I selected from the menu, Terminal->Configure Tasks

    and added the following to the tasks.json file:

    {
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "my custom build",
                "type": "COBOL-shell",
                "command": ".\\buildit.bat"
                "problemMatcher": "$COBOLErrFormat3",
                "group": "build"
            }
        ]
    }

    Then select Terminal->Run Build Task or Run Task and select the "my custom build"

    This should compile the program.

    I am using identical versions and OS that you are, and this is working for me.

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0   in reply to   

    sorry I have a missing comma in my task file. Please use this instead:

    {
        // for the documentation about the tasks.json format
        "version": "2.0.0",
        "tasks": [
            {
                "label": "my custom build",
                "type": "COBOL-shell",
                "command": ".\\buildit.bat",
                "problemMatcher": "$COBOLErrFormat3",
                "group": "build"
            }
        ]
    }

    Chris Glazier
    Rocket Software - Principal Technical Support Specialist
    If you found this post useful, give it a “Like” or click on "Verify Answer" under the "More" button

  • 0 in reply to   

    There is nothing difference between the default directive and the .bat file. 

    Though, I still try to run via .bat file. Still same error

    "Invalid argument in SQL(DBMAN=ODBC)"

    I wonder what I am missing? Is there specific .dll file that my machine should be having?