Guru: AI Pair Programming In RPG With GitHub Copilot
February 17, 2025 Gregory Simmons
If you have been meaning to give VS Code a try, but just haven’t had a chance, I encourage you to avail yourself today. Yes, for you RDi users, it will take a little bit to migrate your favorite settings, code snippets, and compile commands – but I promise, you won’t regret the move.
In my article, Getting Started With The Code 4 i Extension Within VS Code, I offer a few more insights to help get you started. And if you are an SEU user, yes, the switch may seem daunting, but one of the great things about the IBM i community is that there are plenty of people who would be happy to help you.
In this article, I want to share with you two of my favorite extensions: GitHub Copilot and GitHub Copilot Chat. These two extensions are available on GitHub. Since their initial launch in October of 2021, GitHub Copilot and GitHub Copilot Chat have accumulated over 22 million and 16 million downloads respectively and they continue to add great updates to their already fabulous functionality. As far as code assistants go (for the RPG programmer), I feel GitHub Copilot is the quickest and easiest to install and start exploring what it can do.
The cost of these extensions is very reasonable in my opinion. You can start with a free 30-day trial, then choose from three pricing levels; Copilot Individual is $10 per month or $100 per year, Copilot Business is $19 per user per month and Copilot Enterprise is $39 per user per month. For the demos in this article, I will be using Copilot Business. The list of features they provide is extensive. You can review and compare the pricing levels and features on github.com/features/copilot. Today, I just want to focus on a few of them to show how an RPG programmer can benefit.
Okay, so one quick example. If I write a small SQL statement in an RPG program and specify my ‘from’ statement first, then enter my ‘select’ statement, Copilot will suggest some fields for me:
This is cool, but without context, Copilot doesn’t know which fields I want. In my experience, however, it does look at context when you have more business logic and the suggestions get better.
It is claimed that using the Copilot code assistant increases developer speed by 25-55 percent. Are code assistants going to do your work for you? No. What I like about Copilot is that it takes care of the majority of the mundane code I write.
For example, I’m in the habit (and I hope you are as well) of following every SQL statement with a check to see if SQLCODE is less than zero. If it is less than zero, something went wrong. I would then log this using our in-house logging facility. This If statement and logging call is usually less than 10 lines of code
EXEC SQL UPDATE file_1 SET fldCH1 = :dsRecord.fldch1, fldCH2 = :dsRecord.fldch2, fldCH3 = :dsRecord.fldch3 WHERE FLDKEY = :dsRecord.fldkey; if sqlcode < 0; common_logger('Failed to update file_1 record' + '. key - ' + %Char(dsRecord.fldkey) + '. CH1 - ' + %Char(dsRecord.fldch1) + '. CH2 - ' + %Char(dsRecord.fldch2) + '. CH3 - ' + %Char(dsRecord.fldch3) + '. SQLCODE - ' + %Char(SQLCODE) + '. SQLSTATE - ' + sqlstate + '. SQLERRMC - ' + sqlerrmc); Endif;
Once Copilot observed that my coding was to do this, as soon as I pressed enter after the SQL statement, it suggested the entire If statement! It noticed that I like (for readability) to have the text lines line up with the previous line. It formatted the host variables from my SQL statement into the line and then followed it up with the SQLCODE, SQLSTATE, and the SQLERRMC information. Notice how it also noticed that I like to have my plus signs line up! I pressed tab to accept the suggestion, and done! This is fabulous! Logging errors is important, and with Copilot’s suggestion, I can quickly move along to the more important business logic.
One of the more recent features added to Copilot is a handy icon to open Ask Copilot:
This opens the world of AI at your fingertips and allows you to start conversing with Copilot. But notice that at the bottom, you’ll have the ability to choose which LLM you’d like to use for your conversation.
Then I asked Copilot if it would write a small RPG program to demonstrate the Fibonacci Sequence. Cool. I haven’t tried to compile this response, but at a first glance it looks pretty close.
It cannot be stressed enough that when working with AI code assistants, or any AI based tool, you need to take the result as a starting point; not necessarily the final answer.
For a 30-second install of an extension, this is phenomenal.
I encourage you to give this a try and see if you find it to be worth the small price tag, as I have. In my next article, I will explore whether there’s a totally free AI code assistant you might elect to use instead. Tune in next time as I continue my AI code assistant exploration for use with the RPG language.
Until next time, happy coding.
Gregory Simmons is a software engineer with PC Richard & Son. He started on the IBM i platform in 1994, graduated with a degree in Computer Information Systems in 1997 and has been working on the OS/400 and IBM i platform ever since. He has been a registered instructor with the IBM Academic Initiative since 2007, an IBM Champion and holds a COMMON Application Developer certification. When he’s not trying to figure out how to speed up legacy programs, he enjoys speaking at technical conferences, running, backpacking, hunting, and fishing.
RELATED STORIES
Guru: RPG Receives Enumerator Operator
Guru: RPG Select Operation Gets Some Sweet Upgrades
Guru: Growing A More Productive Team With Procedure Driven RPG
Guru: With Procedure Driven RPG, Be Precise With Options(*Exact)
Guru: Testing URLs With HTTP_GET_VERBOSE
Guru: Fooling Around With SQL And RPG
Guru: Procedure Driven RPG And Adopting The Pillars Of Object-Oriented Programming
Guru: Getting Started With The Code 4 i Extension Within VS Code
Guru: Procedure Driven RPG Means Keeping Your Variables Local
Guru: Procedure Driven RPG With Linear-Main Programs
Guru: Speeding Up RPG By Reducing I/O Operations, Part 2
Guru: Speeding Up RPG By Reducing I/O Operations, Part 1
Guru: Watch Out For This Pitfall When Working With Integer Columns