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
Moving characters to numeric field
-
- Global moderator
- Posts: 3025
- Joined: Sun Jul 04, 2010 12:13 am
- Skillset: JCL, PL/1, Rexx, Utilities and to a lesser extent (i.e. I have programmed using them) COBOL,DB2,IMS
- Referer: Google
- Location: Pushing up the daisies (almost)
Re: Moving characters to numeric field
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
Regards
Nic
Re: Moving characters to numeric field
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

Cheers
Harald
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: Moving characters to numeric field
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.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.
Since there is no conversion done, your question is nonsensical. To wit:but it should be numeric since it was converted and stored in pic 9-parameter?
Code: Select all
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.
Code: Select all
SOURCE >ABCDEFGHIJKLMNOPQRSTUVWXYZ---------<
DEST >XYZ--------0<
Re: Moving characters to numeric field
Hi Robert, thanks for input!
Cheers
Harald
Cheers
Harald
-
- Posts: 1
- Joined: Thu May 05, 2022 12:47 am
- Skillset: mainframe cobol, rexx,
microfocus cobol, cics
sql - Referer: Been lurking here for many years
Re: Moving characters to numeric field
Hi Robert -
I think you missed that the OP was not moving all 35 bytes, instead he was moving only 12:
The subscript (21:12) indicates that 12 bytes will be moved from WP51I-VALFRI-TEXT to WS-PAYMENT-AMT, starting from byte number 21 of the sending field.
I have an issue with using reference modification like this. I am making some assumptions but this is what I would do, using Robert's example. My assumption is that there are valid numeric values in (21:12):
BTW, here is a link to one of the IBM manuals regarding MOVE: https://www.ibm.com/docs/en/cobol-zos/4.2?topic=statements-move-statement
I've been programming in COBOL since pre-Y2K, and there are still things I need assistance with. Unless you know exactly what you are looking for it may be difficult to find, in this case subscripting the sending field in a MOVE statement.
@HarryBoy, if WP51I-VALFRI-TEXT contains data for more than one field I would create a group with elementals below it, one for each field. If that data is coming in from another process I would also put that code into a copybook which will make maintenance much easier. Take it from someone maintaining a 40+ year old COBOL implementation...
You have probably already solved this issue but I am putting this out to possibly help the next new user.
Finally, I have an issue with those who use the RTFM or RTFF response. It is a Microsoft answer, totally correct but utterly useless...
Cheers,
Will
I think you missed that the OP was not moving all 35 bytes, instead he was moving only 12:
Code: Select all
MOVE WP51I-VALFRI-TEXT(21:12) TO WS-PAYMENT-AMT
The subscript (21:12) indicates that 12 bytes will be moved from WP51I-VALFRI-TEXT to WS-PAYMENT-AMT, starting from byte number 21 of the sending field.
I have an issue with using reference modification like this. I am making some assumptions but this is what I would do, using Robert's example. My assumption is that there are valid numeric values in (21:12):
Code: Select all
environment division.
configuration section.
data division.
working-storage section.
01 WS-FILLER.
05 WS-SOURCE.
10 FILLER PIC X(20).
10 WS-PAYMENT-AMOUNT PIC X(12).
10 FILLER PIC X(3).
01 WS-DEST PIC 9(12).
procedure division.
MOVE 'ABCDEFGHIJKLMNOPQRST123456789012---'
TO WS-SOURCE.
MOVE WS-PAYMENT-AMOUNT TO WS-DEST.
DISPLAY 'SOURCE >' WS-SOURCE '<'.
DISPLAY 'DEST >' WS-DEST '<'.
STOP RUN.
end program Program1.
BTW, here is a link to one of the IBM manuals regarding MOVE: https://www.ibm.com/docs/en/cobol-zos/4.2?topic=statements-move-statement
I've been programming in COBOL since pre-Y2K, and there are still things I need assistance with. Unless you know exactly what you are looking for it may be difficult to find, in this case subscripting the sending field in a MOVE statement.
@HarryBoy, if WP51I-VALFRI-TEXT contains data for more than one field I would create a group with elementals below it, one for each field. If that data is coming in from another process I would also put that code into a copybook which will make maintenance much easier. Take it from someone maintaining a 40+ year old COBOL implementation...
You have probably already solved this issue but I am putting this out to possibly help the next new user.
Finally, I have an issue with those who use the RTFM or RTFF response. It is a Microsoft answer, totally correct but utterly useless...
Cheers,
Will
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Moving High-Values from Comp-3 - COBOL Ver 6.4
by girik1001 » Thu Jul 20, 2023 12:08 pm » in IBM Cobol - 1
- 3893
-
by sergeyken
View the latest post
Thu Jul 20, 2023 6:38 pm
-
-
-
Recatalog Error:Moving a dataset entry from one cat to other
by gselvasridharan » Fri Apr 07, 2023 1:33 pm » in VSAM/SMS - 3
- 4865
-
by gselvasridharan
View the latest post
Mon Apr 10, 2023 12:58 pm
-
-
- 1
- 1753
-
by sergeyken
View the latest post
Fri Mar 26, 2021 11:59 pm
-
- 0
- 3780
-
by zosser
View the latest post
Thu Jul 15, 2021 2:25 am
-
-
Retain non numeric character in IFTHEN - BUILD
by Shambu » Wed Dec 01, 2021 5:00 pm » in Syncsort/Synctool - 1
- 1958
-
by sergeyken
View the latest post
Sat Dec 04, 2021 2:28 pm
-