MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Right-Justifying text in COBOL
Goto page Previous  1, 2
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
CraigG
Intermediate


Joined: 02 May 2007
Posts: 202
Topics: 0
Location: Viginia, USA

PostPosted: Thu Apr 03, 2008 3:12 pm    Post subject: Reply with quote

COBOL was never designed to handle strings, it works with fields. If you move an X(10) field to an X(20) left justified field it will put 10 spaces followed by the x(10) field even if the X(10) field only contains 1 character followed by 9 spaces.
Back to top
View user's profile Send private message
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Sat Apr 05, 2008 9:53 am    Post subject: Reply with quote

That's why you must use ref/mod to do the move. MOVE then uses the ref/mod length to JUST.
_________________
Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Sun Apr 06, 2008 11:31 am    Post subject: Reply with quote

The important concept to grasp with JUST RIGHT is that the MOVE statement looks at the lengths of the PICTUREs of the fields, not the contents of the fields. Look again at Craig's example. Also, I think he intended to say right justified, not left justified in his post.
_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Sun Apr 06, 2008 1:24 pm    Post subject: Reply with quote

I agree, when reference to the variable is not modified. If it is reference modified and moved to a just variable, the move uses the modified length.

Using Craig's example:

MOVE X10-FLD(1:1) TO X20-JUST-RIGHT

Produces a one char string at pos 20 of X20-JUST-RIGHT preceded by 19 spaces.
_________________
Regards, Jack.

"A problem well stated is a problem half solved" -- Charles F. Kettering
Back to top
View user's profile Send private message
Terry_Heinze
Supermod


Joined: 31 May 2004
Posts: 391
Topics: 4
Location: Richfield, MN, USA

PostPosted: Fri Jul 31, 2009 6:59 pm    Post subject: Reply with quote

This might be similar to other posts, but here's my contribution for right justifying the contents of any field:
Code:
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
           05  WS-ANYFIELD                 PIC  X(??) VALUE 'XXX'.             
           05  WS-WORK-FIELD               PIC  X(100).                         
      *        LENGTH of WS-WORK-FIELD must be >=                               
      *        WS-LENGTH-OF-ORIG-FIELD                                         
           05  WS-LENGTH-OF-ORIG-FIELD     PIC  999.                           
           05  WS-NBR-OF-TRAILING-BLANKS   PIC  999.                           
           05  WS-LENGTH-OF-DATA           PIC  999.                           
           05  WS-START-POS                PIC  999.                           
                                                                               
                                                                               
      *    The following will right justify the contents of                     
      *    WS-ANYFIELD.                                                         
           IF         WS-ANYFIELD = SPACE                                       
                   OR WS-ANYFIELD (LENGTH OF WS-ANYFIELD:1) NOT = SPACE         
               CONTINUE                                                         
           ELSE                                                                 
               MOVE WS-ANYFIELD            TO WS-WORK-FIELD                     
               MOVE LENGTH OF WS-ANYFIELD  TO WS-LENGTH-OF-ORIG-FIELD           
               PERFORM XXXX-RIGHT-JUSTIFY                                       
               MOVE SPACE                  TO WS-ANYFIELD                       
               MOVE WS-WORK-FIELD (1:WS-LENGTH-OF-DATA)                         
                 TO WS-ANYFIELD   (WS-START-POS:WS-LENGTH-OF-DATA)             
           END-IF                                                               
           .                                                                   
                                                                               
                                                                               
      *  Right justify the contents of WS-WORK-FIELD.                           
       XXXX-RIGHT-JUSTIFY.                                                     
           MOVE ZERO                   TO WS-NBR-OF-TRAILING-BLANKS             
           INSPECT FUNCTION REVERSE (WS-WORK-FIELD)                             
               TALLYING WS-NBR-OF-TRAILING-BLANKS FOR LEADING SPACE             
           COMPUTE WS-LENGTH-OF-DATA                                           
               = LENGTH OF WS-WORK-FIELD - WS-NBR-OF-TRAILING-BLANKS           
           COMPUTE WS-START-POS                                                 
               = WS-LENGTH-OF-ORIG-FIELD - WS-LENGTH-OF-DATA + 1               
           .                                                                   

_________________
....Terry
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group