subprocedure basics _ ibm i

7
Administrator Backup and Recovery DB2 High Availability LPAR Networks Performance Security Systems Management Tivoli Trends AIX Linux Open Source What's New Tips & Techniques Application Development Systems Management Miscellaneous Case Studies Automotive Healthcare Manufacturing Miscellaneous Non-profit Retail Storage Disk Servers Software Tape Product News Buyer's Guide Administrator Backup and Recovery DB2 Domino High Availability LPAR Networks Performance Printing Security Systems Management WebSphere Windows Integration Developer General Java Modernization RPG WebSphere Trends IBM Announcements Linux Open Source SOA What's New Tips & Techniques Application Development Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx 1 of 7 9/27/2010 8:53 AM

Upload: nairarung

Post on 07-Feb-2016

7 views

Category:

Documents


0 download

DESCRIPTION

as400

TRANSCRIPT

Page 1: Subprocedure Basics _ IBM i

Administrator

Backup and Recovery

DB2

High Availability

LPAR

Networks

Performance

Security

Systems Management

Tivoli

Trends

AIX

Linux

Open Source

What's New

Tips & Techniques

Application Development

Systems Management

Miscellaneous

Case Studies

Automotive

Healthcare

Manufacturing

Miscellaneous

Non-profit

Retail

Storage

Disk

Servers

Software

Tape

Product News

Buyer's Guide

Administrator

Backup and Recovery

DB2

Domino

High Availability

LPAR

Networks

Performance

Printing

Security

Systems Management

WebSphere

Windows Integration

Developer

General

Java

Modernization

RPG

WebSphere

Trends

IBM Announcements

Linux

Open Source

SOA

What's New

Tips & Techniques

Application Development

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

1 of 7 9/27/2010 8:53 AM

Page 2: Subprocedure Basics _ IBM i

Systems Management

Case Studies

Automotive

Banking/Finance

Healthcare

Insurance

Manufacturing

Miscellaneous

Non-profit

Retail

Storage

Disk

Optical

Servers

Tape

Product News

Product Reviews

ENDPGM Main Page

Administrator

Backup and Recovery

CICS

DB2

High Availability

IMS

LPAR

Migration

Networks

Performance

Security

Systems Management

Tivoli

Trends

Linux

Open Source

Security

SOA

What's New

z/OS

z/VM

Tips & Techniques

Application Development

Systems Management

Case Studies

Automotive

Banking/Finance

Healthcare

Insurance

Manufacturing

Miscellaneous

Retail

Storage

Disk

Servers

Software

Tape

Product News

Stop Run

Buyer's Guide Main Page

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

2 of 7 9/27/2010 8:53 AM

Page 3: Subprocedure Basics _ IBM i

Business Strategy

Competitive Advantage

Consolidation

Executive Perspective

Green IT

Migration

Open Source

ROI

Infrastructure

Blades

Storage

Systems Management

Case Studies

Distribution

Healthcare

Manufacturing

Services

Web 2.0

Cloud

Social Media

Trends

Collaboration

IBM Announcements

IBM Research

Open Source

Social Media

What's New

Product News

AIX

MAINFRAME

POWER

Newsletters

About Us

Subscribe

Current Issue

Archive

IBM i

ALL EDITIONS

ADMINISTRATOR

DEVELOPER

TRENDS

TIPS & TECHNIQUES

CASE STUDIES

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

3 of 7 9/27/2010 8:53 AM

Page 4: Subprocedure Basics _ IBM i

STORAGE

PRODUCT NEWS

ENDPGM

BUYER'S GUIDE

Developer > RPG

Subprocedure Basics

How and why to convert subroutines to subprocedures

August 2009 | by Susan Gantner and Jon Paris

Print Email

Last month, we wrote about why we write subprocedures instead of subroutines, and we promised to cover the basic “how to” this month. We'll use

the same example (i.e., a subroutine that takes a date and calculates the day of the week for that date) and convert the code to a subprocedure, which

gives us the chance to not only show the syntax changes needed, but also illustrate the benefits in more detail.

Here's the original subroutine code. We're not showing the entire program here—only the parts specifically relevant to the subroutine and one instance

of calling it.

Initially, we're going to simply convert this subroutine into an internal subprocedure. Later, as we mentioned last month, we could choose to

externalize that subprocedure to be able to access it from multiple programs. But in this article, we'll just concentrate on the first step.

First, we may need to move the code for the subroutine within the source member. Subprocedures go after all of the ordinary main program logic.

Subprocedures go after any O specs the member may contain but before any compile-time data.

The next step is to replace the BEGSR and ENDSR operations with P specifications. The P spec contains the name of the subprocedure (aka

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

4 of 7 9/27/2010 8:53 AM

Page 5: Subprocedure Basics _ IBM i

procedure) and either a B for begin or E for end. The procedure name is optional on the ending P spec, but it's a good idea to code it there for clarity

when scrolling through the code. So our beginning and ending P specs will look like this:

A subprocedure can be thought of as a cross between a subroutine and a program. Like a subroutine, it can be (but doesn't have to be) coded in the

same source member as the code that calls or runs it. However, it's more like a program in the sense that it accepts parameters and has its own local

data definitions.

Next page: >>

Page 1 2 3

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.

More Articles From Susan Gantner

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

More Articles From Jon Paris

Advertisement

WEBINAR

Thursday, September 30 – 2pm (ET) from LANSA

IBM i Enterprise Web Development ---- Fact or Fiction?

Browse products and services for Developer.

Advertisement

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

5 of 7 9/27/2010 8:53 AM

Page 6: Subprocedure Basics _ IBM i

Maximize your IT investment with monthly information from THE source...IBM Systems Magazine EXTRA & Marketplace eNewsletters.

SUBSCRIBE NOW.

View past IBM i EXTRAs here

Related Articles

V5R4 Introduces Subroutines for CL

Administrator

The Case for CODE/400

E-Newsletter Exclusive

Paging RPG IV

RPG for the Web

Three Good Reasons to Stop Writing Subroutines

E-Newsletter Exclusive | Save time and reduce errors with subprocedures

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

6 of 7 9/27/2010 8:53 AM

Page 7: Subprocedure Basics _ IBM i

IBM i

AIX

MAINFRAME

POWER

Homepage

About Us

Contact Us

Subscriptions

Editorial Calendar

Advertise With Us

Reprints

Privacy Policy

Terms of Service

Sitemap

IBM Systems Magazine is a trademark of International Business Machines Corporation. The editorial content of IBM Systems Magazine is placed on

this website by MSP TechMedia under license from International Business Machines Corporation.

© 2010 MSP Communications, Inc. All rights reserved

Subprocedure Basics | IBM i | IBM Systems Magazine http://www.ibmsystemsmag.com/ibmi/enewsletterexclusive/26220p1.aspx

7 of 7 9/27/2010 8:53 AM