RGP Hello World Tutorial

Last Edited: 2018-05-29 17:08:49

When I started working for my current employer, I was sat at an iSeries command line. I really struggled in the beginning with finding a good set of tutorials to show me some of the basic beginner stuff. It's been 5 years since then and RPG has changed to a new format called free-form or free format RPG. I have written numerous programs and scripts in the greenscreen native languages now. Being from an open source background, and knowing that a lot of RPGers out there are trying to learn PHP, I figured I could put together some cross-reference tutorials that can be used by both parties.

This tutorial will also include the way I've learned to compile "on the side". We use a version control system called "Aldon" in the greenscreen that manages our deployment; I won't be going into Aldon - but a lot of the commands and interfaces are the same. I will be using a program called PDM, which stands for Program Development Manager.

Where objects live vs. files in PHP


The way that I learned how to manage what I would call "files" are called "members" in IBM world. "Members" live in "objects" and "objects" live in "libraries". Only for the sake of simplicity, you could say that a library is like a drive, an object is like a directory, and a member is like a file. This is not correct at all; just an easy way to get the nomenclature. This is how it loosely works vs. a Windows or Linux filesystem. There's a whole 'nother filesystem on the i called the IFS (integrated file system) which works a lot like Linux and is a completely different animal.

When I started on the iSeries, I was given a library to use called FREDDYLIB and a few sources objects to hold my source members. RPG source was stored in a object called QRPGLESRC. This is a common IBM practice for the naming of the source objects that hold your source. Unlike PHP, once you compile your source, you will be left with the source where you wrote it, and an object which is your executable program.


// declare a variable to use
DCL-S num int(10);
// start a loop that goes from 1 to 3
for num = 1 to 3;
// display the number as a char
dsply ('var i = ' + %char(num));
endfor;
// end the program
return;



DSPLY var i = 1
DSPLY var i = 2
DSPLY var i = 3

Comments