IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DB2 with C programming language


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
zanyzap4u

New User


Joined: 13 Dec 2008
Posts: 38
Location: Mexico City

PostPosted: Fri Apr 10, 2009 12:27 pm
Reply with quote

Hi all
I am trying to do a DB2 Select from a table in C language.But the job is abending with an error code

Code:

SELECT TXN_ID,PARAM_A,PARAM_B         
                    INTO  DCLMONITOR.TXN_ID,             
                     DCLMONITOR.PARAM_A.PARAM_A_data,     
                     DCLMONITOR.PARAM_A.PARAM_B_data     
                    FROM BMXSMG.MONITOR WHERE             
                    TXN_ID = :ws_record->ws_txn_id ; 
 


error code:

Code:

                                               
SQLCODE = -84;                                         
strcpy( SQLSTATE, "42612" ) ;     
CCN5256 (S) A parameter of type "char *" cannot be initialized with an expression of type "unsigned char Ý5¨" 
CCN6205 (I) The error occurred while converting to parameter 1 ofy(char *, const char *)".


Can you please assist?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Apr 10, 2009 12:46 pm
Reply with quote

Quote:
CCN5256 (S) A parameter of type "char *" cannot be initialized with an expression of type "unsigned char Ý5¨"


I would say that the message is self explanatory icon_biggrin.gif

quoting from the manual
( which You should have read before posting)
Quote:
CCN5256 A parameter of type "%2$s" cannot be initialized with an expression of type "%1$s".

Explanation: The type of the argument for the function does not match the type of the parameter.

In the message text:

"%2$s" is the parameter type. "%1$s" is the initialization expression type.

User Response: Change the type of the parameter to match the expected type.
Back to top
View user's profile Send private message
zanyzap4u

New User


Joined: 13 Dec 2008
Posts: 38
Location: Mexico City

PostPosted: Fri Apr 10, 2009 3:33 pm
Reply with quote

We have made some change to the code,but still facing same problem
Here is the sample code:


Code:

EXEC SQL                     
  SELECT PARAM_A,PARAM_B     
  INTO                       
  :ws_paramaa,               
  :ws_parambb                 
  FROM BMXSMG.MONITOR WHERE   
  TXN_ID =:ws_tran_id ;

where definitions for host variables are as:

Code:

EXEC SQL BEGIN DECLARE SECTION;
  char ws_tran_id<:5:>;         
  char ws_paramaa<:10:>;         
  char ws_parambb<:10:>;         
 EXEC SQL END DECLARE SECTION;

Declare table statement:

Code:

EXEC SQL DECLARE MONITOR TABLE                               
           ( TXN_ID                         CHAR(4) NOT NULL, 
             PARAM_A                        VARCHAR(10) NOT NUL
             PARAM_B                        VARCHAR(10) NOT NUL
           )               

and the compiler generated output:

Code:

334 | /***$$$                                           
335 |                  EXEC SQL                         
336 |                    SELECT PARAM_A,PARAM_B         
337 |                    INTO                           
338 |                    :ws_paramaa,                   
339 |                    :ws_parambb                     
340 |                    FROM BMXSMG.MONITOR WHERE       
341 |                    TXN_ID =:ws_tran_id             
342 | $$$***/                                           
343 |   SQLCODE = -84;                                   
344 |   strcpy( SQLSTATE, "42612" ) ;   
==========================¬     
"//'SYS09100.T150007.RA000.BMXSMGDB.SYSCIN.H01'", line 344.11: CCN5256 (S) A parameter of type "char *" cannot be initialized with nsigned char Ý5¨".
"//'SYS09100.T150007.RA000.BMXSMGDB.SYSCIN.H01'", line 344.11: CCN6205 (I) The  error occurred while converting to parameter 1 of "strcpy(char *, const char *)".


Can you please tell us whether there is something wrong in the SELECT statement or in declaration of variables?SQLCODE = -84 refers to UNACCEPTABLE SQL STATEMENT.What does that refer to in our case?Also,why is the strcpy generated?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 10, 2009 3:54 pm
Reply with quote

here is a link to the documentation
(to which you should have refered before posting this question)

publib.boulder.ibm.com/infocenter/db2luw/v9/topic/com.ibm.db2.udb.apdv.embed.doc/doc/c0005912.htm

then expand (on the left side) looking for
Declaration of fixed-length, null-terminated and variable-length character host variables in C and C++ embedded SQL applications
Back to top
View user's profile Send private message
zanyzap4u

New User


Joined: 13 Dec 2008
Posts: 38
Location: Mexico City

PostPosted: Fri Apr 10, 2009 5:00 pm
Reply with quote

Thank you dbzTHEdinosauer for the quick reply.. icon_smile.gif

That problem has got solved,after going through the link you had sent. But now the jcl is returning a new error code:

Code:

 
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 447.18: CCN5280 (S) The initializer is too long.
                                               
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 481.3: CCN5274 (S)The name lookup for "DSNHLI" did not find a declaration.


We found that the DSNHLI was included as the below by the precompiler

#pragma linkage (DSNHLI,OS)

portion of source:
Code:

EXEC SQL       
 INCLUDE SQLCA;
EXEC SQL       
 INCLUDE SQLDA;

 EXEC SQL BEGIN DECLARE SECTION;     
  struct tag                         
        {                             
          char ws_tran_id;           
          struct                     
          {                           
            short length_a;           
            char  ws_param_a;         
          } param_a;                 
          struct                     
          {                           
            short length_b;           
            char  ws_param_b;         
          } param_b;                 
        } record;                     
EXEC SQL END DECLARE SECTION;   

EXEC SQL                         
  SELECT TXN_ID,PARAM_A,PARAM_B 
  INTO :record                   
  FROM BMXSMG.MONITOR           
  WHERE TXN_ID = 'BMX1' ; 


compiler listing:

Code:

436 |          /*    EXEC SQL END DECLARE SECTION; */     
437 |                                                     
438 | /***$$$                                             
439 |                  EXEC SQL                           
440 |                    SELECT TXN_ID,PARAM_A,PARAM_B     
441 |                    INTO :record                     
442 |                    FROM BMXSMG.MONITOR               
443 |                    WHERE TXN_ID = 'BMX1'             
444 | $$$***/                                             
445 |   {                                                             
446 |   SQLPLIST SQLPLIST1 =                                         
447 |   {64, 1028, 30, "\x4D\x4F\x4E\x54\x4F\x52\x43\x32", 0, 0, 0, 0,
=================================¬                                             
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 447.18: CCN5280 (S) The initializer is too long.
          448 |    1, 0, 0, 0, 1208, 231, 143, 0, 0, 0, 0, 0};     
          449 |   SQLELTS_PTR SQLELTS_PTR1;                         
          450 |   struct                                           
          451 |      { char   SQLDAID??(8??);                       
          452 |        long   SQLDABC;                             
          453 |        short  SQLN;                                 
          454 |        short  SQLD;                                 
          455 |        char  SQLAVELT??( (sizeof(SQLELTS) * 2) ??);
          456 |      } SQLAVARS1;                                   
          457 |   SQLELTS_PTR1 = (SQLELTS *) &SQLAVARS1.SQLAVELT;             
          458 |   SQLELTS_PTR1->SQLTYPE = 452;                                 
          459 |   SQLELTS_PTR1->SQLLEN  = 1;                                   
          460 |   SQLELTS_PTR1->SQLADDR = (char *)                             
          461 |   &( record.ws_tran_id );                                     
          462 |   SQLELTS_PTR1->SQLIND  = NULL;                               
          463 |   SQLELTS_PTR1->SQLNAMLEN  = 0;                               
          464 |   SQLELTS_PTR1 = SQLELTS_PTR1 + 1;                             
          465 |   SQLELTS_PTR1->SQLTYPE = 320;                                 
          466 |   SQLELTS_PTR1->SQLLEN  = 2;                                   
          467 |   SQLELTS_PTR1->SQLADDR = (char *)                             
          468 |   &( record.param_b );                                         
          469 |   SQLELTS_PTR1->SQLIND  = NULL;                               
          470 |   SQLELTS_PTR1->SQLNAMLEN  = 0;                               
          471 |   strcpy(SQLAVARS1.SQLDAID, "\xE2\xD8\xD3\xC4\xC1\x40\x40\x08")
          472 |   SQLAVARS1.SQLDABC = 104;                                               
          473 |   SQLAVARS1.SQLN    = 2;                                 
          474 |   SQLAVARS1.SQLD    = 2;                                 
          475 |   SQLPLIST1.SQLAPARM = (char *) &SQLAVARS1.SQLDAID;     
          476 |   SQLPLIST1.SQLCODEP = (char *) &sqlca;                 
          477 |   SQLPLIST1.SQLTIMES??( 0 ??) = 0x1880;                 
          478 |   SQLPLIST1.SQLTIMES??( 1 ??) = 0x8367;                 
          479 |   SQLPLIST1.SQLTIMES??( 2 ??) = 0x19D5;                 
          480 |   SQLPLIST1.SQLTIMES??( 3 ??) = 0xFDA4;                 
          481 |   DSNHLI ( (unsigned int * ) &SQLPLIST1);               
==================¬                                                     
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 481.3: CCN5274 (S)The name lookup for "DSNHLI" did not find a declaration.


Thanks in advance..[/code]
Back to top
View user's profile Send private message
arkabag

New User


Joined: 10 Apr 2009
Posts: 3
Location: India

PostPosted: Mon Apr 13, 2009 11:27 am
Reply with quote

Hi,

I too am facing the same problem. I could figure out that he had defined the var char data type as char array. So I made the modification as:

Code:

EXEC SQL BEGIN DECLARE SECTION;       
 struct tag                           
       {                               
         char ws_tran_id<:4:>;       
         struct                       
         {                             
           short length_a;             
           char  ws_param_a<:10:>;   
         } param_a;                   
         struct                       
         {                             
           short length_b;             
           char  ws_param_b<:10:>;   
         } param_b;                   
       } record;
 


But it gives the same error:

1. The initializer is too long.
2. The name lookup for "DSNHLI" did not find a declaration.

Here is the detailed error listing:

Code:

436 |          /*    EXEC SQL END DECLARE SECTION; */     
437 |                                                     
438 | /***$$$                                             
439 |                  EXEC SQL                           
440 |                    SELECT TXN_ID,PARAM_A,PARAM_B     
441 |                    INTO :record                     
442 |                    FROM BMXSMG.MONITOR               
443 |                    WHERE TXN_ID = 'BMX1'             
444 | $$$***/                                             
445 |   {                                                             
446 |   SQLPLIST SQLPLIST1 =                                         
447 |   {64, 1028, 30, "\x4D\x4F\x4E\x54\x4F\x52\x43\x32", 0, 0, 0, 0,
=================================¬                                             
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 447.18: CCN5280 (S) The initializer is too long.
          448 |    1, 0, 0, 0, 1208, 231, 143, 0, 0, 0, 0, 0};     
          449 |   SQLELTS_PTR SQLELTS_PTR1;                         
          450 |   struct                                           
          451 |      { char   SQLDAID??(8??);                       
          452 |        long   SQLDABC;                             
          453 |        short  SQLN;                                 
          454 |        short  SQLD;                                 
          455 |        char  SQLAVELT??( (sizeof(SQLELTS) * 2) ??);
          456 |      } SQLAVARS1;                                   
          457 |   SQLELTS_PTR1 = (SQLELTS *) &SQLAVARS1.SQLAVELT;             
          458 |   SQLELTS_PTR1->SQLTYPE = 452;                                 
          459 |   SQLELTS_PTR1->SQLLEN  = 1;                                   
          460 |   SQLELTS_PTR1->SQLADDR = (char *)                             
          461 |   &( record.ws_tran_id );                                     
          462 |   SQLELTS_PTR1->SQLIND  = NULL;                               
          463 |   SQLELTS_PTR1->SQLNAMLEN  = 0;                               
          464 |   SQLELTS_PTR1 = SQLELTS_PTR1 + 1;                             
          465 |   SQLELTS_PTR1->SQLTYPE = 320;                                 
          466 |   SQLELTS_PTR1->SQLLEN  = 2;                                   
          467 |   SQLELTS_PTR1->SQLADDR = (char *)                             
          468 |   &( record.param_b );                                         
          469 |   SQLELTS_PTR1->SQLIND  = NULL;                               
          470 |   SQLELTS_PTR1->SQLNAMLEN  = 0;                               
          471 |   strcpy(SQLAVARS1.SQLDAID, "\xE2\xD8\xD3\xC4\xC1\x40\x40\x08")
          472 |   SQLAVARS1.SQLDABC = 104;                                               
          473 |   SQLAVARS1.SQLN    = 2;                                 
          474 |   SQLAVARS1.SQLD    = 2;                                 
          475 |   SQLPLIST1.SQLAPARM = (char *) &SQLAVARS1.SQLDAID;     
          476 |   SQLPLIST1.SQLCODEP = (char *) &sqlca;                 
          477 |   SQLPLIST1.SQLTIMES??( 0 ??) = 0x1880;                 
          478 |   SQLPLIST1.SQLTIMES??( 1 ??) = 0x8367;                 
          479 |   SQLPLIST1.SQLTIMES??( 2 ??) = 0x19D5;                 
          480 |   SQLPLIST1.SQLTIMES??( 3 ??) = 0xFDA4;                 
          481 |   DSNHLI ( (unsigned int * ) &SQLPLIST1);               
==================¬                                                     
"//'SYS09100.T164055.RA000.BMXSMGDB.SYSCIN.H01'", line 481.3: CCN5274 (S)The name lookup for "DSNHLI" did not find a declaration.


Thanks in advance.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Cobol-DB2 Programming - Better perfor... DB2 1
No new posts IMS DB using Natural Language IMS DB/DC 0
No new posts Learning about Systems Assembler prog... PL/I & Assembler 5
No new posts CICS file processing using applicatio... CICS 3
No new posts Usage of processor directive and firs... PL/I & Assembler 4
Search our Forums:

Back to Top