You are on page 1of 8

Main Procedure:(Program name is MAIN)---Option 15 to create Module

dprocb1 pr
da 2p 0
db 2p 0
dc 3p 0
dprocb2 pr
da 2p 0
db 2p 0
dc 3p 0
c dsply a 20
c dsply b 20
c z-add 0 c 30
c z-add 0 d 30
c callp procb1(a:b:c)
c c dsply
c callp procb2(a:b:d)
c d dsply
c seton lr

Sub Procedure1(Program name is ADD)--Option 15 to create Module


hnomain
dprocb1 pr
da 2p 0
db 2p 0
dc 3p 0
pprocb1 b export
dprocb1 pi
da1 2p 0
db1 2p 0
dc1 3p 0
c a1 add b1 c1
pprocb1 E

Sub Procedure2(Program name is SUB)--Option 15 to create Module


hnomain
dprocb2 pr
da1 2p 0
db1 2p 0
dc1 3p 0
pprocb2 b export
dprocb2 pi
da1 2p 0
db1 2p 0
dc1 3p 0
c a1 sub b1 c1
pprocb2 e
To Create a Program:
CRTPGM PGM(PGM1) MODULE(MAIN ADD SUB)

Binding Directory:(Collection of Modules or Service Programs)


All the subprocedures(Example ADD,SUB)I am going to bind with one name(example Binding1)
so hereafter while creating Program I am going to bind all the modules,Just I am going to use this
Binding1(Binding Directory name).

To Create a Binding Directory:

CRTBNDDIR BNDDIR(BINDING1)

To Add modules in this Binding Directory:


1.ADDBNDDIRE BNDDIR(BINDING1) OBJ((ADD *MODULE))
2.ADDBNDDIRE BNDDIR(BINDING1) OBJ((SUB *MODULE))

similarly u can add many modules to this Binding Birectory.

How to use this Binding Directory in Program:

CRTPGM PGM(PGM1) MODULE(MAIN) BNDDIR(BINDING1)

Service Program:(Collection of Modules)


In Normal Binding the Module and in use of Binding Directory,there is a problem if u change the
module...
Example:If u change the module means the programs which all using this module is also wants to
change....
It is very difficult to find whatall Programs using this module and update it using UPDPGM.
So in order to avoid this Service Programs is Created. Its also Not executable and it can be used in
CRTPGM and Binding Directory.

To Create Service Program:

CRTSRVPGM SRVPGM(SRVPGM1) MODULE(ADD SUB) EXPORT(*ALL)


Explanation:
EXPORT(*ALL)---is important becauz it automatically create one signature.
Based on this signature only the Program will fetch the Procedures(from ADD and SUB Module)
SIGNATURE------while creating service program itself it will create signature(Hexadecimal value
created based on procedures)Here u binded 2 modules(means 2 procedures)so based on these 2
procedures siganture will be created.If u r using 3 or many procedures means based on these
procedures signature will be created.
Example of signature is 0000000000000000000F0EEE00437647.
To see the signature:

DSPSRVPGM SRVPGM(SRVPGM1)

To update Service Program:


If any modules updated means U can update ur service Program using UPDSRVPGM.

How to use this service program in your Program:

CRTPGM PGM(PGM1) MODULE(MAIN) BNDSRVPGM(SRVPGM1)

So finally Our main aim to create a Main Procedures (Based on our requirements)and use the service
Program whenever its necessary.

Drawbacks in Using EXPORT(*ALL)While Creating Service Program:-


Consider Service Program is Created Using EXPORT(*ALL)with 3 procedures(Procedure name and
Module Name can be same) and its Binded in CRTPGM as PGM1,PGM2.....So many Programs is
using this Service Program...If I change the service program with one more Procedures(4
Procedures)means Then all the Programs(example may be 100 Pgms) have to be changed becauz its
referenced by old service program with old signature but not based on one more added Procedure new
signatureis created so for the same service Program 2 signature is created. So signature violation Error
will Occur.
In Order to avoid this Binder Language is Used.
In This Binder Language for Old 3 Procedures One Signature is created and for added 4 Procedures
One signature is Created. So whenever Service Program is Updated with additional Module we have to
modify only Binder Language as follows..
STRPGMEXP ------------Default Current Signature
EXPORT SYMBOL(PROCB1)
EXPORT SYMBOL(PROCB2)
EXPORT SYMBOL(PROCB3)
endpgmexp
STRPGMEXP PGMLVL(*PRV) ----Old Signature For Older Service program(means Signature will
be there based on theses 2 Procedures)
EXPORT SYMBOL(PROCB1)
EXPORT SYMBOL(PROCB2)
endpgmexp

ACTIVATION GROUP:
Is a memory allocation for the execution of job.It holds system Resources,variables,files open etc
All ILE Programs will run only in Activation Group.
While creating Program using F10,U can see the activation group.
3 types of Action Group:
1.*NEW
2.*CALLER
3.Named Activation Group(Default QILE is the named Activation Group)
Here is an simple example How the variables are reused if we use Activation Group:

*NEW
HDFTACTGRP(*NO) ACTGRP(*new)
dcounter s 10p 0 export
c eval counter=counter + 1
c counter dsply
c seton lr

Compile this Program using 14---becaus in H spec u specified Activation group.


Then call it The output is 1 Then call now the output is 1 and Then also 1 and goes on .....becauz each
time while execution its taking in new activation Group.

Named Activation Group:.


HDFTACTGRP(*NO) ACTGRP('JAGADESH')
dcounter s 10p 0 export
c eval counter=counter + 1
c counter dsply
c seton lr

Compile this Program using 14---becaus in H spec u specified Activation group.


Then call it The output is 1 Then call now the output is 2 and Then 3 and goes on .....becauz each time
while execution its taking in same activation Group (JAGADESH).

To clear the Activation group:


RCLACTGRP ACTGRP(JAGADESH)
or
SIGNOFF

*CALLER
Mostly this Activation Group can be used only for calling Program so that whatever called Program
uses Activation group....The calling program can also use the same activation Group.
The Advantage of using this is both can run in one activation group and varibales Reused,Open files
reuse etc.

COPYBOOK(Type is RPGLE,TXT or anytype)But if u use RPGLE means Its easier to expand)


some Important code,variable declaration,exfmt,Repeated code can be used in copybook.
It will expand at the time of compilation.
The main aim of copybook is to avoid writing repeated code in ur program.
Example:(name of the copybook is jaga)
C Z-ADD 5 A 20
C Z-ADD 6 B 20
C Z-ADD 0 C 20

Program:
C/COPY JAGADESH1/QUINNOX,JAGA
C EVAL C=A+B
C C DSPLY
C SETON LR

Here in this program I havent declared any variables...I used only copybook...Its expanded at the time
of compilation.

FREE-FORM SYNTAX:
Here no need of Factor1,Factor2,result etc As u like u can code..
and semicolon is mandatory...
Example:
fJaga if e disk USROPN
c
c/FREE
open jaga;
read jaga;
dsply eno;
/END-FREE ---------------------this is very important it should start from 8th line as /END-FREE
c* read jaga 55
c SETON LR

My Programs:
Compiled with opt-15 name:ADDPRC
Hnomain
daddprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
d*
paddprc b export
daddprc pi 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
d*
/free
res = num1 + num2;
return res;
eval *inlr = *on;
/end-free
p e

Name:SUBPRC compiled with opt-15


hnomain
dsubprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
psubprc b export
dsubprc pi 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
d*
/free
if num1 > num2;
res = num1 - num2;
else;
res = num2 - num1;
endif;
return res;
eval *inlr = *on;
/end-free
p e

Name: MULTPRC compiled with opt-15


hnomain
dmultprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
pmultprc b export
dmultprc pi 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
d*
/free
res = num1 * num2;
return res;
eval *inlr = *on;
/end-free
p e

Name: MOD1(main procedure) compiled with opt-15


h*
dnum1 s 2p 0
dnum2 s 2p 0
d*
dres s 4p 0
dentmod pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
daddprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
dsubprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
dmultprc pr 4p 0
d num1 2p 0
d num2 2p 0
d res 4p 0
p*entmod b
d*entmod pi 4p 0
d* num1 2p 0
d* num2 2p 0
d*res s 4p 0
d*res1 s 4p 0
d*res2 s 4p 0
d*
d*
c z-add 0 res 4 0
c z-add 0 res1 4 0
c z-add 0 res2 4 0
c*
c*
/free
eval num1 = 15;
eval num2 = 12;
callp addprc(num1:num2:res);
dsply res;
callp subprc(num1:num2:res1);
dsply res1;
callp multprc(num1:num2:res2);
dsply res2;
eval *inlr = *on;
/end-free

Create service program:CRTSRVPGM


Service program . . . . . . . . > CALCULATOR
Library . . . . . . . . . . . > X4128
Module . . . . . . . . . . . . . > ADDPRC
Library . . . . . . . . . . . > X4128
> SUBPRC
> X4128
+ for more values > MULTPRC
> X4128
Export . . . . . . . . . . . . . > *ALL
Export source file . . . . . . . > QRPGSRC
Library . . . . . . . . . . . > X4128
Export source member . . . . . . *SRVPGM
Text 'description' . . . . . . . *BLANK

Create program:CRTPGM
Program . . . . . . . . . . . . > CALC
Library . . . . . . . . . . . > X4128
Module . . . . . . . . . . . . . > MOD1
Library . . . . . . . . . . . > X4128
+ for more values
*LIBL
Text 'description' . . . . . . . *ENTMODTXT
Additional Parameter

Program entry procedure module > MOD1


Library . . . . . . . . . . . > X4128
Bind service program . . . . . . > CALCULATOR
Library . . . . . . . . . . . > X4128

You might also like