Real usage of RPG is in AS/400. In RPG you can embed SQL statements. Handling strings possible with VARCHAR data type.
What is RPG
RPG is another programming 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.
Sub-Procedure Properties
- Parameters you can pass in Sub Procedures
- Returned value you can be used in somewhere else in a program
- 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
- You can access database objects in RPG
- You can embed SQL
- Easy to call Stored procedures
- Apply Triggers
You must be logged in to post a comment.