?
Solved

Translating datatype

Posted on 2006-04-07
5
Medium Priority
?
228 Views
Last Modified: 2010-04-23
Hello everyone...
I have a problem here..ill explain...

I have a column in my database which contains data about mainframe's datatypes.. like this...
pix x
pix xx
pix x(5)
pic 9
pic 9(4)


Thats how the data exists in the column.
Now I need to retrieve that data and convert them and store them into 2 columns in another database like this....This is the translated form of the example shown above...
DATA TYPE COLUMN    .  DATA LENGTH COLUMN
Alpha numeric             .  1
Alpha numeric             .  2
Alpha numeric             .  5
Numeric                      .  1
Numeric                      .  1

Im trying to make my program to do this...Can anyone help a bit?
Thanks
0
Comment
Question by:godwindotnet
  • 3
  • 2
5 Comments
 
LVL 11

Accepted Solution

by:
LordWabbit earned 2000 total points
ID: 16401071
Greetings

There are just so many ways to declare a variable in COBOL that what you are asking for is huge in scope.  However I have written some code to cater for your example, as well as a few more eg.
Pic X
Pic XX
Pic X(5)
Pic 9
Pic 9(4)
Pic 9(4)V(4)
Pic 9(14)V999

and the result

Alpha Numeric : 1
Alpha Numeric : 2
Alpha Numeric : 5
Numeric : 1
Numeric : 4
Numeric : 4.4
Numeric : 14.3

For debugging etc. I used two list boxes, source and result, modify this as you see fit.  Be aware though that if you encounter a data type definition which does not fit into the above examples to some degree or other that the code will probably break.  You will then need to alter the code to cater for the new variation (as well as ensuring that it does not break for previously working data types.  You also might want to add a check for a . (period) used in display fields etc.  Like I said it's not a small thing u are asking for.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For intIdx As Integer = 0 To lstSource.Items.Count - 1
            Dim strType As String = "Numeric"
            Dim dblLength As Double
            Dim strSource As String = lstSource.Items(intIdx).ToString.ToLower.Replace("pic", "").Trim
            If strSource.Substring(0, 1) = "x" Then
                strType = "Alpha Numeric"
            End If
            Dim intStart As Integer = strSource.IndexOf("(")
            Dim intEnd As Integer
            If intStart > -1 Then intEnd = strSource.IndexOf(")", intStart)
            If intStart > 0 And intEnd > 0 Then
                dblLength = strSource.Substring(intStart + 1, intEnd - intStart - 1)
            Else
                dblLength = strSource.Length
            End If
            If strSource.Contains("v") Then
                Dim intRem As Integer = strSource.IndexOf("v")
                intStart = strSource.IndexOf("(", intRem)
                intEnd = strSource.IndexOf(")", intRem)
                Dim strRem As String
                If intStart > 0 And intEnd > 0 Then
                    strRem = strSource.Substring(intStart + 1, intEnd - intStart - 1)
                    dblLength += intRem / (10 * strRem.Length)
                Else
                    strRem = strSource.Length - intRem - 1
                    dblLength += strRem / (10 * strRem.Length)
                End If
            End If
            lstResult.Items.Add(strType & " : " & dblLength)
        Next
    End Sub
0
 
LVL 11

Expert Comment

by:LordWabbit
ID: 16401103
Tried a pic 999v999 and it came back with 7.3, you will need to put some extra code to check for v or . in the else where
dblLength = strSource.Length

I hope for your sake that there are no display type datatypes in that table, things could get really hairy then.
0
 

Author Comment

by:godwindotnet
ID: 16414111
Can you please modify that one to work with the v and stuff?
Thanks
0
 
LVL 11

Assisted Solution

by:LordWabbit
LordWabbit earned 2000 total points
ID: 16415186
There is still no guarentee it will work with all definitions, if you encounter one which gives you problems or incorrect values let me know.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For intIdx As Integer = 0 To lstSource.Items.Count - 1
            Dim strType As String = "Numeric"
            Dim dblLength As Double
            Dim strSource As String = lstSource.Items(intIdx).ToString.ToLower.Replace("pic", "").Trim
            If strSource.Substring(0, 1) = "x" Then
                strType = "Alpha Numeric"
            End If
            Dim intStart As Integer = strSource.IndexOf("(")
            Dim intEnd As Integer
            If intStart > -1 Then intEnd = strSource.IndexOf(")", intStart)
            If intStart > 0 And intEnd > 0 Then
                dblLength = strSource.Substring(intStart + 1, intEnd - intStart - 1)
            Else
                If strSource.Contains("v") Then
                    Dim intRem As Integer = strSource.IndexOf("v")
                    dblLength = strSource.Length - intRem - 1
                Else
                    dblLength = strSource.Length
                End If
            End If
            If strSource.Contains("v") Then
                Dim intRem As Integer = strSource.IndexOf("v")
                intStart = strSource.IndexOf("(", intRem)
                intEnd = strSource.IndexOf(")", intRem)
                Dim strRem As String
                If intStart > 0 And intEnd > 0 Then
                    strRem = strSource.Substring(intStart + 1, intEnd - intStart - 1)
                    dblLength += intRem / (10 * strRem.Length)
                Else
                    strRem = strSource.Length - intRem - 1
                    dblLength += strRem / (10 * strRem.Length)
                End If
            End If
            lstResult.Items.Add(strType & " : " & dblLength)
        Next
    End Sub
0
 

Author Comment

by:godwindotnet
ID: 16415264
Awesomeeee :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question