Return to the RPG Tips
Centering Text with RPG III
Here's a handy subroutine Gary Whitten published in Midrange Computing.
You'll need to define twocharacter fields in your program: INPUT and OUTPUT.
They may be of any valid RPG character field length, but they should be the same size.
Before you execute the CENTER subroutine, place the text you want to center in the INPUT field.
After your program executes the subroutine,the centered text will be contained in the OUTPUT field:
C CENTER BEGSR C MOVE *BLANKS OUTPUT C 'X' CHEKROUTPUT LEN 30 C ' ' CHEKRINPUT POS 30 C POS IFLT LEN C LEN SUB POS BLKS 30 C BLKS DIV 2 HAF 30 C CAT INPUT:HAF OUTPUT C ELSE C MOVE INPUT OUTPUT C ENDIF C ENDSR
[report a broken link by clicking here]