Forum Discussion
MarcusH
1 day agoValued Contributor
There is the Fixed Debit Credits parser script in GolfStream that might give you a clue:
Namespace OneStream.BusinessRule.Parser.XFR_ParseFixedDebitsCredits
Public Class MainClass
'------------------------------------------------------------------------------------------------------------
'Reference Code: XFR_ParseFixedDebitsCredits
'
'Description: Parse a fixed numeric column based on a mid-point position in order to determine debits and credits.
' This script is required for file formats that have values in both the Debit and Credit column. It performs
' extra tests to if the debit column is zero, if so it moves on to the take the credit column as the value.
'
'Usage: Parser business rule intended to be used on numeric field containing a values for debits and credits.
'
'Created By: Tom Shea
'Date Created: 1-13-2014
'------------------------------------------------------------------------------------------------------------
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As ParserDimension, ByVal args As ParserArgs) As Object
Try
'Make sure the line is longer than the amount field position + length of field
If (args.Line.Length >= (api.DimensionStartPosition + api.DimensionLength - 1)) Then
'Declare the Debit/Credit midpoint position
Dim midPoint As Integer = 12
Dim fieldValue As String = Mid(args.Line, api.DimensionStartPosition, api.DimensionLength)
'Parse the Debits & Credits in order to return the NON-ZERO value
If fieldValue.Length > midPoint Then
Dim strDebit As String = fieldValue.Substring(0, midPoint).Trim
Dim strCredit As String = fieldValue.Substring(midPoint, fieldValue.Length - midPoint).Trim
If IsNumeric(strDebit) And IsNumeric(strCredit) Then
If CType(strDebit, Double) = 0 And CType(strCredit, Double) = 0 Then
'Both a values are non-numeric, just return the incoming value so we can log it
api.ValueIsZeroSuppressed = True
Return "0"
Else
If CType(strDebit, Double) <> 0 Then
'Debit is not zero
api.ValueIsnumeric = True
Return strDebit
Else
'Debit was zero, so return the credit
api.ValueIsnumeric = True
Return strCredit & "-"
End If
End If
Else If IsNumeric(strDebit) Then
'Debit is a valid number
api.ValueIsnumeric = True
Return strDebit
Else If IsNumeric(strCredit) Then
'Credit is a valid number
api.ValueIsnumeric = True
Return strCredit & "-"
Else
'Both a values are non-numeric, just return the incoming value so we can log it
api.ValueIsnumeric = False
Return args.Value
End If
Else
'Value is less than mid point, just return the incoming value so we can log it
api.ValueIsnumeric = False
Return args.Value
End If
Else
'Line is blank or not long enough
Return args.Value
End If
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
End Class
End Namespace
Related Content
- 2 months ago