Moving characters to numeric field



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Moving characters to numeric field

Postby HarryBoy » Fri Jan 11, 2019 2:22 pm

Hi! the below code moves a pic x(35) to a pic 9(12), as I understand the pic x is then converted to pic 9-format when the data is moved.
The moved data consists of a couple of numbers but the last part is a character in this case a "-". But then the "-" should be converted to
a numeric representation, yes?

However as you can see below it checks if the position in the pic 9-parameter is not numeric, but it should be numeric since it was converted and stored in pic 9-parameter?

The code is below:
MOVE WP51I-VALFRI-TEXT(21:12) TO WS-PAYMENT-AMT

EVALUATE TRUE
WHEN WS-PAYMENT-AMT(12:1) IS NUMERIC
SET NUMERIC-FLAG TO TRUE
CONTINUE
WHEN WS-PAYMENT-AMT(12:1) = '-'
MOVE '0' TO WS-PAYMENT-AMT(12:1)



Cheers
Harald
HarryBoy
 
Posts: 8
Joined: Tue Dec 11, 2018 2:24 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving characters to numeric field

 

Re: Moving characters to numeric field

Postby NicC » Fri Jan 11, 2019 4:23 pm

Please look at all the other topics on this subject and read and understand the relevant section of the cobol language reference manual.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2885
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 129 times

Re: Moving characters to numeric field

Postby HarryBoy » Fri Jan 11, 2019 5:31 pm

Noooo. I want it explained without me having to do anything, served to me on a silver plate! :-) (kidding, I will check the forum posts).

Cheers
Harald
HarryBoy
 
Posts: 8
Joined: Tue Dec 11, 2018 2:24 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Moving characters to numeric field

Postby Robert Sample » Fri Jan 11, 2019 7:48 pm

the below code moves a pic x(35) to a pic 9(12), as I understand the pic x is then converted to pic 9-format when the data is moved.
I think you have a DRASTIC misunderstanding about how COBOL works. When you MOVE a PIC X(35) to a PIC 9(12), there is no conversion done -- period. The data is moved (byte by byte) and if the moved data matches the requirements for a zoned decimal number, great -- but if not then you can have non-numeric data in the zoned decimal variable.
but it should be numeric since it was converted and stored in pic 9-parameter?
Since there is no conversion done, your question is nonsensical. To wit:
WORKING-STORAGE SECTION.                        
 01  WS-FILLER.                                  
     05  WS-SOURCE               PIC X(35) VALUE
     'ABCDEFGHIJKLMNOPQRSTUVWXYZ---------'.      
     05  WS-DEST                 PIC 9(12).      
 PROCEDURE DIVISION.                            
      MOVE WS-SOURCE             TO  WS-DEST.    
      DISPLAY 'SOURCE >' WS-SOURCE '<'.          
      DISPLAY 'DEST   >' WS-DEST   '<'.          
      STOP RUN.                                  
produces results of
SOURCE >ABCDEFGHIJKLMNOPQRSTUVWXYZ---------<
DEST   >XYZ--------0<                        
Notice that the ONLY numeric character in the destination is the final zero -- and that is because COBOL forces the final byte of a zoned decimal variable to have a zone when a MOVE to the variable is done (depending upon the compile options, of course). And it is a zero because the EBCDIC collating sequence for a dash is X'60' so COBOL changed the X'60' to X'F0'; if you use something like a period (X'4B') then you would get X'FB' in that final byte.
Robert Sample
Global moderator
 
Posts: 3581
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 261 times

Re: Moving characters to numeric field

Postby HarryBoy » Mon Jan 14, 2019 2:01 pm

Hi Robert, thanks for input!

Cheers
Harald
HarryBoy
 
Posts: 8
Joined: Tue Dec 11, 2018 2:24 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post