IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Variable declaration


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Mind

New User


Joined: 04 Nov 2010
Posts: 9
Location: bangalore

PostPosted: Thu May 19, 2011 5:45 pm
Reply with quote

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
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Thu May 19, 2011 7:44 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Thu May 19, 2011 8:13 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 19, 2011 8:13 pm
Reply with quote

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
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Thu May 19, 2011 8:22 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu May 19, 2011 8:45 pm
Reply with quote

sort of like the south-end of a north-bound cow?
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu May 19, 2011 8:45 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu May 19, 2011 8:55 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Variable Output file name DFSORT/ICETOOL 8
No new posts Moving Or setting POINTER to another ... COBOL Programming 2
No new posts parsing variable length/position data... DFSORT/ICETOOL 5
No new posts Masking variable size field - min 10 ... DFSORT/ICETOOL 4
Search our Forums:

Back to Top