Visual Studio Code, RPG and IBM i

Visual Studio Code 1.35 iconVisual Studio Code is an IDE and platform for developers to write backend, progressive web apps, frontend, and everything on the spectrum of development. I have created an extension for VS Code, called Code for IBM i, that allows users to work on and maintain their IBM i code. VS Code is the best IDE for extensibility, which is why I wanted to take on such a task.

While Visual Studio Code was built to work with all languages, in my opinion it didn’t have much support for RPGLE or COBOL on IBM i until this point. We’re streamlining RPGLE development in terms of tools and speed for our users. We want to make developing RPGLE and COBOL easy for everyone in the most efficient way possible.

Since 2017, I have been building extensions and standalone IDEs, like IBMiCmd, ILEditor 1, and ILEditor 2. I firmly believe that Code for IBM i is the best iteration of my work, and it makes me so happy that I can share it with everyone.

As of 2021, Code for IBM i has been available for free on the Visual Studio Code Marketplace. It is also open source and relies heavily on user feedback and input (as well as the occasional PR.) Code for IBM i has a ton of functionality… too much for a single article. This post will run you through the setup of VS Code and Code for IBM i.

Installation

Visual Studio Code is available for most operating systems, including Windows and Mac. The very first thing is to download it from the VS Code website. Following that, you can install the extension from the Marketplace.

  1. Open the extensions view
  2. Search ‘ibmi’ and find Code for IBM i
  3. Hit install

Connecting to your IBM i

The installation should really only be a single click. From there, it’s time to connect to an IBM i. It’s important to note that to connect to your IBM i, you need the SSH Daemon started on your system. Usually a simple STRTCPSVR *SSHD  will get that started for you, but you can check out Getting Started with SSH on IBM i if you need more assistance.

After Code for IBM i is installed, you will see a new icon appear on the left. That is the Code for IBM i extension! You can click that, select ‘Connect to an IBM i’, fill out the information, and then hit connect. Code for IBM i will store that connection info for later so you don’t have to type all that in again.

You’ll see a nice info message appear when you are connected successfully.

Editing members

When you connect to a new system for the first time, you will see the Member Browser has only QSYSINC/H in the list. Of course, we don’t want to edit anything in there. When hovering over the Member Browser, you will see a button that will let you add other source files to that list. Let’s add one that we can edit members in!

When the item has been added, you can click on the source file to show the members inside of it. To open a member, you can simply click on it to open it in a new tab. When the source is open, you can do all your usual editing.

Compiling code

Of course, the second most important thing other than editing is compiling your source code. In this case, we have an SQLRPGLE program called DEPTS_WEB. Code for IBM i adds a new shortcut to compile the source code you’re currently working with. To show what compile options you have, you can use the Control + E shortcut (or Command + E on Mac). This will show a dropdown with the available Actions (another topic worth its own blog post). Each Action has a different command that it will run.

In our case, we want to run CRTSQLRPGI to compile our program and there is a default action for that.

After the compile runs, Code for IBM i will display the errors from the compile in line with the source code (as you would expect). It looks like, in this case, the pre-compiler couldn’t find a file definition. That usually indicates that there is a library list issue / the library with that table is missing from the library list.

Editing the library list

The connection to Code for IBM i has its own library list. That means any time a command is sent to the server, it uses the library list from the settings rather than the library list from the user. It’s very easy to change this library list. In the Code for IBM i extension there is a User Library List view. In that view you can:

  • Change your current library
  • Edit your user library list for any future commands
  • Re-order your user library list

For our DEPTS_WEB program to compile, we need to add the missing library with the DEPARTMENT table. That just so happens to be in the SAMPLE library/schema. You can click the add button in the User Library List view to add a library.

Now that SAMPLE has been added, the next time we try to compile our program there should be no issues. Code for IBM i will tell you that the command ran successfully with an informational message.

Closing

These are just the very basics of Code for IBM i. There is so much to it. For example, some of the other functionality in Code for IBM i includes:

  • Editing and compiling sources from the IFS (RPG, PHP, Python, JavaScript, etc.)
  • Searching through the contents of source files and IFS directories
  • Browsing and maintaining objects in libraries
  • Running SQL statements and viewing results visually
  • Content assist for free-format RPGLE and fixed-format RPGLE

There are also extensions to Code for IBM i which add:

  • Source date support
  • Integrated unit testing for RPGLE
  • Code Coverage for IBM i

Check out the:

For training on this or any other IBM i development technology—including APIs or open source on IBM i—contact us.

15 replies
  1. Frank
    Frank says:

    Each time I connect to our IBM i and open a src-pf (ccsid=37) I sooner or later see all my members as undefined.undefined. These members can not be opened. CPFA0A9: OJBECT NOT FOUND. I can’t get rid of this problem.

    Reply
  2. Michael Wisolmerski
    Michael Wisolmerski says:

    Hi –

    I don’t know what happened to my last post, but I asked if CCSID 64K would be supported. Nearly all of out many source files are CCSID 65535.

    Thanks!
    Mike W.

    Reply
    • Alan Seiden
      Alan Seiden says:

      Mike, CCSID 65535 means you have to manually say what kind of encoding to use. You could specify a CCSID in the Code for i plugin settings. Could you try that? Maybe 37, unless you need to use another one?

      Reply
      • Michael Wisolmerski
        Michael Wisolmerski says:

        Alan –

        When I try to open a source member, I get:
        CPD0085: Range of parameter DBFCCSID does not include 65535. CPF0006: Errors occurred in command.

        Reply
      • Michael Wisolmerski
        Michael Wisolmerski says:

        Alan –
        I just tried to open a CCSID 37 source file and I got the same error – I don’t see a setting for CCSID – could you let me know where that is?
        Thanks!

        Reply
  3. Michael Wisolmerski
    Michael Wisolmerski says:

    Hi Liam –

    Our source files are all CCSID 64K – I think this is due to I18N requirements. Can Code for IBM i. be made to work CCSID 64K?

    Thanks!

    Reply
      • Michael Wisolmerski
        Michael Wisolmerski says:

        Hi Alan –

        They are all CCSID 64K – 65535 and there are MANY – changing them is not possible – and we have a couple at CCSID 37

        And nice to talk to you again – you and I talked several years ago about PHP – I was working for Mayors Jewelers.

        Reply
        • Alan Seiden
          Alan Seiden says:

          Hi, Michael, look at configuring it here:

          Additional settings

          Source file CCSID
          The CCSID of source files on your system. You should only change this setting from *FILE if you have a source file that is 65535 – otherwise use *FILE. Note that this config is used to fetch all members.

          Reply
  4. Dylan Hague
    Dylan Hague says:

    Been looking for something like this for quite some time! Will be watching this repo closely, cheers!

    Reply
  5. Richard Nemerovsky
    Richard Nemerovsky says:

    Nice! We’ve been exploring possibly going the GitHub route with all of our RPGLE, etc. code and were planning on going the RDi route along with EGit. Any thoughts on how approach like that would work in relation to this? Thanks.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.