Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

left-justified to right-justified 1

Status
Not open for further replies.

rlh145

Programmer
Feb 19, 2001
36
US
I am somewhat rusty in Cobol and have not kept up with the latest versions in Cobol. Is there some good functions available now to shift a field that is left-justified to a field that will make it right-justified? Thanks for any help you can offer me!!

Ralph
 
Hi Ralph,

No, nothing new. I assume you want to get rid of leading/trailing blanks. The JUSTIFY clause in the DD only works for fields of differing lengths.

If you're trying to get blanks out of a numeric field you could use the new NUMVAL intrinsic function. Else you'd have to use something like string/unstring or inspect (they combined some/most of the functions of transform and, I think, examine).

But anyway, there's not much new.

Hope this helps, Jack.
 
There is no native function for such justification. (The Justify clause comes close, but doesn't do EXACTLY what you are looking for). For example if you have a field that contains:

"XX " and you move it to a 10 byte field with justify, you will get: " XX ".

You still have the trailing spaces.

Tell me what compiler and version you are using. I might have some code.
 
I don't know any function. But I know work around

Try this:
EX:
DATANAME-LEFT PIC X(30).
DATA-LENGTH PIC 9(3).
DATANAME-RIGHT PIC X(30).

MOVE LENGTH OF DATANAME-LEFT TO DATA-LENGTH.
SUBTRACT DATANAME-LENGTH FROM 30 GIVING DATA-START.
MOVE DATANAME-LEFT TO DATANAME-RIGHT(DATA-START:DATA-LENGTH).


 
HI GOTLURU....I DONT THINK UR METHOD CAN GIVE THE DESIRED RESULT..LENGTH OF GIVES THE LENGTH AS 30 (MENTIONED IN UR ABOVE EG) WE DONT GET THE LENGTH OF THE VARIABLE ENTERED BUT WE GET THE LENGTH AS IS DECLARED...
UR METHOD CAN BE MODIFIED AND CORRECTED USING AN ARRAY USED TO RETRIEVE THE LENGTH OF THE VARIABLE ENTERED AND THEN USING IT IN PLACE OF DATA-LENGTH....AM I CORRECT....?
KURUP
 
Hi Kurup,

You are right, I am getting length of declared. As you said get the length from an array and use my logic.

Thanks for correcting me..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top