Hi!
I use the function WRITE WORK FILE to write data in the file.
If fields are the negative number, the data is written not correct.
Example:
Data field: -2.15
Write as : 21u
Correct : -215
As I understand, this happening when data converted to a string.
How to get around this problem?
Thanks in advance!
Alexander,
Is the output you are looking for -215 or is -2.15 acceptable? Is a delimited file acceptable?
If -2.15 is acceptable, you can define your work file type as CSV. When using type CSV, numeric fields will be written out correctly, regardless if N, P or I. This is probably the cleanest solution but a delimited file must be acceptable.
If you need the output to be -215, or CSV is not acceptable you can move the numeric field to a alpha field for writing out to the work file. You can suppress the decimal by either using a redefinition as shown below, or MOVE EDITED the N7.2 then deleting the decimal from the alpha variable using an EXAMINE DELETE (you may also need to do a MOVE RIGHT to get the desired output).
DEFINE DATA
1 #N7_2 (N7.2) INIT <-2.15>
1 REDEFINE #N7_2
2 #N9 (N9)
1 #A (A10)
END-DEFINE
MOVE EDITED #N9 (EM=-ZZZZZZZZ9) TO #A
WRITE WORK FILE 1 #A
END
1 Like
What you’re seeing is an overstruck sign. If you read the numeric field with the same format definition as was used to write it, you won’t have this problem. If you need to read the number into a numeric field, you can force a trailing sign.
DEFINE DATA LOCAL
1 #A (A2) INIT <'Ab'>
1 #N (N3.2) INIT <-123.45>
1 #E (A7)
1 #W (A14)
END-DEFINE
MOVE EDITED #N (EM=999.99-) TO #E
WRITE WORK 1 #A #N #E
READ WORK 1 ONCE #A #N #E
WRITE '=' #A '=' #N '=' #E
*
WRITE WORK 1 #A #N #E
READ WORK 1 ONCE #W
WRITE '=' #W
END
#A: Ab #N: -123.45 #E: 123.45-
#W: Ab1234u123.45-
1 Like