AZK RPG - Modular Programs using Service Program

  1. Bind-by-reference
    • CRTSRVPGM (bind) - creates *Srvpgm object
    • - There only one copy of the code, which is loaded at runtime and shared with other Pgms or Service Pgms
    • - Binder does NOT have to physically copy the subprocedure code into each program
  2. Procedures in Service Program
    • - are *Nomain module
    • - uses the *Export KW to be available to client program
    • - compiled using CRTRPGMOD command creating *Module object
    • - bind Service Program from
    •      - single module
    •           - using CRTPGM command
    •      - multiple module
    •           - using CRTSRVPGM command
    •           - CRTSRVPGM requires a list of modules to copy into *Srvpgm object (no parms for entry module)
  3. CRTRPGMOD
    - Create RPG Module

    • CRTRPGMOD MODULE(Lib_name/Module_name)
    •      SRCFILE(Lib_name/Source_File_name)
    •      SRCMBR(Source_Member_name)
  4. Create RPG Module command
    • CRTRPGMOD MODULE(Lib_name/Module_name)
    •      SRCFILE(Lib_name/Source_File_name)
    •      SRCMBR(Source_Member_name)
  5. CRTSRVPGM
    - Create Service Program

    • CRTSRVPGM SRVPGM(SRVPGM_name)
    •      MODULE(MOD_1 MOD_2...)
    •      EXPORT(*SRCFILE)
    •      SRCFILE(SRCF_name)
    •      SRCMBR(SRCM_name)
    •      BNDSRVPGM(SRVPGM_name)
    •      BNDDIR(BNDDIR_name)
    •      ACTGRP(Act_Grp_name)
    • .
    • MODULE(MOD_1 MOD_2...)
    •    - list of service Modules that are copied and bound together to create the service program object
    • .
    • EXPORT(*SRCFILE)
    •    - *SRCFILE
    •       - Binder Language source file member identified by the Source file (SRCFILE) and Source member (SRCMBR) parameters
    •    - *ALL
    •       - All data and procedures that are exported from the specified modules are also exported from the service program.
    • .
    • SRCFILE(SRCF_name)
    •    - Source File name containing the Binder Language source member
    •    - Default: QSRVSRC
    • .
    • SRCMBR(SRCM_name)
    •    - Binder Language source member name (contains signature with list of exported data and procedures)
    •    - Default: same name as SRVPGM
    • .
    • BNDSRVPGM(SRVPGM_name)
    •    - list of Service Programs that have procedures that your procedures refer to
    • .
    • BNDDIR(BNDDIR_name)
    •    - list of Binding Directories that contain reusable Modules and Service Programs that may not be explicitly listed w binder command
    • .
    • ACTGRP(Act_Grp_name)
    •    - determines which activation group a program is to use
    •    - Default: *CALLER
  6. Create Service Program command
    • CRTSRVPGM SRVPGM(SRVPGM_name)
    •      MODULE(MOD_1 MOD_2...)
    •      EXPORT(*SRCFILE)
    •      SRCFILE(SRCF_name)
    •      SRCMBR(SRCM_name)
    •      BNDSRVPGM(SRVPGM_name)
    •      BNDDIR(BNDDIR_name)
    •      ACTGRP(Act_Grp_name)
  7. CRTPGM and CRTSRVPGM have parameters that control the binding technique
    • CRTPGM and CRTSRVPGM
    •    - Both commands bind these components in order
    • .
    • 1) MODULE
    •      - list of service Modules
    •      - binds modules by copy
    • .
    • 2) BNDSRVPGM
    •      - list of Service Programs that have procedures that your procedures refer to
    •      - all object listed in BNDSRVPGM are bound by reference
    • .
    • 3) BNDDIR
    •      - Binding Directory
    •      - list of reusable Modules and Service Programs that may not be explicitly listed w binder command
    •      - binds *Module by copy
    •      - binds *Srvpgm by reference
    •      - Binder ignores all unnecessary binding directory entries to complete the binding process
    •      - however, if binder has modules that declare the same procedure name, system will give an error -
    • .
    • "Definition supplied multiple times for symbol 'CELSIUS'."
    • .
  8. RTVBNDSRC (WITH creating Service Program Signature)
    • - Retrieve Binder Source
    • - to create Binder Language Source Member...
    • .
    •    - specify Service Program which contains exported procedures that will be included into Binder Language Source Member
    • .
    • RTVBNDSRC SRVPGM(SRVPGM_name)
    •      SRCFILE(Source_File_name)
    •      SRCMBR(Source_Member_name) 
    •      MBROPT(*ADD/*REPLACE)
    • .
    • SRVPGM(SRVPGM_name)
    •      - Service Program Name
    • .
    • SRCFILE(Source_File_name)
    •      - Default - QSRVSRC
    • .
    • SRCMBR(Source_Member_name) 
    •      - Default - *DFT
    •           - name is taken from SRVPGM parm
    • .
    • MBROPT(*ADD/*REPLACE)
    •      - Default - *REPLACE
    •           - old version of Binder Language Source Member will be replaced with new
    •      - *ADD
    •           - SRVPGM_name language source member automatically created in QSRVSRC source file, including (Srv Pgm Signature) all exported procedures from Service Program
    • .
    • STRPGMEXP PGMLVL(*CURRENT) SIGNATURE(X'00000C3D3CF1')
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
    • .
    • - in this case we need only one Export Block and one Signature
    • - we can add new procedures to the end of the block and existing programs will still run
  9. Command to create Binder Language Source Member with SIGNATURE
    • - Retrieve Binder Source
    • .
    • RTVBNDSRC SRVPGM(SRVPGM_name)
    •      SRCFILE(Source_File_name)
    •      SRCMBR(Source_Member_name) 
    •      MBROPT(*ADD/*REPLACE)
    • .
    •    - specify Service Program which contains exported procedures that will be included into Binder Language Source Member
    •  .
    • STRPGMEXP PGMLVL(*CURRENT) SIGNATURE(X'00000C3D3CF1')
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
  10. Command to create Binder Language Source Member without SIGNATURE
    • - Retrieve Binder Source
    • .
    • RTVBNDSRC MODULE(MOD_1 MOD_2)
    •      SRCFILE(Source_File_name)
    •      SRCMBR(Source_Member_name) 
    •      MBROPT(*ADD/*REPLACE)
    • .
    •    - specify list of modules, with exported procedures that will be included into Binder Language Source Member
    • .
    • STRPGMEXP PGMLVL(*CURRENT)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
  11. RTVBNDSRC (WITHOUT creating Service Program Signature)
    • - Retrieve Binder Source
    • - to create Binder Language Source Member...
    • .
    •    - specify list of modules, with exported procedures that will be included into Binder Language Source Member
    • .
    • RTVBNDSRC MODULE(MOD_1 MOD_2)
    •      SRCFILE(Source_File_name)
    •      SRCMBR(Source_Member_name) 
    •      MBROPT(*ADD/*REPLACE)
    • .
    • MODULE(MOD_1 MOD_2)
    •      - list of modules with exported procedures that will be included into Binder Language Source Member
    •      - MOD_1 contains PROC_1
    •      - MOD_2 contains PROC_2
    • .
    • SRCFILE(Source_File_name)
    •      - Default - QSRVSRC
    • .
    • SRCMBR(Source_Member_name) 
    •      - Default - *DFT
    •           - name is taken from SRVPGM parm
    • .
    • MBROPT(*ADD/*REPLACE)
    •      - Default - *REPLACE
    •           - old version of Binder Language Source Member will be replaced with new
    •      - *ADD        
    •          - SRVPGM_name language source member automatically created in QSRVSRC source file, including (WITHOUT Srv Pgm Signature) all exported procedures from listed modules.
    • .
    • STRPGMEXP PGMLVL(*CURRENT)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
    • .
    • - to add new procedure we need 2 Export Blocks
    • .
    •    1) Current
    • STRPGMEXP PGMLVL(*CURRENT)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    •    EXPORT SYMBOL("PROC_3")
    • ENDPGMEXP
    • .
    •    2) Previous 
    • STRPGMEXP PGMLVL(*PRV)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
  12. Add PROC_3 to the Binder Language Source Member

    STRPGMEXP PGMLVL(*CURRENT)
       EXPORT SYMBOL("PROC_1")
       EXPORT SYMBOL("PROC_2")
    ENDPGMEXP
    • STRPGMEXP PGMLVL(*CURRENT)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    •    EXPORT SYMBOL("PROC_3")
    • ENDPGMEXP

    • STRPGMEXP PGMLVL(*PRV)
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    • ENDPGMEXP
  13. Add PROC_3 to the Binder Language Source Member

    STRPGMEXP PGMLVL(*CURRENT) SIGNATURE(X'00000C3D3CF1')
       EXPORT SYMBOL("PROC_1")
       EXPORT SYMBOL("PROC_2")
    ENDPGMEXP
    • STRPGMEXP PGMLVL(*CURRENT) SIGNATURE(X'00000C3D3CF1')
    •    EXPORT SYMBOL("PROC_1")
    •    EXPORT SYMBOL("PROC_2")
    •    EXPORT SYMBOL("PROC_3")
    • ENDPGMEXP
  14. Command to create Binding Directory
    • - Create Binding Directory
    • .
    • CRTBNDDIR BNDDIR(BNDDIR_name)
  15. CRTBNDDIR
    • - Create Binding Directory
    • .
    • CRTBNDDIR BNDDIR(BNDDIR_name)
  16. Command to add/remove Modules/SRVPGM's to/from Binding Directory
    • - Work with Binding Directory Entries
    • .
    • WRKBNDDIRE BNDDIR(BNDDIR_SRV)
    • .
    •         BNDDIR_SRV
    • MODAFTAX *MODULE *LIBL
    • MODBFTAX *MODULE *LIBL
  17. WRKBNDDIRE
    • - Work with Binding Directory Entries
    • - to add/remove Modules/SRVPGM's to/from Binding Directory
    • .
    • WRKBNDDIRE BNDDIR(BNDDIR_SRV)
    • .
    •         BNDDIR_SRV
    • MODAFTAX *MODULE *LIBL
    • MODBFTAX *MODULE *LIBL
  18. Activation parameter in CRTPGM command
    • - When we first activate an ILE program or service program, by default, all the service programs bound by reference are also activated
    • .
    • - We can choose to defer activation of a particular service program until the caller invokes one of the exported procedures (until it truly uses the service program)
    • .
    •      - when we specify
    •           - service program in the binder's BNDSRVPGM parameter -
    • .
    • CRTPGM PGM(ANATOLIYK/CALL_SRVP)
    •      MODULE(ANATOIYK/CALL_SRVP)
    •      BNDSRVPGM((ANATOLIYK/SRVPGM3 *DEFER))
    • .
    •           - or or list in the binding directory
    • .
    •      SRV_CEL      *MODULE   *LIBL        *DEFER
    • .
    •      - ... indicate *DEFER instead of *IMMED
    • .
    •    - that can offer a small performance improvement if pgm binds many service programs, but uses some of them
  19. Command to display lists the modules and service programs that make up the Program *Pgm
    • DSPPGM - Display Program
    • .
    • - DSPPGM PGM(CALL_SRVP) DETAIL(*MODULE *SRVPGM)
  20. DSPPGM
    • - Display Program
    • - lists the modules and service programs that make up the program
    • .
    • DSPPGM PGM(CALL_SRVP) DETAIL(*MODULE *SRVPGM)
  21. Command to display lists the modules and service programs that make up the Service Program *Srvpgm
    • DSPSRVPGM - Display Service Program
    • .
    • DSPSRVPGM SRVPGM(SRVPGM3) DETAIL(*MODULE *SRVPGM)
  22. DSPSRVPGM
    • - Display Service Program
    • - shows the modules and service programs
    • - to view the Service Program used by client w their signatures
    • .
    • DSPSRVPGM SRVPGM(SRVPGM3) DETAIL(*MODULE *SRVPGM)
  23. Command that lets you to list just the modules(s) that you want to replace w the new update modules w/i Service Program
    • UPDSRVPGM
    • .
    • - same as CRTSRCPGM except that it replaces only the changed modules
  24. UPDSRVPGM
    • - lets you list just the module(s) that you want to replace w the new updated module w/i Service Program
    • - same as CRTSRCPGM except that it replaces only the changed modules
  25. Service Program Signature
    • - service program attributes that identifies its external interface
    • - is a property that is stored w the service program
    • - it's identity is usually a SYSTEM-GENERATED STRING
    • - at run-time client pgm checks if signature in client and Srvpgm match
    • - if signature DOES NOT match, program fails to load
    • .
    • - If changes to a service program do not affect it's Program Signature
    •      - the programs that use that service program require NO ACTION to reflect the change
    • .
    • SrvPgm can retain (remember) many previous signatures reperesenting many differemt interfaces
    • .
    • - External Interface of Service Program
    •      - list of exported procedures (and data items) pgm contains
  26. Why we need Service Program Signature (example)
    • - Let say SrvPgm WWWRPG contains only 4 procedures and many client programs using those procedures
    • .
    • WWWDECODE
    • WWWDUMP
    • WWWECHO
    • WWWECSTRACT
    • .
    • At socme point, 3 procedures where added
    • .
    • WWWGETDOC
    • WWGETENV
    • WWWGETIFS
    • .
    • We have to
    •    1) Code those procedures in additional Nomain modules
    •    2) Bind them to the WWWRPG SrvPgm
    •    3) Rebind all existing client programs that use WWWRPG SrvPgm
    • .
    • To avoid step 3 this SrcPgm needs to have 2 signatures
    •    1) Current signature would support all 7 exported procedures
    •    2) Older signature would support only original 4 procedures
    • .
    • To enable this scenario ILE allows you to manage the the Binder Language
  27. Binder Language
    • - special commands to describe Service Program's external interface
    • - using editor we can enter those command in source member of type BND
    • - when you create Service Program refer to that source member
  28. Binder Language Commands
    • 1) STRPGMEXP PGMLVL(*CURRENT/*PRV)
    •      - Start Program Export List
    • .
    • 2) EXPORT SYMBOL(Proc_name)
    •      - Export Block
    •      - Export a Program Symbols 
    •           - list of procedures to include in signature
    •           - procedures must be created w 'Export' kw
    • .
    • 3) ENDPGMEXP
    •      - End Program Export List
  29. Does order of the Procedures in the Export Block affect the signature?
    • - order in the Export Block affects the signature
    • - you should not change the order after SrvPgm is created
    • - procedures from Export Block must be created in ILE RPG w Export k/w
    • - if procedure nane is case sensetive, inclose name b/w apostrophies ( ' )
  30. Create new source member named WWWRPG with 3 procedures
    • - Binder Source member name is usualy the same as Service Program
    • .
    • STRPGMEXP PGMLVL(*CURRENT)
    •    EXPORT SYMBOL(PROC_1)
    •    EXPORT SYMBOL(PROC_2)  
    •    EXPORT SYMBOL(PROC_3)
    • ENDPGMEXP
    • .
    • - PGMLVL(*Current)
    •    specifies that signature is to be current signature
  31. How to use Binder Source?
    • - Binder Source cannot be compiled, but MUST be refered in CRTSRVRPG command
    • .
    • CRTSRVPGM SRVPGM(ANATOLIYK/SRVPGM3)
    •    MODULE(WWWDECODE WWWDUMP WWWECHO WWWECSTRACT)
    •    EXPORT(*SRCFILE)
    •    SRCFILE(QSRVSRC)
    •    SRCMBR(SRVPGM3)
    • .
    • EXPORT(*SRCFILE)
    •    - *SRCFILE
    •       - Binder Language source file member identified by the Source file (SRCFILE) and Source member (SRCMBR) parameters
    •    - *ALL
    •       - All data and procedures that are exported from the specified modules are also exported from the service program.
    • .
    • SRCFILE(SRCF_name)
    •    - Source File name containing the Binder Language source member
    •    - Default: QSRVSRC
    • .
    • SRCMBR(SRCM_name)
    •    - Binder Language source member name (contains signature with list of exported data and procedures)
    •    - Default: same name as SRVPGM
  32. When we bind service program to a client program what happened to signature on a client site?
    • When we bind service program SRVPGM3 to a client program CALL_SRVP...
    • .
    • CRTPGM PGM(ANATOLIY/CALL_SRVP)
    •    MODULE(ANATOLIY/CALL_SRVP)
    •    BNDSRVPGM(ANATOLIYK/SRVPGM3)
    • .
    • - ... client also stores current signature (their signatures must match)
  33. If we do not want to support a previous signature
    • - simply remove the entire signature from the binder language
    • - update Srv Pgm usint UPDSRVPGM command
    • - any client that are still using removed signature will no longer run until they are rebound
  34. SIGNATURE Parameter in Binder Language
    • - we can explicitly name (max 16 chars) service program signature instead letting system automatically generate one
    • - in this case we need only one Export Block and one Signature
    • - we can add new procedures to the end of the block and existing programs will still run
    • .
    • STRPGMEXT PGMLVL(*CURRENT) SIGNATURE(WWWRPG)
    •    EXPORT SYMBOL (WWWDECODE)
    •    EXPORT SYMBOL (WWWDUMP)
    • ENDPGMEXP
  35. Superglobal definition
    • - EXPORT
    •    - defines a variable or DS available across modules 
    • - IMPORT
    •    - defines a variable that using data item allocated by exporting module
    • .
    •               Module PRIMARY
    • Dcl-s Mydata Packed(9:2) Export Inz(200);
    • .
    •               Module PROCA
    • Dcl-s Mydata Packed(9:2) Import;
    • .
    • - compile this 2 models and bind them into a program
    • - Module PRIMARY allocates and initialize the storage Mydata
    • - both modules use the same storage for Mydata with superglobal definition
  36. Activation Groups
    • - attribute of a job (subjob )
    • - subdivision of a job that ILE enlists (involves) to keep track of resources a program uses
    • .
    • Resources include
    •    - storage a program uses
    •    - error handling routines
    •    - temporary data management resources
    • .
    • - each job has its own activation groups
    • - w/i a job program can run its own activation group, independent from other programs in the same group
    • - is used to allows a job to create logical boundaries (borders) around applications in a job
    • - give a programmer a means to cleanup storage and close files related  to an application w/o affecting other applications in a job
  37. Activation Groups used by CTRPGM / CTRSRVPGM commands
    • 1) Default Activation Group 
    •      - CRTBNDRPG PGM(Pgm-name)...
    •             DFRACTGRP(*YES)
    •      - does NOT support modules, procedures or service programs
    • .
    • 2. User-named ILE Activation Group
    •      - CRTPGM PGM(pgm-name)...
    •             ACTGRP(ag-name) 
    •      - CRTSRVPGM PGM(pgm-name)...
    •             ACTGRP(ag-name)
    •      - remains active until job ends or until user explicitly reclaims it using RCLACTGRP command
    • .
    • 3) System Named Activation Group
    •      - CRTMGM PGM(pgm-name)
    •             ACTGRP(*NEW)
    •      - service program cannot use *NEW activation group
    •      - stays active while the program that uses it still in the call stack
    •      - allow program to call itself
    •      - DO NOT use *NEW activation group unless require RECURSIVE call
    • .
    • 4) Caller Activation Group
    •      - CRTSRVPGM PGM(pgm-name)
    •             ACTGRP(*CALLER) - Default
    •      - works especially for Service Program
    •      - *Caller can run in any activation group including Default
    •      - program runs in the same activation group as program that called it
  38. Default Activation Group (DAG)
    • - DFTACTGRP(*YES)
    • - DOES NOT support modules, procedures or service programs
    • - we can use it only with
    • .
    • CRTBNDRPG PGM(pgm-name)... DFTACTGRP(*YES)
    • .
    • - job includes 2 default groups
    •      1) used by operation system
    •      2) used by application program
    • .
    • - RPG/400 (RPGIII)
    •      - OPM - Original Program Module
    •           - does NOT support modules, procedures of Srv Pgms
    •           - has no option, but to run in Default Activation Group
    • .
    • - ILE RPG
    •      - supports modules, procedures of Srv Pgms
    •      - can run in DAG
    •      - but should not (otherwise it will not support modules, procedures or Srv Prms)
  39. User-named ILE Activation Group
    • - CRTPGM PGM(pgm-name) ... ACTGRP(ag-name)
    • - CRTSRVPGM PGM(pgm-name) ... ACTGRP(ag-name)
    • .
    • - is genuine (real) ILE RPG activation group
    • - many IBM commands using QILE name
    • - created by a job when first program that is to use that activation group starts
    • - remains active until job ends or until user explicitly reclaims it using RCLACTGRP command
  40. RCLACTGRP
    • - Reclaim Activation Group
    • - reclaims activation group that is not used by any program
  41. System-named (*NEW) Activation Group
    • - CRTPGM PGM(pgm-name) ... ACTGRP(*NEW)
    • .
    • - is genuine (real) ILE RPG activation group
    • - created whenever program is called and destroyed when program ends
    • - stays active while the program that uses it still in the call stack
    • - service program cannot use *NEW activation group
    • - allow program to call itself
    • - DO NOT use *NEW activation group unless your application require RECURSIVE call
  42. Caller Activation Group
    • CRTPGM PGM(pgm-name) ... ACTGRP(*CALLER)
    • CRTSRVPGM PGM(pgm-name) ... ACTGRP(*CALLER)
    • .
    • - works especially for Service Program
    • - program runs in the same activation group as program that called it
    • - no new activation group is created
    • - *Caller CAN run in any activation group including default
    • - appropriate for most single entry-point programs in application
    • - offers most flexibility by not imposing specific activation group
    • - it can be called from either default or any ILE activation group
  43. For most single entry-point programs in an application which Activation Group to use?
    ACTGRP(*CALLER)
  44. If initial program that starts application is an ILE program, which Activation Group to use?
    • - it should use a named activation group, called QILE
    • - QILE is the name IBM choose for most programs if we do not choose activation group
    • .
    • ACTGRP(QILE)
  45. If we do not choose an activation group?
    • Default
    • .
    • CRTPGM ... ACTGRP(*ENTMOD)
    • .
    • - binder examines the entry module of the program
    • - if module is RPGLE, binder assign QILE act group
  46. To update initial program to assign it to a different act group (Payables)
    UPDPGM ... ACTGRP(PAYABLES)
  47. Override Database File
    • OVRDBF
    •      - to redirect a file declaration to process a file...
    •         - in specific library
    •         - of another name
    •         - to specific file member
    •     - to change some other attributes of the file
    •     - all overrides are temporary
    •     - they affect only job or activation group in which are executed
  48. Override Database File structure
    • OVRDBF FILE(overridden-file-name)
    •      TOFILE(lib-name/file-name)
    •      MBR(member-name)
    •      SHARE(open-data-path-sharing-option)
    •      OVRSCOPE(override-scope)
    • .
    •     - FILE(overridden-file-name)
    •         - original file declared in the program
    • .
    •     - TOFILE(lib-name/file-name)
    •          - file that replacing the references of original file
    • .
    •     - MBR(member-name)
    •         - to process specific member instead of first
    • .
    •     - SHARE(*YES/*NO)
    •         - enables the program to share the File Open Data Path with other programs
    • .
    •     - OVRSCOPE(override-scope)
    •         - an extend of influence for the override
    •         - override is effective only for specific scope (3 options)
    • .
    •         1) OVRSCOPE(*ACTGRPDFN)
    •             - (default) determines scope of override automatically, based on act group of the program
    • .
    •         2) OVRSCOPE(*CALLLVL)
    •             - explicitly calls for call-stack-levl scoping of override
    • .
    •         3) OVRSCOPE(*JOB)
    •             - scopes override to entire job
    • .
    • DLTOVR - deletes override command
  49. OVRDBF SHARE(*YES)
    • - to permit several programs w/i a single job to share the same open data path to a file
    • - an Open Data Path has 'File Cursor' that points to the next record
    • - each file has only one Cursor that shared  b/w programs
    • - each program that share Data Path is responsible for positioning the Cursor
    • - each time control is back to called program, it suppose to reposition Cursor


    • OVRDBF FILE(CUSTOMRES)
    •      TOFILE(MYLIB/CUSTFILE)
    •      OVRSCOPE(*CALLLVL)
    •      SHARE(*YES)
    •      OPNSCOPE(*ACTGRPDFN)
  50. Command to permit several programs w/i a single job to share the same open data path to a file
    • OVRDBF FILE(CUSTOMRES)
    •      TOFILE(MYLIB/CUSTFILE)
    •      OVRSCOPE(*CALLLVL)
    •      SHARE(*YES)
    •      OPNSCOPE(*ACTGRPDFN)
  51. OPNSCOPE in OVRDBF
    • - lets to control the extent of influence of the shared Open Data Path
    • .
    • - *ACTGRPDFN
    •      - determines scope of override automatically, based on act
    • .
    • - *JOP
    •      - scopes override to entire job
    • .
    • OVRDBF FILE(CUSTOMRES)
    •      TOFILE(MYLIB/CUSTFILE)
    •      OVRSCOPE(*CALLLVL)
    •      SHARE(*YES)
    •      OPNSCOPE(*ACTGRPDFN)
  52. Service Program External Interface
    • - Exported Procedures
    • - Procedure's Parameters
    • - Return Value
  53. Service Program Attributes
    • Service Program Signature
    •    - service program attributes that identifies its external interface
    •    - those are the exported procedures (and data items) pgm contains
    • - is a property that is stored w the service program
    • - it's identity is usually a SYSTEM-GENERATED STRING
  54. Steps to create Service Program
    • 1) Create 2 *Nomain Source members
    •      1.1) MODAFTAX.RPGLE
    •             - to calculate After Tax Amount
    •             - contains Export Procedure 'AFTAXCALC'
    •      1.2) MODBFTAX.RPGLE
    •             - to calculate Before Tax Amount
    •             - contains Export Procedure 'BFTAXCALC'
    • .
    • 2) Create modules from those source members
    • .
    •      2.1) CRTRPGMOD MODULE(MODAFTAX)
    •                                 SRCFILE(ABOOK_TAX)
    •                                 SRCMBR(MODAFTAX)
    • .
    •      2.2) CRTRPGMOD MODULE(MODBFTAX)
    •                                 SRCFILE(ABOOK_TAX)
    •                                 SRCMBR(MODBFTAX)
    • .
    • 3) Create Service Program SRVPGMTAX *SRVPGM object binding modules MODAFTAX and MODBFTAX
    • .
    •      CRTSRVPGM PGM(SRVPGMTAX)
    •                         MODULE(MODAFTAX MODAFTAX)
    •                         EXPORT(*ALL)
    • .
    • 4) Create Binder Language Source Member
    • .
    •      RTVBNDSRC SRVPGM(SRVPGMTAX)
    •                         SRCFILE(QSRVSRC)
    •                         SRCMBR(SRVPGMTAX)
    • .
    •     - Automatically creates QSRVSRC Source File with SRVPGMTAX Source Member with Current Signature of SRVPGMTAX Secvice Program
    • .
    •      STRPGMEXP PGMLVL(*CURRENT)SIGNATURE(X'00000000FDD0')
    •         EXPORT SYMBOL("AFTAXCALC")
    •         EXPORT SYMBOL("BFTAXCALC")
    •      ENDPGMEXP
    • .
    • 5) Create Binding Directory BNDDIR_SRV - *BNDDIR object
    • .
    •      CRTBNDDIR BNDDIR(BNDDIR_SRV)
    • .
    • 6) Add MODAFTAX and MODBFTAX modules to BNDDIR_SRV
    • .
    •      WRKBNDDIRE BNDDIR(BNDDIR_SRV)
    • .
    •                 BNDDIR_SRV
    •      MODAFTAX *MODULE *LIBL
    •      MODBFTAX *MODULE *LIBL
    • .
    • 7) Recreate Service Program Program SRVPGMTAX using Binding Directory BNDDIR_SRV
    • .
    •      CRTSRVPGM PGM(SRVPGMTAX)
    •                         MODULE(MODAFTAX)
    •                         EXPORT(*SRCFILE)
    •                         BNDDIR(BNDDIR_SRV)
    • .
    • Done: Service Program SRVPGMTAX *SRVPGM object is created
  55. Steps to use Service Program by Client Program
    • 1) Create Binding Directory BNDDIR_TAX
    • .
    •      CRTBNDDIR BNDDIR(BNDDIR_TAX)
    • .
    • 2) Add SRVPGMTAX *SRVPGM to
    • BNDDIR_TAX
    • .    
    •      WRKBNDDIRE BNDDIR(BNDDIR_TAX)
    • .
    •                        BNDDIR_TAX
    •      SRVPGMTAX  *SRVPGM  *LIBL  *IMMED
    • .
    • 3) Add H specification to the PGMTAXSTAT.SQLRPGLE Client Program using Conditional Compiller Directives
    • .
    •    - /If Defined(*CRTBNDRPG)
    •       - begins in position 7 
    •    - H DftActGrp(*No) BndDir('BNDDIR_TAX')
    •       - begins in position 6
    • .
    •        /If Defined(*CRTBNDRPG)
    •      H DftActGrp(*No) BndDir('BNDDIR_TAX')
    •        /Endif
    • .
    •      This condition is defined only if your program is being compiled by the CRTBNDRPG command, which will create a program with DftActGrp(*No) and reference to BndDir('BNDDIR_TAX').
    • .
    • 4) Add code to your PGMTAXSTAT Client program to execute subprocedures specified in SRVPGMTAX *SRVPGM
    • .
    •      DS1 = AFtaxCalc(Z_STBFNUM:STSLRATE);
    •      DS1 = BFtaxCalc(Z_STBFNUM:STSLRATE);
    • .
    • 5) Compile PGMTAXSTAT.SQLRPGLE using Option 14
  56. Steps to Add a new module to existing SRVPGMTAX *SRVPGM
    • 1) Create new *Nomain Source member WNDSTATMOD.RPGLE
    •      - to display window w list of all states
    • .
    • 2) Create new module from that source members
    • .
    •      CRTRPGMOD MODULE(WNDSTATMOD)
    •                           SRCFILE(ABOOK_TAX)
    •                           SRCMBR(WNDSTATMOD)
    • .
    • 3) Add new WNDSTATMOD *MODULE to BNDDIR_SRV
    • .
    •      WRKBNDDIRE BNDDIR(BNDDIR_SRV)
    • .
    •                   BNDDIR_SRV
    •      MODAFTAX   *MODULE *LIBL
    •      MODBFTAX   *MODULE *LIBL
    •      WNDSTATMOD *MODULE *LIBL
    • .
    • 4) Add new WNDMOD procedure to SRVPGMTAX Binder Language Source Member
    • .
    •                      SRVPGMTAX
    •      STRPGMEXP PGMLVL(*CURRENT)SIGNATURE(X'00000000FDD0')
    •         EXPORT SYMBOL("AFTAXCALC")
    •         EXPORT SYMBOL("BFTAXCALC")
    •         EXPORT SYMBOL("WNDMOD")
    •      ENDPGMEXP
    • .
    • 5) Recreate SRVPGMTAX *SRVPGM using the same command
    • .
    •      CRTSRVPGM PGM(SRVPGMTAX)
    •                         MODULE(MODAFTAX)
    •                         EXPORT(*SRCFILE)
    •                         BNDDIR(BNDDIR_SRV)
    • .
    • 6) Add code to the Client program to execute new subprocedure that is added to SRVPGMTAX *SRVPGM
    • .
    •      Wndmod(Abbrev);
    •      DS1 = AFtaxCalc(Z_STBFNUM:STSLRATE);
    •      DS1 = BFtaxCalc(Z_STBFNUM:STSLRATE);
    • .
    • 7) Compile PGMTAXSTAT.SQLRPGLE using Option 14
Author
flashsmilenet
ID
341574
Card Set
AZK RPG - Modular Programs using Service Program
Description
AZK RPG - Modular Programs using Service Program
Updated