Re: Right justifying (arbitrary) alphanumeric input
From: James J. Gavan (jgavandeletethis_at_shaw.ca)
Date: 03/03/05
- Next message: Richard: "Re: moving data from one place to another in a text file"
- Previous message: jce: "Re: moving data from one place to another in a text file"
- In reply to: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Next in thread: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Reply: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 02 Mar 2005 23:32:43 GMT
epc8@juno.com wrote:
>
> Thanks. I have since learned that expressions are allowed in reference
> modificaion, once I separate the operators from the operands. So the
> program simplifies to this:
>
> identification division.
> program-id. test1.
> data division.
> working-storage section.
> 01 x pic x(26) value "abcdefghijklmnopqrstuvwxyz".
> 01 y pic x(26).
> 01 i pic 99.
> 01 j pic 99.
> procedure division.
> main.
> compute j = function length(x).
> perform next-i varying i from 0 by 1
> until i is greater than j.
> stop run.
> next-i.
> move x to y.
> if i is > 0 and i < j perform
> move function reverse(y(1:i)) to y(1:i)
> move function reverse(y(i + 1:j - i)) to y(i + 1:j - i)
> move function reverse(y) to y
> end-perform.
> display i space y.
>
> -- Elliot
>
OK so it works - but what does it actually do ? (Lazy way - I compiled
and ran it) - but it will hiccup if you do the following. Take your two
fields pic x(26) and make them pic x(44, or 50, or....). Take the
"a.....z" and put the relevant number of spaces in FRONT of the
alphabet, similarly put the spaces after the alphabet - although you
don't need to do that because the spaces are understood when you say pic
x(44). Other permutations using pic x(44), some spaces in front and at
the end, and split the alphabet so there are spaces in the middle -
"abcdefghij klmnopqrstuvwxyz".
To be worthwhile it has to handle the above options and possibly more I
haven't thought of. I can do it quite simply using some OO methods (The
code is already there without me thinking about it) - but that's not
much help to you.
But I can give you some pointers, and this is NOT a
recommendation/suggestion how you should do it using Procedural COBOL -
the string and length are passed to a method which using an array
technique, (a TABLE in COBOL parlance), i.e. each incoming character
(not just alpha or numeric) is identified by a position/index in the
array. Take the split alpha above - it ignores the spaces at the front
and end and the spaces between "...hij" and "klm". Trying to keep this
simple - it has a second array of 'words' the 'semi-words' you find
without a space - those 'semi-words' get stored with differing lengths
and then they are all STRUNG back together again.
You need to keep a count of the words it finds. So what's happening in
OO - your y pic x(44) is initialized then I can do a
perform varying n from 1 by 1 until n > MyWordCount
STRING the current "semi-word" into y.
Second time around y contains the first 'semi-word' and now
we string the second 'semi-word" into the existing y
etc...
end-perform
Simplest way I would suggest, keeping a count of total characters found
- do a Reference Modification where you want right justified, otherwise
automatically left justified.
Now the original version I wrote, using the support methods just handled
strings with the option of including one space between 'real words' in
the resultant 01 y pic x(44) above, or string the whole thing together
ignoring ALL spaces. Then because I want to take a text field and
display it in a Dialog or as a label in a Treeview, then I added options
to get back the text with/without x'00' at the end.
If the last bit sounds like first-class gibberish :-
01 x pic x(50) value "George Washington".
then you get back
01 y pic x(50)
which will have a value of 'George Washington" + x'00' - a 'real' total
of 18 used characters.
Jimmy, Calgary AB
- Next message: Richard: "Re: moving data from one place to another in a text file"
- Previous message: jce: "Re: moving data from one place to another in a text file"
- In reply to: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Next in thread: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Reply: epc8_at_juno.com: "Re: Right justifying (arbitrary) alphanumeric input"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|