FREE FORMAT RPG : SAMPLE CODE AND COMMENTS
Here is a sample code to add 2 number in Free Format RPG
0001.00 D Total S 10 0 INZ 0002.00 C *ENTRY PLIST 0003.00 C PARM Number1 5 0 0004.00 C PARM Number2 5 0 0005.00 /FREE 0006.00 Total = Number1 + Number2 ; // Get total for both input values 0007.00 DSPLY Total '*EXT' ; // Display value of Total 0008.00 *InLR = *ON; // End of program 0009.00 /END-FREE
This program accept two numbers as entry parameters, add these two number and display total to screen. As you noticed *ENTRY is not inside /FREE /END-FREE block of code because Free Format does not support *ENTRY of specifically saying PLIST opcode. We will talk about this is coming posts.
- Line 0005.00 : Complier directive “/FREE” is used at position 7(same position where “*” is used in Fixed format RPG for comments ).
- Line 0006.00 : RPG code to add two and save their sum in variable “Total”. There is no Eval required in Free Format. EVAL opcode is optional in Free format. We will talk about Free Format opcode in coming posts.
- Line 0007.00 : Use opcode “DSPLY” to show value of variable “Total” on “*EXT” message queue.
- Line 0008.00 : Turn on LR indicator to tell compiler where to end this program.
- Line 0009.00 : Use “/END-FREE” compiler directive to define the boundary of “/FREE”.
In Free format RPG you must define boundary for each line of code. So to tell compiler where line of code is complete Semicolon “;” is used. For example in above code every code line is ended with “;”. This does not apply for comments.
Comments in Free Format
Like most modern programming languages Free Format RPG use double forward slash(//) to add comments. Unlike Fixed format where you need to add asterisk (*) at 7th position to add comment , in free format you can add comment at any position. Comments are allowed even after “;” of code line like shown in example above these are called inline comments.