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


  • Subject: RE: Elementary... Procedure Question?
  • From: Buck Calabro <mcalabro@xxxxxxxxxxxx>
  • Date: Tue, 4 Jan 2000 17:56:30 -0500

Subprocedures are not the same as Auto-copy modules.
Defining a sub-procedure is a two-step process:
1) define the procedure prototype
2) define the procedure code (interface)

Here's an example of defining and using a simple sub-procedure:
Prototype:
D* Convert EBCDIC text to ASCII text        
D E2A             PR            50A         
D  E2AStrIn                     50A   Const 

use in calcs:
C                   Eval      NewUsrCmdX=E2A(NewUsrCmd)

Interface:
PE2A              B                                                 
D* Convert EBCDIC text to ASCII text                                
D E2A             PI            50A                                 
D  E2AStrIn                     50A   Const                         
                                                                    
D E2AStrOut       S                   Like(E2AStrIn)                
D E2AStrLen       S              5P 0                               
D E2ATable        S             10    Inz('QASCII')                 
                                                                    
C                   Eval      E2AStrLen=%len(E2AStrIn)              
C                   Eval      E2AStrOut=E2AStrIn                    
C                   CallP     QDCXLATE(E2AStrLen:E2AStrOut:E2ATable)
C                   Return    E2AStrOut                             
PE2A              E                                                 

Note that fields E2AStrOut, E2AStrLen and E2ATable are local to this
subprocedure; that means that you could have the same field names defined in
other procedures (or mainline) but they don't get reflected in THESE fields.

Most people would put the prototype in a /COPY module (so you don't have to
copy the code into every program that wants to use the sub-procedure.)

There's a whole new thought process that comes into play when you use
prototyped procedures - break your code into many tiny functions.  Make each
function completely independent of all the others, and of the mainline: use
parameters to send data into or extract data out of a procedure.  Once
you've written, debugged and tested a procedure, you can use it over and
over again knowing that the code works.

I hope this helps.  

Buck Calabro

> -----Original Message-----
> From: a b 
> Sent: Tuesday, January 04, 2000 4:17 PM
> To:   RPG400-L@midrange.com
> Subject:      Elementary... Procedure  Question?
> 
> I'm trying to learn how to use subprocedures and was
> wondering if someone could point me in the right
> direction?  
> 
> 
> For example... How do I compile a subprocedure... or
> do I need to compile it in order to use is it in an
> RPG program (e.g /copy misclib/source,mysource)? 
> 
> 
> 
> Any help would greatly be appreciated!
> 
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.