Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

insertion of Packed decimal data into Db2 table from Java

 
RajaAmirapu Sekhar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Need help on storing packed decimal data into Db2 table from Java.

Our requirement is we need to store packed decimal data into Db2 table, which can be read successfully from Cobol program.

The structure of Db2 table is

01 Misc_info CHAR(256)
02 Drive_UpPACK(5,2)3 bytes
02 Tax_AmountPACK(7,2)4 bytes
02 Adj_DriveUpPACK(5,2)3 bytes

We are following the below specified steps to insert data into this table.

MainframeWriter mf = new MainframeWriter();

BigDecimal strDriveUp=new BigDecimal(strValue1);
strDriveUp=strDriveUp.setScale(2,BigDecimal.ROUND_HALF_UP);

BigDecimal strTaxAmount=new BigDecimal(strValue2);
strTaxAmount=strTaxAmount.setScale(2,BigDecimal.ROUND_HALF_UP);

BigDecimal strAdjDriveUp=new BigDecimal(strValue3);
strAdjDriveUp=strAdjDriveUp.setScale(2,BigDecimal.ROUND_HALF_UP);
mf.writePacked(strDriveUp,5,2,0);
mf.writePacked(strTaxAmount,7,2,0);
mf.writePacked(strAdjDriveUp,5,2,0);

byte[] buffer = mf.toByteArray();

ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(buffer, 0, buffer.length);
strMiscInfo = bos.toString(�Cp1047�);

And inserting the value of �strMiscInfo� in the Misc_Info field of DB2 table.

The value was inserted successfully, but when we are trying to read the same record and assigning the value of Misc_Info field to the working storage section fields as specified above. Sometimes it is giving errors and sometimes it is giving wrong values and some times it is correct values.

Could anyone guide us to resolve this problem?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic