|
Nathan, Thanks for your input! I was thinking on this approach of multipying the data with one instance of the program and saving the data using dynamic storage allocation too. There are some details, I would change in your program (I would define the car DS in the /Copy with the prototypes and use LIKEDS and qualified names for the Car Properties), but that's not the issue of importance. I skipped this approach ta the point, I began tho think about composition. A car has a motor and a gearbox and some other complex components. A motor itself is composed from other complex objects and maybe 10 steps down their is a screw, wich is combined of elementar values. Stability of this approach is rather weak too (its not you, who is responsable for this, its ile). The Pointer to the car is located in the upper programm (the example), storage allocation is done in the car programm, if the amounts differ after a change of one of these programms we will get MCHCK conditions. What about the activation group aspect here? What's happening if the example runs in a diffrent activation group than the car programm? Now we have a pointer in the example activation group pointing to storage allocated in the car activation group, doesn't this get inconsistent if I would reclaim one of them? Controlling Heap Size might be another problem to solve. To avoid this, we can run car in the *CALLER Activation Group. Now it might happen, that there exist two instances of the car programm in diffrent Activation groups. Passing a car from one program to another the RCLACTGRP problem comes back. If we never reclaim Activation Groups the storage of the program grows and grows. I don't want to say, that you did not solve this problems, but it took you some time to do. And same question to you I asked to Phil: is this available as Open Source or Freeware, or has everybody to reevent the wheel and to write this stuff on his own? In java it would be available as Open Source, if java wouldn't have this capabilities already as base functinality. And at least the java code to use a car object is more easy and the compiler makes extensive type checks for you, even error conditions, that might occur are checked by the complier. That all will make the java code more readable and stable without any work of the programmer, than the rpg code could be made by a very experienced rpg programmer like you. Its not a comparison of programmers we need, its a comparison of compilers and runtime enironments we have to do in a mailing list like java400-l. writing in java, we don't need storage allocation by our own, we don't need prototypes, the declaration (call it PI) is enough, there are no /copy modules, that could differ. In java there is no binding of arrays of procedure pointers at compile times, there are many things rpg doesn't provide. You get this stuff all without paying, but not for free, you pay with runtime overhead, but IMHO today the power of CPUs is high enough by low costs to get the power this needs. Dieter On Freitag, 19. März 2004 21:50, Nathan M. Andelin wrote: > > The problem here is: you have no qualified naming > > for referencing methods and you can't have more > > than one instance of a rpg program. > > Dieter, > > The following program uses a "Car" class to save and retrieve car > properties. I've also included code to the *SRVPGM which defines the Car > class, and procedure prototypes included in both modules, if you'd like to > build and test this yourself. > > One instance of the *SRVPGM is used to create multiple instances of the Car > object. If you read the *SRVPGM code carefully, I think you'll see the > technique. > > HTH, > > Nathan. > > > ********************************************* > > Example: > program using "car" class > > ********************************************* > > *----------------------------------------------------------------- > > /COPY *LIBL/QRPGLESRC,CAR#1 > > *----------------------------------------------------------------- > > D car DS > D car_make 20A > D car_model 20A > D car_year 4S 0 > > *----------------------------------------------------------------- > > D car1 S * > D car2 S * > > *----------------------------------------------------------------- > * create two (2) instances of car object > > C Eval car1 = carNew > C Eval car2 = carNew > > *----------------------------------------------------------------- > * set car # 1 properties > > C Callp carSetInst(car1) > > C Callp carSetMake('Ford') > C Callp carSetModel('Taurus') > C Callp carSetYear(1996) > > *----------------------------------------------------------------- > * set car # 2 properties > > C Callp carSetInst(car2) > > C Callp carSetMake('Volkswagon') > C Callp carSetModel('Beetle') > C Callp carSetYear(1964) > > *----------------------------------------------------------------- > * get car # 1 properties > > C Callp carSetInst(car1) > > C Eval car_make = carGetMake > C Eval car_model = carGetModel > C Eval car_year = carGetYear > > *----------------------------------------------------------------- > * display car # 1 > > C car dsply > > *----------------------------------------------------------------- > * get car # 2 properties > > C Callp carSetInst(car2) > > C Eval car_make = carGetMake > C Eval car_model = carGetModel > C Eval car_year = carGetYear > > *----------------------------------------------------------------- > * display car # 2 > > C car dsply > > *----------------------------------------------------------------- > * destroy both cars > > C Callp carSetInst(car1) > C Callp carDestroy > C Callp carSetInst(car2) > C Callp carDestroy > > *----------------------------------------------------------------- > * end program > C Seton LR > C Return > > > ********************************************* > > Example: > *SRVPGM defining car class > > ********************************************* > > H NoMain > > * ---------------------------------------------------------------- > > /COPY *LIBL/QRPGLESRC,CAR#1 > > * ---------------------------------------------------------------- > > D car DS Based(carPtr) > D car_make 20A > D car_model 20A > D car_year 4S 0 > > D carSz C %Size(car) > > * ---------------------------------------------------------------- > > P carNew B Export > > * ---------------------------------------------------------------- > > D carNew PI * > > * ---------------------------------------------------------------- > > C Alloc carSz carPtr > > C Clear car > > C Return carPtr > > P carNew E > > * ---------------------------------------------------------------- > > P carSetInst B Export > > * ---------------------------------------------------------------- > > D carSetInst PI > D ptr * Value > > * ---------------------------------------------------------------- > > C Eval carPtr = ptr > > P carSetInst E > > * ---------------------------------------------------------------- > > P carSetMake B Export > > * ---------------------------------------------------------------- > > D carSetMake PI > D make 20A Const > > * ---------------------------------------------------------------- > > C Eval car_make = make > > P carSetMake E > > * ---------------------------------------------------------------- > > P carSetModel B Export > > * ---------------------------------------------------------------- > > D carSetModel PI > D model 20A Const > > * ---------------------------------------------------------------- > > C Eval car_model = model > > P carSetModel E > > * ---------------------------------------------------------------- > > P carSetYear B Export > > * ---------------------------------------------------------------- > > D carSetYear PI > D year 4S 0 Const > > * ---------------------------------------------------------------- > > C Eval car_year = year > > P carSetYear E > > * ---------------------------------------------------------------- > > P carGetMake B Export > > * ---------------------------------------------------------------- > > D carGetMake PI 20A > > * ---------------------------------------------------------------- > > C Return car_make > > P carGetMake E > > * ---------------------------------------------------------------- > > P carGetModel B Export > > * ---------------------------------------------------------------- > > D carGetModel PI 20A > > * ---------------------------------------------------------------- > > C Return car_model > > P carGetModel E > > * ---------------------------------------------------------------- > > P carGetYear B Export > > * ---------------------------------------------------------------- > > D carGetYear PI 4S 0 > > * ---------------------------------------------------------------- > > C Return car_year > > P carGetYear E > > * ---------------------------------------------------------------- > > P carDestroy B Export > > * ---------------------------------------------------------------- > > C Dealloc carPtr > > P carDestroy E > > ********************************************* > > Example: > Car procedure prototypes > > ********************************************* > > D carNew PR * ExtProc('carNew') > > D carSetInst PR ExtProc('carSetInst') > D inst * Value > > D carSetMake PR ExtProc('carSetMake') > D make 20A Const > > D carSetModel PR ExtProc('carSetModel') > D model 20A Const > > D carSetYear PR ExtProc('carSetYear') > D year 4S 0 Const > > D carGetMake PR 20A ExtProc('carGetMake') > > D carGetModel PR 20A ExtProc('carGetModel') > > D carGetYear PR 4S 0 ExtProc('carGetYear') > > D carDestroy PR ExtProc('carDestroy') > > > _______________________________________________ > This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) > mailing list To post a message email: JAVA400-L@xxxxxxxxxxxx > To subscribe, unsubscribe, or change list options, > visit: http://lists.midrange.com/mailman/listinfo/java400-l > or email: JAVA400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/java400-l. -- mfG Dieter Bender DV-Beratung Dieter Bender Wetzlarerstr. 25 35435 Wettenberg Tel. +49 641 9805855 Fax +49 641 9805856 www.bender-dv.de eMail dieter.bender@xxxxxxxxxxxx
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.