要求:将字符串转化为对应的数值,如‘123’转为 1.2300000000000000E+02, ‘123a’会转化为0.0000000000000000E+00。
当字符串为空,先赋给它为‘0’.
data: ZUEGNRT_STR type c LENGTH 5 , res type c LENGTH 1.
DATA: ZUEGNRT_F TYPE F,ZUEKFRT_F TYPE F.
ZUEGNRT_STR = '123'.
CONDENSE ZUEGNRT_STR NO-GAPS.
if ZUEGNRT_STR = ''.
ZUEGNRT_STR = '0'.
ENDIF.
CALL FUNCTION 'CHAR_FLTP_CONVERSION' "Format conversion: Character --> Floating point
EXPORTING
* dyfld = SPACE " Screen Field name for cursor positioning
* maskn = SPACE " Masking character if input screen
* maxdec = '16' " t006-decan Maximum number of input decimal places
* maxexp = '59+' " t006-expon Maximum gross power of 10
* minexp = '60-' " t006-expon Minimum gross power of 10
string = ZUEGNRT_STR " CHAR input field for conversion to FLTP
* msgtyp_decim = 'W' " sref-msgtyp Message type for 'TOO_MANY_DECIM' (see domains)
IMPORTING
" decim = 2 " Number of decimal places determined
" expon = 3 " Gross power of 10 determined
flstr = ZUEGNRT_F " FLTP output field, from CHAR conversion
" ivalu = 'X' " Value in STR;ING flag
EXCEPTIONS
EXPONENT_TOO_BIG = 1 " Gross power of 10 is too big
EXPONENT_TOO_SMALL = 2 " Gross power of 10 is too small
STRING_NOT_FLTP = 3 " STRING cannot be interpreted as floating point
TOO_MANY_DECIM = 4 " Too many decimal places
OTHERS = 5.
if ZUEGNRT_F > 0 .
res = 'Y'.
else.
res = 'N'.
ENDIF.
write: / ZUEGNRT_F.