Forums >> Programming >> RPG Programming >>
Creating Our First Service Program




Posted:
bvstone

Creating Our First Service Program

 
Creating Our First Service Program

Now that we are comfortable with a simple module, lets look at it's big brother, the Service Program.

A service program can be created using a couple different ingredients, but the one thing that is required is a module.  An optional ingredient is Binder Language, but we'll touch on that later.  You can also include additional modules and or other service programs, but for now, lets look at creating a service program named F.MATH from our single module, also named F.MATH.

Creating a service program uses the Create Service Program (CRTSRVPGM) command.  On this command you can specify a list of modules, service programs, and/or a Binding Directory which is nothing more than a list of modules and/or service programs.  Our example will be quite simple though, since we are only interested in converting our F.MATH module into a service program:

CRTSRVPGM SRVPGM(ILESAMPLE/F.MATH) MODULE(ILESAMPLE/F.MATH) EXPORT(*ALL)

Examining our command we will so two obvious pieces.  First is the name of the service program we are creating (F.MATH), and second is the name of a module that the service program will be created from (F.MATH).

We will also see that we are specifying EXPORT(*ALL).  I'll be the first to say that in production using this is a no-no.  The "why" will make more sense when we get into Binding Directories, Binder Language and Signatures but for now it will service the purpose.  But please, do NOT use this keyword in production.

To understand why it's not a good idea, let's first examine what the EXPORT keyword does.

                      Create Service Program (CRTSRVPGM)      
          
Type choices, press Enter. 

Service program  . . . . . . . . > F.MATH        Name
  Library  . . . . . . . . . . . >   ILESAMPLE   Name, *CURLIB
Module . . . . . . . . . . . . . > F.MATH        Name, generic*, *SRVPGM, *ALL
  Library  . . . . . . . . . . . >   ILESAMPLE   Name, *LIBL, *CURLIB...
               + for more values                 
                                     *LIBL       
Export . . . . . . . . . . . . . > *ALL          *SRCFILE, *ALL
Export source file . . . . . . .   QSRVSRC       Name, QSRVSRC
  Library  . . . . . . . . . . .     *LIBL       Name, *LIBL, *CURLIB
Export source member . . . . . .   *SRVPGM       Name, *SRVPGM
Text 'description' . . . . . . .   *BLANK

We see that the EXPORT keyword accepts 2 values, *SRCFILE and *ALL.  What this does is tell the system which procedures we want to export to make available for use in our service program.  When we say *ALL this tells the system that each procedure coded with the EXPORT keyword (remember that?) will be exported.  So that means that for our service program the #math_getSumInt procedure will be exported and available in our F.MATH service program.

We can view the available procedures using the DSPSRVPGM command:

DSPSRVPGM SRVPGM(ILESAMPLE/F.MATH) DETAIL(*PROCEXP)

                      Display Service Program Information 
                                                                 Display 1 of 1 
 Service program  . . . . . . . . . . . . :   F.MATH     
   Library  . . . . . . . . . . . . . . . :     ILESAMPLE  
 Owner  . . . . . . . . . . . . . . . . . :   BVSTONE    
 Service program attribute  . . . . . . . :   RPGLE      
 Detail . . . . . . . . . . . . . . . . . :   *PROCEXP   

                               Procedure Exports: 

 Procedure Name                                                          ARGOPT 
 #MATH_GETSUMINT                                                         *NO    

Up next, we will look at using the *SRCFILE option and Binder Language for the EXPORT keyword on the CRTSRVPGM command.

 


Last edited 04/03/2015 at 07:44:52


Reply




Copyright 1983-2017 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).