× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




On 31/05/2010, at 5:38 PM, David FOXWELL wrote:

I'm trying to imagine what the code would look like in RPG?

In i/o module, I hard code the equivalent of the client record to be returned to the caller :

D ClientDS_V1 DS QUALIFIED
D Field1

The client file gets changed, so I add a new version of this DS :

D ClientDS_V2 DS QUALIFIED
D Field1
D Field2

Yes. The I/O procedure will now have two data structures defined.

Caller :

CallP GetClient_V1 ( ClientDS : Error );

No, that's just ugly. What will things look like after the fifth or 27th version?

In the called procedure, each modification of the client file would mean duplication of the last version plus the modification. Or would it be called like this with the version as a parameter :

CallP GetClient_V1 ( ClientDS : version : Error ); If this way, how would you return the right DS?


This is better. You return the right structure by accepting a blob of space (i.e., big char variable with OPTIONS(*VARSIZE) to allow large chunks of space.

The caller provides the space, the size of the space, the format/ version of the structure, plus some sort of error field.

The I/O procedure loads the appropriate DS, based on the version/ format, internally and then copies from the DS to the caller's space for the lesser of the DS size or as much as the caller said they provided.

The caller can either define the DS as based and assign the address of the DS to the big variable, or can just pass the DS itself which, after all, is just a blob of (structured) space.

Examine any of the IBM APIs that return various structures for ideas. QUSRJOBI would be a good example.

Thus in the caller:

D GetClient PR
D rcvVar 32767 OPTIONS(*VARSIZE)
D rcvVarLen 10I 0 CONST
D version 10I 0 CONST
D selection ???? CONST
D error ????

D rcvVar S 1000
D clientData DS LIKEDS(clientData_V2) BASED(@clientData)
D client DS LIKEDS(clientSelection)

/free

// Populate client DS with selection criteria e.g., ID. name, number, etc.

GetClient( rcvVar : %SIZE(rcvVar) : CLIENT_DS_V2 : client : error );
@clientData = %ADDR(rcvVar);

// do stuff with Client DS


or alternatively

D clientData DS LIKEDS(clientData_V2)
D client DS LIKEDS(clientSelection)

/free

// Populate client DS with selection criteria e.g., ID. name, number, etc.

GetClient( clientData : %SIZE(clientData) : CLIENT_DS_V2 : client : error );

// do stuff with Client DS


In the I/O procedure:

D GetClient PI
D rcvVar 32767 OPTIONS(*VARSIZE)
D rcvVarLen 10I 0 CONST
D version 10I 0 CONST
D selection ???? CONST
D error ????

D clientDS_V1 DS LIKEDS(clientDS_V1) BASED(@clientDS)
D clientDS_V2 DS LIKEDS(clientDS_V2) BASED(@clientDS)
D clientSize S 10I 0
D length S 10I 0

/free
select;
when ( version = CLIENT_DS_V1 );
clientSize = %SIZE(clientDS_V1);
when ( version = CLIENT_DS_V2);
clientSize = %SIZE(clientDS_V2);
other;
// error condition
endsl;

@clientDS = %ALLOC( clientSize );

// read the desired record using selection information

select;
when ( version = CLIENT_DS_V1 );
// populate DS version 1
when ( version = CLIENT_DS_V2);
// populate DS version 2
endsl;

if ( rcvVarLen >= clientSize );
length = clientSize;
else;
length = rcvVarLen;

memcpy( %ADDR(rcvVar) : @clientDS : length );

dealloc(n) @clientDS;
return;
/end-free

Written in e-mail without testing so there may be syntax errors but you should get an idea of what's necessary. Actual code will vary according to your needs.



Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.