Inequality between length and maximum digit count of packed decimal type causes great confusion even among seasoned developers. ABAPDOCU explains the relation with a fairly complicated formula:
Depending on the field length len and the number of decimal places dec, the following applies to the value range: (-10^(2len-1) +1) / (10^(+dec)) to (+10^(2len-1) -1) /(10^(+dec)) in increments of 10^(-dec)
Actually it’s simple: Multiply the length by 2 and you will have total digit count including decimal places and the sign. If you have a packed decimal of length 13, you are allowed 25 digits for integer part and fractional part cumulated plus one place for the sign. In case you are in doubt, ABAP has a pretty nifty class to get minimum and maximum values of a numeric variable. Here is how to use it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
DATA: pack TYPE p LENGTH 2 DECIMALS 2, result TYPE REF TO data. FIELD-SYMBOLS <result> TYPE ANY. result = cl_abap_exceptional_values=>get_min_value( pack ). IF result IS NOT INITIAL. ASSIGN result->* TO <result>. cl_demo_output=>write_data( <result> ). ENDIF. result = cl_abap_exceptional_values=>get_max_value( pack ). IF result IS NOT INITIAL. ASSIGN result->* TO <result>. cl_demo_output=>write_data( <result> ). ENDIF. cl_demo_output=>display( ). |