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

How to remove space in edited picture clause


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
lanand_hps

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Wed Nov 05, 2008 4:17 pm
Reply with quote

hi,
I have a variable declared as
01 WS-VAR1 PIC -$$$,$$$,$$9.99. (15 characters)

if i move 1.25 to this variable, it is dispayed as
-(9 spaces)$1.25

I want to remove the space between - and $ for all values.
I dont want to have - at the end.
Please comment.
Back to top
View user's profile Send private message
Harsh Saxena

New User


Joined: 10 Jul 2007
Posts: 2
Location: Pune

PostPosted: Wed Nov 05, 2008 6:07 pm
Reply with quote

move the variable WS-VAR1 to a temp variable of same size

Eg : WS-VAR2 pic x(15)

Unstring WS-VAR2 delimited by all spaces into WS-TEMP1, WS-TEMP2.

Now WS-TEMP1 carries all the spaces and WS-TEMP2 carries the actual data.

Move WS-TEMP2 TO WS-FINAL(being WS-
FINAL a destination field).
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: Wed Nov 05, 2008 6:15 pm
Reply with quote

In COBOL, the $ and the - can be floating insertion characters. However, they both cannot be floating insertion characters in the same PICTURE clause. Use PIC $$$$,$$$,$$9.99 and then use reference modification to insert the minus sign where you want it.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Nov 05, 2008 9:05 pm
Reply with quote

Hello,

If you are willing to show the minus (-) on the right, this will do what you want:

Code:
       01  SOME-MONEY        PIC $$,$$$,$$$.99-.

           MOVE -1236.88 TO SOME-MONEY.   
           DISPLAY SOME-MONEY.   

Output:
Code:
   $1,236.88-
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Nov 06, 2008 11:21 am
Reply with quote

Dick's example is usually the preferred method of displaying a signed currency amount. Is it a business requirement to "not show the - at the end"?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Fri Nov 07, 2008 3:22 pm
Reply with quote

For this you need bit of coding icon_sad.gif
Code:

01 RECVAR2 PIC -$$$,$$$,$$9.99.
01 alnum redefines recvar2.   
   02 sgn pic x.               
   02 numbr pic x(14).         
.
.
.
inspect  numbr tallying cnt for leading spaces.
compute strcnt = cnt + 1.                     
compute strend = 14 - cnt.                     
display sgn numbr(strcnt:strend).             
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Nov 07, 2008 4:14 pm
Reply with quote

Working-Storage
Code:

05  EDIT-MASK               PIC -$$$,$$$,$$9.99.
05  WS-SUB-1                PIC S9(4) COMP.
05  LEN-OF-EDIT-MASK        PIC S9(4) COMP.


Procedure
Code:

MOVE LENGTH OF EDIT-MASK  TO LEN-OF-EDIT-MASK
MOVE -12.34               TO EDIT-MASK

PERFORM VARYING WS-SUB-1
           FROM 2
             BY 1
          UNTIL WS-SUB-1 > LEN-OF-EDIT-MASK
             OR EDIT-MASK(WS-SUB-1:1) > SPACE
END-PERFORM

DISPLAY ':'  EDIT-MASK  ':'

MOVE EDIT-MASK(1:1)  TO EDIT-MASK(WS-SUB-1 - 1:1)

DISPLAY ':'  EDIT-MASK  ':'

MOVE SPACE           TO EDIT-MASK(1:1)

DISPLAY ':'  EDIT-MASK  ':'



OUTPUT:
Code:

:-        $12.34:
:-       -$12.34:
:        -$12.34:
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic 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 3
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
Search our Forums:

Back to Top