Omni Tech 17 Morris Deep Diveinto RPGFree Form
Omni Tech 17 Morris Deep Diveinto RPGFree Form
Barbara Morris
IBM
**free
ctl-opt bnddir('ACCRCV');
First line has **FREE
dcl-f custfile usage(*update);
dcl-ds custDs likerec(custRec); All free-form statements
dcl-f report printer;
No fixed-form allowed
read custfile custDs;
dow not %eof;
if dueDate > %date(); // overdue?
sendOverdueNotice ();
write reportFmt;
exec sql insert :name, :duedate into
mylib/myfile;
endif;
read custfile custDs;
enddo;
inlr = '1';
dcl-proc sendOverdueNotice;
/copy invoices
sendInvoice (custDs : IS_OVERDUE);
end-proc;
PTFs for 7.1 and 7.2 provide the ability to code free-form RPG starting in column 1 and going
to the end of the line.
There is no practical limit on the length of a source line.
Various style-guides for other languages recommend a maximum line length of 80, 132, 120
etc.
Google [maximum length of a code line] to see some of discussions about line length.
If you create your RPG source files with RCDLEN(112), then that gives you 100 characters,
which is probably ideal.
**FREE
ctl-opt main(greeting);
dcl-proc greeting;
dsply ‘Hello’;
end-proc;
• All code in a **FREE source member must be free-form. If you need any fixed-form code,
you can put it in a /COPY file
• Source lines must not begin with ** unless they are the special directives for compile-time
data, file-translation, or alternate collating sequence.
• A copy file is always assumed to have column-limited source mode unless it has **FREE
in line 1
**FREE
dcl-s greeting char(10);
There are still some areas where RPG is not yet free
New programmers will only have to learn how to use RPG, without
having to struggle with how it is coded
vs
dcl-pr getNextCustomer;
vs
dcl-c HSSFCellStyle 'org.apache.poi.hssf.usermodel.HSSFCellStyle';
Documentation
- The ILE RPG Reference in the 7.2 and 7.3 Knowledge Center
has all the information about free-form. The free-form
information applies to both 7.1.
• General features
• Control (H)
• File declaration (F)
• Data declaration (D)
• Procedure (P)
ctl-opt; // no keywords
ctl-opt option(*srcstmt : *nodebugio)
dftactgrp(*no); // two keywords
H datfmt(*iso) text('My Program')
ctl-opt alwnull(*usrctl); // free again
USAGE keyword
*INPUT, *OUTPUT, *UPDATE, *DELETE
// USAGE(*INPUT : *UPDATE)
dcl-f orders disk usage(*update);
// output only
dcl-f f1 disk usage(*output);
key.item_num = 14;
chain key generic;
Fixed length:
• CHAR(characters)
• GRAPH(characters)
• UCS2(characters)
Varying length
• VARCHAR(characters)
• VARGRAPH(characters)
• VARUCS2(characters)
Indicator
• IND
Date, time
• DATE(*YMD-)
• TIME(*HMS:)
Object
• OBJECT(*JAVA : CLASS) (parameters not needed for the prototype
of a constructor)
© 2017 IBM Corporation
40
Tip for remembering the data-type keywords
dcl-ds info;
name varchar(25);
price packed(4 : 2);
end-ds info;
dcl-ds info;
name char(25);
dcl-subf select int(10);
end-ds info;
dcl-ds info;
sub1 char(10) pos(25);
sub2 date pos(100);
sub3 packed(5 : 2) pos(1);
end-ds info;
Bonus feature:
dcl-pr qcmdexc extpgm;
EXTPGM parameter
cmd char(3000);
is optional
cmd_len packed(15 : 5);
end-pr;
dcl-pr init;
end-pr; // can be a separate statement
A common bug:
EXTPROC is needed for the mixed-case name
The programmer uses copy-paste and forgets one change
D Qc3EncryptData...
D pr extproc('Qc3EncryptData')
D Qc3DecryptData...
D pr extproc('Qc3EncryptData')
Begin a procedure
• DCL-PROC
• Procedure name
• Keywords
• End with semicolon
End a procedure
• END-PROC
• Optional procedure name
• End with semicolon
end-proc myProc;
or
end-proc;
© 2017 IBM Corporation
51
Procedure example
return curUser;
end-proc;
© Copyright IBM Corporation 2011. All rights reserved. The information contained in these materials is provided for informational purposes only, and is provided AS IS without warranty of any
kind, express or implied. IBM shall not be responsible for any damages arising out of the use of, or otherwise related to, these materials. Nothing contained in these materials is intended to, nor
shall have the effect of, creating any warranties or representations from IBM or its suppliers or licensors, or altering the terms and conditions of the applicable license agreement governing the
use of IBM software. References in these materials to IBM products, programs, or services do not imply that they will be available in all countries in which IBM operates. Product release dates
and/or capabilities referenced in these materials may change at any time at IBM’s sole discretion based on market opportunities or other factors, and are not intended to be a commitment to
future product or feature availability in any way. IBM, the IBM logo, Rational, the Rational logo, Telelogic, the Telelogic logo, and other IBM products and services are trademarks of the
International Business Machines Corporation, in the United States, other countries or both. Other company, product, or service names may be trademarks or service marks of others.
A full list of U.S. trademarks owned by IBM may be found at: http://www.ibm.com/legal/copytrade.shtml.
Adobe, the Adobe logo, PostScript, and the PostScript logo are either registered trademarks or trademarks of Adobe Systems Incorporated in the United States, and/or
other countries.
AltiVec is a trademark of Freescale Semiconductor, Inc.
AMD Opteron is a trademark of Advanced Micro Devices, Inc.
InfiniBand, InfiniBand Trade Association and the InfiniBand design marks are trademarks and/or service marks of the InfiniBand Trade Association.
Intel, Intel logo, Intel Inside, Intel Inside logo, Intel Centrino, Intel Centrino logo, Celeron, Intel Xeon, Intel SpeedStep, Itanium, and Pentium are trademarks or registered
trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
IT Infrastructure Library is a registered trademark of the Central Computer and Telecommunications Agency which is now part of the Office of Government Commerce.
Java and all Java-based trademarks and logos are trademarks or registered trademarks of Oracle and/or its affiliates.
Linear Tape-Open, LTO, the LTO Logo, Ultrium, and the Ultrium logo are trademarks of HP, IBM Corp. and Quantum in the U.S. and other countries.
Linux is a registered trademark of Linus Torvalds in the United States, other countries or both.
Microsoft, Windows and the Windows logo are registered trademarks of Microsoft Corporation in the United States, other countries or both.
NetBench is a registered trademark of Ziff Davis Media in the United States, other countries or both.
SPECint, SPECfp, SPECjbb, SPECweb, SPECjAppServer, SPEC OMP, SPECviewperf, SPECapc, SPEChpc, SPECjvm, SPECmail, SPECimap and SPECsfs are
trademarks of the Standard Performance Evaluation Corp (SPEC).
The Power Architecture and Power.org wordmarks and the Power and Power.org logos and related marks are trademarks and service marks licensed by Power.org.
TPC-C and TPC-H are trademarks of the Transaction Performance Processing Council (TPPC).
UNIX is a registered trademark of The Open Group in the United States, other countries or both.
Other company, product and service names may be trademarks or service marks of others.
Revised December 2, 2010