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 

question on C langauge

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


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Fri Aug 29, 2003 12:41 am    Post subject: question on C langauge Reply with quote

In a C pgm how do i define DB2 host variable say name of length 20.
In Db2 table name is defined as Char of length 20.
SO i tried char name[20] in C but it gives error saying undefined or unusable host varibale.

Let me know if you have answer
Back to top
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Fri Aug 29, 2003 2:52 am    Post subject: Reply with quote

DB2 adds 1 to all C char buffers for the NULL terminator (even if it's not a string). If you use the DCLGEN utility you should have no problems.
_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Fri Aug 29, 2003 8:30 am    Post subject: Reply with quote

Thanks you Dave,
But >
declgen created the name field as
char NAME 41Y; and when I compile, I get UNDEFINED OR UNUSABLE HOST VARIABLE "NAME". so I changed it to "char NAME;" it made to work fine. Since char is only 1 byte i am getting onyl the 1st character of name in NAME field.

How do i solve it. I cannot declare NAME as array, as DB2 will not know it.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Aug 29, 2003 12:01 pm    Post subject: Reply with quote

Naren,

How about defining like this ???


Code:

struct                               
  { char       NAME??(20??)


Hope this helps..

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Fri Aug 29, 2003 12:17 pm    Post subject: Reply with quote

Hurray! it works. but would request you to explain about it, and where can i find more on the same.
Thanks once again Kolusu Very Happy
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Fri Aug 29, 2003 2:27 pm    Post subject: Reply with quote

Naren,

I just ran DCLGEN in batch for one of my existing table.DCLGEN generates the approriate language declarations.

Code:

//STEP0100 EXEC PGM=IKJEFT01
//SYSTSPRT DD  SYSOUT=*                                   
//SYSTSIN  DD  *                                         
 DSN SYSTEM(XXX)                                 
 DCLGEN TABLE(TBLNAME)         -                           
        OWNER(TBL-OWNER)       -                           
        ACTION(REP)            -                           
        LANGUAGE(C)            -                           
        LIBRARY('YOUR.PDS(TBLINCL)') 
 END                                               
//*


check this link for a detailed explanation of options with examples of DCLGEN

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNCRH11/2.16?DT=20010723111607

check this link for a detailed explanation of Generating declarations for your tables using DCLGEN through DB2I

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DSNAPH11/2.3?DT=20010710165542
Hope this helps...

cheers

kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
naren_ab
Beginner


Joined: 07 Jan 2003
Posts: 32
Topics: 10

PostPosted: Fri Aug 29, 2003 3:00 pm    Post subject: Reply with quote

I have used spufi to create the DCLGEN. But where did you see this syntax
"char NAME??(20??) " what does "??" mean?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Sat Aug 30, 2003 7:49 am    Post subject: Reply with quote

Naren,

There is a seperate option for DCLGEN on DB2I panel. option 1 is spufi and option 2 is DCLGEN. once you run the dclgen initially you will see the table declaration and if you scroll down you will find the approriate language declarations below.The links posted above explains clearly the DCLGEN for both batch and interactive

Why dont you run the sample jcl I provided above and check out the include in your pds ??

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Mon Sep 01, 2003 3:45 am    Post subject: Reply with quote

??( is called a trigraph. The problem is the DB2 pre-compiler doesn't recognise the locale you are using (I think it uses 1047). I run a translation program before the DB2 precompile

Code:

//**********************************************************************
//*                                                                    *
//* Convert locale from 037 to 1047.                                   *
//*                                                                    *
//* The DB2 preprocessor does not recognize the z/OS C/C++ compiler's  *
//* diffent locales. Code must be in codepage 1047...                  *
//*                                                                    *
//**********************************************************************
//CONVERT  EXEC PGM=EDCICONV,REGION=6M,                                 
//             PARM=('FROMCODE(IBM-037),TOCODE(IBM-1047)')             
//SYSUT1   DD  DISP=SHR,DSN=DOC.USER.C(&MEM)                           
//SYSUT2   DD  DISP=SHR,DSN=DOC.USER.SOURCE(&MEM)                       
//SYSPRINT DD  SYSOUT=*                                                 
//SYSOUT   DD  SYSOUT=*                                                 
//SYSIN    DD  DUMMY                                                   
//*                                                                     

_________________
Dave Crayford
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming 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