Hi

Ask question on - DataBase Concepts, IBM Mainframe DB2, DB2/UDB, DB2 Tools, SQL , DB2 programming with languages like COBOL, PL1.

Moderators: Kalicharan, Moderator Group

Post Reply
sekhar.k
Member
Posts: 7
Joined: Tue Oct 12, 2010 11:35 am

Hi

Post by sekhar.k » Wed Dec 29, 2010 2:42 pm

I am coding one cobol db2 program. I am trying to code dynamic sql. But I want to pass the field names also dynamically. Is there any possibility?
EX:
Select empno, empname, esal from emp where empno = 01;

But some times i want to take different filelds also other than empno, empname, esal.


Please help me on this.

Regards,
Sekhar

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Wed Dec 29, 2010 2:58 pm

do you mean column names?

records have fields
db2 rows have columns.

use the correct terminology and you will be able to easily find answers in the manuals.

Suggest you do some reading. Vsn8 and Vsn9 sql reference and appl/programmers manuals have good discussions about dynamic sql.
ibm developerworks have an endless supply of examples (you have to join, but it is free) http://www.ibm.com/developerworks
This is a link for ibmdeveloperworks searches http://www.ibm.com/developerworks/views ... =15&Go.y=9

You will also benefit from the DB2 on-Campus videos

The answer to your question is yes it can be done.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
Krishna
Site Admin
Posts: 1052
Joined: Fri Jan 27, 2006 7:50 am

Post by Krishna » Wed Dec 29, 2010 4:09 pm

You need to use dynamic sql to do that.
ie, use of EXEC SQL PREPARE, EXEC SQL EXECUTE or EXECUTE IMMEDIATE

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others