Hi Scott,

Just a question - do you separate your data retrieval logic from your
business logic, or couple them closely together?

Brenden Conolly

From: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
To: RPG programming on the IBM i / System i <rpg400-l@xxxxxxxxxxxx>
Date: 05/04/2012 02:35 AM
Subject: Re: File Encapsulation Quandary
Sent by: rpg400-l-bounces@xxxxxxxxxxxx


I agree with Eric.

I would add that "encapsulating" the database (in the manner that Kurt
has demonstrated) doesn't provide much encapsulation. The caller still
has to know which tables (PFs) he's accessing, and what the keys are to
that table, etc. If you changed the underlying storage method, the
caller would need to be changed to reflect that. Where's the

So you're doing your "chain" in a SRVPGM instead of the same source
member. So what? You still need to understand the tables and their
relationships, you still need to code all that into your program. you
still need to code the record retrieval methods (such as "chain") into
your program.

What on earth is this gaining you other than added complexity? How will
this save development time, ease development efforts, support efforts,
or improve the user experience?

Code your logic based on the business transactions you need to perform,
not the underlying method that you're using to perform them! That's how
you encapsulate things.

A routine, for example, to retrieve inventory for a given SKU might look
like this:

if item_getInventory( sku : InvArray ) = FAIL;
errMsg = item_getLastError();
// log error

Here you are working with business objects. You sell items, so you need
to know what's in inventory. You identify your items with a sku, so you
pass that sku as a parameter. InvArray is returned and is an array
containing a list of inventory locations, quantities, etc.

All the business logic needed to retrieve inventory for a SKU is
encapsulated into the item_getInventory() routine. The caller doesn't
need to know which database table(s) the data is stored in. It doesn't
need to know what gyrations you have to go through to look up the
inventory values. In fact, the data might not be in a databaase at
all... maybe it's in an XML file in the IFS, or maybe it's accessed
through a web service from some remote location... all of that will work
fine because the caller makes no attempt to know how that data is stored.

Compare that to Kurt's approach:

$declareItemMast( *off: sku );

// no idea how I'm supposed to get fields.

$declareInventory( *off : sku: itemstgcode );
dow $readeInventory() = SUCCESS;
// combine fields from both ITemMast and Inventory
// tables to get needed inventory data.

Now your caller needs to know that part of the needed data is in the
"itemmast" table, and part is in the "inventory" table (and who knows
what else would be required in a "real world" application instead of
this simple example I threw together)

It has to know which fields are in which table, etc. It has to
understand that these are database tables that are keyed in a particular
way. If you want to change any of that, you have to rewrite both the
caller and the database "encapsulation" *srvpgm, because they are
inextricably linked.

What's the point? If you're going to take Kurt's approach, why not
simply do the SETLL/READE or CHAIN in the RPG program to begin with?
you haven't gained anything over and above that approach.

In my (and, presumably, Eric's) approach, you achieve some layer of
independence from the database itself. In Kurt's, you really don't.

That's my thought, anyway.

On 4/4/2012 11:13 AM, DeLong, Eric wrote:
> Which is really not of much value when writing RPG applications... I'm
just saying, it never made much sense to me... RPG is inextricably tied
to DB2i, and given the simplicity and power of database I/O within RPG,
why try to achieve database independence.
> To me, for business development, the transaction is everything... You
"do stuff" with "things". Your "things" are business-centric concepts,
like Customer, Product, Address, Invoice, A/R Account, etc. "things" are
described as data structures, which can be used by your procs to pass
metadata, not record formats...
> Oh well, we know all about opinions, right? ;-)
> -Eric DeLong
This is the RPG programming on the IBM i / System i (RPG400-L) mailing
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: [1]http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at [2]http://archive.midrange.com/rpg400-l.

This email is sent by Auto & General Insurance Company Ltd, A&G Insurance Services Pty Ltd, Australian Insurance Holdings Pty Ltd or a related body corporate (A&G) and is for the intended addressee.
The views expressed in this email and attachments (email) reflect the views of the stated author but may not reflect views of A&G. This email is confidential and subject to copyright.
It may be privileged. If you are not the intended addressee, confidentiality and privilege have not been waived and any use, interference with, or disclosure of this email is unauthorised.
If you are not the intended addressee please immediately notify the sender and then delete the email. A&G does not warrant that this email is error or virus free.


Visible links
1. http://lists.midrange.com/mailman/listinfo/rpg400-l
2. http://archive.midrange.com/rpg400-l

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].