Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Converting Text String to Numeric data

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
ojdiaz

New User


Joined: 19 Nov 2008
Posts: 90
Location: Spain

PostPosted: Mon Feb 18, 2013 3:08 pm    Post subject: Converting Text String to Numeric data
Reply with quote

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
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon Feb 18, 2013 3:24 pm    Post subject: Reply to: Converting Text String to Numeric data
Reply with quote

"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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Mon Feb 18, 2013 3:31 pm    Post subject:
Reply with quote

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
View user's profile Send private message
ojdiaz

New User


Joined: 19 Nov 2008
Posts: 90
Location: Spain

PostPosted: Mon Feb 18, 2013 5:42 pm    Post subject:
Reply with quote

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
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Mon Feb 18, 2013 6:03 pm    Post subject: Reply to: Converting Text String to Numeric data
Reply with quote

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
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7904
Location: Bellevue, IA

PostPosted: Mon Feb 18, 2013 6:25 pm    Post subject:
Reply with quote

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
View user's profile Send private message
ojdiaz

New User


Joined: 19 Nov 2008
Posts: 90
Location: Spain

PostPosted: Mon Feb 18, 2013 7:15 pm    Post subject:
Reply with quote

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 icon_smile.gif

Oliver
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts ODPP(Optim Data privacy Provider) Iss... Rama kishore IBM Tools 1 Mon Nov 07, 2016 5:46 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Can sending 5 MB data between cobol p... Kevin Vaz CICS 12 Tue Oct 18, 2016 4:50 pm
No new posts output data in CSV Format janmejay COBOL Programming 8 Sat Oct 15, 2016 2:20 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us