The RPG code:
* ....................................................
* : This program shows a method for :
* : centering text in a field :
* : :
* : 4/98 Booth M. :
* : :
* : (Note: this program uses the Opcode CHEKR. :
* : Originally the program did a loop, starting at :
* : the high number and decrementing column by :
* : column until a blank was encountered. CHEKR :
* : does this, as an Opcode. Many thanks to :
* : Mark Westphal for pointing this out to me.) :
* : < Mark Westfall vtas400@together.net > :
* : :
* ::::::::::::::::::::::::::::::::::::::::::::::::::::
FCENTERFMCF E WORKSTN
E CF 30 1
C* ..................................................
C *INKC DOUEQ*ON
C EXFMTFMT01
C MOVE *OFF *IN41
C FIELD IFNE *BLANKS
C EXSR CHOOSE
C ELSE
C MOVE *ON *IN41
C END
C END
C MOVE *ON *INLR
C* ....................................................
C* : S U B R O U T I N E S :
C* ::::::::::::::::::::::::::::::::::::::::::::::::::::
C* Center the typed field.
C CHOOSE BEGSR
C MOVE *BLANKS CF
C* CHEKR reads a field character by character, right to left.
C* Factor 1 is what is being compared too.
C ' ' CHEKRFIELD I 20
C* I equals the position in the FIELD of the last non-blank character.
C* The field's length (30) less I equals the number of empty columns.
C* Dividing by 2 is the correct place to place the beginning of FIELD.
C I IFGE 29
C Z-ADD1 I
C ELSE
C 30 SUB I I
C I DIV 2 I
C* Add one, to move over one space to start with.
C ADD 1 I
C END
C MOVEAFIELD CF,I
C MOVE *BLANKS FIELD
C MOVEACF FIELD
C ENDSR
C*-------------------------------------------------------------------
|