472,371 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Passing parms to a C Stored Proc

Hi All,

I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the
IBM Stored Procedure guide (SG24-7083-00). The database calls to read and
update the database work fine...however, I can't seem to figure out how to
pass parms to the C Program. The compile, bind, and run using DB2BATCH all
work fine, however, when I attempt to access any values passed into the
program, they're not present.

Here's part of the JCL I'm using to run the proc:

//EMSDB2 EXEC PGM=DB2BATCH,DYNAMNBR=20
//STEPLIB DD DSN=DBMT.TEST.DSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
//SYSTSIN DD *
DSN SYSTEM(DBMS)
RUN PROGRAM(PTMFMBID) PLAN(PTMFMBID) PARMS('TEST') -
LIB('NGST.MCMILP2.DB2.LOADLIB' )
END
//*

In my C program (PTMFMBID), I'm attempting to access argv[1] (which I think
should be "TEST", based on the call above). This parm is simply not being
passed in.

My create proc statements look like this:

CREATE PROCEDURE TMFDBC.PTMFMBID
(
MAILBOXID VARCHAR(8) IN
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL WITH NULLS
....

Have I missed something?

Apr 20 '06 #1
6 2073
Paul M wrote:
Hi All,

I'm currently writing a z/OS DB2 Stored Proc in C, using an example from
the
IBM Stored Procedure guide (SG24-7083-00). The database calls to read and
update the database work fine...however, I can't seem to figure out how to
pass parms to the C Program. The compile, bind, and run using DB2BATCH
all work fine, however, when I attempt to access any values passed into
the program, they're not present.

Here's part of the JCL I'm using to run the proc:

//EMSDB2 EXEC PGM=DB2BATCH,DYNAMNBR=20
//STEPLIB DD DSN=DBMT.TEST.DSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
//SYSTSIN DD *
DSN SYSTEM(DBMS)
RUN PROGRAM(PTMFMBID) PLAN(PTMFMBID) PARMS('TEST') -
LIB('NGST.MCMILP2.DB2.LOADLIB' )
END
//*

In my C program (PTMFMBID), I'm attempting to access argv[1] (which I
think
should be "TEST", based on the call above). This parm is simply not being
passed in.

My create proc statements look like this:

CREATE PROCEDURE TMFDBC.PTMFMBID
(
MAILBOXID VARCHAR(8) IN
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL WITH NULLS
...


I don't know exactly how DB2 on z/OS handles this, but on DB2 for LUW you
have to
(1) create a function with some name of your choosing
(2) adhere to the protocol used by DB2 to pass the parameters to this
function

Step (2) is a bit more involved because it depends on the PARAMETER STYLE.
You are using GENERAL WITH NULLS and that means (on LUW) that each
parameter is passed separately via pointer and all the NULL indicators are
passed in a single array. You should really expect all those parameters,
otherwise you're stack is not properly aligned and you won't find the
correct variables and parameters. This could effectively lead to a stack
corruption.

Have a look at the PARAMETER STYLE and its influence on your platform.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 20 '06 #2
Hi Knut,

Thanks for your assistance and reply!

I recreated the Stored Proc definition without the "WITH NULLS" keywords
(ie. "PARAMETER STYLE GENERAL") hoping so simplify debugging this problem.
Unfortunately, I still got the same results - the C code does not receive
the parm I'm trying to pass in.

How does the variable used on the stor proc define...

CREATE PROCEDURE TMFDBC.PTMFMBID
(
INOUT MAILBOXID VARCHAR(8) CCSID EBCDIC
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL

....MAILBOXID, in this case, relate to the argv[] array in C?

I'm assuming that since I'm only specifying 1 parameter, I *should* be able
to reference it using argv[1]? (argv[0] being the program name by default).

This is making me crazy! I'm following the example in the Redbook, but I
can't get it to work!

Thanks again for your help with this.


"Knut Stolze" <st****@de.ibm.com> wrote in message
news:e2**********@lc03.rz.uni-jena.de...
Paul M wrote:
Hi All,

I'm currently writing a z/OS DB2 Stored Proc in C, using an example from
the
IBM Stored Procedure guide (SG24-7083-00). The database calls to read
and
update the database work fine...however, I can't seem to figure out how
to
pass parms to the C Program. The compile, bind, and run using DB2BATCH
all work fine, however, when I attempt to access any values passed into
the program, they're not present.

Here's part of the JCL I'm using to run the proc:

//EMSDB2 EXEC PGM=DB2BATCH,DYNAMNBR=20
//STEPLIB DD DSN=DBMT.TEST.DSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
//SYSTSIN DD *
DSN SYSTEM(DBMS)
RUN PROGRAM(PTMFMBID) PLAN(PTMFMBID) PARMS('TEST') -
LIB('NGST.MCMILP2.DB2.LOADLIB' )
END
//*

In my C program (PTMFMBID), I'm attempting to access argv[1] (which I
think
should be "TEST", based on the call above). This parm is simply not
being
passed in.

My create proc statements look like this:

CREATE PROCEDURE TMFDBC.PTMFMBID
(
MAILBOXID VARCHAR(8) IN
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL WITH NULLS
...


I don't know exactly how DB2 on z/OS handles this, but on DB2 for LUW you
have to
(1) create a function with some name of your choosing
(2) adhere to the protocol used by DB2 to pass the parameters to this
function

Step (2) is a bit more involved because it depends on the PARAMETER STYLE.
You are using GENERAL WITH NULLS and that means (on LUW) that each
parameter is passed separately via pointer and all the NULL indicators are
passed in a single array. You should really expect all those parameters,
otherwise you're stack is not properly aligned and you won't find the
correct variables and parameters. This could effectively lead to a stack
corruption.

Have a look at the PARAMETER STYLE and its influence on your platform.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany

Apr 20 '06 #3
Paul M wrote:
Hi Knut,

Thanks for your assistance and reply!

I recreated the Stored Proc definition without the "WITH NULLS" keywords
(ie. "PARAMETER STYLE GENERAL") hoping so simplify debugging this problem.
Unfortunately, I still got the same results - the C code does not receive
the parm I'm trying to pass in.

How does the variable used on the stor proc define...

CREATE PROCEDURE TMFDBC.PTMFMBID
(
INOUT MAILBOXID VARCHAR(8) CCSID EBCDIC
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL

...MAILBOXID, in this case, relate to the argv[] array in C?

I'm assuming that since I'm only specifying 1 parameter, I *should* be
able
to reference it using argv[1]? (argv[0] being the program name by
default).

This is making me crazy! I'm following the example in the Redbook, but I
can't get it to work!


First, check how DB2 for z/OS passes the parameters to a procedure. You
have probably some samples shipped with DB2. I'll I'm saying now refers to
DB2 for LUW.

A procedure declared as above would require the following C code:

int function(char *mailBoxId)
{
// ...
}

Note that the argc/argv stuff is only applicable to a "main" function in
C/C++. In particular, DB2 sends the parameters not in an array but rather
as separate parameters (or rather separate pointers to the parameters).

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Apr 20 '06 #4
In article <w7*******************@news20.bellglobal.com>,
no****@nospam.com says...
Hi All,

I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the
IBM Stored Procedure guide (SG24-7083-00). The database calls to read and
update the database work fine...however, I can't seem to figure out how to
pass parms to the C Program. The compile, bind, and run using DB2BATCH all
work fine, however, when I attempt to access any values passed into the
program, they're not present.

Here's part of the JCL I'm using to run the proc:

//EMSDB2 EXEC PGM=DB2BATCH,DYNAMNBR=20
//STEPLIB DD DSN=DBMT.TEST.DSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
//SYSTSIN DD *
DSN SYSTEM(DBMS)
RUN PROGRAM(PTMFMBID) PLAN(PTMFMBID) PARMS('TEST') -
LIB('NGST.MCMILP2.DB2.LOADLIB' )
END
//*

In my C program (PTMFMBID), I'm attempting to access argv[1] (which I think
should be "TEST", based on the call above). This parm is simply not being
passed in.

My create proc statements look like this:

CREATE PROCEDURE TMFDBC.PTMFMBID
(
MAILBOXID VARCHAR(8) IN
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL WITH NULLS
...

Have I missed something?


I downloaded these samples so I could understand what you're trying to
do. It looks like you missed one step. The samples don't show how to run
the stored procedure directly because the stored procedures are called
by the main C program (CAL*.SRC). You can run these programs with the
CAL*.JCL members. The EMP*.JCL contains the JCL to compile the stored
procedures (EMP*.SRC).

Hope this helps.

Kind regards, Gert
Apr 20 '06 #5
Thanks Knut!

I was able to get the Stored Proc working finally!

Thank you again for your assistance!

"Knut Stolze" <st****@de.ibm.com> wrote in message
news:e2**********@lc03.rz.uni-jena.de...
Paul M wrote:
Hi Knut,

Thanks for your assistance and reply!

I recreated the Stored Proc definition without the "WITH NULLS" keywords
(ie. "PARAMETER STYLE GENERAL") hoping so simplify debugging this problem. Unfortunately, I still got the same results - the C code does not receive the parm I'm trying to pass in.

How does the variable used on the stor proc define...

CREATE PROCEDURE TMFDBC.PTMFMBID
(
INOUT MAILBOXID VARCHAR(8) CCSID EBCDIC
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL

...MAILBOXID, in this case, relate to the argv[] array in C?

I'm assuming that since I'm only specifying 1 parameter, I *should* be
able
to reference it using argv[1]? (argv[0] being the program name by
default).

This is making me crazy! I'm following the example in the Redbook, but I can't get it to work!
First, check how DB2 for z/OS passes the parameters to a procedure. You
have probably some samples shipped with DB2. I'll I'm saying now refers

to DB2 for LUW.

A procedure declared as above would require the following C code:

int function(char *mailBoxId)
{
// ...
}

Note that the argc/argv stuff is only applicable to a "main" function in
C/C++. In particular, DB2 sends the parameters not in an array but rather
as separate parameters (or rather separate pointers to the parameters).

--
Knut Stolze
DB2 Information Integration Development
IBM Germany

Apr 24 '06 #6
Hi Gert,

Thank you for taking the time to help me with this. I took a closer look at
the examples and discovered where I had gone wrong.

The Stored Proc is now working and I'm back to being happy again!

Thanks again for your help!

"Gert van der Kooij" <no****@nl.invalid> wrote in message
news:MP************************@news.xs4all.nl...
In article <w7*******************@news20.bellglobal.com>,
no****@nospam.com says...
Hi All,

I'm currently writing a z/OS DB2 Stored Proc in C, using an example from the IBM Stored Procedure guide (SG24-7083-00). The database calls to read and update the database work fine...however, I can't seem to figure out how to pass parms to the C Program. The compile, bind, and run using DB2BATCH all work fine, however, when I attempt to access any values passed into the
program, they're not present.

Here's part of the JCL I'm using to run the proc:

//EMSDB2 EXEC PGM=DB2BATCH,DYNAMNBR=20
//STEPLIB DD DSN=DBMT.TEST.DSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSIN DD *
//SYSTSIN DD *
DSN SYSTEM(DBMS)
RUN PROGRAM(PTMFMBID) PLAN(PTMFMBID) PARMS('TEST') -
LIB('NGST.MCMILP2.DB2.LOADLIB' )
END
//*

In my C program (PTMFMBID), I'm attempting to access argv[1] (which I think should be "TEST", based on the call above). This parm is simply not being passed in.

My create proc statements look like this:

CREATE PROCEDURE TMFDBC.PTMFMBID
(
MAILBOXID VARCHAR(8) IN
)
EXTERNAL NAME PTMFMBID LANGUAGE C
PARAMETER STYLE GENERAL WITH NULLS
...

Have I missed something?


I downloaded these samples so I could understand what you're trying to
do. It looks like you missed one step. The samples don't show how to run
the stored procedure directly because the stored procedures are called
by the main C program (CAL*.SRC). You can run these programs with the
CAL*.JCL members. The EMP*.JCL contains the JCL to compile the stored
procedures (EMP*.SRC).

Hope this helps.

Kind regards, Gert

Apr 24 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
5
by: Phil Hellmuth | last post by:
I hope this is the correct forum for this issue. I'm trying to call a SQL stored procedure using parameters, but am running into problems. Here's pertinent SP code: CREATE PROCEDURE...
0
by: mirandacascade | last post by:
Questions toward the bottom of the post. Situation is this: 1) Access 97 2) SQL Server 2000 3) The Access app: a) sets up pass-thru query b) .SQL property of querydef is a string, the...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.