View previous topic :: View next topic
|
Author |
Message |
Mind
New User
Joined: 04 Nov 2010 Posts: 9 Location: bangalore
|
|
|
|
Hello Everyone,
I am a beginner in PL/I,
A variable is declared as char(80), in the program many operations are performed on that variable like substring and etc.
My question here is how can i right justify with ZEROES if at all the variable is less than 80 length. Every time any operation is performed on that variable, it should be right justified with ZEROES.
Please advice and let me know if the information is not sufficient.
Thanks in advance. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
The variable is declared with a fixed length of 80, so it can NEVER be less than or greater thasn 80 in length.
Garry. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
I think you mean the actual (non-blank) content is < 80 chars - is this correct?
Justify which way - right or left?
Sub-stringing a value from the var will not modify it at all (in any language), so that part of your query is odd.
Sub-stringing a value into the var will affect just those positions, right? So that cannot affect justification or the fill character either.
Given my comments, please reformulate your question with no extraneous information. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
don't know anything about PL/1,
but normally,
in a char field, everything is left-justified,
numeric field, everything is right-justified.
in COBOL, if i really wanted all zeroes in the 80 char, i would stipulate that in the VALUE clause.
If I wanted only a certain number of zeroes,
i would subdivide the 80 chars into two parts,
the first populated with spaces,
the second with zeros.
I have to ask though,
why do you want zeroes (how many) in the ass-end of an 80 char field? |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
Quote: |
why do you want zeroes (how many) in the ass-end of an 80 char field?
|
Dick,
S/he wants to right-justify, so that'd put the non-zeroes in the ass-end, surely?
Garry. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
sort of like the south-end of a north-bound cow? |
|
Back to top |
|
|
Akatsukami
Global Moderator
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
|
|
|
|
As indicated by Messrs. Brenholz, Carroll, and Phrzby, this is a damned strange requirement. Assuming that you actually mean what you're saying, however, this should provide you with an example:
Code: |
foo20: proc options (main);
dcl (var1, var2) char (80);
dcl (var1_5) char (80) var;
var1 = '123456789';
var1_5 = trim(var1);
if (length(var1_5)=80)
then var2 = var1_5;
else var2 = repeat('0',(80-length(var1_5))-1) || var1_5;
put skip edit ('Var2 = [', var2, ']') (a, a, a);
end foo20; |
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Mind wrote: |
Hello Everyone,
I am a beginner in PL/I,
A variable is declared as char(80), in the program many operations are performed on that variable like substring and etc.
My question here is how can i right justify with ZEROES if at all the variable is less than 80 length. Every time any operation is performed on that variable, it should be right justified with ZEROES.
Please advice and let me know if the information is not sufficient.
Thanks in advance. |
I'm not PL/I either. But, do you want a right-justified field, left-filled with zeros, or a left-justified field, right-filled with zeros.
AAAAAA000000
or
000000AAAAAA
I guess the normal contents of the field, after a "move", would be data left-jutified and space-filled to the right. If that is the way PL/I is operating and you need zeros, translate (in whatever way there is) the spaces to zeros.
Note, if your "string" has trailing spaces, those will translate as well.
Or, as Dick said and if you are only placing data in the left of the field (with a length, so the compiler will not do the space filling) set the whole thing to zero first. This would preserve trailing spaces in your string.
However, until you are clearer about what you want, we won't get much closer to how to do it. |
|
Back to top |
|
|
|