DB2 - to add char fields having 450{ as one of its value

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
chandana
Member
Posts: 6
Joined: Mon Jun 21, 2010 2:50 pm

DB2 - to add char fields having 450{ as one of its value

Post by chandana » Mon Jun 21, 2010 3:07 pm

Hi,
Please let me know
how to add two fileds which are chars...
they may have the values as
premium1 = 0450{
premium2=0325{
the braces indicate positive or negative premium

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

Post by dbzTHEdinosauer » Mon Jun 21, 2010 4:03 pm

well,
first, where is the result to be 'stored'?
and second,
you need to cast the char columns to integer (or some numeric type) first.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

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

Post by dbzTHEdinosauer » Mon Jun 21, 2010 4:32 pm

as an after thought.

1. only idiots use char columns to contain numeric data that is intended for arithmetics.

2. you may end-up having to select both columns into host variables (pic x-type)
then use your programming language to place the data into numeric variables
and then perform the addition.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

chandana
Member
Posts: 6
Joined: Mon Jun 21, 2010 2:50 pm

Post by chandana » Mon Jun 21, 2010 5:21 pm

we have a field called pos_12_to_98 in the table which may have both digits and alphabets... we have to add the data in particular positions in which we have digits and braces... we know that we can use cast for datatype conversion..
the problem is how to add when we have braces in the value? Is there any way to convert braces to '+' or '-'
POS
12
TO
98
+---------------------
00000000010}000000
00000000010}000000

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

Post by dbzTHEdinosauer » Mon Jun 21, 2010 5:41 pm

well, the close brace means -0,
and the others are as follows:

Code: Select all

0	{	  
1	A 
2	B 
3	C 
4	D 
5	E 
6	F 
7	G 
8	H 
9	I 
-0	} 
-1	J 
-2	K 
-3	L 
-4	M 
-5	N 
-6	O 
-7	P 
-8	Q 
other values such as -104 would be stored as 10M.

and sure, there are all kinds of columnar functions that you could use to get the substr of the column
(db2 tables do not have fields)
into a usable format for arithmetics.

suggest you look at the manuals for your version of db2 and determine what you can do.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

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