Sunteți pe pagina 1din 4

For which reason might you create a subprogram within a procedure?

to bypass a pragma restriction


to bypass the CURRENT AUTHID restriction
to allow execution within a S! statement
to store a repeating bloc" o# co$e once without creating a separate construct
Explanation:
Subprograms allow you to create just one occurrence of a piece of code that must be
executed in different locations of a procedure.
Use subprograms when the code is only executed within the procedure. If the code is
executed from outside the procedure then the subprogram should be written as a pac!aged
or stand"alone procedure instead.
Example: #calc$comm is the subprogram%
&'E()E *' 'E+,(&E +'*&E-U'E update$employee
#.$emp$id I/ /U01E'%
IS
.$comm /U01E'2
+'*&E-U'E calc$comm
IS
.$total /U01E'2
1E3I/
SE,E&) SU0#ord.total%
I/)* .$total
F'*0 ordcustomer
45E'E ord.custid 6 customer.custid
(/- customer.repid 6 .$emp$id2
.$comm :6 .$total 7 .892
E/- calc$comm2
1E3I/
...
calc$comm2
...
calc$comm2
...
calc$comm2
E/-2
Examine this procedure:
&'E()E *' 'E+,(&E +'*&E-U'E find$seats$sold
#.$mo.ie$id I/ /U01E' -EF(U,) :; .$theater$id I/ /U01E'%
IS
.$seats$sold gross$receipt.seats$sold<)=+E2
1E3I/
SE,E&) seats$sold
I/)* .$seats$sold
F'*0 gross$receipt
45E'E mo.ie$id 6 .$mo.ie$id
(/- theater$id 6 .$theater$id2
E/-2
4hich command will successfully in.o!e this procedure in S>,7+lus?
E%ECUTE #in$&seats&sol$'
RUN #in$&seats&sol$ ()&theater&i$ *+ ,--. )&mo)ie&i$ *+ /01'
E%ECUTE #in$&seats&sol$ ()&theater&i$ *+ ,--. )&mo)ie&i$ *+ /01'
E%ECUTE #in$&seats&sol$ ()&theater&i$ 2* ,--. )&mo)ie&i$ 2* /01'
Explanation:
=ou can specify argument .alues using the positional or named method. )he named
method re?uires the use of the @6A@ operator to specify a .alue for each argument.
)he named method:
EBE&U)E find$seats$sold #.$theater$id 6A C99 .$mo.ie$id 6A :;%2
)he positional method:
EBE&U)E find$seats$sold #C99 :;%2
)he .alue of C99 is assigned to the first argument listed in the procedure header and :; is
assigned to the second argument.
)he U+-()E$E0+,*=EE procedure contains an algorithm that calculates an
employeeDs commission multiple times throughout the program. If a change is
made to the algorithm the change must be made multiple times. 5ow can this
procedure be modified to simplify the code and reduce duplicated code?
A$$ an algorithm exception han$ler3
Create a library containing the algorithm3
A$$ a local subprogram containing the algorithm3
Create multiple anonymous bloc"s containing the algorithm3
Explanation:
Subprograms allow you to create just one occurrence of a piece of code that must be
executed in different locations of a procedure.
Use local subprograms when the code is only executed within the procedure. If the code will
be executed from outside the procedure then the subprogram should be written as a
pac!aged or stand"alone procedure instead.
Example: #calc$comm is the subprogram%
&'E()E *' 'E+,(&E +'*&E-U'E update$employee
#.$emp$id I/ /U01E'%
IS
.$comm /U01E'2
+'*&E-U'E calc$comm
IS
.$total /U01E'2
1E3I/
SE,E&) SU0#ord.total%
I/)* .$total
F'*0 ordcustomer
45E'E ord.custid 6 customer.custid
(/- customer.repid 6 .$emp$id2
.$comm :6 .$total 7 .892
E/- calc$comm2
1E3I/
...
calc$comm2
...
calc$comm2
...
calc$comm2
E/-2
4hich type of construct should you create to solely perform an action without
returning a .alue?
)iew
#unction
proce$ure
pac"age$ #unction
Explanation:
+rocedures are usually created to perform an action without returning a .alue. +rocedures
can return a .alue using an *U) argument. Functions must return a .alue.
Examine this procedure:
&'E()E *' 'E+,(&E +'*&E-U'E find$seats$sold
#.$mo.ie$id I/ /U01E'%
IS
.$seats$sold gross$receipt.seats$sold<)=+E2
1E3I/
SE,E&) seats$sold
I/)* .$seats$sold
F'*0 gross$receipt
45E'E mo.ie$id 6 .$mo.ie$id2
E/-2
4hich command will successfully in.o!e this procedure in S>,7+lus?
RUN #in$&seats&sol$(/01'
E%ECUTE #in$&seats&sol$'
E%ECUTE #in$&seats&sol$ (/01'
#in$&seats&sol$ (4Ri)erplace Theater41'
Explanation:
Executing a procedure in S>,7+lus re?uires the EBE&U)E command. )his procedure has
one I/ argument. )herefore use this command:
EBE&U)E find$seats$sold #:;%2
4hen in.o!ing a procedure you can specify the arguments using the positional
method by listing the .alues in the order of the argument list. 4hich method
would you use to list .alues in an arbitrary order?
5I56
list
type
name$
Explanation:
=ou can specify argument .alues using the positional or named method. )he named
method re?uires the use of the @6A@ operator to specify a .alue for each argument and
allows for an arbitrary assignment of .alues.
)he named method:
EBE&U)E find$seats$sold #.$theater$id 6A C99 .$mo.ie$id 6A :;%2
)he positional method:
EBE&U)E find$seats$sold #C99 :;%2
)he .alue of C99 is assigned to the first argument listed in the procedure header and :; is
assigned to the second argument.

S-ar putea să vă placă și