Newsletters Subscriptions Forums Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 79 -- November 21, 2003

Alternate Methods for Returning Data Structures from Subprocedures


I have a concern with Steven Gray's technique [see "Returning a Pointer to a Data Structure from a Function"] using %STR to enable returning a pointer to a data structure: If there are UCS-2, packed, or integer fields in the data structure, it is highly probably that any fields following those fields will be skipped by %STR, because these data types frequently contain x'00' as part of their byte value. If a maintenance programmer unfamiliar with pointers added a subfield of one of those types, the mystery of the missing subfield data would be very difficult to solve.

I think the calling interface would be just as simple if coded this way:

C                   Callp     getCustDS(zCustNum : CustDS)

Here is the alternate procedure:

P getCustDS       B
D getCustDS       PI
D  zCustNum                     05P 0 value
D  zDs                                likeds(CustDS)
*
C     pCustNum      Chain     cfmt
C                   If        %found
* load DS here
C            Eval      zDs.CustNum    = CustomerNo
C            Eval      zDs.Name       = %trim(FName) + ' ' +
C                                       %trim(MidInit) + ' ' +
C                                       %trim(LName) + ' '
C            Eval      zDs.Addr       = address1
C            Eval      zDs.CityStZip  = %trim(city)  + ', '
C                                     + %trim(state) + '  '
C                                     + %trim(zipcode)
C            Eval      zDs.CurBal     = Balance
C            Eval      zDs.CredBal    = Credit - Balance
C            Else
C            Eval      zDs.CustNum    = *zeros
C            Endif
P getCustDS       E

--Barbara Morris
IBM Toronto


Steven Gray responds: Barbara is correct. In my example the first hex 00's within the returned string will cause the %STR() function to stop copying data to the target DS. To prevent this, I should have pointed out that, when using this technique, the data structure should be made up of only CHAR and ZONED subfields.

However, using a subprocedure this way puts the DS within the list of parameters, and I prefer to get my results as part of an EVAL statement whenever possible. If I modify Barbara's method slightly, I can still return the results with an EVAL. The keyword LIKEDS can be used in the procedure interface to let the compiler set up the returned DS. Here's how it works.

First, here's the main body with the revised prototype and the revised call to the function statement:

FCustomer  IF   E           K DISK    rename(Customer:Cfmt)
 * function prototype
D getCustDS       PR                  likeds( CustDS )
D  pCustNum                     05P 0 value
 *
D CustDS          DS                  qualified
D   CustNum                     10S 0
D   Name                        40
D   Addr                        40
D   CityStZip                   40
D   CurBal                       9S 2
D   CredBal                      9S 2
 *
D  zCustNum       S             10S 0
 * main
C                   Eval      zCustNum = 1001
 * 
C                   Eval      CustDS = getCustDS( zCustNum )

Notice the use of LIKEDS in the procedure interface to define the return value. Also, for readability, I include the QUALIFIED keyword when I define the first copy of the data structure. The call to the function is a simple EVAL statement, with my results on the left side and outbound parameters on the right.

Next, this is what the procedure interface looks like:

P getCustDS       B
D getCustDS       PI                  likeds( CustDS )
D  pCustNum                     05P 0 value
 *
D lds             DS                  likeds( CustDS )

The use of the LIKEDS keyword will set up storage for the return data that matches the target DS. Actually, I could just say return a 148-byte-character field (and the compiler won't complain), but I want to avoid any hard-coded values. I also use LIKEDS to define a local DS for working storage.

Then, within the body of the function, use the qualified naming format, dsl.subfield, when working with individual subfields in the DS. Whenever LIKEDS is used, you must use qualified naming to access subfields. Here's the body of the function:

C     pCustNum      Chain     cfmt
C                   If        %found
C                   Eval      lds.CustNum   = CustomerNo
C                   Eval      lds.Name      = %trim(FName) + ' ' +
C                                             %trim(MidInit) + ' ' +
C                                             %trim(LName) + ' '
C                   Eval      lds.Addr      = address1
C                   Eval      lds.CityStZip = %trim(city)  + ', ' +
C                                             %trim(state) + '  ' +
C                                             %trim(zipcode)
C                   Eval      lds.CurBal    = Balance
C                   Eval      lds.CredBal   = Credit - Balance
C                   Else
C                   Eval      lds.CustNum   = *zeros
C                   Endif

Last, the RETURN statement simply brings back the entire DS:

C                   Return    ( lds )                          
P getCustDS       E                                                      

Whichever way you prefer, both methods allow you to bundle complex data in a structure and to simplify the use of subprocedures.


Steven Gray is a consultant with Paradigm Business Solutions, a Lawson and Microsoft business partner. Steven has worked with the AS/400 and iSeries (starting with the S/38) for over 16 years. E-mail: steven.gray@rcn.com


Sponsored By
GST

AIT Backup for iSeries

GST, Inc.
Phone: 866-478-4621 or 949-900-1090 (for sales x 300)
Web: http://www.gstinc.com
Email: sales@gstinc.com

---------------------------------------------------------------------

SUMMARY

Compact, modular and reliable backup solution at unbeatable prices

· Powerful 3lb drive in small form factor
· LCD module for backup effiency
· Capacity up to 260GB
· Speed up to 112GB/hour
· LVD, HVD, and fibre connectivity
· Starts at $2,000 USD

---------------------------------------------------------------------

THE BIG PICTURE

· A single AIT tape drive in external, modular, stackable enclosure.
· Capacity: AIT-3 100GB native (260 GB compressed).
· Speed: AIT-3 43GB/hour native (112GB/hour compressed).
· Single subsystem is field-upgradeable to dual drive subsystem.
· LCD display panel improves backup efficiency.
· Supports AIT-1, AIT-2 and AIT-3.
· Roadmap to AIT-4, AIT-5, AIT-6.
· AIT range: single drive to enterprise-wide libraries.
· Supports LVD and HVD SCSI connections directly.
· Supports Fibre Channel via our bridges and routers.

The Single AIT Tape Subsystem is part of GST's EntryDR™ family. Single AIT Tape Subsystems are housed in upgradeable modular enclosures. This subsystem delivers high-performance and high reliability at cost-effective pricing to meet basic backup needs for the small to medium range of servers.

Building-block modularity enables the Single AIT Tape Subsystem to be upgraded to GST's Dual AIT Tape Subsystem to strengthen disaster recovery protection. An LCD panel provides an advanced operator interface for visibility over the backup operation.

The Single AIT Tape Subsystem can backup IBM eServer family members: iSeries, pSeries and xSeries servers. They connect natively with LVD (low voltage differential) and HVD (high voltage differential) SCSI connections, and with Fibre Channel (FC) through our BridgeLink™ family of bridges and SanMatrix™ family of routers. Model overview.

GST's Single AIT Tape Subsystem is available in a variety of models. Each AIT technology (AIT-1, AIT-2, AIT-3) is available in two server-to-SCSI Adapter interfaces:

LOW VOLTAGE DIFFERENTIAL (LVD). Connectivity with eServer family. iSeries uses IBM SCSI Adapter feature code: FC 5702, 5705. pSeries and xSeries servers use a variety of LVD SCSI adapters.

HIGH VOLTAGE DIFFERENTIAL (HVD). Connectivity with eServer family. iSeries uses IBM SCSI Adapter feature code: FC 2729, 2749, 6501, 6534. pSeries and xSeries servers use a variety of HVD SCSI adapters.

AIT TECHNOLOGY

AIT tape technology has evolved through three generations: AIT-1, AIT-2 and AIT-3 and provides outstanding capacity and performance with a highly stable technology roadmap. AIT cartridges utilize Memory-in-Cassette (MIC) architecture providing rapid time-to-data and multiple load points for partitioning data.

Native cartridge capacities for AIT-1, AIT-2 and AIT-3 are 35GB, 50GB and 100GB (91GB, 130GB, 260GB compressed) with speeds of 14GB/hour, 22GB/hour and 43GB/hour (37GB/hour, 56GB/hour and 112GB/hour compressed). Scalability is planned to a 6th generation product with native capacity of 800GB (2TB compressed) and a speed of 345GB/hour (900GB/hour compressed). A 2-to-1 compression ratio is achieved with Adaptive Lossless Data Compression (ALDC) technology.

KEY BENEFITS

DUAL DRIVE UPGRADE - A second modular drive and controller can be added later to upgrade to a Dual AIT Tape Subsystem as backup needs evolve that require DR protection, fault tolerant backup or greater unattended backup capacity.

HARDWARE INVESTMENT PROTECTION - The modular design of the Single AIT Tape Subsystem protects user investment by permitting the original single drive unit to be retained unmodified as part of the upgraded Dual AIT Tape Subsystem.

SPACE SAVER - The small dimensions and weight of the modular configurations facilitate the optimum use of datacenter space.

MEDIA INVESTMENT PROTECTION - For IT sites with an investment in AIT-1 media and drives, the newer AIT-2 and AIT-3 technologies are backward-read compatible, and forward-read compatible to future generations.

SERVICEABILITY - Modularity of design permits individual drives to be easily replaced in building-block fashion by the user.

KEY FEATURES

STACKABLE ENCLOSURES - Individual modular enclosures enable each drive and the mirrored backup controller to be handled as separate building blocks; facilitates field upgrade from single to dual drives.

LCD DISPLAY PANEL - Multi-function LCD continuously displays drive and backup status.

CONVENIENT DRIVE INTERFACE - RS232 interface for updating firmware and optimizing drive performance.

SERVICE AND SUPPORT - A variety of support programs provide installation and onsite service; includes GST's Accelerated Ship Program (GASP) to get replacement units on the scene rapidly.

WARRANTY - Purchase price includes a built-in manufacturer's warranty of three years.

GST, Inc.
Phone: 866-478-4621 or 949-900-1090 (for sales x 300)
Web: http://www.gstinc.com
Email: sales@gstinc.com



Editors: Howard Arner, Joe Hertvik, Ted Holt, David Morris
Managing Editor: Shannon Pastore
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.


THIS ISSUE
SPONSORED BY:

inFORM Decisions
GST


BACK ISSUES

TABLE OF
CONTENTS

Views for Query/400!

Alternate Methods for Returning Data Structures from Subprocedures

Reader Feedback and Insights: Why People Ask Basic Questions



Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.