- First things first
- 1) Install the required extensions.
- 2) Setup your local folder
- 3) Connect to IBMi
A setup guide to get started on VS Code and IBMi. This guide includes,
- Installing the required extensions
- Setup your local folder
- Connect to the IBMi
- Coding in VS Code
- Compiling in VS Code
- Terminal (TN5250)
It is best to sync the settings of your VS Code preferences to your company's GitHub account. So that when you reinstall VS Code (for some weird reasons), you will have an option to reset your preferences and plugins. Follow the below steps to get started.
-
Open VS Code and click on the accounts icon on the bottom left
-
Click "Turn on Settings sync". You will be prompted with the list of settings you want to sync. Tick whatever settings you want to sync. I prefer to sync them all.
-
Click "Sign in & Turn on" >> Click Sign in with GitHub.
-
Click open on the browser window (that just got opened)
-
Click open again inside VS Code and you're all set.
-
Go to the extensions panel (Ctrl + Shift + X) and install the extension "IBM i Development Pack". This is a collection that contains 13 extensions useful for coding in IBMi.
Most of the extensions are open source, except for the ones created by IBM. You can view about the authors and the respective licenses on the market place page.
-
If you're having any issues installing the plugin, you need to make the below changes. Click the bottom left corner as shown in the screenshot below.
On the right side pane, click "Trust Window" (mine is already trusted)
It is important to setup a local folder if you wish to keep a copy of the sources in your local machine as a backup.
-
Go to the Explorer Tab (Ctrl + Shift + E) and click on "Open Folder".
-
Navigate to your local folder. For this tutorial, I have created a new folder called "MySourceCodes". Be sure to "Trust the authors of the files in this folder" as shown below.
-
It is important to have SSH installed in our IBM server. SSH, SFTP, and related programs are provided by the 5733-SC1 Licensed Program Product by default, but it doesn't hurt to check.
In your IBMi, check whether SSH Server is already started. Run the CL command
NETSTAT *CNN
and search for any activity on port 22. If you don't see any activity then you can start SSH with the CL commandSTRTCPSVR *SSHD
. TypingWRKACTJOB
should now show jobs running function “PGM-sshd.” To end SSH, typeENDTCPSVR *SSHD
.You can also autostart the SSH daemon by modifying this entry here.
select * from qusrsys.qatocstart
-
Once the SSH daemon is started on your IBMi head back to VS Code. Now you should see a new IBMi icon present on the left most panel. Click on it and select "Connect to an IBM i" button.
-
Enter the connection details such as connection name, IP address, User Name & Password and click connect.
-
Once a connection is made, depending upon your IBMi server configuration, you might or might not see some notifications/warnings/error messages at the bottom right like below. If you get multiple notifications and they all disappeared before you read them fully, fret not. All the notification will reside in the bottom right "bell" icon. We will go through one by one.
a. Debug PTF Installed
This means your IBMi has the debug PTF installed in it. We can make use of this PTF to debug the programs from outside of IBMi (In our case it is VS Code). Click this link to see how to setup debug in VS Code.
b. Current Library is set to XXXXXX
We can setup the current library for this VS Code connection to our liking. You can either change now or if you decide to change later, you can do so by accessing the "User Library List" pane on the left.
c. IBM recommends using bash as your default shell.
You can set the bash as your default shell for this session instead of the usual QSH (QShell). Why? Because BASH has many more cooler features and command history (using up arrow keys to access previous commands) is one of them. If you wish to do later, you can do so by issuing
/QOpenSys/pkgs/bin/chsh -s /QOpenSys/pkgs/bin/bash
command (Ctrl + Shift + J to open PASE Terminal from VS Code) or you may refer to this guided. Deploy Directory
You can set you default deploy directory to the specified IFS folder. Remember the previously created folder "My Source Codes"? Whatever code you write and save in this location will have the ability to be pushed to your IBMi IFS folder that you specify in the "Deploy Directory". Once the source code has come to your IBMi you can easily issue a
CPYFRMIMPF
CL command to copy the sources to your IBMi libraries.e. QCCSID is set to 65535. Disabling SQL support.
In order to have the ability to run SQL Queries from within VS Code, we need to set the CCSID of this session to 37. If you get any error related to SQL Queries and CCSID, then you need to head over to your IBMi and set the CCSID as 37. The default is 65535.
f. Code for IBM i may not function correctly until your user has a home directory...
In order to have a deploy directory(where your source codes will be deployed), it is must to create your own user profile directory inside the /home directory in the IFS. You might be shown with this warning message if the home directory is not set correctly. The fix is to create a user_profile directory. If you're comfortbale with Shell command, you can use PASE (Ctrl + Shift + J from VS Code) to create a directory. The command is
mkdir /home/<your_ibmi_username>
. If you're comfortable with IBMi green screen, then you can issue aMKDIR DIR('/home/<your_ibmi_username>')
CL command. I would suggest you to use lower case while creating your directory as UNIX Shell is case sensitive.
Further Reading Since VS Code is using SSH to connect with IBMi, it is better to run the SSHD in a separate subsystem for better management of resources
To edit
- Starting SSH Daemon
- Connecting the IBMi mulitple times.