|
>>But you are not constructing anything! True, but so what? We want it to work like that, so it should. -Bob -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Simon Coulter Sent: Friday, April 16, 2004 7:01 PM To: RPG programming on the AS400 / iSeries Subject: Re: *INZSR equivalent with NOMAIN On Saturday, April 17, 2004, at 04:32 AM, mwalter@xxxxxxxxxxxxxxx wrote: > It would be nice to have some sort of 'CONSTRUCTOR' for Service > Programs. On Saturday, April 17, 2004, at 04:52 AM, Bob Cozzi wrote: > And a Destructor as well! But you aren't constructing anything! Invoking a service program is not the same as creating a NEW object even if you think it is similar. What you are asking for is a function to be run automatically when a service program is invoked for the first time and a corresponding function to be invoked when the service program ends. Tracking first invocation is easy enough but there is no way to determine when a service program ends except by ending the activation group. It's not as if this is difficult to do. The tools already exist. Here is a module you can compile into a service program. It contains a constructor that is invoked 'automatically' on the first invocation. It also sets up a destructor which will be invoked automatically when the activation group ends. Although the producer must understand the magic it is hidden from the consumer thus providing the effect you desire. H NOMAIN /copy rpgleinc,leenv D function PR D parm1 10I 0 D parm2 100 D constructor PR N D destructor PR D actGrpMark LIKE(UINT4_) D reason LIKE(UINT4_) D resultCode LIKE(UINT4_) D userRtnCode LIKE(UINT4_) D constructed S N INZ(*OFF) P function B EXPORT D function PI D parm1 10I 0 D parm2 100 C IF NOT(constructed) C CALLP constructor C ENDIF * Do function stuff C 'Function' DSPLY C RETURN P function E P constructor B D constructor PI N * Do constructor stuff such as: * -- Open files * -- Allocate storage * -- etcetera * Register activation group exit C CALLP CEE4RAGE( %PADDR('DESTRUCTOR') : *OMIT ) C EVAL constructed = *ON C 'Constructor' DSPLY C RETURN constructed P constructor E P destructor B D destructor PI D actGrpMark LIKE(UINT4_) D reason LIKE(UINT4_) D resultCode LIKE(UINT4_) D userRtnCode LIKE(UINT4_) * Do destructor stuff * -- Close files * -- Clean up storage * -- etcetera C EVAL constructed = *OFF C 'Destructor' DSPLY C RETURN P destructor E Here is a trivial test program: D function PR D parm1 10I 0 D parm2 100 D p1 S 10I 0 D p2 S 100 C CALLP function( p1 : p2 ) C RETURN C SETON LR Compile both modules, create a service program from the first module using EXPORT(*ALL), create a program from the second module and bind it to the service program using ACTGRP(*NEW), then call the program. You'll see that the constructor is invoked when function() is called, and the destructor is invoked when the program ends. I don't see any need for compiler support to implement this all they will provide is the invocation mechanism. You still have to write the code to implement the so-called constructor and destructor. I see no practical difference between the above example and special *CONSTRUCTOR/*DESTRUCTOR procedures. Regards, Simon Coulter. --------------------------------------------------------------------- Arterial Software IBM Tower Level 3, 60 City Road Southgate Victoria 3006 Australia http://www.arterialsoftware.com +61 3 9421 5911 (Phone) +61 3 9428 3729 (Fax) --------------------------------------------------------------------- This message together with any attachment is intended for the use of the person to whom it is addressed and contains information that is privileged and confidential. If you are not the intended recipient, or the employee or agent responsible for its delivery to the intended recipient, you are hereby notified that any dissemination, distribution or copying of it is strictly prohibited. Please notify us if you have received it in error, and otherwise take all necessary steps to delete it from any transient or permanent storage device or medium and notify us by e-mail at "support@xxxxxxxxxxxxxxxxxxxx". Any views expressed in this e-mail and any files transmitted with it are those of the individual sender, except where the sender specifically states them to be the views of Arterial Software. Arterial Software does not represent or warrant that the attached files are free from computer viruses or other defects. The user assumes all responsibility for any loss or damage resulting directly or indirectly from the use of any attached files. ---------------------------------------------------------------------- _______________________________________________ This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options, visit: 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 http://archive.midrange.com/rpg400-l.
As an Amazon Associate we earn from qualifying purchases.
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.