× 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.



> 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')



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.