Subject: | |
From: | |
Reply To: | |
Date: | Wed, 3 May 2000 11:51:41 -0700 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
While not exactly what you asked for, this may spark some ideas.
From an RCEN in our database...
A1375391
COBOL - right justify and fill with leading zeros
Problem Description
In COBOL, how can I take a X(6) field, ACCEPTed from the screen,
move it to another X(6) field, right justify the input, and fill
with leading zeros?
Solution
COBOL'85 has a feature called "REFERENCE MODIFICATION", COBOLII
Manual (part number 32233-90001) p. 8-39. This feature is a SUBSTRING
type function which allows referencing pieces of a string field. Use
the following example:
IDENTIFICATION DIVISION.
...
WORKING-STORAGE SECTION.
01 FIELDS.
05 INPUT-FIELD PIC X(6).
05 OUTPUT-FIELD PIC X(6) VALUE ZEROS JUST.
...
PROCEDURE DIVISION.
MAIN-CONTROL.
ACCEPT INPUT-FIELD FREE.
EXAMINE INPUT-FIELD REPLACING LEADING " " BY "0".
EXAMINE INPUT-FIELD TALLYING UNTIL FIRST " ".
MOVE INPUT-FIELD(1:TALLY) TO OUTPUT-FIELD.
EXAMINE OUTPUT-FIELD REPLACING ALL " " BY "0".
...
TAWNY TRAN wrote:
>
> Dear Listers,
> I haven't code COBOL for a while, so I wonder if there is other way to do
> right justify for an alphanumeric field from input?
>
> The input is from 12 to 16 digits. If there are 12 digits, I must discard
> all trailing spaces, so only I can think of is PERFORM
> ...VARYING indexed FROM 16 BY -1 UNTIL...... to do the job.
>
> Or is something new I don't know...?
>
> Thanks,
|
|
|