---
title: "RPG Programming Language – How to Learn Easily"
description: "RPG being used extensively in AS/400 environment. The language is different from other languages such as JAVA or COBOL. You can learn unique features here."
url: https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/
date: 2018-09-13
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2018/09/imac-apple-mockup-app-38544.jpeg?fit=1880%2C1249&ssl=1
categories: ["Categories"]
tags: ["RPG Language for AS/400 developers"]
type: post
lang: en
---

# RPG Programming Language – How to Learn Easily

The RPG [language is](https://srinimf.com/2019/04/14/golang-know-about-it-why-this-is-popular/) commonly used in AS/400 systems. RPG allows you to include SQL statements in your code and handle strings using the VARCHAR data type.

## [What is](https://srinimf.com/2012/07/21/sql-what-is-package/) RPG

RPG is anothe[r programming](https://srinimf.com/2017/07/16/3-best-r-language-books-analytics/) language. Always you need to write naming conventions in Upper case. An example is /INCLUDE

### Sample Code of RPG

```
/Free
Read(E) TransFile;         // Read file to prime do loop
DoW not %EOF(TransFile);   // Continue until all processed
   If %Error;
    Dsply 'The read failed';
     Leave;
Else;
    Chain(N) CustNo CustMast CustData;
     CustName = %Xlate(Upper : Lower : CustName);
     ExSr CalcDividend;
     Read(E) TransFile;
   EndIf;
EndDo;

BegSr CalcDividend;
   TotalSales = %XFoot(MthSales);
   Eval(H) Dividend = TotalSales / 100 * DivPerc;
   Record_transaction();
 EndSr;
```

### Declaration

```
dcl-Ds APIError lqualified;
   bytesprovided int(10) inz(%size(APIError));
   bytesavail    int(10) inz(0);
   msgid         char(7);
   *N            char(1);
   msgdata       char(240);
end-Ds;
```

### Sub-routine Vs Sub-procedure

Subroutines are different from sub-procedures, but in a conceptual way they are often interchanged because they provide the same basic function in basic structured programming methodologies. Both provide a way to wrap re-usable code within a container.

![AS 400 Language](https://i0.wp.com/srinimf.com/wp-content/uploads/2018/09/as-400-language.jpg?h=305&ssl=1)

### Sub-Procedure Properties

1. Parameters you can pass in Sub Procedures
2. Returned value you can be used in somewhere else in a program
3. Sub-procedures act as functions

### Global Definitions

- IMPORT and EXPORT are two key words you can use a Global variable across sub modules

### Use of Sub-routines

- Use of Sub-routines is very less in RPG. Mostly developers use Sub-procedures.
- You can convert your sub-routines into Sub-procedures

### Accessing Database

1. You can access database objects in RPG
2. You can embed SQL
3. Easy to call Stored procedures
4. Apply Triggers

Related[M204 – Model 204 Database](https://srinimf.com/2014/09/11/m204-model-204-database/)

#### **References**

- [IBM User Guide on RPG Language](https://www.redbooks.ibm.com/redbooks/pdfs/sg245402.pdf)

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2018%2F09%2F13%2Frpg-programming-language-unique-concepts-to-learn-quickly%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2018%2F09%2Fimac-apple-mockup-app-38544.jpeg%3Ffit%3D1200%252C797%26ssl%3D1&description=RPG%20Programming%20Language%20-%20How%20to%20Learn%20Easily)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2018/09/13/rpg-programming-language-unique-concepts-to-learn-quickly/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20RPG%20Programming%20Language%20-%20How%20to%20Learn%20Easily&body=https%3A%2F%2Fsrinimf.com%2F2018%2F09%2F13%2Frpg-programming-language-unique-concepts-to-learn-quickly%2F&share=email)
-

### Like this:

Like Loading…
