Return to the RPG Tips
Convert alpha value to any size numeric value
* Convert Character field to numeric D CharToNum PR 30 10 D InPutText 32a Const D InPutLength 2 0 Const D InPutDec 2 0 Const * Convert numeric fields. * STN C Eval Wrk3010 = CharToNum(' ' + P6Son:7:0) C If Wrk3010 <> 0 C Z-Add wrk3010 Wrk70 C Move Wrk70 X6Son C Move Wrk70 Stn6a C Move Wrk70 HoldSon C Else C Eval msg = 'Invalid STN Number' C Exsr ErrFound C Endif C Eval X6Amt1 = CharToNum(P6Amt1:11:2) C If Balance1 = '-' C Eval Wrk3010 = CharToNum('-' C + NumberTo:13:2) C Else C Eval Wrk3010 = CharToNum(' ' C + NumberTo:13:2) C Endif *===================================================================== * Service Program.: CharToNum * Input Parameter.: 32 position text field. * Input Parameter.: 2.0 Field Length. * Input Parameter.: 2.0 Decimal Position * OutPut Parameter: 30.10 Numeric field * * Converts character field to numeric field * * Example ' 00000200000' 11 2 returns 000002000.00 * Example '-00000200000' 11 2 returns 000002000.00- * *===================================================================== P CharToNum B Export D PI 30 10 D InPutChar 32a Const D InPutLength 2 0 Const D InPutDec 2 0 Const D WorkNumber S 31a D OutPutNum S 30 10 D Result S 2 0 D One s 2 0 Inz(10) D Two s 3 0 Inz(100) D Three s 4 0 Inz(1000) D Four s 5 0 Inz(10000) D Five s 6 0 Inz(100000) D Six s 7 0 Inz(1000000) D Seven s 8 0 Inz(10000000) D Eight s 9 0 Inz(100000000) D Nine s 10 0 Inz(1000000000) D Ten s 11 0 Inz(10000000000) * Indicator Definition D Indicators DS Based(IndicatorP) D Numeric 88 88 D IndicatorP S * Inz(%Addr(*In)) D False C *Off D True C *On C Eval %Subst(WorkNumber: C 31 - InputLength: C InputLength + 1) = InputChar C Eval %Subst(WorkNumber:1: C 31 - InputLength) = *All'0' C TestN WorkNumber 88 C If Numeric = True C Move WorkNumber OutPutNum C Eval Result = 10 - InputDec C Select C When Result = 1 C Mult One OutPutNum C When Result = 2 C Mult Two OutPutNum C When Result = 3 C Mult Three OutPutNum C When Result = 4 C Mult Four OutPutNum C When Result = 5 C Mult Five OutPutNum C When Result = 6 C Mult Six OutPutNum C When Result = 7 C Mult Seven OutPutNum C When Result = 8 C Mult Eight OutPutNum C When Result = 9 C Mult Nine OutPutNum C When Result = 10 C Mult Ten OutPutNum C EndSl C If %SubSt(InputChar:1:1) = '-' C Eval OutPutNum = -OutPutNum C EndIf C Else C Eval OutPutNum = *Zero C EndIf C Return OutPutNum P CharToNum E[report a broken link by clicking here]