system i cgi toolkits - rpg world - system i cgi toolkits.pdf · system i cgi toolkits ... • erpg...
TRANSCRIPT
www.bvstools.com
System i CGI Toolkits
Bradley V. Stone
www.bvstools.com
www.bvstools.com© 2007 Cozzi Productions, Inc.
Topics
• Where to StartWhat You Need to Know
• Toolkit ConceptsHow Does a Toolkit Help Me?
• Toolkit FunctionalityThe Template and Substitution Variables
• The Toolkit in ActionExamples
• e-RPG SDK and CGIDEV2Which is Right for You?
• Closing Thoughtse-RPG and Toolkit Benefits
• ResourcesBooks, Training Manuals and Toolkits to Get You Started or Take you Further
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to Start
True or False:
A web toolkit (any kind) is a great way to learn how to create web applications.
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to Start
Answer:
It depends on:– Previous Experience
– Willingness to Learn
– Available Team Members and Resources
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartWhat you Need to Know
Using a toolkit doesn’t mean you don’t have to learn!
• The Integrated File System (IFS)
• Integrated Language Environment (ILE)
• Web Server Configuration
• Web Programming Concepts
• Templates and Replacement Variables
• Team Roles
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartThe Integrated File System (IFS)
• Different from the Library/File file system we are used to
• Similar to Windows or Unix file systems
• Used to store static web pages, JavaScript, Stylesheets, Templates, etc.
• Used to store Apache configuration files
• Access through green screen, FTP, Windows Explorer
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartIntegrated Language Environment
• RPG Toolkits consist mainly of ILE subprocedure calls
• Integration is fairly painless in most cases (H-Specs for compiler options, /COPYs for prototype definitions, etc)
• Toolkits are a great introduction to what can be done with ILE, something every RPG programmer should be focusing on!
• “Trick” yourself into learning ILE!
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartWeb Server Configuration
• Most toolkits will set up a basic configuration for you
• Using a toolkit doesn’t mean you must use the configuration it creates
• Future server updates (ie Virtual Hosts, SSL, new paths, directories, Security, etc)
• Additional Servers (ie Development, Test, Production)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartWeb Programming Concepts
Understanding the basics of web programming will further help you utilize the functionality of any toolkit!
• How CGI programs create dynamic output
• How CGI programs read input• What other data is available (ie
Environment Variables)• Web Page Design (HTML,
Stylesheets, JavaScript, SSI, etc)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartTeam Roles
• Core functionality of application
• Business Rules
• Database Administration
• Web page design
• Web page functionality
• Graphic Artist?
www.bvstools.com© 2007 Cozzi Productions, Inc.
Where to StartTemplates and Repl. Variables
• How templates work
• Where templates are stored
• How template sections work
• How replacement variables work
• Efficient use of templates and sections! (Don’t put all your data in one template or section!)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit ConceptsHow Does a Toolkit Help Me?
• Removes Most if not All HTML from your RPG programs
• Allows updates of web applications without re-compilation of programs
• Easy to use functions to create dynamic web pages
• Allows separation of display and business layers
• Increases productivity
• Can be used for functionality other than web pages!
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit ConceptsHow a Toolkit Does NOT Help
A toolkit is a HUGE help, but it alone will NOT help you to become a better web application programmer. You still need to learn the basics of:
• Web Server Configuration
• Web Application Design
• Web Application Functionality
• CGI Programming
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit ConceptsHow Does it Work?
• Template contains your basic web page layout divided into “sections”
• Template is loaded into application
• Substitution variables inside the template are replaced with actual data
• Sections of data are written to the browser
• Repeat until the entire page is complete!
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityThe Template
• Contains the “basic” layout of your web page separated into “sections”
• Created and stored externally from your program
• Similar to external DDS for printouts or green screens
• Stored in a PF or Stream File in the IFS
• Not only used for Web Pages!
www.bvstools.com© 2007 Cozzi Productions, Inc.
The TemplateAn Example
/$top
Content-type: text-html
<html>
<body>
We will count from 1 to /%end%/<br>
/$count
Current count: /%count%/<br>
/$end
</body>
</html>
Top section including HTTP Headers
“Looping” Section
End Section
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalitySubstitution Variables
• Used to place dynamic data into your web page
• Variables are replaced with “real” data from your application
• Makes your web pages “dynamic”
• As your data changes, the web page changes
www.bvstools.com© 2007 Cozzi Productions, Inc.
Substitution VariablesAn Example
/$top
Content-type: text-html
<html>
<body>
We will count from 1 to /%end%/<br>
/$count
Current count: /%count%/<br>
/$end
</body>
</html>
“end” variable to be replaced with a value
“count” variable to be replaced with value on each iteration
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityHow Storage is Used
TemplateData
WorkingBuffer
Web Output
•Data is loaded From the template into a “Working Buffer”
•Data is manipulated in the “Working Buffer” (sections are loaded, replacement variables are substituted with data, etc)
•Data is written from the “Working Buffer” to the web page
•Process repeats until entire page is built
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityBasic Functions
• Initialization or Startup
• Loading a template and/or section
• Reading input from the browser
• Placing data into the output
• Writing the output to the browser
• Creating Cookies
• Retrieving Cookie data
• End Processing
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityInitialization
• Used to set up the environment
• Clears buffers, starts everything “fresh”
CGIDEV2: ClrHTMLBuffer
eRPG SDK: #startup
Examples:Callp ClrHTMLBuffer
Callp #startup
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityLoad Template
• Loads template into “buffer”• Prepares template data to be written to
output
CGIDEV2: GetHTMLIfseRPG SDK: #loadTemplate
Examples:Callp GetHTMLIfs(‘/path/file.ext’)Callp #loadTemplate(‘file.ext’)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityLoad Section
• eRPG SDK only
• Loads a section into the “working buffer”
#loadSection(section)
Example:Callp #loadSection(‘detail’)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityRead Input
• Reads data in from web form
• Normally read in by field name
CGIDEV2: ZhbGetVar(fieldname)
eRPG SDK: #getData(fieldname)
Examples:Eval firstname = ZhbGetVar(‘firstname’)
Eval firstname = #getData(‘firstname’)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityReplace Data
• Used to replace “fields” in template with actual data
• The main function that makes your web pages “dynamic”
CGIDEV2: UpdHTMLVar(field:data)
eRPG SDK: #replaceData(string:data)
Examples:Callp UpdHTMLVar(‘name’:firstname)
Callp #replaceData(‘/%name%/’:firstname)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityWrite Section
• Writes data from buffer to output
• Output can be web, file, or both
CGIDEV2: WriteSection(section)
eRPG SDK: #writeSection
Examples:Callp WriteSection(‘detail’)
Callp #writeSection
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityWrite Section Cont…
Writing output to a file:
CGIDEV2:* Normal Processing, replacements, etc.eval rc = WrtHTMLToStmf(‘/output/file.ext’)
eRPG SDK:CallP #setWriteTo(W_FILE)CallP #openOutFile('test2.test')* Normal Processing, replacements, etc.CallP #writeSection
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityBuild a Cookie
• Builds a string containing cookie data• Data is replaced in template
CGIDEV2: CrtCookie(name:value:rc:domain:path:[..])
eRPG SDK: #buildCookie(name:value:[..])
Examples:Eval cookie = CrtCookie(‘id’:userid)Eval cookie = #buildCookie(‘id’:userid)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityRetrieve a Cookie
• Retrieves cookie data by name
• Simplifies process!
CGIDEV2: GetCookieByName(cookie)
eRPG SDK: #getCookie(cookie)
Examples:Eval id = GetCookieByName(‘id’)
Eval id = #getCookie(‘id’)
www.bvstools.com© 2007 Cozzi Productions, Inc.
Toolkit FunctionalityEnd Processing
• Writes remaining data to web page (flushes any buffers)
• Performs cleanup
CGIDEV2: wrtsection('*fini')eRPG SDK: #cleanup
Examples:Callp wrtsection(‘*fini’)
Callp #cleanup
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionExamples
The best way to comprehend a concept is to see it in action!
• “Native” CGI (with API Wrappers) vs. Toolkit
• Looping, Table, and Input Toolkit Examples
• More examples online
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in Action“Native” CGI vs. Toolkit
eval WrtDta = %trim(HTTPHeader) +
NewLine + NewLine
CALLP #WrStout(WrtDta)
eval Method =
#GetEnv2(‘REQUEST_METHOD’)
If (Method = 'POST')
eval RcvRec = #CGIParse('-init')
CALLP #PutEnv(RcvRec)
endif
eval FirstName =
#CGIParse('-value firstname')
eval LastName =
#CGIParse('-value lastname')
eval WrtDta = '<html><body>' +
'First=' + %trim(FirstName) +
'<br>' +
Last=' + %trim(LastName) +
'</body></html>' +
NewLine
CALLP #WrStout(WrtDta)
eval *INLR = *on
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in Action“Native” CGI vs. Toolkit Cont…
Content-type: text/html
<html><body>
First=/%fname%/<br>
Last=/%lname%/
</body>
</html>
Callp #startup
Callp#loadTemplate(‘input.erpg’)
Eval FirstName =
#getData(‘firstname’)
Eval LastName =
#getData(‘lastname’)
Callp #replaceData(‘/%fname%/’:
FirstName)
Callp #replaceData(‘/%lname%/’:
LastName)
Callp #writeSection
Callp #cleanup
Eval *INLR = *ON
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionA Looping Example (CGIDEV2)
• http://www.bvstools.com/cgidev2/loop1(local)
• Template Source
• RPG Source
This application shows the basic functionality behind using a toolkit and using replacement variables and repeating sections.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionA Looping Example (eRPG SDK)
• http://www.erpgsdk.com/e-rpg/loop2(local)
• Template Source
• RPG Source
• Standard HTML Header
This example is the same as the previous, only using eRPG SDK instead of CGIDEV2.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionA Table Example (CGIDEV2)
• Shopping Basket Example
• Template Source
• RPG Source
This example shows a more involved example displaying the contents of a shopping cart.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionAn Input Example
• http://www.erpgsdk.com/input1.html
• Template Source
• RPG Source
This example shows the basics behind reading input from a web page using a toolkit.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionCookie Creation
• http://www.bvstools.com/erpg/cgidev2/examples/cookie1main.html
• Template
• RPG Source
This example shows the basics behind creating a cookie using a toolkit.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionCookie Retrieval
• http://www.bvstools.com/erpg/cgidev2/examples/cookie2main.html
• Template
• RPG Source
This example shows the basics behind retrieving a cookie using a toolkit.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit in ActionCreating Dynamic Email
• Program EMAILSAMP in library BVSTOOLS (Green Screen)
• Template
• RPG Source
This example shows how a toolkit can be used for creating dynamic files other than HTML. In this case it creates a dynamic email message.
www.bvstools.com© 2007 Cozzi Productions, Inc.
The Toolkit In ActionOnline Examples
• CGIDEV2 examples can be found at http://www.easy400.net– Click on “Deliverables” in left
hand column– Click on RPG CGI Programming
Toolset (CGIDEV2)– More examples from “eRPG
PowerTools: Stone on CGIDEV2”at www.bvstools.com/erpg/
• eRPG SDK examples can be found at www.erpgsdk.com
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Which is Right for You?
• General Comparison
• Installation
• Service Programs
• Templates and Variables
• Basic Program Flow
• Performance
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2General Comparison
eRPG SDK• Created and supported
by Bradley V. Stone (www.bvstools.com)
• Available at www.erpgsdk.com
• Apache Only• Includes Example
Source and Templates• Closed Source and
Purchased Registration with free trial
CGIDEV2• Created by Mel
Rothman of IBM• Supported by Giovanni
Perotti and Mel Rothman
• Available at www.easy400.net
• Classic or Apache• Includes Example
Source and Templates• Free of charge
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Installation
eRPG SDK• Download from
www.erpgsdk.com (about 1.5 meg, temporary key required)
• Upload Save File to iSeries
• Restore ERPGSDK library
• Run SETUP command (restores objects, directories, creates new HTTP Config)
• Start HTTP Server
CGIDEV2• Download from
www.easy400.net (about 8 meg, registration required)
• Upload Save File to iSeries
• Restore CGIDEV2 library
• Run 1st install Program (Regenerate Programs)
• Run 2nd install Program (Restore /cgidev2 directory and update existing HTTP Config)
• Start HTTP Server
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Service Programs
eRPG SDK• Seven total service
programs, each with a specific function and a single module
• Each service program contains operation specific functionality
• Date, String, IFS, Library List, Messaging and CGI subprocedures are separately usable
CGIDEV2• One service program
containing 17 or more modules
• “Generic” subprocedures could be used separately including the entire service program or by recompiling specific modules into separate service programs
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Templates and Variables
eRPG SDK• Section delimiters can be set
globally or in program• Replacement functions replace
anything, not just delimited data, no need for setting delimiters
• Replacement affects only “loaded section”, not entire template
• Allows default input and output directories to be set with a simple command (good for different environments, ie test/production)
CGIDEV2• Section delimiter is set in
program (defaults can be changed in source)
• Replacement delimiters are set in program (defaults can be changed in source)
• Replacement affects all variables in entire template
• Fully qualified path to templates and output files specified in program source
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Basic Program Flow
eRPG SDK• Initialization• Read Input• Load Template
– Load Section by Name (Optional)
– Replace Variable(s)– Write Section
• End Processing
CGIDEV2
• Initialization
• Read Input
• Load Template
– Replace Variable(s)
– Write Section By Name
• End Processing
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Performance
• Looping program that replaces one variable per iteration (iteration count is read from input)
• Execution time is from beginning until end of application
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Performance Cont…Model 170 V5R2
0
10
20
30
40
50
60
70
80
90
10 50 100
200
500
1000
2500
5000
1000
0
Number of Iterations
Exe
cuti
on
Tim
e (i
n S
eco
nd
s)
eRPG SDK
CGIDEV2
www.bvstools.com© 2007 Cozzi Productions, Inc.
eRPG SDK and CGIDEV2Performance Cont…Model 520 V5R4
www.bvstools.com© 2007 Cozzi Productions, Inc.
Closing Thoughtse-RPG and Toolkit Benefits
• Use existing skill set
• Very small learning curve
• Easy on resources
• Split up business and presentation layers
• No more hard-coding HTML!
• Not just for web pages!
• RPG is Still Cool!
www.bvstools.com© 2007 Cozzi Productions, Inc.
Resourcese-RPG Books
• Great starting book
• Covers topics ranging from HTML to JavaScript
• Covers AS/400 APIs
• Includes Examples and Source
www.bvstools.com© 2007 Cozzi Productions, Inc.
ResourcesBooks Cont…
• Follow up to first eRPG book
• Contains more in depth materials and examples
• Chapters on dynamic SQL and ILE
www.bvstools.com© 2007 Cozzi Productions, Inc.
ResourcesBooks Cont…
• CGIDEV2 Toolkit Training Course
• Hours of Labs and Self-Study materials
• From installation to creating applications
www.bvstools.com© 2007 Cozzi Productions, Inc.
ResourcesBooks Cont…
• eRPG Training Manual
• Brand New Material!
• Updated information including Powered by Apache HTTP Configuration
• Great starting book for any web programming plan
• Self-Paced Training and Labs
www.bvstools.com© 2007 Cozzi Productions, Inc.
Resources
• e-RPG Books and Training Manualswww.bvstools.com/erpg/
• Web400-L Mailing List:www.midrange.com
• The CGIDEV2 Toolkitwww.easy400.net
• The eRPG SDKwww.erpgsdk.com