Run COBOL / gnuCOBOL inside Vs Code within MSYS2

Submitted by Dickens A S on Thu, 07/29/2021 - 03:51

This article demonstrates how to compile COBOL and see the output within VS Code UI

Install COBOL within MSYS2

  Follow this article cobol-windows-msys2 and install gnuCOBOL using pacman command line

Launch VS Code within MSYS2

  Follow this article launch-vscode-from-msys2 and launch the vs code 

Install Extensions

  install the bellow 4 extensions

  https://marketplace.visualstudio.com/items?itemName=bitlang.cobol
  https://marketplace.visualstudio.com/items?itemName=bitlang.gnucobol
  https://marketplace.visualstudio.com/items?itemName=OlegKunitsyn.gnucobol-debug
  https://marketplace.visualstudio.com/items?itemName=webfreak.debug

Open launch.json

  in VS Code go to the below menu option

  Run -> Open Configurations

  Edit the launch.json as below

{
    "version": "0.2.0",
    "configurations": 
    [
        {
            "name": "COBOL debugger",
            "type": "gdb",
            "request": "launch",
            "cobcargs": ["-free", "-x"],
            "group": ["${file}"]
        }
    ]
}

Write a COBOL code (test.cob)

       IDENTIFICATION DIVISION.
       PROGRAM-ID. HELLO-WORLD.

       DATA DIVISION. 
       WORKING-STORAGE SECTION.
       01 WS-OUT PIC X(80) VALUE SPACES.
       01 WS-N PIC 9(2) VALUE 0. 
       01 WS-CENTER PIC 9(2) VALUE 20.

       PROCEDURE DIVISION.

           PERFORM VARYING WS-N FROM 1 BY 2 UNTIL WS-N > 26
           MOVE ALL '*' TO WS-OUT(WS-CENTER:WS-N)
           COMPUTE WS-CENTER = WS-CENTER - 1
           DISPLAY WS-OUT
           END-PERFORM.

           STOP RUN.

Open Debug Console

    in VS Code choose the below menu

    View -> Debug Console

    Or press Ctrl+Shift+Y

Run the code

    in VS Code choose the below menu

    Run -> Run Without Debugging

    You will see the below output in VS Code

    COBOL Debug Console VS Code

Finished !

 

Add new comment