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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Centre a string in AS400 Colbol

Status
Not open for further replies.

Uvaiz

MIS
Jun 13, 2003
38
CA
HI,

I was wondering if someone can help me how to center a string in a variable field in COLBOL/400.

Thank you
Tony
 
The same way you would center it elsewhere. Divide your string by 2, subtract result from the middle of the variable, and you found your starting point.

Use reference modification to insert your string into the variable.

Dimandja
 
There isn't a direct method, so you will need to something along the following lines. (It is not complete nor correct)

First get the size of the text of the string you wish to center. (A)

Then subtract that size from the total size of the field that is going to have the string centered. (B)

Divide the result by 2 (C)

Then using reference modification move the text to be centred into the destination string starting on the result C.


For help on the above search this forum for string, inspect and size
thread209-281365 will be an option also.

Once you have digested the results of your search please post your code and we will try and help you further if you still need it.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Thanks Dimandja / fredericofonseca

I shall try this sometime today. I am sure this should work.


Thanks very much.

Tony
 
Frederico's method is pretty standard. Only thing to be aware of... Result C is the number of leading spaces in the receiving field. You want to use reference modification to move your sending field to position C + 1 of the receiving field. This becomes especially important if the result C is zero.

example:
Sending field is 6 bytes long (A)
Receiving field is 10 bytes long (B)
C = (B - A) / 2 = (10-6)/2 = 2
You want to move the sending field into position 3 of the receiving field.
 
Tony, you can find an example of a COBOL routine that does centering plus left or right justification of a text string within a field at the following URL


The source code is downloadable and conforms to the ANSI/85 standard so it should run on the AS/400.

Hope this is helpful,

Saginaw
helpdesk@simotime.com
 
Hi saginaw,

Thank you very much for the info. The site is very informative and useful.

Shall try some of the examples.

Thanks again.
Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top