Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about numeric operands 2

Status
Not open for further replies.

laughing

Programmer
Apr 1, 2011
3
0
0
US
Hi guys,

Firstly, Thank you very much for reading and hopefully answering my question. I'm in my first COBOL I class at college and to be frank, i'm floating around hoping i'm on the right track.

My questions is I have a string of numbers in my input file:
028238.24

However, when I compile it comes up with an error for a section of the file that uses that specific spot:
Operand must be an arithmetic expression
as well as Operand must be a numeric data-name or a numeric literal.

I've read some of the question on this forum already and they haven't helped me much, so i'm hoping a more specific question will do the trick.

What I want displayed 28,238.24 I would like to have commas as well as the 0 to be purged. I tried to do a numeric literal but it is giving me these errors.

05 CM-BEGINNING-BALANCE PIC 9(7)V99.
Is my routine to pull it from the input file.

and my Customer-Line (What i want to be printed, basically) is coded as:
05 CL-BEGINNING-BALANCE PIC ZZZ,ZZ9.99.

Thank you very much.


 
If the number appears as "028238.24" in the file, then the period is not a numeric value consistent a PIC 9 field. Furthermore, you have an intended format of PIC 9(6)V99 which is unworkable as well.

I don't know what compiler you are on (that matters), but I would try either a literal "." in the input definition (it may or may not work), or barring that, processing to force the "." out of the input since it is not a numeric.

As a hint, a proper PIC 9(7)V99 appears in input as "002823824" (the V is an implied decimal and not a literal decimal).

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Glenn, Thank you very much for your post. It seemed to make sense, but after trying everything (to my knowledge, atleast) I haven't been able to convert it.

I changed the input file to not use any decimals at all.

It seems like i'm running out of options. What would you try?

I'm just using PuTTy to connect to my school and editing it through there. So i'm not entirely sure.

Thank you very much.
 
For this being a "first COBOL class", your best option is probably your instructor. For being a "first COBOL class" as well, removing the period is (I'm guessing) probably above your pay grade. So you would do well to check with your instructor to clarify on how you need to be making your test files for your assignments, since it seems you are uncertain on what is required.

That being said, I'm sure simple questions are okay here, but helping too much on homework would be a TOS violation here. So please keep that in mind if you post any more questions.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Thanks anyways Glenn. Was just hoping if someone could help correct the error. I've met with my instructor several times and no avail.

As said, Thank you anyways.
 
1. What is the error message?
2. What compiler and o/s are you using?
3. What is the source of the file?
 
You can write a procedure which tries to convert the given string into a number according the rules you define.
Here is a simple example:
Code:
       [COLOR=#804040][b]IDENTIFICATION[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].            
       [COLOR=#804040][b]PROGRAM-ID[/b][/color]. STR2NUM.                
       [COLOR=#804040][b]ENVIRONMENT[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].               
       [COLOR=#804040][b]CONFIGURATION[/b][/color][COLOR=#804040][b] SECTION[/b][/color].              
       [COLOR=#804040][b]SOURCE-COMPUTER[/b][/color]. IBM-ISERIES.       
       [COLOR=#804040][b]OBJECT-COMPUTER[/b][/color]. IBM-ISERIES.       
       [COLOR=#804040][b]SPECIAL-NAMES[/b][/color].                      
       [COLOR=#804040][b]DATA[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].                      
       [COLOR=#804040][b]WORKING-STORAGE[/b][/color][COLOR=#804040][b] SECTION[/b][/color].            
       [COLOR=#2e8b57][b]01 [/b][/color]STR-LEN9    [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]).            
       [COLOR=#2e8b57][b]01 [/b][/color]STR-DEC6V2 [COLOR=#6a5acd]REDEFINES[/color] STR-LEN9.   
          [COLOR=#2e8b57][b]05 [/b][/color]BEFORE-POINT [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]6[/color]).        
          [COLOR=#2e8b57][b]05 [/b][/color][COLOR=#804040][b]FILLER[/b][/color]       [COLOR=#804040][b]PIC[/b][/color] X.           
          [COLOR=#2e8b57][b]05 [/b][/color]AFTER-POINT  [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]2[/color]).        
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]6[/color]).            
       [COLOR=#2e8b57][b]01 [/b][/color]DEC2        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]2[/color]).
       [COLOR=#804040][b]WORKING-STORAGE[/b][/color][COLOR=#804040][b] SECTION[/b][/color].                                     
       [COLOR=#2e8b57][b]01 [/b][/color]STR-LEN9    [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]).                                     
       [COLOR=#2e8b57][b]01 [/b][/color]STR-DEC6V2 [COLOR=#6a5acd]REDEFINES[/color] STR-LEN9.                            
          [COLOR=#2e8b57][b]05 [/b][/color]BEFORE-POINT [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]6[/color]).                                 
          [COLOR=#2e8b57][b]05 [/b][/color][COLOR=#804040][b]FILLER[/b][/color]       [COLOR=#804040][b]PIC[/b][/color] X.                                    
          [COLOR=#2e8b57][b]05 [/b][/color]AFTER-POINT  [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]2[/color]).                                 
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]6[/color]).                                     
       [COLOR=#2e8b57][b]01 [/b][/color]DEC2        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]2[/color]).                                     
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6V2      [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]6[/color])[COLOR=#ff00ff]V9[/color]([COLOR=#ff00ff]2[/color]).                                
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6V2-DSP  [COLOR=#804040][b]PIC[/b][/color] ZZZ,[COLOR=#ff00ff]ZZ9[/color].[COLOR=#ff00ff]99[/color].                               
      [COLOR=#0000ff]*                                                             [/color]
       [COLOR=#2e8b57][b]01 [/b][/color]MY-STRING1     [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]) [COLOR=#804040][b]VALUE[/b][/color] [COLOR=#ff00ff]"028238.24"[/color].                
       [COLOR=#2e8b57][b]01 [/b][/color]MY-STRING2     [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]) [COLOR=#804040][b]VALUE[/b][/color] [COLOR=#ff00ff]"  123.245"[/color].                
       [COLOR=#804040][b]PROCEDURE[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]MAIN[/b][/color].
      [COLOR=#0000ff]*    Trying it with MY-STRING1                                [/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"Trying to convert the string '"[/color] MY-STRING1 [COLOR=#ff00ff]"'"[/color]. 
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]INITIALIZE[/b][/color] DEC6V2                                        
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] MY-STRING1 [COLOR=#804040][b]TO[/b][/color] STR-LEN9 
      [COLOR=#6a5acd]     [/color][COLOR=#008080]PERFORM[/color] PROC-STR2NUM                                     
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] DEC6V2 [COLOR=#804040][b]TO[/b][/color] DEC6V2-DSP.                               
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"The number is "[/color] DEC6V2-DSP                      
      [COLOR=#6a5acd]                                                              [/color]
      [COLOR=#0000ff]*    Trying it with MY-STRING2                                [/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"Trying to convert the string '"[/color] MY-STRING2 [COLOR=#ff00ff]"'"[/color]. 
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]INITIALIZE[/b][/color] DEC6V2                                        
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] MY-STRING2 [COLOR=#804040][b]TO[/b][/color] STR-LEN9        
      [COLOR=#6a5acd]     [/color][COLOR=#008080]PERFORM[/color] PROC-STR2NUM                
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] DEC6V2 [COLOR=#804040][b]TO[/b][/color] DEC6V2-DSP.          
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"The number is "[/color] DEC6V2-DSP 
      [COLOR=#0000ff]*                                        [/color]
      [COLOR=#6a5acd]     [/color][COLOR=#008080]GOBACK[/color]                              
      [COLOR=#6a5acd]     [/color].                                   
      [COLOR=#6a5acd]                                         [/color]
        [COLOR=#804040][b]PROC-STR2NUM[/b][/color].                          
      [COLOR=#6a5acd]      [/color][COLOR=#804040][b]IF[/b][/color] BEFORE-POINT [COLOR=#804040][b]IS[/b][/color] [COLOR=#804040][b]NUMERIC[/b][/color] [COLOR=#804040][b]AND[/b][/color]     
      [COLOR=#6a5acd]         [/color]AFTER-POINT  [COLOR=#804040][b]IS[/b][/color] [COLOR=#804040][b]NUMERIC[/b][/color]         
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]MOVE[/b][/color] BEFORE-POINT [COLOR=#804040][b]TO[/b][/color] DEC6          
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]MOVE[/b][/color] AFTER-POINT  [COLOR=#804040][b]TO[/b][/color] DEC2          
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]COMPUTE[/b][/color] DEC6V2 = DEC6 + DEC2 / [COLOR=#ff00ff]100[/color] 
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]ELSE[/b][/color]                                  
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"This doesn't work !"[/color]      
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]END-IF[/b][/color]                                
      [COLOR=#6a5acd]     [/color].
Output:
Code:
Trying to convert the string '028238.24'            
The number is  28,238.24                            
Trying to convert the string '  123.245'            
This doesn't work !                                 
The number is       0.00
 
The source above has bug - 2x working storage.
Here is the correct source:
Code:
       [COLOR=#804040][b]IDENTIFICATION[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]PROGRAM-ID[/b][/color]. STR2NUM.
       [COLOR=#804040][b]ENVIRONMENT[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]CONFIGURATION[/b][/color][COLOR=#804040][b] SECTION[/b][/color].
       [COLOR=#804040][b]SOURCE-COMPUTER[/b][/color]. IBM-ISERIES.
       [COLOR=#804040][b]OBJECT-COMPUTER[/b][/color]. IBM-ISERIES.
       [COLOR=#804040][b]SPECIAL-NAMES[/b][/color].
       [COLOR=#804040][b]DATA[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]WORKING-STORAGE[/b][/color][COLOR=#804040][b] SECTION[/b][/color].
       [COLOR=#2e8b57][b]01 [/b][/color]STR-LEN9    [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]).
       [COLOR=#2e8b57][b]01 [/b][/color]STR-DEC6V2 [COLOR=#6a5acd]REDEFINES[/color] STR-LEN9.
          [COLOR=#2e8b57][b]05 [/b][/color]BEFORE-POINT [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]6[/color]).
          [COLOR=#2e8b57][b]05 [/b][/color][COLOR=#804040][b]FILLER[/b][/color]       [COLOR=#804040][b]PIC[/b][/color] X.
          [COLOR=#2e8b57][b]05 [/b][/color]AFTER-POINT  [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]2[/color]).
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]6[/color]).
       [COLOR=#2e8b57][b]01 [/b][/color]DEC2        [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]2[/color]).
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6V2      [COLOR=#804040][b]PIC[/b][/color] [COLOR=#ff00ff]9[/color]([COLOR=#ff00ff]6[/color])[COLOR=#ff00ff]V9[/color]([COLOR=#ff00ff]2[/color]).
       [COLOR=#2e8b57][b]01 [/b][/color]DEC6V2-DSP  [COLOR=#804040][b]PIC[/b][/color] ZZZ,[COLOR=#ff00ff]ZZ9[/color].[COLOR=#ff00ff]99[/color].
      [COLOR=#0000ff]*[/color]
       [COLOR=#2e8b57][b]01 [/b][/color]MY-STRING1     [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]) [COLOR=#804040][b]VALUE[/b][/color] [COLOR=#ff00ff]"028238.24"[/color].
       [COLOR=#2e8b57][b]01 [/b][/color]MY-STRING2     [COLOR=#804040][b]PIC[/b][/color] X([COLOR=#ff00ff]9[/color]) [COLOR=#804040][b]VALUE[/b][/color] [COLOR=#ff00ff]"  123.245"[/color].
       [COLOR=#804040][b]PROCEDURE[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]MAIN[/b][/color].
      [COLOR=#0000ff]*    Trying it with MY-STRING1[/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"Trying to convert the string '"[/color] MY-STRING1 [COLOR=#ff00ff]"'"[/color].
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]INITIALIZE[/b][/color] DEC6V2
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] MY-STRING1 [COLOR=#804040][b]TO[/b][/color] STR-LEN9
      [COLOR=#6a5acd]     [/color][COLOR=#008080]PERFORM[/color] PROC-STR2NUM
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] DEC6V2 [COLOR=#804040][b]TO[/b][/color] DEC6V2-DSP.
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"The number is "[/color] DEC6V2-DSP

      [COLOR=#0000ff]*    Trying it with MY-STRING2[/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"Trying to convert the string '"[/color] MY-STRING2 [COLOR=#ff00ff]"'"[/color].
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]INITIALIZE[/b][/color] DEC6V2
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] MY-STRING2 [COLOR=#804040][b]TO[/b][/color] STR-LEN9
      [COLOR=#6a5acd]     [/color][COLOR=#008080]PERFORM[/color] PROC-STR2NUM
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]MOVE[/b][/color] DEC6V2 [COLOR=#804040][b]TO[/b][/color] DEC6V2-DSP.
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"The number is "[/color] DEC6V2-DSP
      [COLOR=#0000ff]*[/color]
      [COLOR=#6a5acd]     [/color][COLOR=#008080]GOBACK[/color]
      [COLOR=#6a5acd]     [/color].

       [COLOR=#804040][b]PROC-STR2NUM[/b][/color].
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]IF[/b][/color] BEFORE-POINT [COLOR=#804040][b]IS[/b][/color] [COLOR=#804040][b]NUMERIC[/b][/color] [COLOR=#804040][b]AND[/b][/color]
      [COLOR=#6a5acd]        [/color]AFTER-POINT  [COLOR=#804040][b]IS[/b][/color] [COLOR=#804040][b]NUMERIC[/b][/color]
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]MOVE[/b][/color] BEFORE-POINT [COLOR=#804040][b]TO[/b][/color] DEC6
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]MOVE[/b][/color] AFTER-POINT  [COLOR=#804040][b]TO[/b][/color] DEC2
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]COMPUTE[/b][/color] DEC6V2 = DEC6 + DEC2 / [COLOR=#ff00ff]100[/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]ELSE[/b][/color]
      [COLOR=#6a5acd]        [/color][COLOR=#804040][b]DISPLAY[/b][/color] [COLOR=#ff00ff]"This doesn't work !"[/color]
      [COLOR=#6a5acd]     [/color][COLOR=#804040][b]END-IF[/b][/color]
      [COLOR=#6a5acd]     [/color].
 
COBOL is being taught in college? I didn't know that.
 
It should be. COBOL is a modern language and the only one that supports many accounting and other business concerns, such as working with 16 (now 31) digit numbers with no rounding errors, as well as code that can be understood by non-programmer auditors and users.
 
No flame, but I cannot agree with "COBOL is a modern language" :)
OK it has now more intrinsic functions and on some platforms greate enhancements like the statements XML PARSE and XML GENERATE,...but I still miss at least local variables.
I had an occasion to work with ABAP - only one week. ABAP is IMHO an improved COBOL. But I found in ABAP everything I missed in COBOL i.e: local variables and recursion. I know you can declare now in some COBOL dialects, that program should be recursive
Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID. FACTORIAL RECURSIVE.
       ....
but I mean a recursion at paragraph level, something like this (in ABAP paragraph is marked with the keyword FORM):
Code:
* Form with recursive call for computation of factorial 
FORM faktorial USING value(n) TYPE i CHANGING fak TYPE f.
* local variables
  DATA: n_1 TYPE i,
        fak_n_1 TYPE f.

  IF n <= 0.
    fak = 1.
  ELSE.
    n_1 = n - 1.
    PERFORM faktorial USING n_1 CHANGING fak_n_1.
    fak = n * fak_n_1.
  ENDIF.
ENDFORM.
If it could be possible to enhance COBOL in the direction of ABAP, so that it supports at least local variables and maybe recursion, then it would be "modern language" for the next 50 years.
 
Yes, not all versions support local variables and recursion. The problem with recusion at the paragraph level is the whole design structure of COBOL where the variables must be declared at the beginning of the program. However, the version I use at least, allows embedded subprograms which can be of any size. And, of course, local variables are supported.

But is there any other high-level language that supports 31-digit fixed-point decimal arithmetic?
 
webrabbit said:
However, the version I use at least, allows embedded subprograms which can be of any size. And, of course, local variables are supported.
And can you say what compiler do you use?

I'm using ILE COBOL on iSeries. It supports procedures and recursion, but using this features requires multiple compilation/binding steps - see this thread from COBOL/400 mailing list
webrabbit said:
But is there any other high-level language that supports 31-digit fixed-point decimal arithmetic?
Not so far from COBOL and mainframe: REXX has decimal arithmetic with arbitrary precision, which you can set/change during computation.
For example this code
Code:
rslt [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b]/[/b][/color]6
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"1/6 with"[/color] [COLOR=#008080]DIGITS()[/color] [COLOR=#ff00ff]"digits precission:"[/color]
rslt [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b]/[/b][/color]6
[COLOR=#804040][b]say[/b][/color] rslt
[COLOR=#804040][b]say[/b][/color]

[COLOR=#804040][b]NUMERIC DIGITS[/b][/color] 31
rslt [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b]/[/b][/color]6
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"1/6 with"[/color] [COLOR=#008080]DIGITS()[/color] [COLOR=#ff00ff]"digits precission:"[/color]
rslt [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b]/[/b][/color]6
[COLOR=#804040][b]say[/b][/color] rslt
[COLOR=#804040][b]say[/b][/color]

[COLOR=#804040][b]NUMERIC DIGITS[/b][/color] 66
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"1/6 with"[/color] [COLOR=#008080]DIGITS()[/color] [COLOR=#ff00ff]"digits precission:"[/color] 
rslt [COLOR=#804040][b]=[/b][/color] 1[COLOR=#804040][b]/[/b][/color]6
[COLOR=#804040][b]say[/b][/color] rslt
computes
Code:
1/6 with 9 digits precission:
0.166666667

1/6 with 31 digits precission:
0.1666666666666666666666666666667

1/6 with 66 digits precission:
0.166666666666666666666666666666666666666666666666666666666666666667
 
webrabbit,

I didn't want to imply that it shouldn't be taught. I am surprised that it is. I cut my programming teeth on COBOL and RPG along with a little FORTRAN and BASIC.
 
I do recursion and use local variables with an even older compiler (on Unix):
Micro Focus cobol v3.1.31-Be
 
This should be a simple problem given that this is an introductory COBOL course. The compiler involved likely is at least 1985 standard compliant which means it should support de-edited moves:

Code:
01  WS-INPUT-NUMBER    PIC 9(6).99.
01  WS-OUTPUT-NUMBER   PIC ZZZ,ZZ9.99.
...
MOVE WS-INPUT-NUMBER TO WS-OUTPUT-NUMBER
That should do the trick.

Glenn
 
I thought that the question was about converting the content of string into number (if possible), i.e
from
Code:
01  WS-INPUT-NUMBER    PIC X(9).
to
Code:
01  WS-OUTPUT-NUMBER   PIC ZZZ,ZZ9.99.
where this
Code:
MOVE WS-INPUT-NUMBER TO WS-OUTPUT-NUMBER
doesn't work.
 
I thought that the question was about converting the content of string into number (if possible), i.e

No. Homework question. I gather that the OP didn't understand the course problem well enough to generate a test data file properly (or got the format wrong entirely). His/her instructor is the best person that they need to be dealing with for this problem.

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
Why not simply this ?

05 CM-BEGINNING-BALANCE PIC X(9).

05 CL-BEGINNING-BALANCE PIC ZZZ,ZZ9.99.


MOVE FUNCTION NUMVAL(CM-BEGINNING-BALANCE) TO CL-BEGINNING-BALANCE

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top