Esto de las conversiones, me ha gustado -:) Así que después de mi post de "Decimal a Romanos en Ruby", decidí hacer la misma implementación en ABAP.
REPORT Z_DECIMAL_TO_ROMAN.
DATA: BEGIN OF T_ROMAN_TABLE OCCURS 0,
KEY TYPE I,
VALUE TYPE STRING,
END OF T_ROMAN_TABLE.
DATA: RESULTADO TYPE STRING.
SELECTION-SCREEN BEGIN OF BLOCK TEST.
PARAMETERS:
DEC_NUM TYPE I.
SELECTION-SCREEN END OF BLOCK TEST.
T_ROMAN_TABLE-KEY = 1000.
T_ROMAN_TABLE-VALUE = 'M'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 900.
T_ROMAN_TABLE-VALUE = 'CM'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 500.
T_ROMAN_TABLE-VALUE = 'D'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 400.
T_ROMAN_TABLE-VALUE = 'CD'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 100.
T_ROMAN_TABLE-VALUE = 'C'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 90.
T_ROMAN_TABLE-VALUE = 'XC'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 50.
T_ROMAN_TABLE-VALUE = 'L'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 40.
T_ROMAN_TABLE-VALUE = 'XL'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 10.
T_ROMAN_TABLE-VALUE = 'X'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 9.
T_ROMAN_TABLE-VALUE = 'IX'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 5.
T_ROMAN_TABLE-VALUE = 'V'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 4.
T_ROMAN_TABLE-VALUE = 'IV'.
APPEND T_ROMAN_TABLE.
T_ROMAN_TABLE-KEY = 1.
T_ROMAN_TABLE-VALUE = 'I'.
APPEND T_ROMAN_TABLE.
WHILE DEC_NUM GT 0.
LOOP AT T_ROMAN_TABLE.
IF DEC_NUM GE T_ROMAN_TABLE-KEY.
CONCATENATE RESULTADO T_ROMAN_TABLE-VALUE INTO RESULTADO.
DEC_NUM = DEC_NUM - T_ROMAN_TABLE-KEY.
EXIT.
ENDIF.
ENDLOOP.
ENDWHILE.
WRITE:/ 'El número en Romanos es: ', RESULTADO.
Saludos,
Blag.
No comments:
Post a Comment