6

Using Condit...1

Embed Size (px)

Citation preview

Page 1: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 1/6

Page 2: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 2/6

Systems Management

Storage

Disk 

Optical

Servers

Tape

Product News

Product Reviews

ENDPGM Main Page

Administrator 

Backup and Recovery

CICS

DB2High Availability

IMS

LPAR 

Migration

 Networks

Performance

Security

Systems Management

Tivoli

Trends

Linux

Open Source

Security

SOAWhat's New

z/OS

z/VM

Tips & Techniques

Application Development

Systems Management

Case Studies

Automotive

Banking/Finance

Healthcare

Insurance

Manufacturing

MiscellaneousRetail

Storage

Disk 

Servers

Software

Tape

Product News

Stop Run

Buyer's Guide Main Page

es EXTRA: Using Conditional Compiler Directives | IBM i | IBM Sy... http://www.ibmsystemsmag.com/ibmi/november01/enewsletterex

9/27/2010

Page 3: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 3/6

Business Strategy

Competitive Advantage

Consolidation

Executive Perspective

Green IT

Migration

Open Source

ROI

Infrastructure

Blades

StorageSystems Management

Case Studies

Distribution

Healthcare

Manufacturing

Services

Web 2.0

Cloud

Social Media

Trends

Collaboration

IBM AnnouncementsIBM 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

es EXTRA: Using Conditional Compiler Directives | IBM i | IBM Sy... http://www.ibmsystemsmag.com/ibmi/november01/enewsletterex

9/27/2010

Page 4: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 4/6

STORAGE

PRODUCT NEWS

ENDPGM

BUYER'S GUIDE

Developer > RPG

iSeries EXTRA: Using Conditional Compiler Directives November 2001 | by Susan Gantner  and Jon Paris

 Print Email

 Authors' note: In this series of articles we intend to feature some of the more useful and lesser known gems in the RPG IV language. If you have any 

suggestions for future editions, please let us know.

Imagine you're trying to debug a particularly stubborn problem with a batch program. In desperation, you decide to add some additional logic to record the details of certain variables as the program progresses. Later, having decided you've fixed the problem, you remove these lines from the program. However, you didn'tcompletely fix it. Oops (that is the polite response); now you must put the lines back in again. When you've "fixed" it a second t ime, instead of removing the lines, youget smart and simply comment them out. Great idea, save for one tiny problem: When you reinstate them again the next t ime around, you accidentally "uncomment"a line of code that was first commented out during a maintenance fix back in 1987. The program still doesn't work, but at least its for a different reason.

If this scenario sounds familiar, you should know about Conditional Compiler Directives. Though these useful little devils were added to RPG IV in V3R7, manyprogrammers have never heard of them.

Let's look at a simple example:

 * Normal program logic goes here

 /If Defined(TESTING) * Include here any lines that relate only to test/debugC Eval DebugRec = CustomerDSC Write DebugFile /EndIf 

 * More regular program logic

If this program is simply compiled with the normal CRTBNDRPG directives, the lines between "/If Defined(TESTING)" and "/EndIF" will be excluded from thecompilation. That is because the ConditionName TESTING hasn't been set. Think of a ConditionName as a named indicator, and you won't go far wrong. Conditionscan be set within the source, or on the CRTBNDRPG or CRTRPGMOD commands. With our simple example, whenever we want to produce a test version, wesimply add the DEFINE(TESTING) option to the compile command. This causes the compiler to include all of the previously excluded lines. It can't get much simpler 

than that. We can also say that a section of source is to be included if t he ConditionName isn't defined -- e.g., /IF NOT DEFINED(TESTING).

In addition to being set on the compile command, Conditions can also be set within the source program itself. They can be set with the /DEFINE(ConditionName)

directive and cleared via /UNDEFINE(ConditionName).

Two other directives are currently supported:

/ELSEIF {NOT} DEFINED(ConditionName)/EOF

The latter is a handy feature that tells the compiler to skip directly to the end of the current source file (i.e., Do not pass Go, do not collect $200...). The links in thefollowing paragraphs will take you to examples of its usage.

 Next page: >>

Page 1 2

es EXTRA: Using Conditional Compiler Directives | IBM i | IBM Sy... http://www.ibmsystemsmag.com/ibmi/november01/enewsletterex

9/27/2010

Page 5: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 5/6

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

How Frontline Homeowners Insurance SOA - Enables their IBM i Policy and Claims ApplicationsWednesday, October 13, 2010 - 2pm EST

Browse products and services for Developer.

Advertisement

es EXTRA: Using Conditional Compiler Directives | IBM i | IBM Sy... http://www.ibmsystemsmag.com/ibmi/november01/enewsletterex

9/27/2010

Page 6: Using Condit...1

8/9/2019 Using Condit...1

http://slidepdf.com/reader/full/using-condit1 6/6

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

RPG for the Web

Paging RPG IV

iSeries EXTRA: Service Programs and Signatures

E-Newsletter Exclusive

Get More from RPG

E-Newsletter Exclusive | SPECIAL files process IFS directories and more

Three Good Reasons to Stop Writing Subroutines

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

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

es EXTRA: Using Conditional Compiler Directives | IBM i | IBM Sy... http://www.ibmsystemsmag.com/ibmi/november01/enewsletterex