View previous topic :: View next topic
|
Author |
Message |
ojdiaz
New User
Joined: 19 Nov 2008 Posts: 98 Location: Spain
|
|
|
|
Hello. We are having a bit of a problem. Maybe this has been answered before, but i can't seem to find an answer.
We have a pic x(20) variable in wich we receive a 16 digits number with this format:
'0000000474747,00'
All the programs are compiled with the DECIMAL POINT IS COMMA operator, so that would be a 13 integer and two decimals number.
We have to move that variable to a S9(15)V9(2) COMP-3. variable, so the program has this declaration in the WS area:
Code: |
05 WS-IMPORTE PIC X(20) VALUE SPACES.
05 NUM-IMPORTE-RED REDEFINES WS-IMPORTE.
10 NUM-IMPORTE PIC S9(13)V9(2).
10 FILLER PIC X(5). |
However, we are getting a data exception when dealing with a move in the following way:
this is an example code:
Code: |
MOVE '0000000474747,00' TO CH25-DES-VAL-CON-E(1)
MOVE CH25-DES-VAL-CON-E(1)
TO WS-IMPORTE
DISPLAY 'WS-IMPORTE-DESP: ' WS-IMPORTE
DISPLAY 'NUM-IMPORTE-A: ' NUM-IMPORTE
DISPLAY 'C388-IMP-SOLI-A: ' C388-IMP-SOLICITADO
MOVE NUM-IMPORTE TO C388-IMP-SOLICITADO
DISPLAY 'NUM-IMPORTE-D: ' NUM-IMPORTE
DISPLAY 'C388-IMP-SOLI-D: ' C388-IMP-SOLICITADO |
where C388-IMP-SOLICITADO is the S9(15)V9(2) COMP-3 receiving variable. The displays and errors we are getting are as follows:
Code: |
WS-IMPORTE-DESP: 0000000474747,00
NUM-IMPORTE-A: 0000000474747,00
C388-IMP-SOLI-A: 00000000000000000
CEE3207S The system detected a data exception (System Completion Code=0C7).
From compile unit KGCRGH25 at entry point KGCRGH25 at statement 1908 at
entry offset +000049A4 at address 4198D9A4.
<> LEAID ENTERED (LEVEL 06/15/2011 AT 18.20)
<> LEAID PROCESSING COMPLETE. RC=0 |
COBOL is not my thing, so i've been reading around and I think the comma migth be giving us trouble. ¿Is that the cause of the problem?
Is there a way arond this?
the input variable will always have the previous format, that is, 13 integer, a comma and two decimals
Thanks a lot in advance
Best regards |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
"DECIMAL POINT IS COMMA" does not affect any PIC X(n) field.
Code: |
01 a-pic-x20-with-nice-name PIC X(20).
01 FILLER REDEFINES a-pic-x20-with-nice-name.
05 a-nice-name-for-integer-part PIC 9(13).
05 a-nice-name-for-decimal-comma PIC X.
88 a-nice-condition-for-valid VALUE ",".
05 a-nice-name-for-decimal-part PIC 99.
01 a-nice-name-for-pic-9-13-v99 PIC 9(13)V99.
01 FILLER REDEFINES a-nice-name-for-pic-9-13-v99.
05 another-nice-name-for-integer-part PIC 9(13).
05 another-nice-name-for-decimal-part PIC 99.
IF ( a-nice-name-for-integer-part NUMERIC )
AND ( a-nice-name-for-decimal-part NUMERIC )
AND ( a-nice-condition-for-valid )
MOVE a-nice-name-for-integer-part TO another-nice-name-for-integer-part
MOVE a-nice-name-for-decimal-part TO another-nice-name-for-decimal-part
MOVE a-nice-name-for-pic-9-13-v99 TO your-comp-3-field
ELSE
MOVE ZERO TO your-comp-3-field
or something else appropriate
END-IF |
|
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
Your first problem is that your PICTURE clause does not match your data. The V in a PICTURE means IMPLIED decimal point -- as in, it does not really exist in the data. Also, the data is not signed so why use the S on the PICTURE clause? Try 9(13).9(2) instead of S9(13)V9(2). Also, your filler should be 4 and not 5 since the decimal point counts as one of the 20 characters. |
|
Back to top |
|
|
ojdiaz
New User
Joined: 19 Nov 2008 Posts: 98 Location: Spain
|
|
|
|
I can't change de S on the picture clause in the receiving variable because in this shop, it belongs to a copy that comunicate with a routine of a different department and is already in use in production. That said, I think then that indeed the comma is the cause of my problems. So the V only tells where the decimal point is, but not the existance of a comma, I should process the integer and decimals by separate?
Could be possible to move redefine the input variable as an numeric edited varibale, and then move this to the numeric destination variable? Something like this?:
Code: |
05 WS-IMPORTE PIC X(20) VALUE SPACES.
05 NUM-IMPORTE-RED REDEFINES WS-IMPORTE.
10 NUM-IMPORTE PIC S9(13)V9(2).
10 FILLER PIC X(5).
05 NUM-IMPORTE-RED-2 REDEFINES WS-IMPORTE.
10 NUM-IMPORTE2 PIC 9999999999999,99.
10 FILLER PIC X(4). |
So, the idea would be to move NUM-IMPORTE2 to the C388-IMP-SOLICITADO pic s9(13)v99 comp-3 variable. Do you think that would be ok?
Otherwise, i'll try anyways to implement bill's suggestion
Thanks a lot |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You can use the "repetition factor" for all those 9s - 9(13).
Either yours or 9(13),99 being MOVEd to the comp-3 field should work, as it will be "de-editing" the value (you are specifying a "numeric-edited" picture).
There will be no "validation". You will be relying on the format and validity of the data coming in. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
I think you do not understand what you've been told.
Code: |
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-SRC.
05 SRC-VAR PIC 9(13),9(02).
05 PIC X(04).
77 DEST-VAR PIC S9(13)V9(02).
77 COMP3-VAR PIC S9(15)V9(02) COMP-3.
PROCEDURE DIVISION.
0000-START.
MOVE '0000000474747,00' TO WS-SRC.
MOVE SRC-VAR TO DEST-VAR
COMP3-VAR.
DISPLAY 'SOURCE >' SRC-VAR '<'.
DISPLAY 'DEST >' DEST-VAR '<'.
DISPLAY 'COMP3 >' COMP3-VAR '<'.
STOP RUN. |
produces output of
Code: |
SOURCE >0000000474747,00<
DEST >00000004747470{<
COMP3 >00000000047474700< |
which exactly matches what you claim you need -- and no S0C7 abends, either. |
|
Back to top |
|
|
ojdiaz
New User
Joined: 19 Nov 2008 Posts: 98 Location: Spain
|
|
|
|
Robert, Bill. I've got exactly what you've been trying to tell me. Thanks a lot. The input variable is validated in a front app and I'll always receive the data in that format, so there is a very low, to non existant, risk of receiving inconsistant data on that variable.With that, I know that I'll always receive 13 integers, a comma and 2 decimals, so the last example given by Robert is just what I needed to acomplish this.
I'll simplify the memory definition of the variable, changing the redefines by two variables that sums 20 bytes and use that solution.
BTW, I prefer to write the numeric edited variables with a long string of 9's or other characters because that way I identify them easily as numeric edited instead of regular variables.
Thanks a lot for you help
Best Regards
Oliver |
|
Back to top |
|
|
|