IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Missing Negative sign in COBOL


IBM Mainframe Forums -> COBOL Programming
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Sat Sep 26, 2020 11:32 am
Reply with quote

i've got the following code fragment:

Code:

01 WS-NUMFMT    PIC Z(12)9.99- BLANK WHEN ZERO.
01 MNTH_ONG_LIAB_AMT    PIC X(11) JUSTIFIED.
...
 
MOVE 12345.67 TO WS-NUMFMT
MOVE WS-NUMFMT TO MNTH_ONG_LIAB_AMT


this produces the correct result : "12345.67-"

however, with the definition :

01 WS-NUMFMT PIC -Z(12)9.99 BLANK WHEN ZERO.

... I lose the sign, and get only "12345.67"

any help appreciated !
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Tue Sep 29, 2020 7:07 pm
Reply with quote

How can moving a positive value to WS-NUMFMT produce a "correct" (as you say) negative result?

I would expect the "-" in the edit mask to be replaced with a blank since your value is positive.

You need to show results as produced, not just say what they are.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Tue Sep 29, 2020 7:24 pm
Reply with quote

I think at a minimum you have a typo; at the maximum you are lying. Code:
Code:
000800  WORKING-STORAGE SECTION.                                       
000900  01  WS-VARS.                                                   
001000      05  WS-NUMVAR1              PIC Z(12)9.99- BLANK WHEN ZERO.
001100      05  WS-NUMVAR2              PIC -Z(12)9.99 BLANK WHEN ZERO.
001200  PROCEDURE DIVISION.                                             
001300      MOVE 12345.67               TO  WS-NUMVAR1                 
001400                                      WS-NUMVAR2.                 
001500      DISPLAY 'NUMVAR1 >' WS-NUMVAR1 '<'.                         
001600      DISPLAY 'NUMVAR2 >' WS-NUMVAR2 '<'.                         
001700      DISPLAY ' ' .                                               
001800      MOVE -12345.67              TO  WS-NUMVAR1                 
001900                                      WS-NUMVAR2.                 
002000      DISPLAY 'NUMVAR1 >' WS-NUMVAR1 '<'.                         
002100      DISPLAY 'NUMVAR2 >' WS-NUMVAR2 '<'.                         
produces results of
Code:
NUMVAR1 >        12345.67 < 
NUMVAR2 >         12345.67< 
                             
NUMVAR1 >        12345.67-< 
NUMVAR2 >-        12345.67< 
These results are precisely as expected -- and completely contradict what you posted. Hence my earlier statement that you have typo(s) or are lying.
Back to top
View user's profile Send private message
jzhardy

Active User


Joined: 31 Oct 2006
Posts: 131
Location: brisbane

PostPosted: Thu Oct 01, 2020 4:39 pm
Reply with quote

there was an obvious typo in the original post; but equally true you didn't read the post.

error on my part was not using a floating sign. The definition should have been:

01 WS-NUMFMT PIC -(12)9.99 BLANK WHEN ZERO.


The 'lying' suggestion both unprofessional and unbecoming of a 'moderator'
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2011
Location: USA

PostPosted: Thu Oct 01, 2020 7:12 pm
Reply with quote

jzhardy wrote:
there was an obvious typo in the original post; but equally true you didn't read the post.

error on my part was not using a floating sign. The definition should have been:

01 WS-NUMFMT PIC -(12)9.99 BLANK WHEN ZERO.


The 'lying' suggestion both unprofessional and unbecoming of a 'moderator'

I recommend you either to RTFM, or move your questions to the Beginners Forum.
No way to discuss in your manner here.
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu Oct 01, 2020 7:23 pm
Reply with quote

I stand by my reply.

You still moved an unsigned number to WS-NUMFMT, and you have not replied to that.

Your post: MOVE 12345.67 TO WS-NUMFMT
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Oct 01, 2020 8:28 pm
Reply with quote

You CANNOT, under any circumstances, get the value 12345.67- when you move 12345.67 to your WS-NUMFMT variable. I showed this in my code post. So when you tell us you got certain results, and it has been proved beyond any doubt that you CANNOT get those results with what you posted, what conclusion should we draw? Furthermore, I did NOT accuse you of lying -- what I said was that you either have a typo or you were lying.

Start posting on Beginners and Students Forum as it is much more suited for your skill set. It doesn't matter how many "years" of experience you claim, you are a beginner.

Topic locked to prevent further waste of time.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top