future proofing your rpg applications (and yourself)€¦ · 6: modernize your development toolset...

15
Susan Gantner Susan.Gantner @ Partner400.com www.Partner400.com SystemiDeveloper.com Future Proofing Your RPG Applications (And Yourself) A lot has changed since RPG IV was introduced, so come learn how to bring modern development tools and techniques to bear in your RPG applications. Uncover the key things every RPGer should be doing to ensure that he/she remains an asset to their company. Understand the critical techniques, tools, and best practices you should be using when developing your RPG applications. Then, get advice on the tools and capabilities that your RPG applications should be exploiting, and see illustrations of the key points. The author, Susan Gantner, makes up half of Partner400, a consulting company focused education and mentoring services related to application modernization on the IBM i platform. They are also members of System i Developer, a consortium of IBM i educators who host the RPG & DB2 Summit events twice annually. Together with a small group of industry experts, they co-authored IBM's Redbook for RPG programmers, entitled: Who Knew You Could Do That with RPG IV - A Sorcerer's Guide to System Access and more recently they co-authored the new Application Modernization Redbook. Susan and her partner, Jon Paris, are technical editors and authors for IBM Systems Magazine - IBM i Edition along with other media outlets related to IBM i. Follow Jon and Susan's weekly blog at ibmsystemsmag.com/Blogs/iDevelop/ Feel free to contact the author at: Susan.Gantner @ partner400.com or visit the Partner400 web site at www.partner400.com © Copyright Partner400, 2018. Page 1

Upload: others

Post on 30-Jul-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

Susan Gantner

Susan.Gantner @ Partner400.com www.Partner400.com SystemiDeveloper.com

Future Proofing Your RPG Applications

(And Yourself)

A lot has changed since RPG IV was introduced, so come learn how to bring modern development tools and techniques to bear in your RPG applications. Uncover the key things every RPGer should be doing to ensure that he/she remains an asset to their company. Understand the critical techniques, tools, and best practices you should be using when developing your RPG applications. Then, get advice on the tools and capabilities that your RPG applications should be exploiting, and see illustrations of the key points. The author, Susan Gantner, makes up half of Partner400, a consulting company focused education and mentoring services related to application modernization on the IBM i platform. They are also members of System i Developer, a consortium of IBM i educators who host the RPG & DB2 Summit events twice annually. Together with a small group of industry experts, they co-authored IBM's Redbook for RPG programmers, entitled: Who Knew You Could Do That with RPG IV - A Sorcerer's Guide to System Access and more recently they co-authored the new Application Modernization Redbook. Susan and her partner, Jon Paris, are technical editors and authors for IBM Systems Magazine - IBM i Edition along with other media outlets related to IBM i. Follow Jon and Susan's weekly blog at ibmsystemsmag.com/Blogs/iDevelop/ Feel free to contact the author at: Susan.Gantner @ partner400.com or visit the Partner400 web site at www.partner400.com

© Copyright Partner400, 2018.

Page 1

Page 2: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

10 Ways to Future-Proof Your Applications

1. Use modern RPG practices

2. Learn a new language

3. Build/use libraries of parts

4. Make your RPG callable from anywhere

5. Be the data interchange King / Queen

6. Modernize your development toolset

7. Enhance your user interface

8. Let Db2 do the work for you

9. Exploit SQL

10. Exploit free stuff

1: Use Modern RPG Practices ...You should be able to answer "Yes" to all of these

All my RPG/400 code has been converted to RPG IV

I use long mixed case variable names

I never use numbered indicators

I code all my RPG code in freeform (at least all new code)

I prototype all program calls

I use subprocedures (not subroutines) to structure my code

I build service programs for my reusable components

I often use SQL for data access

© Copyright Partner400, 2018.

Page 2

Page 3: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

1: Use Modern RPG Practices ...Readability = Maintainability = Reliability • Important because readable code is easier to maintain

Readability features in RPG IV • Free form notation • Mixed case source • Longer names

✦ Remember you haven't been limited to 6 character names for a very long time - e.g. use customerName not CUSTNM, accountBalance not ACCBAL, etc. etc.

• Use blank lines - completely blank - no * or // at the beginning Use Subprocedures to increase readability • More on this later

1: Use Modern RPG Practices ...Don't use numbered indicators - Anywhere in your RPG • And yes that does mean that you can't use O-specs • *IN47 has absolutely zero meaning

✦ Much better to use names like outOfStock_47 - The suffix _47 allows you to tie the name to the number in the DDS - Use named constants as indexing to the *IN array - Or use INDDS keyword on file declarations to may numbered indicators to a DS

• Use Built-ins to replace resulting indicators on I/O & TEST operations ✦ e.g. %EOF, %ERROR, %FOUND, %LOOKUP

DO use Prototypes when calling external routines • The modern way to call anything

✦ e.g., program, procedure, function, API ...

• Parameter mismatches can become a thing of the past! ✦ Prototypes allow the compiler to validate:

- The number of parameters and - Their data type and size

• Prototypes can also accommodate differences in data definition ✦ e.g. Pass an integer when the callee expects a value with decimal places

© Copyright Partner400, 2018.

Page 3

Page 4: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

1: Use Modern RPG Practices ...

ctl-opt DftActGrp(*No);

dcl-f Xproducts Keyed;

dcl-s currentCategory Like(CatCode);

dcl-f XCategors Keyed Prefix('XC');

dcl-f ProdRptF Printer OFLind(pageFull);

dcl-s totalSell packed(11:2); dcl-s totalDisc packed(11:2); dcl-s descr Char(30);

New style H-spec

Easier to read/write File definitions intermixed with related data definitions

Stand-alone field definitions

1: Use Modern RPG Practices ... Write Heading;

// Read product file to prime Do loop and set current category Read XProducts; currentCategory = catCode;

Dow Not %EOF(XProducts); // Continue reading until EOF If catCode <> currentCategory; // If Category has changed print totals WriteTotals(); currentCategory = catCode; EndIf;

If pageFull; Write Heading; pageFull = *Off; EndIf; totalSell += (sellPrice * qtyOnHand); totalDisc += (discPrice * qtyOnHand); descr = shortDesc;

Write Detail;

// Read next record and return to top of loop Read XProducts; EndDo;

© Copyright Partner400, 2018.

Page 4

Page 5: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

1: Use Modern RPG Practices

// Output final set of totals WriteTotals(); *inLR = *on;

// Subprocedure to print total information dcl-proc WriteTotals;

Chain currentCategory XCategors;

If Not %Found(XCategors); XCcatName = '*** Missing ***'; EndIf;

Write CatTotals;

// Reset totals totalSell = 0; totalDisc = 0;

Return;

end-proc WriteTotals;

Subprocedure declaration - No prototype needed V7+

2: Learn a New Language Even if there is apparently no current need for it in your shop • No requirement today does not mean no requirement tomorrow

It really doesn't matter which language ... • Python, node.js, PHP, Java, Ruby, whatever ...

✦ All of these can be installed and used on your PC ✦ And are all are also supported on your IBM i • RPG has traditionally been rather insular

✦ There is no other language quite like it ✦ But most other modern languages have many similarities

- Learning any one of them will help with learning others

This also presents you with a win-win situation • At best you can use it at work to help modernize your IBM i apps • Worst case, it will teach you to write better RPG code!

✦ Ask IBM's George Farr if you doubt me ... I'm NOT saying to give up RPG • Be I am saying that these days just knowing RPG is not always enough

© Copyright Partner400, 2018.

Page 5

Page 6: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

If DayOfWeek(DeliveryDate) > 5; DeliveryDate = GetNextMonday(DeliveryDate); EndIf;

If ValidCustomer(CustomerNbr); ProcessOrder(OrderData); EndIf;

3: Build/Use libraries of (reusable) partsCall them as functions - just like RPG’s built-in functions • Code becomes more readable • Parameters are passed, results returned with subroutine-like speed • Even if not reusable by other programs, great subroutine replacements

Written as RPG subprocedures - internal or external • All of today’s modern languages (including RPG) are function-based

If reusable by other programs, house the functions in Service Programs • Grouped by logical function or application function • Service Programs may be referenced from many programs • No extra copies of code - source or compiled • Better productivity and more efficient at run time

Dcl-Proc DayOfWeek;

Dcl-Pi *N Zoned(1); WorkDate Date; End-Pi;

Dcl-S AnySunday Date INZ(D'04/02/1995'); Dcl-S WorkDay Zoned(1); WorkDay = %Rem((%Diff(InpDate : AnySunday : *D)) : 7); If WorkDay < 1; WorkDay = WorkDay + 7; EndIf; Return WorkDay; End-Proc DayOfWeek;

V7 Free-format Subprocedure ExampleBegin Procedure

Procedure Interface

Local Data

End Procedure

Return ValueNo more /Free &

/End-Free!

© Copyright Partner400, 2018.

Page 6

Page 7: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

Service ProgramsThe home for your external subprocedures • Make your subprocedures reusable / sharable! • Service Programs allow you to package your reusable routines • Easily reference and use these routines from multiple programs • Binding Directories make it simple

The process • Compile your procedures into modules (CRTRPGMOD) • Create Service Program(s) from the modules (CRTSRVPGM) • Create/maintain a Binding Directory with Service Program name(s) in it

✦ CRTBNDDIR and/or WRKBNDDIRE (...E for "entries") • Place Binding Directory on the H/Control spec of the RPG members that need

to use the subprocedures - BNDDIR('MYBNDDIR') • You need to learn to manage signatures & you need to learn enough about

Activation Groups to avoid dreaded "bad default value" pitfalls !! ✦ The Seven Deadly Sins of ILE

- www.ibmsystemsmag.com/ibmi/developer/7923p1.aspx ✦ ILE Concepts reference manual, esp. chapters 2, 3 & 6

- www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/ilec/sc415606.pdf

4: MakeYour RPG Callable from AnywhereThe only thing constant is change • Who knows what environment your code needs to run in tomorrow?

✦ Browser, mobile, web service & whatever happens next • Make sure your background business logic is bulletproof and flexible

enough to be callable from anywhere How? • Write in small, independently callable functional pieces of logic

✦ Parameter passing vs. shared data ✦ Separate background logic/processing from screen I/O • The concept is discussed and implemented in many ways

✦ Modularization, SAS, Model-View-Controller, Event-driven logic

• The same logic called from traditional green screen or batch programs ✦ And from browser-based, mobile or multi-platform applications of today

- And/or tomorrow

© Copyright Partner400, 2018.

Page 7

Page 8: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

Implementing “Callable from Anywhere”Many options - the best choice will depend on the situation • RPG Stored Procedures or RPG User Defined Functions

✦ Callable from any SQL (or ODBC or JDBC) interface • Remote procedure call

✦ Many environments (e.g., PHP, Java) have special call mechanisms for i • Web services

✦ Wrapper your RPG code as a web service - XMLSERVICE helpful in some environments

• Can turn virtually any RPG program into a web service - IBM i Integrated Web Server - SQL scalar function call

Resources to help you get started on next chart

Get Started with “Callable from Anywhere” Resources to help • Recycling RPG as Stored Procedures

✦ Part 1: www.ibmsystemsmag.com/ibmi/developer/rpg/rpg_stored_procedures/ ✦ Part 2: www.ibmsystemsmag.com/ibmi/developer/rpg/rpg_stored_procedures2/ • XMLSERVICE Offers New Life for RPG Programs

✦ www.ibmsystemsmag.com/ibmi/developer/rpg/xmlservice_new_life/ • Need a Rest?

✦ www.ibmsystemsmag.com/ibmi/developer/rpg/web_service_rest/ • Providing RPG Web Services (by Scott Klement)

✦ www.scottklement.com/presentations/#Providing • IBM i Integrated Web Services Server

✦ www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzaie/rzaiewebservices.htm • RPG Talks To Watson by Paul Tuohy

✦ www.itjungle.com/fhg/fhg092716-story01.html

© Copyright Partner400, 2018.

Page 8

Page 9: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

5: Be The Data Interchange King / QueenAccess to "Foreign" Databases • i.e. Oracle, SQL Server, MySQL, Db2 on other platforms, etc. • You could do it the hard way by learning how to interface RPG with JDBC

drivers or ... • Use JDBCR4 from Scott Klement to simplify the whole thing

✦ An example of using function libraries! ✦ Find out more at: www.scottklement.com/jdbc

Generating and Consuming XML and/or JSON • RPG's built-in XML-INTO does a great job when consuming XML

✦ You can also use eXpat as ported for the IBM i by Scott Klement ✦ powerExt also provides routines for consuming bot XML and JSON

• RPG's latest DATA-INTO can handle any kind of data ✦ An example JSON parser is shipped

• For XML generation use: ✦ CGIDEV2 or ✦ powerExt or ✦ Larry Ducie's XMLi package or ✦ SQL

6: Modernize your Development ToolsetGreen screens are inadequate for editing source code • Especially with today’s more modular coding styles

✦ A small sampling of features not possible in PDM/SEU follows

• Workstation-based tooling is used in all development environments ✦ Why not for i/RPG code?

• Open source Eclipse base means others can (& do) supply plug-ins ✦ For change management SW interfaces ✦ For other application interfaces ✦ To add functionality IBM hasn’t had time to do

How to get started? • Try the “RSE Quick Start Guide”

✦ www.systemideveloper.com/downloadRSEQuickStartGuide.html

Budget-tight? Consider RDi alternatives • ILEditor from Liam Allan

✦ www.common.org/scotts-iland-blog/free-ileditor-ibm-technology-refresh-recap/

• MiWorkPlace from Michael Schmidt ✦ www.itjungle.com/2017/03/13/guru-miworkplace-alternative-seu/

© Copyright Partner400, 2018.

Page 9

Page 10: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

Things not possible in SEU/PDMA small sampling of my favourite RDi features • Multiple members open at once

✦ Split screen or not - all editable • Unlimited levels of undo & redo • Typically 2 to 3 times the lines of code viewable at a time • Hover text for definitions of variables, prototypes in code

✦ Including associated comments • Source code filtering

✦ e.g., filter out commented LOCs, filter by change date, by text/field name

• Compile time error list integrated with editor - No spooled file needed! • Outline of program with complete cross-reference

✦ for fields, subroutines, procedures, prototypes, etc. • Short cut key jumps to & from subroutine/subprocedure code & mainline • Easy Service Entry Point debugging • True graphical drag-and-drop DDS screen/report designer

RDi Outline with Cross Reference

© Copyright Partner400, 2018.

Page 10

Page 11: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

RDi Hover Info - Enhanced in V9.6

Compile Errors & Editor Integration

© Copyright Partner400, 2018.

Page 11

Page 12: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

7: Enhance Your User InterfaceA green screen is NOT good enough in today's world • No matter what your users may tell you today

✦ Their attitude will change overnight if a new CIO comes on the scene • Most "inefficient" GUI interfaces are the result of poor design

✦ A well designed interface should be easier to use than a green screen There are many tools that can help you update your applications • Or you can do it "by hand"

✦ Using free tools such as CGIDEV2, powerExt, Renaissance, Valence, etc. • Start with low-hanging fruit - convert reports to use a browser

✦ Don't start out by trying to build a full update-capable subfile application Many of the current third party tools use IBM's Open Access (OA) • For example tools from Asna, lookSoftware, ProfoundLogic, Rocket, etc. • You can also use OA yourself to allow simplified access to IFS files etc.

Be aware of the potential for mobile devices in your organization • If you are not thinking about it you can be sure that someone else is

8: Let Db2 Do the Work for YouCheck Constraints, Referential Integrity, Views, Triggers • Make your database work for you!

Business rules embedded into your database • Reduce application logic

✦ Constraints reduce RPG code needed to enforce constraints and relationships - e.g. range or values checks, invoice header must exist before invoice details

✦ Views can reduce RPG code for complex selection criteria - Build an SQL view instead of OPNQRYF - Simplify complex SQL statements by querying views

✦ Triggers can ensure more complex logic is always called when necessary • Eliminate the growing list of "fix-up" programs when application logic

failed to check the integrity or validity of the data! Why is it so important to put rules into the database? • ODBC/JDBC and other forms of remote access to data should adhere to

the same rules as your RPG programs, but you don't control them • Your users may not have that kind of access today, but tomorrow?

© Copyright Partner400, 2018.

Page 12

Page 13: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

9: Exploiting SQLSQL is no longer optional for some new features in DB2 It’s the foundation of virtually ALL database access - on i & others • Also the foundation for ODBC and JDBC

It's here to stay - time to learn what it can do for you • If nothing else, it makes a great OPNQRYF replacement! • It can even be used to process or generate XML, JSON, access web

services, even Watson! Learn to think of data in “sets” • Set operations using SQL are far more efficient than row by row retrieval

Tip: Get into the habit of speaking the language of database • Table, Column, Row, Index, View

✦ Rather than File, Field, Record, Logical File • Build credibility when conversing with non-i colleagues

✦ Credibility for both you and for Db2 for i

Learning to Exploit SQLNeed to learn more? • IBM's DB2 for i site - especially useful white papers and articles

✦ esp. "Indexing and Statistics Strategy for DB2 for i" - www.ibm.com/systems/power/software/i/db2/docs/whitepapers.html

• Bringing the Power of SQL to Your RPG Program - www.ibmsystemsmag.com/ibmi/developer/rpg/Bringing-the-Power-of-SQL-to-Your-RPG-

Program • A SQL Sequel

- www.ibmsystemsmag.com/ibmi/developer/rpg/dynamic_SQL/

For inspiration, follow Mike Cain’s blog - db2fori.blogspot.com/

© Copyright Partner400, 2018.

Page 13

Page 14: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

10: Learn to Exploit Free StuffOpen Source has opened up a wealth of possibilities for IBM i • You owe it to yourself and your company to explore what is available

For example: • From the PHP world we can get:

✦ CRM software ✦ Help Desk Systems (Hesk, osTicket, etc.) ✦ Wikis (PMWiki, MediaWiki, etc.) ✦ Content Management Systems (Drupal, Joomla!, WordPress, and many more)

• From the open source world: ✦ eMail (JavaMail) ✦ Spreadsheets (Apache POI via Scott Klement's port of HSSF) ✦ Create and consume JSON via YAJL

• And of course from our RPG universe: ✦ Consuming Web Services (HTTPAPI, WSDL2RPG, powerExt) ✦ Writing web apps (CGIDEV2, powerExt, Renaissance, Valence, Icebreak CE, etc.) ✦ eMail (MMail) ✦ Generating XML and JSON (CGIDEV2, powerExt, XMLi)

• More examples on the following notes page

NotesThere was not enough room on the previous chart for URLs for all the different possibilities but here are a few to get you started: SugarCRM (sugarcrm.com) Hesk (hesk.com) osTicket (osticket.com) PMWiki (pmwiki.org) MediaWiki (mediawiki.org) Drupal (drupal.com) Joomla! (joomla.org) WordPress (wordpress.com) JavaMail (oracle.com/technetwork/java/javamail/index.html)

- Aaron Bartell's RPG interface for JavaMail (mowyourlawn.com/RPGMail.html) Apache POI (poi.apache.org)

- Scott Klements' RPG interface for POI (scottklement.com/poi) JFreeChart (jfree.org/jfreechart)

- Aaron Bartell's RPG interface for JFree (mowyourlawn.com/RPGChartEngine.html) HTTPAPI (www.scottklement.com/httpapi) WSDL2RPG (tools400.de/English/Freeware/WSDL2RPG/wsdl2rpg.html) CGIDEV2 - also MMail and many other utilities (easy400.net) powerExt - also generating and consuming XML and JSON (powerext.com) Renaissance (renaissanceframework.com) Valence (cnxcorp.com/valence) Icebreak CE (system-method.com/IceBreakCE) XMLi (sourceforge.net/projects/xmli)

© Copyright Partner400, 2018.

Page 14

Page 15: Future Proofing Your RPG Applications (And Yourself)€¦ · 6: Modernize your Development Toolset Green screens are inadequate for editing source code • Especially with today’s

Other ResourcesBooks • New Redbook: Modernize IBM i Applications

✦ www.redbooks.ibm.com/Redbooks.nsf/RedbookAbstracts/sg248185.html

• New/Updated Redbook: Who Knew You Could Do That with RPG IV? ✦ www.redbooks.ibm.com/abstracts/sg245402.html

IBM Systems Magazine - Partner400 articles • Three Good Reasons to Stop Writing Subroutines

✦ www.ibmsystemsmag.com/ibmi/developer/rpg/Three-Good-Reasons-to-Stop-Writing-Subroutines/

• Subprocedure Basics ✦ www.ibmsystemsmag.com/ibmi/developer/rpg/Subprocedure-Basics/

• A Traditional Approach to a Modern Technology (XML) ✦ www.ibmsystemsmag.com/ibmi/developer/rpg/A-Traditional-Approach-to-a-Modern-

Technology/

• More on RPGs XML Support ✦ www.ibmsystemsmag.com/ibmi/developer/rpg/More-on-RPG-s-XML-Support/

iProDeveloper - Scott Klement's handout • Choices for Integrating RPG with the Web

✦ www.scottklement.com/presentations/#April08

© Copyright Partner400, 2018.

Page 15