MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamic SQl

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
ashutosh_agl3
Beginner


Joined: 14 Aug 2003
Posts: 28
Topics: 15

PostPosted: Mon Mar 22, 2004 7:08 am    Post subject: Dynamic SQl Reply with quote

How can we use dynamic sql in cobol.

I need to know how can we specify parameters to Fixed List SELECT class of dynamic sql.

eg:

SELECT <parm1>, <parm2> from <tablename> where <colname1> = :<Value1> and <colname2> = :<Value2>


<tablename>, <colname1>, <Value1>,<colname2> and <Value2> are the possible dynamic values which will be coming from somewhere else.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 22, 2004 7:30 am    Post subject: Reply with quote

Ashutosh,

This is a formal warning for your posting the same topic in more than 1 forum. Also you posted a similar question a few days back(Mar 17th) and did you go thru the responses? Did you even bother to read the manual listed by me? The link to your topic if you have forgotten.

http://www.mvsforums.com/helpboards/viewtopic.php?p=9285

Thanks

Kolusu

Ps: I have deleted your other post in application programming forum.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ashutosh_agl3
Beginner


Joined: 14 Aug 2003
Posts: 28
Topics: 15

PostPosted: Mon Mar 22, 2004 10:03 am    Post subject: Reply with quote

I had gone thru the link but it didnt solve the purpose as the link had a number of issues unresolved and the examples were not clear.

I am sorry if i violated any rules of the forum and will try to make sure that next time it wont happen.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 22, 2004 10:30 am    Post subject: Reply with quote

Ashutosh,

If you had gone thru the link provided you would have found this section(6.16) which explains in detail as to how to code Dynamic SQL for fixed-list SELECT statements

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ashutosh_agl3
Beginner


Joined: 14 Aug 2003
Posts: 28
Topics: 15

PostPosted: Mon Mar 22, 2004 10:49 am    Post subject: Reply with quote

the link does not describe how to supply PARAMETER MARKERS...most of the book i refered used some default characer like '?' to show the use of PARAMETER MARKER...but didnt actually specify how PARAMETER markers are specified so that one to one mapping can be done while supplying the values of parameters at time of OPEN.

eg:


SELECT <parm1>, <parm2> from <tablename> where <colname1> = ? and <colname2> = ?

open cursor using :value1 ,:value2

now how exactly the earlier dynamic query must be built so that value1 and value 2 are replaced at their appropriate place.
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Mar 22, 2004 11:38 am    Post subject: Reply with quote

Ashutosh,

You need to generate the sql statement to be used in the dynamic sql. Let us say you wanted this sql statement.

Code:

SELECT EMP_NO,
       EMP_NAME FROM EMPLOYEE WHERE EMP_NO = 1234 AND EMP_NAME = 'ASHUTOSH'


In your program you will declare a cursor as follows:
Code:

EXEC SQL DECLARE C1 CURSOR FOR W-DYNAM-SQL;

Now using string function in cobol you will prepare the statement W-DYNAM-SQL.

Code:


WORKING-STORAGE SECTION.                                 
                                                         
01 W-COL1               PIC X(18) VALUE 'EMP_NO'.         
01 W-COL2               PIC X(18) VALUE 'EMP_NAME'.       
01 W-TABLE-NAME         PIC X(18) VALUE 'EMPLOYEE'.       
01 W-COL1-VALUE         PIC 9(04) VALUE ZERO.             
01 W-COL2-VALUE         PIC X(50) VALUE SPACES.           
01 W-DYNAM-SQL.                                           
   05 W-SQL-LENGTH         PIC S9(4) COMP.               
   05 W-SQL-TEXT           PIC X(120) VALUE SPACE.       
                                                         
                                                         
PROCEDURE DIVISION.                                       
                                                         
     MOVE 1           TO W-SQL-LENGTH                     
     MOVE 1234        TO W-COL1-VALUE                     
     MOVE 'ASHUTOSH'  TO W-COL2-VALUE                     
                                                         
     STRING 'SELECT '              DELIMITED BY SIZE     
          W-COL1                   DELIMITED BY SPACE     
          ', '                     DELIMITED BY SIZE     
          W-COL2                   DELIMITED BY SPACE     
          ' FROM '                 DELIMITED BY SIZE     
          W-TABLE-NAME             DELIMITED BY SPACE     
          ' WHERE '                DELIMITED BY SIZE     
          W-COL1                   DELIMITED BY SPACE     
          ' = '                    DELIMITED BY SIZE     
          W-COL1-VALUE             DELIMITED BY SIZE     
          ' AND '                  DELIMITED BY SIZE     
          W-COL2                   DELIMITED BY SPACE     
          ' = '                    DELIMITED BY SIZE     
          QUOTE                    DELIMITED BY SIZE     
          W-COL2-VALUE             DELIMITED BY SPACE     
          QUOTE                    DELIMITED BY SIZE     
       INTO W-SQL-TEXT                                   
       POINTER W-SQL-LENGTH                               
     END-STRING.                                         




Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ashutosh_agl3
Beginner


Joined: 14 Aug 2003
Posts: 28
Topics: 15

PostPosted: Mon Mar 22, 2004 10:58 pm    Post subject: Reply with quote

this is exactly the way i have done...but i wanted to know how to use PARAMETER MARKERS whichhave been described in text but the usage is not clear.
Back to top
View user's profile Send private message Yahoo Messenger
Maton_Man
Beginner


Joined: 30 Jan 2004
Posts: 123
Topics: 0

PostPosted: Tue Mar 23, 2004 12:37 am    Post subject: Reply with quote

There is extensive discussion of parameter markers and their use in the DB2 Application Programming Guide (eg Look under topic 6.1.5.2.1 Using parameter markers) and in the DB2 SQL Reference (eg. Look under topic 5.74 PREPARE)

Basically they replace host variables in dynamic SQL, so where you would have:

Static SQL
SELECT EMP_NO FROM A.EMPTABLE WHERE EMP_NO = :EMP

...in dynamic SQL you would have...

SELECT EMP_NO FROM A.EMPTABLE WHERE EMP_NO = ?

You would supply the value for EMP_NO when you EXECUTE the statement.

Read the manuals I have pointed you to because there is too much to write about it here.
_________________
My opinions are exactly that.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group