View previous topic :: View next topic
|
Author |
Message |
Rajeev_mainframe
New User
Joined: 21 Aug 2006 Posts: 13
|
|
|
|
Hi,
I am using enterprise cobol compiler and have a problem in moving data from edited-numeric to numeric field. The input output filed declaration is
Input
05 WS-I-AVG-COST-PER-SHARE PIC -9(08).9(07).
output
05 WS-O-AVG-COST-PER-SHARE-SIGN PIC X(01).
05 WS-O-AVG-COST-PER-SHARE PIC 9(10).9(6).
Code:
INITIALIZE WS-COUNT.
INSPECT WS-I-AVG-COST-PER-SHARE
TALLYING WS-COUNT FOR ALL '-'
IF WS-COUNT > 0
MOVE '-' TO WS-O-AVG-COST-PER-SHARE-SIGN
ELSE
MOVE '+' TO WS-O-AVG-COST-PER-SHARE-SIGN
END-IF.
DISPLAY 'WS-I-AVG-COST-PER-SHARE: ' WS-I-AVG-COST-PER-SHARE.
INSPECT WS-I-AVG-COST-PER-SHARE REPLACING ALL " " BY "0".
DISPLAY 'WS-I-AVG-COST-PER-SHARE: ' WS-I-AVG-COST-PER-SHARE.
MOVE WS-I-AVG-COST-PER-SHARE TO WS-O-AVG-COST-PER-SHARE.
The output values are coming as:
WS-I-AVG-COST-PER-SHARE: 100.000000
WS-I-AVG-COST-PER-SHARE: 0000000100.000000
WS-O-AVG-COST-PER-SHARE: 0000000010.00000
can anyone advise me on the solution to this. The value of 100 is truncated to 10 in the output.
Thanks,
Rajeev |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
you are moving a numeric edit mask to a numeric edit mask. both are x type. |
|
Back to top |
|
|
Rajeev_mainframe
New User
Joined: 21 Aug 2006 Posts: 13
|
|
|
|
Yes I see that, but I am moving some other values in the same fashion and getting the data before and after decimal without truncation.
example:
05 WS-I-FX-RATE PIC -9(06).9(09).
05 WS-O-FX-RATE-SIGN PIC X(01).
05 WS-O-FX-RATE PIC 9(07).9(9).
code:
INITIALIZE WS-COUNT.
INSPECT WS-I-FX-RATE
TALLYING WS-COUNT FOR ALL '-'
IF WS-COUNT > 0
MOVE '-' TO WS-O-FX-RATE-SIGN
ELSE
MOVE '+' TO WS-O-FX-RATE-SIGN
END-IF.
INSPECT WS-I-FX-RATE REPLACING ALL " " BY "0".
MOVE WS-I-FX-RATE TO WS-O-FX-RATE.
Values:
WS-I-FX-RATE: 1.000000000
WS-O-FX-RATE: 0000001.000000000 |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
The output values are coming as:
Quote: |
WS-I-AVG-COST-PER-SHARE: 100.000000
WS-I-AVG-COST-PER-SHARE: 0000000100.000000
WS-O-AVG-COST-PER-SHARE: 0000000010.00000
|
this does not jive with the definition: (actually it is BS)
Quote: |
WS-I-AVG-COST-PER-SHARE PIC -9(08).9(07). |
you could never have moved anything numeric to the edit-mask WS-I-AVG-COST-PER-SHARE
and have a resultant value 100.000000
Quote: |
edited-numeric to numeric field |
and this is incorrect. you are moving edited-numeric to edited-numeric.
had your original edit-mask display been correct,
I would have explained what is going on.
but you have an unobtainable value to start with.
you are probably redefining edit-masks (and failed to show us)
or you are not cutting and pasting but typing in your data.
I can't help you. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Your data is not consistent with your PICTURE clauses. I tested with a value of 123.4567891 using your variable definitions and PROCEDURE DIVISION statements and do not see the results you're getting. Nor are your results in line with the COBOL Language Reference, section 6.2.24.1.1 Elementary Move Rules, which says in part
Quote: |
Numeric or numeric-edited:
* Except when zeros are replaced because of editing requirements, alignment by decimal point and any necessary zero filling take place, as described under "Alignment rules" in topic 5.1.6.8.
* If the receiving item is signed, the sign of the sending item is placed in the receiving item, with any necessary sign conversion. If the sending item is unsigned, a positive operational sign is generated for the receiving item.
* If the receiving item is unsigned, no operational sign is generated for the receiving item and the absolute value of the sending item is used in the move.
* When the category of the sending item is alphanumeric, alphanumeric-edited, national, or national-edited, the data is moved as if the sending item were described as an unsigned integer.
* When the sending item is floating-point, the data is first converted to either a binary or internal decimal representation and is then moved.
* When the receiving item is numeric-edited, editing takes place as defined by the picture character string or BLANK WHEN ZERO clause associated with the receiving item.
* When the sending item is numeric-edited, the compiler de-edits the sending data to establish the unedited value of the numeric-edited item (this value can be signed). The unedited numeric value is used in the move to the receiving numeric or numeric-edited data item. |
The output with input of +123.4567891 is 0000000123.456789 -- just what was expected based upon your variable definitions. |
|
Back to top |
|
|
Rajeev_mainframe
New User
Joined: 21 Aug 2006 Posts: 13
|
|
|
|
I managed to resolve it by moving the input read value to a temprory variable of PIC X(17) and then moving it to output variable through NUMVAL
COMPUTE WS-O-AVG-COST-PER-SHARE = FUNCTION NUMVAL
(WS-TEMP-SHARE-VALUE). |
|
Back to top |
|
|
|