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.
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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.