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



Hi Paul,

to call modules oder better procedures dynamically, you have to use
prototyping and procedure pointers.
In contrary to programs that are called dynamically, that means they aren't
activated before the CALL statement is executed, the procedures must exist
at compile time. The module object that contains the procedures or the
signature of the service program where the module is bound to are physically
embedded into the program object.

Here an example:
I have three procedures that convert a date into a character representation.

The first procedure converts to *EUR format, the second to *USA-Format and
the third to *JIS-Format.
You will see the prototypes for these functions
D CvtDateToEur    PR            10A   extproc('CVTDATEUR')

D   ParmDate                      D   const options(*NoPass)     
                                                                 
D CvtDateToUSA    PR            10A   extproc('CVTDATUSA')

D   ParmDate                      D   const options(*NoPass)     
                                                                 
D CvtDateToJIS    PR            10A   extproc('CVTDATJIS)

D   ParmDate                      D   const options(*NoPass) 

Here are the functions:
  ************************************************************
  * Converte Date into European Format                 
  ************************************************************
 P CvtDateToEur    B                   Export                 
 D CvtDateToEur    PI            10A                          
 D   ParmDate                      D   const options(*NoPass) 
  *-----------------------------------------------------------
  /Free                                                       
     If %Parms >= 1;                                          
        Return  %Char(ParmDate: *Eur);                        
     else;                                                    
        Return  %Char(%Date(): *Eur);                         
     EndIf;                                                   
  /End-Free                                                   
 P CvtDateToEur    E                                          
  ************************************************************
  * Convert Date into USA Format                          
  ************************************************************
 P CvtDateToUSA    B                   Export                     
D CvtDateToUSA    PI            10A                               
D   ParmDate                      D   const options(*NoPass)      
 *----------------------------------------------------------------
 /Free                                                            
    If %Parms >= 1;                                               
       Return  %Char(ParmDate: *USA);                             
    else;                                                         
       Return  %Char(%Date(): *USA);                              
    EndIf;                                                        
 /End-Free                                                        
P CvtDateToUSA    E                                               
 *****************************************************************
 * Convert Date into Japanese Format                       
 *****************************************************************
P CvtDateToJIS    B                   Export                      
D CvtDateToJIS    PI            10A                               
D   ParmDate                      D   const options(*NoPass)      
 *----------------------------------------------------------------
 /Free                                                            
    If %Parms >= 1;  
        Return  %Char(ParmDate: *JIS);                     
     else;                                                 
        Return  %Char(%Date(): *JIS);                      
     EndIf;                                                
  /End-Free                                                
P CvtDateToJIS    E 

Depending on the language or country you want to call one of these
functions.
To do this you need an additional prototype. Add the Keyword EXTPROC and
specify a procedure pointer variable instead of a procedure name.
A procedure pointer has the data type * and the key word PROCPTR.
The following example shows you the additional prototype and the definition
of the procedure pointer variable:

D CvtDate         PR            10A   ExtProc(MyProcPtr)      
D   ParmDate                      D   const options(*NoPass)  
                                                              
D MyProcPtr       S               *   ProcPtr                 

This prototype and procedure pointer must be embedded in the source where
you want to calle the functions "dynamically".
The next example shows you how to call these functions.
D ConstProcUSA    C                   const(%PAddr('CVTDATUSA'))

D ConstProcJIS    S               *   ProcPtr inz(%PAddr('CVTDATJIS'))

 /Free
   Select;                                       
   When Country   = 'DE ';                          
        MyProcPtr = %PAddr('CVTDATEUR');      
   When Country   = 'USA';                          
        MyProcPtr = ConstProcUSA;                
   When Country   = 'JPN';                          
        MyProcPtr = ConstProcJIS;                
   EndSL;                                        
                                              
   MyCharDate = CvtDate(MyDate);
 /End-Free     

I hope this helps!                

Birgitta                                  
                                             
Mit freundlichen Grüßen
 
i.A. Birgitta Hauser
 
LUNZER + PARTNER GMBH
Unternehmensberatung
Carl-Zeiss-Straße 1
63755 Alzenau
 
Tel:         + 49 6023 951-255
Fax:        + 49 6023 951-111
Internet.  www.lp-gmbh.com
              www.rpg-schulung.de
 


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.