[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
How do you write packed fields to file? - Solution
- Subject: How do you write packed fields to file? - Solution
- From: Jim Hardesty <jhardest@LMBERRY.COM>
- Date: Mon, 23 Nov 1998 08:09:10 -0500
Danny,
EBCDIC...BEBCDIC. It turns out there is no brain surgery involved.
Attached should be an sqc with procedures to convert from and to zoned decimal.
The procedures are from the earliest mists of our implementation, so they are a
little brute force, but they work just fine.
Let me know if the attachment doesn't make it through,
jim
>>> Daniel Guynes <Daniel_Guynes@PEOPLESOFT.COM> 11/22/98 08:49am
>>>
I am in a situation where a client needs an interface file ... but half of
the fields must be in packed format. I have never come across this, much
less have any idea how to do it. So, any help is greatly appreciated ...
thank you.
Danny
!*************************************************************
! bcnv#2zd Convert number to zone decimal *
!*************************************************************
! KDB - 08/12/94 - This SQC will convert a numeric field to zone
! decimal.
! This program needs the following fields:
! #workin: numeric field to be converted
! #decimals: number of decimals desired
! must be 0 - 6
! #integers: number of integers desired
! the total of #decimals and #integers
! must be less than 16
! The following fields are output from this program:
! #error: 1 indicates an error was encountered
! and the program was unable to continue
! $workout: The converted field.
!
! EXAMPLES:
! #workin: 126.59 -90591.00
! #decimals: 02 05
! #integers: 04 00
! $workout: 01265I 9059J
!*************************************************************
! KDB 04/95 Modifications to also convert from zone decimal
! to numeric.
! Example 1: (from calling program)
! $Last_digit I
!
! (to calling program)
! $Last_digit 9
! $Sign +
!
! Example 2: (from calling program)
! $Last_digit R
!
! (to calling program)
! $Last_digit 9
! $Sign -
!
! If $Last_digit has an invalid
! value, $Sign will be set to 'E'.
!*************************************************************
begin-procedure Convert-to-zone-decimal
Let #error = 0
If #decimals + #integers > 15
display '# decimals + # integers must be 15 or less'
Let #error = 1
goto bcnv#2zdExit
End-if
If #decimals + #integers < 1
display '# decimals + # integers must be 1 or greater'
Let #error = 1
goto bcnv#2zdExit
End-if
If #decimals > 6
display '# integers must be 6 or less'
Let #error = 1
goto bcnv#2zdExit
End-if
EVALUATE #decimals
When = 0
Let #workin = round(#workin,0)
Break
When = 1
Let #workin = round(#workin,1)
Let #workin = #workin * 10
Break
When = 2
Let #workin = round(#workin,2)
Let #workin = #workin * 100
Break
When = 3
Let #workin = round(#workin,3)
Let #workin = #workin * 1000
Break
When = 4
Let #workin = round(#workin,4)
Let #workin = #workin * 10000
Break
When = 5
Let #workin = round(#workin,5)
Let #workin = #workin * 100000
Break
When = 6
Let #workin = round(#workin,6)
Let #workin = #workin * 1000000
END-EVALUATE
Let $worktm1 = EDIT(#workin,'000000000000000')
Extract $first_14_digits from $worktm1 0 14
Extract $last_digit from $worktm1 14 1
Do PLUG-ZONE-DECIMAL
Let $worktm2 = $first_14_digits || $last_digit
Let #ttlen = #integers + #decimals
Let #position = 15 - #ttlen
Extract $workout from $worktm2 #position #ttlen
bcnv#2zdExit:
end-procedure Convert-to-zone-decimal
Begin-Procedure PLUG-ZONE-DECIMAL
If #workin < 0
DO PLUG-NEGATIVE
Else
DO PLUG-POSITIVE
End-IF
End-Procedure PLUG-ZONE-DECIMAL
Begin-Procedure PLUG-NEGATIVE
EVALUATE $last_digit
When = '0'
Let $last_digit = '}'
Break
When = '1'
Let $last_digit = 'J'
Break
When = '2'
Let $last_digit = 'K'
Break
When = '3'
Let $last_digit = 'L'
Break
When = '4'
Let $last_digit = 'M'
Break
When = '5'
Let $last_digit = 'N'
Break
When = '6'
Let $last_digit = 'O'
Break
When = '7'
Let $last_digit = 'P'
Break
When = '8'
Let $last_digit = 'Q'
Break
When = '9'
Let $last_digit = 'R'
End-Evaluate
End-Procedure PLUG-NEGATIVE
Begin-Procedure PLUG-POSITIVE
EVALUATE $last_digit
When = '0'
Let $last_digit = '{'
Break
When = '1'
Let $last_digit = 'A'
Break
When = '2'
Let $last_digit = 'B'
Break
When = '3'
Let $last_digit = 'C'
Break
When = '4'
Let $last_digit = 'D'
Break
When = '5'
Let $last_digit = 'E'
Break
When = '6'
Let $last_digit = 'F'
Break
When = '7'
Let $last_digit = 'G'
Break
When = '8'
Let $last_digit = 'H'
Break
When = '9'
Let $last_digit = 'I'
End-Evaluate
End-Procedure Plug-Positive
!*************************************************************
! Convert zone decimal to standard numeric.
!*************************************************************
Begin-Procedure Find-Digit
Let #error = 0
Evaluate $Last_Digit
When = '}' !begin with negative.
Let $Last_Digit = '0'
Let $Sign = '-'
When = 'J'
Let $Last_Digit = '1'
Let $Sign = '-'
When = 'K'
Let $Last_Digit = '2'
Let $Sign = '-'
When = 'L'
Let $Last_Digit = '3'
Let $Sign = '-'
When = 'M'
Let $Last_Digit = '4'
Let $Sign = '-'
When = 'N'
Let $Last_Digit = '5'
Let $Sign = '-'
When = 'O'
Let $Last_Digit = '6'
Let $Sign = '-'
When = 'P'
Let $Last_Digit = '7'
Let $Sign = '-'
When = 'Q'
Let $Last_Digit = '8'
Let $Sign = '-'
When = 'R'
Let $Last_Digit = '9'
Let $Sign = '-'
When = '{'
Let $Last_Digit = '0'
Let $Sign = '+'
When = 'A'
Let $Last_Digit = '1'
Let $Sign = '+'
When = 'B'
Let $Last_Digit = '2'
Let $Sign = '+'
When = 'C'
Let $Last_Digit = '3'
Let $Sign = '+'
When = 'D'
Let $Last_Digit = '4'
Let $Sign = '+'
When = 'E'
Let $Last_Digit = '5'
Let $Sign = '+'
When = 'F'
Let $Last_Digit = '6'
Let $Sign = '+'
When = 'G'
Let $Last_Digit = '7'
Let $Sign = '+'
When = 'H'
Let $Last_Digit = '8'
Let $Sign = '+'
When = 'I'
Let $Last_Digit = '9'
Let $Sign = '+'
When-Other !indicate error.
Let $Last_Digit = '0'
Let $Sign = 'E'
Let #error = 1
End-Evaluate
END-Procedure Find-Digit