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 strongm 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
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.


 
Yes I forgot, that now the intrinsic function NUMVAL is available :)
Maybe it's depending on compiler, but in my case this simple move into display variable doesn't work:
Code:
MOVE FUNCTION NUMVAL(CM-BEGINNING-BALANCE) TO CL-BEGINNING-BALANCE
Trying to do it, I got this error:
Code:
 *    17  MSGID: LNC2780  SEVERITY: 30  SEQNBR:  000128                        
          Message . . . . :   Numeric function 'FUNCTION NUMVAL' was found, but
            was not allowed in this context. Statement discarded.
I have first to compute the value of NUMVAL into numeric variable and then move it into numeric edited variable:
Code:
       [COLOR=#804040][b]IDENTIFICATION[/b][/color][COLOR=#804040][b] DIVISION[/b][/color].
       [COLOR=#804040][b]PROGRAM-ID[/b][/color]. STR2NUM2.
       [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]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]COMPUTE[/b][/color] DEC6V2 = FUNCTION NUMVAL(MY-STRING1)
      [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]COMPUTE[/b][/color] DEC6V2 = FUNCTION NUMVAL(MY-STRING2)
      [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].
Using the intrinsic function NUMVAL is simpler than writing an own converting procedure and works better:
Code:
> call STR2NUM2                           
  Trying to convert the string '028238.24'
  The number is  28,238.24                
  Trying to convert the string '  123.245'
  The number is     123.25
 
Hi,

You can try this;

Define your record field as:

PIC 9(6).99. (use your orig value - 028238.24)

Code the receiving field as: PIC ZZZ,ZZ9.99.

Then, MOVE rec-fld TO recv-fld

I haven't tested, but the manual says num-ed to num-ed is permissable.

Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top