HP3000-L Archives

June 2000, Week 1

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Randy Keefer <[log in to unmask]>
Reply To:
Randy Keefer <[log in to unmask]>
Date:
Wed, 7 Jun 2000 09:15:21 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (53 lines)
On Tue, 6 Jun 2000 14:43:25 -0700, Newton, Ernie
<[log in to unmask]> wrote:

>Hi all,
>
>I have a need to pluck out the four rightmost characters of a variable
>length string.  The problem being that the string is alphanumeric and COBOL
>left-justifies those type of things.  Somewhere in the deep recesses of my
>aged mind, I seem to recall that there is a JUSTIFY command available in
>COBOL.  I could do an algorithm to count the characters, but life would be
>so much simpler if I could right-justify it.
>
>Is there such a thing?  And if so, what is the syntax?
>
>Thanks,
>
>
>Ernie Newton
>Computer Systems Specialist
>Yolo County Office of Education
>[log in to unmask]
 ========================================================================
To keep it simple, I'd just do a
'PERFORM VARYING counter UNTIL string(counter:1) <> " " '

As follows:

Data Division.
01  counter         PIC 999 VALUE 0.
01  string          PIC X(100) VALUE "who knows".
01  last-four-chars PIC X(04) VALUE SPACES.

Procedure Division.

     MOVE 100 TO counter.
     PERFORM VARYING counter FROM 100 BY -1
               UNTIL string(counter:1) <> " "
        CONTINUE
     END-PERFORM.
     SUBTRACT 3 FROM counter.
     MOVE string(counter:4) TO last-four-chars.



I hope this helps and isn't too much code.  It's simple, but it works.  I
have had to do this for years in name parsing (ie. "Mr. Cal Ripken, Jr."
becomes TITLE="Mr.", FNAME="Cal", LASTNAME="Ripken", QUALIFYER="Jr.")

Randy Keefer, Consultant

ps.  The opinions do not represent those of Hughes Network Systems or any of
its employees.  They are my opinions alone.

ATOM RSS1 RSS2