Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CRTSRVPGM & CRTPGM Error

Status
Not open for further replies.

Skittle

ISP
Sep 10, 2002
1,528
US
I have just started using RPG to use *MODULE definitions of subprocedures for prototype parameter calls. I have successfully compiled modules ( CRTRPGMOD ) and used modules in a program ( CRTPGM ).

I have not been able to use the same modules via a service program for a call by reference.

The problem I get is when I try to CRTPGM using a service program that contans my modules. I get the following compile errors:-

Code:
CRTRPGMOD MODULE(MyLib/TEST01M1) 
          SRCFILE(MyLib/QRPGSRC) 
          DBGVIEW(*LIST)
CRTRPGMOD MODULE(MyLib/TEST01M2) 
          SRCFILE(MyLib/QRPGSRC) 
          DBGVIEW(*LIST)
CRTRPGMOD MODULE(MyLib/TEST01M3) 
          SRCFILE(MyLib/QRPGSRC) 
          DBGVIEW(*LIST)

CRTSRVPGM SRVPGM(MyLib/TESTSRV1) 
          MODULE(MyLib/TEST01M3 
                 MyLib/TEST01M1 
                 MyLib/TEST01M2) 
                 EXPORT (*ALL)                     

CRTPGM PGM(MyLib/TEST01) 
    MODULE(MyLib/TEST01M1 MyLib/TEST01M2) 
    ENTMOD(TEST01M1) 
    BNDSRVPGM (MyLib/TESTSRV1)

Definition supplied multiple times for symbol 'ADDNUMBERS'.
Definition supplied multiple times for symbol 'TEST01M1'.


AddNumbers is defined in TEST01M2.
TEST01M1 calls the TEST01M2 subprocedure ADDNUMBERS.

Any help would be appreciated.


TEST01M1
Code:
H DEBUG DATEDIT(*YMD)                                                  
D/COPY QRPGSRC,TEST01C1                                                
D W1Number1       S             13  3
D W1Number2       S             13  3
D W1String1       S             10      
D MyResult        S             13  3   
 /FREE                                                                 
  CALLP(E) AddNumbers(10:11:'          '); 
  W1Number1 = 30;           
  W1Number2 = 40;           
  W1String1 = 'XXX';
  MyResult = AddNumbers(W1Number1:W1Number2:W1String1);
 /END-FREE          
C                   SETON        LR

TEST01M2
Code:
H NOMAIN                                     
H DEBUG DATEDIT(*YMD)                        
D/COPY QRPGSRC,TEST01C1                      
 *                                           
 * Prototype Boundry Start ------------------
 *                                           
P AddNumbers      B                   EXPORT 
D                 PI            13  3        
D P1Number1                     13  3 VALUE  
D P1Number2                     13  3 VALUE  
D P1String1                     10    VALUE  
 *                                           
D M1Number1       S             13  3        
D M1Number2       S             13  3        
 /FREE                                       
       M1Number1 = P1Number1;                
       M1Number2 = P1Number2;                
       RETURN P1Number1 + P1Number2;         
 /END-FREE 
*                                                           
P AddNumbers     E                      
*                                       
* Prototype Boundry End   --------------
*

TEST01C1
Code:
  *                                           
  * Universal Prototype Definition            
 D AddNumbers      PR            13  3        
 D                               13  3 VALUE  
 D                               13  3 VALUE  
 D                               10    VALUE




Dazed and confused.

Remember.. 'Depression is just anger without enthusiasum'.
 
What you need to do is define conditions in your copy members, so they are not copied in more than once:

Code:
      /IF NOT DEFINED (Your_Function_DONT_COPY) 
      /DEFINE Your_Function_DONT_COPY           
     DYour_...                                      
     D Function        PR              N               
     D Parm1                         10A   Const       
     D Parm2                         10A   Const       
      /ENDIF

Do this for each function in your copy members (with a separate definition for each).

-- Francis
I'd like to change the world, but I can't find the source code.
 
Skittle,
1/ Why don't you give the same name to source file (TEST01C1) and prototype (AddNumbers), it's confusing ?
Give it the same name or store all the prototypes you need for your app in the same member then copy this member.

2/ Don't use QRPGLESRC to store your /COPY of Prototypes. Use QCOPYSRC or QCPYSRC if you prefer to be created if needed instead.

3/ Give names on your prototype def lines even if not required, it's better for future maintenance.

3/ The " PI " line is equivalent to the old *ENTRY PLIST" so you don't need the useless work fields M1Number1 and 2 in TEST01M2.

4/ If you include the modules in the service program, do not include them again in the user program and never use export(*ALL).

5/ Create a source file named QSRVSRC to be used for exported bind procedure :
Code:
CRTSRCPF Mylib/QSRVSRC TEXT('Bind Language ... ')

6/ Create a new "bind" member (source type "BND") named like the service program in the QSRVSRC source file that'll contain the names of exported procedures defined in the related service program
Code:
 /* ================================================== */     
 /* New exports MUST be added at the end.              */     
 /* Old exports MUST NEVER be removed from the list.   */     
 /* !!! The order MUST NEVER CHANGE !!!                */   
 /* !!! The signature MUST NEVER CHANGE and it         */ 
 /* should always be the name of the associated        */
 /* Service Program !!!                                */   
 /* ================================================== */     
 STRPGMEXP  PGMLVL(*CURRENT) LVLCHK(*YES) SIGNATURE('YourAppNameOrWhatever')   <-- Hint : never change the signature later !
 EXPORT SYMBOL(ADDNUMBERS)                                        
 ENDPGMEXP
- The subsequent exports if any must be added at the end and the exports order must never change. ( swear here :) )
- A "BND" member is never compiled.

7/ Compile the service program like below and never use EXPORT (*ALL) ( swear again ! )
Code:
CRTSRVPGM SRVPGM(MyLib/TESTSRV1)
          MODULE(MyLib/TEST01M3
                 MyLib/TEST01M1
                 MyLib/TEST01M2) 
          EXPORT(*SRCFILE)           
          SRCFILE(MyLib/QSRVSRC)
8/ Create a Bind Directory using
Code:
CRTBNDDIR MyLib/MYBNDDIR TEXT(...)

9/ Add the service program into via ADDBNDDIRE or WRKBNDDIR.
Code:
ADDBNDDIRE BNDDIR(MYLIB/MYBNDDIR) OBJ((MYLIB/TESTSRV1 *SRVPGM))

10/ Add the BNDDIR name on H spec of user program TEST01
Code:
H BNDDIR('MYBNDDIR')

11/ Just compile as usual with opt 14 (PDM) or WDSc (you don't need CRTPGM here) and you're done.




 
Hi,
you forgot to post the source from your 3rd module TEST01M3,
so I tried to cvreate the program only from 2 modules you posted.

You can create/link your main program from the modules so:

1. First create all modules:
Code:
Create modules:

CRTRPGMOD MODULE(mylib/TEST01M1) 
          SRCFILE(IBPDSRC/QRPGLESRC) 
          DBGVIEW(*SOURCE)

CRTRPGMOD MODULE(mylib/TEST01M2) 
          SRCFILE(IBPDSRC/QRPGLESRC) 
          DBGVIEW(*SOURCE)

2. create/link the ILE program:

You can create the ILE program at 2 ways:
2a. ILE program from the modules (without service program):
Code:
CRTPGM PGM(mylib/TEST01) 
       MODULE(mylib/TEST01M1 mylib/TEST01M2) 
       ENTMOD(mylib/TEST01M1)

2b. ILE program from the service program and the main module:
2b-1. create service program from the modules which contain procedures - in your case the procedure is in TEST01M2
Code:
CRTSRVPGM SRVPGM(mylib/TESTSRV1) 
          MODULE(mylib/TEST01M2) 
          EXPORT(*ALL) DETAIL(*BASIC)
2b-2. create the ILE program - link it from the main module
TEST01M1 and the service program
Code:
CRTPGM PGM(mylib/TEST01) 
       MODULE(mylib/TEST01M1) 
       BNDSRVPGM(mylib/TESTSRV1)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top