Code for IBM i: Maintenance of source code

Code for IBM i | Part 3: Maintenance of source code
By Makoto Ogawa, T&Trust K.K.

Maintaining Source Code on the IFS 

Let us now look at how to maintain and compile source code on the IFS of the IBM i.

Currently, most compilers for languages supported on the IBM i support the SRCSTMF parameter, which refers to source code stored on the IFS.

Code for IBM i provides an IFS BROWSER function that references files on the IFS, allowing you to edit and compile source code directly on the IFS with Visual Studio Code.

There is one caveat, however: when you create a new source code from VSCode to IFS, the CCSID of the file will be 1208 (Unicode). However, compilers such as RPG cannot directly reference Unicode files.

To solve this problem, the CCSID of the source code must be converted to something the compiler can read (such as 5035 or 1399) before compilation. As mentioned in the execution environment in the previous section, when using Code for IBM i, the parameter TGTCCSID must be added to each compiler command in advance to specify the target CCSID.

This PTF is 5770WDS-SI62605 for IBM i 7.3. For more information, see Compile RPG from Unicode source – new TGTCCSID parameter in 7.1, 7.2, 7.3 ( -tgtccsid-parameter-71-72-73). 7.4 and later TGTCCSID parameters are supported by default, so PTF does not need to be applied.

Creating Source Code

Now, let’s actually place the try01r.rpgle code described earlier on the IFS, modify it, and compile it.

First, create a new stream file in IFS BROWSER (Figure 31).

Figure 31   Creating a stream file
Figure 31   Creating a stream file

The name of the stream file is “try01r.rpgle”, which is the same as the name of the previous member (Figure 32).

Figure 32   Specifying a new file name
Figure 32   Specifying a new file name

In the created file, copy and paste the code of the previous member.

Note that the paramater of the command at compile time specifies the IFS stream file, so it must be registered as a different action than the previous command.

Since Code for IBM i defines actions for each member and stream file (list below), care should be taken when modifying detailed parameters.

◎Substitution Variables: Explanation
・&FULLPATH: Full path of the file on IBM i
・RELATIVEPATH: Relative path of the streamed file from the home directory or workspace
・PARENT: The name of the parent directory or source file.
・BASENAME: The name of the file including its extension
・NAME: The name of the file.
・&EXT: File extension
・CURLIB: The current library set in the USER LIBRARY LIST.
・&USERNAME: Name of the connected user
・&HOME: working directory name (can be changed using IFS BROWSER)
・&LIBLC: comma-separated library list
・&LIBLS: Space-delimited library list

Streamfile and the following commands, which appear when you click on Actions on the taskbar, are the ones selected when compiling source code on the IFS. Click on Create Bound RPG Program (CRTBNDRPG) and Create Bound RPG Program (CRTBNDRPG) to see the command; if the TGTCCSID(*JOB) parameter is not specified, add it and save it.

After saving, click Ctrl+E and select Create Bound RPG Program (CRTBNDRPG) to run the compile command on the IBM i. If there are no problems, a message will appear in the lower right corner of the screen telling that the compilation was completed successfully (Figure 33).

Figure 33 Display of compile results
Figure 33 Display of compile results

Of course, it is also possible to browse the compilation list by clicking Output on the taskbar.

The rest of what can be done is the same as for source-member, except that the target source exists on IFS and the commands selected in the action are different from those in the member.

Maintaining Local Source Code

So far we have seen how to add, modify, and compile source code directly in a source file member or on the IFS while connected to the IBM i with Code for IBM i.

Now we will look at the process of creating source code on the disk of a development PC and compiling it on IBM i.

First, it is necessary to make the following settings on the assumption that a connection has been created with Code for IBM i.

・Specify the IFS directory where the source code is to be deployed (pushed).
・Specify the json file (.vsco/actions.json) that describes the compilation commands.
・Create a json file (.vsco/actions.json) that describes the compilation com

If you store your source code locally, when you compile it on the IBM i, you must Deploy (push) it to the IBM i disk before compiling it.The location for that push can be set by clicking Yes when you are prompted to set it when you connect to IBM i with Code for IBM i after opening the local folder in VSCode (Figure 34).

Figure 34   Specifying the default deployment destination
Figure 34   Specifying the default deployment destination

If Yes is specified, the destination is set to push to the builds directory in the home directory of the user connecting to IBM i with a local folder name.

If you did not click Yes on the instruction screen or if you want to save the files in a directory other than the builds directory, right-click the directory you want to deploy to in IFS BROWSER and click Set Deploy Workspace Location (Figure 35).

Figure 35    Specify an arbitrary location
Figure 35    Specify an arbitrary location

To check if the Deploy destination has been set correctly, click Deploy on the taskbar to see what appears at the top (Figure 36, Figure 37).

Figure 36   Deploy button on the taskbar
Figure 36   Deploy button on the taskbar
Figure 37    Checking the current deployment destination with the Deploy button
Figure 37    Checking the current deployment destination with the Deploy button

If the settings are not correct, the message shown in Figure 38 will appear in the lower right corner, so please set the IFS directory as the Deploy destination again.

Figure 38   Message when the deploy destination is not set
Figure 38   Message when the deploy destination is not set

Next is the setting of the compile command. Note that the action just described is not used to compile local source code. Instead, a .vscode/actions.json must be created in an open local folder.

To create it, click Run Setup in the message that appears when connecting to IBM i, or in the command palette, select the necessary command in the screen that appears when Launch Actions Setup is executed (Figure 39, Figure 40) and click the OK button in the upper right corner.

Figure 39   Confirmation of action.json creation
Figure 39   Confirmation of action.json creation
Figure 40   Launch Actions Setup
Figure 40   Launch Actions Setup

Then, a .vscode/actions.json file is created in the folder opened in VSCode (Figure 41).

Figure 41   Created actions.json
Figure 41   Created actions.json

Coding and Compilation

Now, let’s look at the procedure for creating source code locally and Deploying/compiling it.

First, open the source code of try01r.rpgle created in the previous section with OBJECT BROWSER, and select and copy the source using Ctrl + A/Ctrl + C (Figure 42).

Figure 42   Copying the RPG IV source
Figure 42   Copying the RPG IV source

Then, click the Explorer icon in VSCode to open the folder, click the Create File icon to create a file with the name try01r.rpgle, and paste the copied source code with Ctrl + v to save it (Figure 43).

Figure 43   Saving the copied source code
Figure 43   Saving the copied source code

Continue to compile; Ctrl + E to select Create RPGLE Program at the top, and the information in Figure 44 will appear on the screen.

Figure 44 Selecting a file to deploy
Figure 44 Selecting a file to deploy

In this case, two files, .vscode/actions.json and try01r.rpgle, have not yet been uploaded, so the message “2 changes detected since last upload”. Clicking on this will push the source files to the Deploy destination IFS directory specified earlier, followed by compilation.

In this example, the correct code is copied, so it should compile without problems. Of course, you can also browse the compilation list by clicking Output on the status bar.

Makoto Ogawa

President and CTO,CIO
T&Trust K.K.

Since 1989, he has been responsible for system development and programming training on AS/400. He learned how IFS works on OS/400 V3R1 through Linux, and since then, he has been deeply interested in open source in IBM i. His theory is that developer needs knowledge of Linux to understand IBM i. He has also written many articles for i Magazine.

[i Magazine・IS magazine]