Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert EBCDIC to ASCII? 1

Status
Not open for further replies.

denosaur

Technical User
Jul 9, 2004
28
0
0
US
I have a fixed width file with multiple 200 byte records that I understand was created on an IBM. The file contains a Zoned Numeric value, which looks like ASCII except for the last byte of the field. The values of the last byte of each field are one of the following characters: {, A, B, C, D, E, F, G, H, or I. I understand that each of these characters represents a signed digit. Can anyone help me translate them?

I have read seveal of the threads and even tried some of the code mentioned in them, but nothing seems to help. Any help would be great. Many thanks!

 
denosaur,

Whew!! This is not such a simple request. I work with many different IBM mainframe and Midrange systems. First a question. These systems can create ASCII files in many different ways (FTP for one). Is there any way you can just ask them for it??

If not first things first. Here is a link to convert ASCII to EBCDIC (and visa versa).


Here is another link for packed (for your information)


Okay now as you know the Zoned fields are your real issue.[bugeyed] but not as bad as packed decimal. You will need to know the lengths of these fields. The IBM systems store the decimal position. You will also need to know this. When using FTP from an IBM system the decimal is populated.

Code ( I found and untested) for last digit..
Code:
Function ConvertSignedChar(C As String) As String
'Converts a single signed character to
'digit with minus sign if needed
Dim j As Long


j = InStr("{ABCDEFGHI", C) - 1
If j >= 0 Then
   ConvertSignedChar = CStr(j)
Else
   j = InStr("}JKLMNOPQR", C) - 1
   If j >= 0 Then
     ConvertSignedChar = "-" & CStr(j)
   Else
     ConvertSignedChar = C
   End If
End If
End Function


Public Function ConvIBMSignedField(V As Variant) As Long
'Converts variant(string) containing signed field
'Modify for other numeric types
Dim blNegative As Boolean
Dim strTemp As String
Dim strSignedChar As String


strTemp = CStr(V)
'Either first or last character is signed
If InStr("0123456789", Right(strTemp, 1)) Then
   'last char is numeric so first is signed
   strSignedChar = ConvertSignedChar(Left(strTemp, 1))
   If Left(strSignedChar, 1) = "-" Then
     strSignedChar = Mid(strSignedChar, 2)
     blNegative = True
   Else
     blNegative = False
   End If
   strTemp = strSignedChar & Mid(strTemp, 2)
Else
   'Last char is signed
   strSignedChar = ConvertSignedChar(Right(strTemp, 1))
   If Left(strSignedChar, 1) = "-" Then
     strSignedChar = Mid(strSignedChar, 2)
     blNegative = True
   Else
     blNegative = False
   End If
   strTemp = Left(strTemp, Len(strTemp) - 1) & strSignedChar
End If
ConvIBMSignedField = CLng(strTemp) * IIf(blNegative, -1, 1)
End Function

Hey just trying to point you in the right direction.

[thumbsup2]

Let me know...
 
HiTechUser,

I had previously tried the link to convert ASCII to EBCDIC (and visa versa) from the microsoft support page to no avail. However, the code that you found and posted worked like a charm. I tested and validated the results (the file, which I am getting third hand, has trailer records with records counts and totals by type). Thanks for the help. You get a star!

Thanks again,
denosaur

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top