12
Jon Paris Jon.Paris @ Partner400.com www.Partner400.com www.SystemiDeveloper.com Open Source and i The best things in life are free Notes This presentation may contain small code examples that are furnished as simple examples to provide an illustration. These examples have not been thoroughly tested under all conditions. We therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. All code examples contained herein are provided to you "as is". THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED. The author, Jon Paris, is co-founder of Partner400, a firm specializing in customized education and mentoring services for AS/400 and iSeries developers. With his partner, Susan Gantner, Jon authors regular technical articles for a number of technical publications including iSeries 400 Experts Journal, IBM Systems Magazine, i5 edition, and its companion electronic newsletter, i5 EXTRA and their weekly iDevelop blog. You may view articles in current and past issues and/or subscribe to the free newsletter or the magazine at: http://www.ibmsystemsmag.com Susan and Jon are also partners in SystemiDeveloper, a company that hosts the RPG & DB2 Summit conferences. See SystemiDeveloper.com for more details. Feel free to contact the author at: jon.paris @ partner400.com or visit the Partner400 web site at http://www.partner400.com © Partner400, 2016 Lecture Notes: Page 1 of 12

Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

  • Upload
    dodiep

  • View
    274

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Jon Paris

Jon.Paris @ Partner400.com www.Partner400.com www.SystemiDeveloper.com

Open Source and i The best things in life are free

NotesThis presentation may contain small code examples that are furnished as simple examples to provide an illustration. These examples have not been thoroughly tested under all conditions. We therefore, cannot guarantee or imply reliability, serviceability, or function of these programs. All code examples contained herein are provided to you "as is". THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY DISCLAIMED.

The author, Jon Paris, is co-founder of Partner400, a firm specializing in customized education and mentoring services for AS/400 and iSeries developers. With his partner, Susan Gantner, Jon authors regular technical articles for a number of technical publications including iSeries 400 Experts Journal, IBM Systems Magazine, i5 edition, and its companion electronic newsletter, i5 EXTRA and their weekly iDevelop blog. You may view articles in current and past issues and/or subscribe to the free newsletter or the magazine at: http://www.ibmsystemsmag.com

Susan and Jon are also partners in SystemiDeveloper, a company that hosts the RPG & DB2 Summit conferences. See SystemiDeveloper.com for more details.

Feel free to contact the author at: jon.paris @ partner400.com or visit the Partner400 web site at http://www.partner400.com

© Partner400, 2016 Lecture Notes: Page 1 of 12

Page 2: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

What do you want to do Today? Other than have a day off work that is!

Whatever it is ... There's probably a (free) App for That!

But ... every time I give this presentation someone tells me I forgot something

Agenda

Note that not all the software

mentioned in this session is strictly "Open Source"

Some is freeware distributed as source code

and some is distributed in object form.

So What Do You Want to Do?Build new RPG-based modern web applications ? • Including generation, consumption and testing of web services

Send email from your RPG programs ? • Or even use RPG to process the content of received emails!

Create, update and read business documents? • Spreadsheets, graphs, charts and reports

Generate and Process XML or JSON ? • Create XML documents • Process XML documents • Transform XML into database and database into XML

Know How To ... ? • Use System APIs • Use C-style functions • Perform common programming tasks

Invoke PC applications from green screens?

We will do our best to show you where you can find code to do

all of these

© Partner400, 2016 Lecture Notes: Page 2 of 12

Page 3: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Let's Start With Creating Web ApplicationsCGIDEV2 - the original and still a great place to start • Easy to use template driven set of APIs to simplify web programming • www.easy400.net • Not actually Open Source but ...

The Renaissance Framework • From CoralTree Systems in the UK • Originally based on CGIDEV2 but now goes far beyond it • Very sophisticated Web 2.0 framework that extends the CGIDEV2 tool set • www.renaissanceframework.com

powerExt • Also based originally on CGIDEV2 • A Web 2.0 oriented RPG framework that also includes excellent XML

tooling ✦ "Pay for" version available with extended features and application generation tooling

• powerext.com

Not Open Source But FreeThese products are the exception in that no source code is supplied • They are free-to-use products • A model for commercial software that is new to the IBM i community

CNX's Valence • RPG oriented commercial product now offering a free community edition • www.cnxcorp.com/valence

System & Method's IceBreak Community Edition (CE) • www.system-method.com/download/icebreakce • Modelled after the Microsoft's ASP approach • Web site features some great "try it and see" features

✦ www.icebreak.org/programs2.htm • Icebreak is unusual in that it also supports COBOL

© Partner400, 2016 Lecture Notes: Page 3 of 12

Page 4: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Consume Web Services From RPGIBM's Web Services Client • Requires that you have the C compiler installed and is limited to SOAP

We prefer Scott's Klement's HTTP API • An easier and more powerful approach

✦ www.scottklement.com/httpapi • A free open source tool that acts as an HTTP client (i.e. a "Browser") • Limited documentation

✦ But excellent demonstration programs

• Presentation handout on Scott's web site ✦ Many articles at iProDeveloper.com

• Very supportive user community ✦ Access the list via Scott's web site ✦ Formal support contracts available vie Profound Logic

Thomas Raddatz offers WSDL2RPG • An easy way of generating programs to consume web services • Builds on Scott's HTTPAPI

✦ www.tools400.de/English/english.html

Simple HTTPAPI Example - GeoIPSOAP = '<soapenv:Envelope + xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" + xmlns:web="http://www.webservicex.net"> + <soapenv:Header/><soapenv:Body> + <web:GetGeoIP> + <web:IPAddress>' + IPADDR + '</web:IPAddress> + </web:GetGeoIP></soapenv:Body></soapenv:Envelope>'; http_setCCSIDs( 1208: 0 ); http_debug( *ON ); rc = http_post_xml( 'http://www.webservicex.net/geoipservice.asmx' : %addr(SOAP) + VARYINGDATAOFFSET : %len(SOAP) : *NULL : %paddr(MapXmlData) : %addr(CountryName) : HTTP_TIMEOUT : HTTP_USERAGENT : 'text/xml; charset=UTF-8' : '"http://www.webservicex.net/GetGeoIP"' ); if (rc<>1); http_crash(); endif; dsply CountryName ' ' wait; *inlr = *on;

© Partner400, 2016 Lecture Notes: Page 4 of 12

Page 5: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

/copy qsource,RPGMailCp /copy qsource,ErrorCp D email s o class(*java: RPGMail) /Free RPGMail_init(); email = RPGMail_new();

RPGMail_addAddress(email: 'FROM': '[email protected]': ' '); RPGMail_addAddress(email: 'TO': '[email protected]': ' '); RPGMail_setSubject(email: 'RPGMail Test'); RPGMail_setBodyText(email: 'The text for my first rpg email message!' : 'text/plain'); RPGMail_setSMTPHost(email: 'smtp.mycompany.com'); RPGMail_setSMTPPort(email: '25');

RPGMail_send(email);

Send email from your RPG programsAaron Bartell's RPGMail2 • A Custom Java interface to the Java Mail APIs

✦ Keeps the RPG simpler so there is no need to create your string objects etc.

Download it from www.mowyourlawn.com • Premium "for fee" version available with support services

Send email from your RPG programsGiovanni Perotti's MMail (Mime and MAIL) • A completely RPG Solution

Download it from www.easy400.net • We wrote an article on it for IBM Systems Magazine in 2004

✦ www.ibmsystemsmag.com/ibmi/tipstechniques/applicationdevelopment/You-ve-Got-Mail!

Provides green screen, Windows, and Browser interfaces • Web interface allows for sending and receiving email

More complex to use than RPGMail2 • But offers broader functionality

✦ Uses a templating system for the body of the email - Very similar in action to CGIDEV2 HTML templating

© Partner400, 2016 Lecture Notes: Page 5 of 12

Page 6: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Create, update and read Excel SpreadsheetsScott Klement has written extensively on the subject • His RPG code wrappers the Jakata POI Java classes

Full details in Scott's presentation on his web site • www.scottklement.com/presentations/Excel Spreadsheets from RPG with

POI.pdf • Presentation provides references to the many articles he has written

✦ The associated code can be downloaded from SystemiNetwork.com

Scott's Service Programs form the foundation for many other utilities • For example, Giovanni Perotti at Easy400 uses them extensively

Giovanni's Excel Utilities include: • XLSCGI

✦ Creates Excel spreadsheets in XML format using CGIDEV2 templates ✦ Templates are defined using a web interface

• HSSFCGI ✦ Based on Scott's HSSFR4 to simplify Excel spreadsheet generation ✦ Uses its own XLSGEN "language" - a simplified XML format for defining spreadsheets

• XLPARSE2 ✦ Uses Scott's XMLPARSER4 to directly convert Excel spreadsheets into database

Want to Generate XML ?Use CGIDEV2 as a templating system • Originally designed to produce web pages

✦ But XML and HTML are very similar • The XML template is external to the program just like DDS

✦ Change the template and you have changed the XML - Not even a recompile needed

Larry Ducie's XMLi Toolkit (xmli.sourceforge.net) • Designed for XML from the ground up • Two "flavors" of operation

✦ API driven and template driven Henrik Rützou's powerExt (powerext.com) • Developed as part of the powerExt web development framework • API driven approach that can handle HTML, JSON, XML and more • XML facilities are part of the free Core features

✦ www.powerext.com/pextdoc_CGI.htm

© Partner400, 2016 Lecture Notes: Page 6 of 12

Page 7: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

/$Header <?xml version='1.0'?> <Customers> /$Customer <Customer> <Contact>/%Contact%/</Contact> <Company>/%Company%/</Company> <Address> <Street>/%Street%/</Street> <City>/%City%/</City> <State>/%State%/</State> <Zip>/%Zip%/</Zip> </Address> </Customer> /$Trailer </Customers>

CGIDEV2 Simple XML TemplateThis example use the default section identifier "/$"

Notice that there are three sections (think record formats) • The first (Header) will be output at the start of the file • The second (Customer) is used for the repeating customer elements • The third (Trailer) wraps up the document

The whole template can be placed in a source physical file or in an IFS file

// Load HTML from source file and write out the Header Section gethtml('HTMLSRC': '*LIBL': 'CUSTXML'); WrtSection('Header') // Update substitution variables for each record & write it out UpdHTMLVar('Contact': ContactName); UpdHTMLVar('Company': CoName); UpdHTMLVar('Street' : Address1); UpdHTMLVar('City' : City); UpdHTMLVar('State' : StateCode); UpdHTMLVar('Zip' : %EditC(ZipCode: 'X')); WrtSection('Customer'); // When all records processed write the trailer and output to the IFS WrtSection('Trailer'); WrtHtmlToStmf('/xml/Customers.xml':819);

CGIDEV2 Code to Process the TemplateGetHTML loads the template into memory UpdHTMLVar supplies the data for the substitution variables

✦ Note that %Char (or %EditC/W) must be used for all numeric fields

WrtSection actually merges the skeleton with the variable content ✦ A substitution variable can appear multiple times just as a DDS variable can

WrtHtmlToStmf writes the buffered XML to the IFS ✦ The second parameter identifies the code page of the file to be created

This portion is repeated for each record to be output

© Partner400, 2016 Lecture Notes: Page 7 of 12

Page 8: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Using powerExt - An API Driven Approach Exec SQL declare customerCursor cursor for select * from QIWS.QCUSTCDT;

Exec SQL open customerCursor;

DoU SQLSTATE = endOfData; Exec SQL fetch next from customerCursor into :customer;

If SQLSTATE <> endOfData; xmlNode('Customer':'ID="'+ %char(cusnum) + '"'); xmlNode('Name':'':LSTNAM); xmlNode('Address'); xmlNode('Street':'':street); xmlNode('City':'':city); xmlNode('State':'':state); xmlNode('Zip':'':%editc(zipcod:'X')); xmlEndNode(); xmlEndNode(); EndIf; EndDo; Exec SQL close customerCursor;

xmlEndNode();

echoToStmf(xmlFilename:1208);

Starts element and

adds attribute value

Note: No element name needed

<xmli:template xmlns:xmli="http://www.sourceforge.net/xmli" ccsid="1208">

<Customers> <xmli:sql name="custCount" statement="select count(*) from mcustomers"> <xmli:for-each> <RecordCount><xmli:value-of select="custCount.1" /></RecordCount> </xmli:for-each>

<xmli:sql name="custRow" statement="select * from mcustomers"> <xmli:for-each>

<Customer ID="${custRow.1}"> <Company><xmli:value-of select="custRow.2" /></Company> <Address> <Street><xmli:value-of select="custRow.3" /></Street> <City><xmli:value-of select="custRow.4" /></City> <State><xmli:value-of select="custRow.5" /></State> <Zip><xmli:value-of select="custRow.6" /></Zip> </Address> </Customer> </xmli:for-each>

</Customers>

<xmli:write-to-file path="'/Partner400/Redbook/Customers.xml'" /> </xmli:template>

XMLi Toolkit - Template OptionXMLi has both template and API options

• The API option is very similar to that of powerExt

© Partner400, 2016 Lecture Notes: Page 8 of 12

Page 9: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

yajl_genOpen(*On ); // Set up to generate in "pretty" format

yajl_beginObj(); // Start Object build yajl_beginArray('Customers'); // Start Customer array

yajl_beginObj(); yajl_addNum( 'ID': cusnum ); yajl_addChar( 'Name': LSTNAM ); yajl_addChar( 'Street': street ); yajl_addChar( 'City': city); yajl_addChar( 'State': state); yajl_addNum( 'Zip': zipcod )); yajl_endObj();

yajl_endArray(); // Close the array yajl_endObj(); // and wrap up the object before writing to IFS

yajl_saveBuf('/Partner400/json/customers.json': errMsg);

yajl_genClose(); // All done

Want to Generate and Consume JSON ?YAJL - An Open Source project ported to IBM i by Scott Klement • Scott has added a set of subprocedures to simplify the interface

✦ More information at scottklement.com/yajl/

Process is similar to the XML generation APIs of powerExt and XMLi • i.e. You add object definitions and then add elements to them, including arrays etc.

This section is repeated for each customer

NotesThe JSON generated from the script shown would look like this: {

"Customers": [

{

"ID": 12345,

"Name": "Paris ",

"Street": "Main Street ",

"City": "Jasontown ",

"State": "GA",

"Zip": 30236

}

]

}

The formatting is the result of using the formatting option "*On" on the yajl_genOpen(*On) call. This is useful during testing to enable you to easily see if the correct levels are being generated, but for production should be set to *Off. That would have resulted in this far more compact output:

{"Customers":[{"ID":12345,"Name":"Paris ","Street":"Main Street ","City":"Jasontown

","State":"GA","Zip":30236}]}

We would also normally make the results even more compact by using %TrimR on the source fields producing this:

{"Customers":[{"ID":12345,"Name":"Paris","Street":"Main Street","City":"Jasontown","State":"GA","Zip":30236}]}

© Partner400, 2016 Lecture Notes: Page 9 of 12

Page 10: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

www.Easy400.netOriginally distributed just CGIDEV2, related tutorials, samples, etc. • CGIDEV2 is the only software on the site that is not Open Source!

✦ IBM have to date refused to release it as OS - The version IBM distribute is out-of-date and the easy400 version is a better choice - Still being enhanced by the original developer

• But there is much more to find than CGIDEV2 Antoon van Os' DB2XTools and WebSql • www.easy400.net/db2xtools/html/db2xtools.htm • Converts a table to an IFS stream file in one of four formats:

✦ CSV, HTML, TXT, and XML • Web or green screen interface • WebSql adds the ability to dynamically define SQL queries

✦ The results are then fed into DB2XTools for output

Places to find "Useful Stuff"David Morris' iSeries Toolkit • http://iseries-toolkit.sourceforge.net

Leif Guldbrand's Think400 • www.think400.dk • There's a LOT of stuff including many API usage examples

✦ Also links to many other useful sites

Henrik Krebs • www.hkrebs.dk/sw.html • A collection of free utilities including spool file cleanup and more

Craig Rutledge • www.jcrcmds.com • Many utility programs including a group that provide sophisticated conversion

of fixed-form RPG to /Free format Martin Rowe's DBG/400 • www.dbg400.net • Original DBG400 utility was to assist in setting up a complete test environment • Several other tools including spool file manipulation added since

© Partner400, 2016 Lecture Notes: Page 10 of 12

Page 11: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Places to find "Useful Stuff"Peter Bishop's AS400Pro.com (No longer updated but useful) • A great resource for finding articles on IBM i tech topics • Home page lists article references added in the last 30 days

✦ The last time I checked there were over 100 listings

• Covers CL, DDS, RPG, SQL, and other topics of interest to i folk ✦ "Tips" page lists topic areas and links to detailed lists for each topic

- as400pro.com/viewTips.php

Albert York • http://www.albertyork.yolasite.com/samples.php • Includes a reformatting utility for /Free RPG Source • Also the famous (or at least it should be) TNAPI

✦ It allows you to control an interactive program in batch!

Help400 • http://www.help400.de/software.html

✦ Sadly this page is no longer available in English but Google Translate is your friend and all utilities identified with a Union Jack are in English

• Links to lots of Open Source and Freeware utilities and samples

Places to find "Useful Stuff"Jean-Paul Lamontre • jplamontre.free.fr/jpltools.htm • Collection of tools for everything from creating emails, PDFs and Excel

spreadsheets to handling QSYSOPR message queues • Also links to many of Jean-Paul's magazine articles

Brian Dietz • bryandietz.us/iseries.html • Variety of communications related tools

✦ Port scanners, and Netstat style tools

• Spool file scanner and the PHP WRKSPLF sample script

homepage1.nifty.com/uzaemon • Don't let the Japanese text put you off

Free 5250 emulation software • tn5250j.sourceforge.net/index.html • Full 5250 support • Highly configurable

© Partner400, 2016 Lecture Notes: Page 11 of 12

Page 12: Open Source and i - NEUGC - Northeast User Groups … · Open Source and i The best things in ... services for AS/400 and iSeries developers. ... The whole template can be placed

Places to find "Useful Stuff"Peter Levy • www.peterlevy.com • Includes Peter's Dynamic Arrays utility

✦ And references to the System i Network articles that describe them

Assorted other sites • www.qpratools.com

✦ Utility functions for everything from spool files to date conversions • slic-systems.org/index.php/downloads

✦ File utilities and editor, Source code formatters, etc.

iSphere - RDi Extensions • Fabulous set of plug-in features for IBM's RDi development tool • New features regularly added • Look out for our article in IBM Systems Mag's Sept 2014 Extra • sourceforge.net/projects/isphere/

© Partner400, 2016 Lecture Notes: Page 12 of 12