Facing problem with decimal values in table



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Facing problem with decimal values in table

Postby ananya1212 » Wed Aug 14, 2013 9:25 pm

Hi,

I'm developing a code wherein my table structure is as follows --

CREATE TABLE TRANSACTION(                                             
  TRANSID        CHAR(6)       NOT NULL,                               
  TRANSTIME      TIME          NOT NULL WITH DEFAULT,                   
  TRANSDATE      DATE          NOT NULL WITH DEFAULT,                   
  TRANSAMT       DECIMAL(10,2) NOT NULL,                               
  TRANSTYPE      CHAR(2)       CHECK(TRANSTYPE IN('DA','WA','AT')),     
  ACCOUNTNO      NUMERIC(12),                                         
  TOACCOUNTNO    NUMERIC(12),                                         
  CONSTRAINT TRANS_FKEY1 FOREIGN KEY(ACCOUNTNO) REFERENCES             
     ACCOUNTS(ACCOUNTNO),                                             
  CONSTRAINT TRANS_FKEY2 FOREIGN KEY(TOACCOUNTNO) REFERENCES           
     ACCOUNTS(ACCOUNTNO),                                             
  CONSTRAINT TRANS_PKEY PRIMARY KEY(TRANSID)                           
  )IN db1.ts1 ;

Now i m passing 2 values to the table as
Accountno and balance in jcl as

//SYSIN DD *                                                           
100000000001                                                           
0000005000                                                             
/*


Th value is not getting inserted in the table . Sql code error -310 is displayed.
Please help.

The pic clause of accountno and balance is declared in cobol pgm as

01  WS-ACCOUNTNO                PIC 9(12).                             
                                                                       
 01  WS-WITHDRAW                 PIC 9(8)V99.



Please let me know where m I going wrong. :(
ananya1212
 
Posts: 7
Joined: Wed Aug 14, 2013 9:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Facing problem with decimal values in table

Postby Akatsukami » Wed Aug 14, 2013 9:49 pm

Read the fine manual on SQLCODE = -310 and see if you can figure out from there (hint: read the "Programmer Response", several times if need be).
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Facing problem with decimal values in table

Postby NicC » Wed Aug 14, 2013 10:33 pm

Welcome to the forum. Please, when posting code or data, use the code tags. (I have done his for you this time.) You can search the forum to find out how to use them but if you use the full editor it should be pretty obvious - highlight the text to be coded and click the 'Code' button. The blue on black does not happen without you doing so. It also maintains spacing thus making your code much more readable.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Facing problem with decimal values in table

Postby ananya1212 » Wed Aug 14, 2013 11:30 pm

Thanks for the code tags NicC. I'm new to this forum.
Please can someone help me out with this problem...please..I need the solution asap :(
ananya1212
 
Posts: 7
Joined: Wed Aug 14, 2013 9:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Facing problem with decimal values in table

Postby ananya1212 » Wed Aug 14, 2013 11:40 pm

I just want someone to cross check if the value i'm oassing through JCL is correct as per the pic clause and table structure.
If not,what values should be passed.
ananya1212
 
Posts: 7
Joined: Wed Aug 14, 2013 9:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Facing problem with decimal values in table

Postby Robert Sample » Wed Aug 14, 2013 11:40 pm

I am not a DB2 person but it seems you have declared TRANSAMT as NOT NULL and yet you do not tell us what value you provided in your program for this variable. Since it is a DECIMAL value, perhaps the lack of a value would cause your SQL return code?
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Facing problem with decimal values in table

Postby ananya1212 » Wed Aug 14, 2013 11:47 pm

Hi.Thanks for your reply Robert .The table transaction contains various columns like (transid,transtime,transdate,transamt,transtype,accountno,toaccountno)

I am autogenerating the transid in my program. Transtime and trainsdate are set with default values. Toaccountno is set as null (through null value indicator concept)
Now I have to accept accountno and transamt through JCL and insert all these value in COBOL pgm.
This is the part where I'm getting this error.
Hope i have made myself clear.
:)
ananya1212
 
Posts: 7
Joined: Wed Aug 14, 2013 9:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Facing problem with decimal values in table

Postby Akatsukami » Wed Aug 14, 2013 11:54 pm

:roll: Ananya-chan, did you read that part of the documentation that said, "Ensure that all decimal variables or parameters contain valid System/370 packed decimal numbers"? What is the COBOL USAGE clause that corresponds to packed decimal?
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Facing problem with decimal values in table

Postby ananya1212 » Wed Aug 14, 2013 11:57 pm

is it COMP 1 ?
ananya1212
 
Posts: 7
Joined: Wed Aug 14, 2013 9:20 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Facing problem with decimal values in table

Postby Akatsukami » Thu Aug 15, 2013 12:18 am

Without wishing to be overly critical, Ananya-chan, I suggest that that answer means that you ought not to be listing COBOL as being among your skills.

No, a packed decimal variable will be defined USAGE COMP-3 in COBOL (COMP-1 is short floating-point). As your variables are not so defined, I opine that that is your problem. I recommend that you code something like:

01  WS-EXTERNAL-VARIABLES.
    05  WS-EXT-ACCOUNT-NO   PIC 9(12).
    05  WS-EXT-XACTION-AMT  PIC 9(8)V99.
01  WS-INTERNAL-VARIABLES.
    05  WS-INT-ACCOUNT-NO   PIC 9(12)    COMP-3.
    05  WS-INT-XACTION-AMT  PIC S9(8)V99 COMP-3  .
  :
  :
MOVE WS-EXT-ACCOUNT-NO  TO WS-INT-ACCOUNT-NO.
MOVE WS-EXT-XACTION-AMT TO WS-INT-XACTION-AMT.

and use the "internal" variables for your insert. There are other problems here, but they amount to poor design rather than outright error.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post