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

How to use LEFT Justified in cobol


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

New User


Joined: 04 Nov 2006
Posts: 5

PostPosted: Mon Nov 06, 2006 2:59 pm
Reply with quote

hi,

i want to know how to use left justified in cobol?

they say that i should use unstring but i cant still get it.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Nov 06, 2006 4:05 pm
Reply with quote

Quick and dirty:
Code:
INSPECT input-field REPLACING LEADING SPACE BY HIGH-VALUE
UNSTRING input-field DELIMITED BY ALL HIGH-VALUE         
    INTO garbage-field output-field

input-field is the input field. It contains data somewhere in the middle or on the right side of the field.
output-field will contain the same data but left justified.
As the delimiter is H-V, all that's on the left of H-V is considered 1st word. All that's right of H-V is 2nd word. garbage-field is necessary to contain the 1st word (which is empty, but we don't care).
INSPECT and UNSTRING are heavy commands. If you know you have to use them 20 million times, beware of the CPU usage!
Back to top
View user's profile Send private message
shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Mon Nov 06, 2006 4:19 pm
Reply with quote

IF can't we use the 'JUST LEFT' when you decalare the field in the Workign storage?

~Vamsi
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Nov 06, 2006 4:34 pm
Reply with quote

JUST LEFT does not exist. It is the default for all PIC X(n) fields.
Only JUST RIGHT can be used to alter the default.

It has meaning only when you move a small field into a large field.
The small field will be placed on the left or right side of the large field.
The rest will be padded with spaces.
If the small field contains spaces, they will stay as they were.
Back to top
View user's profile Send private message
shreevamsi

Active User


Joined: 23 Feb 2006
Posts: 305
Location: Hyderabad,India

PostPosted: Mon Nov 06, 2006 4:44 pm
Reply with quote

Thanks Marso.

I thought since there exits 'JUST RIGHT', there would be 'JUST LEFT'.
Thanks for your clarification.

~Vamsi
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Nov 06, 2006 5:53 pm
Reply with quote

No problem. On second thought, this option is certainly quicker and less dirty:
Code:
MOVE 0 TO counter
INSPECT input-field TALLYING counter FOR LEADING SPACE
MOVE input-field (counter + 1 :) TO output-field

Now, it will work even when there is no leading space, the previous method did not.
The MOVE will be faster than the UNSTRING, that's for sure.
No need for the garbage-field either.
In the whole I would use this method.
Note that initializing the counter before the INSPECT is a must.
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 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