Referencing objects defined in modules can be done from within a module or from outside of the module. The ability to reference objects defined in modules also depends on whether the objects in the module have been published or not.
You can reference module objects by 3-part, 2-part, or sometimes 1-part names. Resolution of name references is done deterministically and depends on the name reference and the context (within the module or outside the module) in which it is used.
Object resolution of 3-part name references
3-part name references are the most straightforward; they are of the form <SCHEMA-NAME>.<MODULE-NAME>.<OBJECT-NAME>. References of this type will always resolve to a unique module object.
CREATE MODULE schema.mod@
ALTER MODULE schema.mod
PUBLISH PROCEDURE proc1 (a integer)
BEGIN
END@
The following is an example of a CALL statement that references the procedure using a 3-part name reference:
CALL schema.mod.proc1@
// Assume that DB2 server has following package and procedure defined
CREATE OR REPLACE PACKAGE MyPackage IS
PROCEDURE MyProcedure(INOUT a INTEGER);
END;
CREATE OR REPLACE PACKAGE BODY MyPackage IS
PROCEDURE MyProcedure(INOUT a INTEGER) IS
a := a + 100;
END;
END;
// Embedded SQL C program snippet
EXEC SQL BEGIN DECLARE SECTION;
sqlint32 inout_val;
EXEC SQL END DECLARE SECTION;
EXEC SQL CALL MySchema.MyPackage.MyProcedure(:inout_val);
Object resolution of 2-part name references
2-part name references are of the form <MODULE-NAME>.<OBJECT-NAME>.
CREATE PROCEDURE S.proc1 (a integer)
BEGIN END@
CREATE MODULE schema.S@
ALTER MODULE schema.S
PUBLISH PROCEDURE proc1 (a integer)
BEGIN END@
CALL S.proc1(5)@ -- This reference resolves to procedure S.proc1()
ALTER MODULE schema.S
PUBLISH PROCEDURE proc2 (a integer)
BEGIN
CALL S.proc1(5) -- This reference resolves to procedure schema.S.proc1()
END@
CREATE MODULE schema.M@
ALTER MODULE schema.M
PUBLISH PROCEDURE proc1 (a integer)
BEGIN END@
CALL M.proc1(5)@ -- This reference resolves to procedure schema.M.proc1()
Object resolution of 1-part name references
1-part name references can be used for module objects only within the context of that module. Only an object within a module can reference another module object using a 1-part name reference.
CREATE PROCEDURE S.proc1 (a integer)
BEGIN
END@
CREATE MODULE schema.S@
ALTER MODULE schema.S
PUBLISH PROCEDURE proc1 (a integer)
BEGIN
END@
CALL proc1(5)@ -- will resolve to S.proc1()
ALTER MODULE schema.S
PUBLISH PROCEDURE proc2 (a integer)
BEGIN
CALL proc1(5) -- will resolve to schema.S.proc1()
END@
CREATE MODULE schema.M@
ALTER MODULE schema.M
PUBLISH PROCEDURE proc1 (a integer)
BEGIN
CALL proc1(5) -- will resolve to S.proc1()
-- (since no proc1() in module M)
END@