View previous topic :: View next topic
|
Author |
Message |
dyobik
New User
Joined: 04 Nov 2006 Posts: 5
|
|
|
|
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 |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
IF can't we use the 'JUST LEFT' when you decalare the field in the Workign storage?
~Vamsi |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
Thanks Marso.
I thought since there exits 'JUST RIGHT', there would be 'JUST LEFT'.
Thanks for your clarification.
~Vamsi |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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 |
|
|
|