×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to use UDT in Visual Basic to depict COBOL Decimal Comp-3?

how to use UDT in Visual Basic to depict COBOL Decimal Comp-3?

how to use UDT in Visual Basic to depict COBOL Decimal Comp-3?

(OP)
how to use UDT in Visual Basic to depict COBOL Decimal Comp-3?

COBOL Decimal Comp-3(precision, scale, size)  are list in the following.
 (15,5,8) (9,0,5)  (11,0,6)  (17,5,9)  (11,2,6)  (3,0,2) (13,5,7)  (7,0,4)  (11,5,6)

For example, in the Invent.btr(This btr file come from business vision), the definition of fields is following:

(Field, Data Type, Size, Precision, Scale)
(I_WHSE,Char,2)
(I_PART_NO,Char,15)
(I_DESCRIPTION,Char,40)
…..
(I_COST_CURRENT,Decimal,8,15,5)
…..
I use the UDT below in Visual Basic:

Public Type InvFull_Fld
    I_WHSE                            As String * 2
    I_PART_NO                     As String * 15
    I_DESCRIPTION             As String * 40
    I_Filler1                            As String * 16
    I_COST_CURRENT        As Double
    I_Filler2                            As String * 967   ' total 1048
End Type

Note I use double data type to depict I_COST_CURRENT field, this field is a decimal(15,5,8) field (here 15 is precision , 5 is scale, and the betrieve size is 8). but when I use this UDT to get the record with Betrieve API, the result is wrong, for example, actually the original data is 0.00000 , and what I got is 6.98350748929955E-251
Thanks.

RE: how to use UDT in Visual Basic to depict COBOL Decimal Comp-3?

This is certainly not a double in the UDT.  You will need to construct a translation between the Cobol format and a VB data type.

Now, I don't have any access to a Cobol-formatted DB, but... since the DataType is Decimal, this should not be too difficult to translate.

Make your UDT for this field a STRING*8, then translate the value with:

Function TranslatePackedDecimal(pd as String, Scale as Integer) as Double
Dim I as Integer
Dim Work As String
Dim B As Byte

For I = 1 to Len(pd)
    B = Asc(Mid$(pd,I,1))
    
    If I = Len(pd) Then
        If ((B And 240) / 16) = 13 Then   ' Negative Sign nibble
            Work = "-" & Work
        End If
    Else
        Work = Work & ((B And 240) / 16)
    End If
    Work = Work & (B And 15)
Next I

TranslatePackedDecimal = CDbl(Work)
If Scale <> 0 Then
   TranslatePackedDecimal = TranslatePackedDecimal / (10^Scale)
End If
End Function

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close