|
#1
|
||||
|
||||
Ejemplo
Mira a mí por ejemplo si me llega un importe de este tipo "45678.23" y lo quiero transformar a "45.678,23"; hago esto:
FORM cambiar_formato CHANGING p_valor. DATA: lv_contador_ent TYPE i, lv_contador_dec TYPE i. DATA: lv_entero(13) TYPE c, lv_decimal(2) TYPE c. DATA: lv_num_aux TYPE string. CLEAR: lv_contador_ent, lv_contador_dec, lv_entero, lv_decimal, lv_num_aux. SPLIT p_valor AT '.' INTO lv_entero lv_decimal. lv_contador_dec = strlen( lv_decimal ). IF lv_contador_dec = 0. lv_decimal = '00'. ELSEIF lv_contador_dec = 1. CONCATENATE lv_decimal '0' INTO lv_decimal. ENDIF. lv_contador_ent = strlen( lv_entero ). CONCATENATE lv_entero lv_decimal INTO lv_num_aux. "POSITIVO... IF p_valor => 0. IF lv_contador_ent = 1. WRITE lv_num_aux USING EDIT MASK '_,__' TO p_valor. ELSEIF lv_contador_ent = 2. WRITE lv_num_aux USING EDIT MASK '__,__' TO p_valor. ELSEIF lv_contador_ent = 3. WRITE lv_num_aux USING EDIT MASK '___,__' TO p_valor. ELSEIF lv_contador_ent = 4. WRITE lv_num_aux USING EDIT MASK '_.___,__' TO p_valor. ELSEIF lv_contador_ent = 5. WRITE lv_num_aux USING EDIT MASK '__.___,__' TO p_valor. ELSEIF lv_contador_ent = 6. WRITE lv_num_aux USING EDIT MASK '___.___,__' TO p_valor. ELSEIF lv_contador_ent = 7. WRITE lv_num_aux USING EDIT MASK '_.___.___,__' TO p_valor. ELSEIF lv_contador_ent = 8. WRITE lv_num_aux USING EDIT MASK '__.___.___,__' TO p_valor. ELSEIF lv_contador_ent = 9. WRITE lv_num_aux USING EDIT MASK '___.___.___,__' TO p_valor. ELSEIF lv_contador_ent = 10. WRITE lv_num_aux USING EDIT MASK '_.___.___.___,__' TO p_valor. ELSEIF lv_contador_ent = 11. WRITE lv_num_aux USING EDIT MASK '__.___.___.___,__' TO p_valor. ELSEIF lv_contador_ent = 12. WRITE lv_num_aux USING EDIT MASK '___.___.___.___,__' TO p_valor. ENDIF. "NEGATIVO... ELSE. IF lv_contador_ent = 1. WRITE lv_num_aux USING EDIT MASK '_,__-' TO p_valor. ELSEIF lv_contador_ent = 2. WRITE lv_num_aux USING EDIT MASK '__,__-' TO p_valor. ELSEIF lv_contador_ent = 3. WRITE lv_num_aux USING EDIT MASK '___,__-' TO p_valor. ELSEIF lv_contador_ent = 4. WRITE lv_num_aux USING EDIT MASK '_.___,__-' TO p_valor. ELSEIF lv_contador_ent = 5. WRITE lv_num_aux USING EDIT MASK '__.___,__-' TO p_valor. ELSEIF lv_contador_ent = 6. WRITE lv_num_aux USING EDIT MASK '___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 7. WRITE lv_num_aux USING EDIT MASK '_.___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 8. WRITE lv_num_aux USING EDIT MASK '__.___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 9. WRITE lv_num_aux USING EDIT MASK '___.___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 10. WRITE lv_num_aux USING EDIT MASK '_.___.___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 11. WRITE lv_num_aux USING EDIT MASK '__.___.___.___,__-' TO p_valor. ELSEIF lv_contador_ent = 12. WRITE lv_num_aux USING EDIT MASK '___.___.___.___,__-' TO p_valor. ENDIF. ENDIF. ENDFORM.
__________________
Consultor técnico SAP Úlima edición por vic3 fecha: 30/01/19 a las 13:39:15. |
#2
|
||||
|
||||
Ejemplo 2
Sí por en contrario me llega de tipo C con este aspecto "4.000,74-" y necesito transformarlo a "-4000,74" para por ejemplo hacer cálculos:
FORM cambiar_formato_2 USING p_bwwrt. DATA: lv_contador TYPE i. DATA: lv_num TYPE i, lv_num_aux(30) TYPE c. DATA: lv_entero(16) TYPE c, lv_decimal(3) TYPE c. CLEAR: lv_contador, lv_num_aux, lv_num, lv_entero, lv_decimal. "4.000,74- >>> Puede ser negativo SPLIT p_bwwrt AT ',' INTO lv_entero lv_decimal. IF lv_decimal+2(1) <> '-'. "-----------------------------> Positivo lv_contador = strlen( p_bwwrt ). *** En mi caso no necesitaba las centenas... tú sácalas si lo necesitas "Miles IF lv_contador = 8. "1.111,11 CONCATENATE p_bwwrt(1) p_bwwrt+2(3) INTO lv_num_aux. ELSEIF lv_contador = 9. "11.111,11 CONCATENATE p_bwwrt(2) p_bwwrt+3(3) INTO lv_num_aux. ELSEIF lv_contador = 10. "111.111,11 CONCATENATE p_bwwrt(3) p_bwwrt+4(3) INTO lv_num_aux. "Millones ELSEIF lv_contador = 12. "1.111.111,11 CONCATENATE p_bwwrt(1) p_bwwrt+2(3) p_bwwrt+6(3) INTO lv_num_aux. ELSEIF lv_contador = 13. "11.111.111,11 CONCATENATE p_bwwrt(2) p_bwwrt+3(3) p_bwwrt+7(3) INTO lv_num_aux. ELSEIF lv_contador = 14. "111.111.111,11 CONCATENATE p_bwwrt(1) p_bwwrt+4(3) p_bwwrt+8(3) INTO lv_num_aux. "Billones ELSEIF lv_contador = 16. "1.111.111.111,11 CONCATENATE p_bwwrt(1) p_bwwrt+2(3) p_bwwrt+6(3) p_bwwrt+10(3) INTO lv_num_aux. ELSEIF lv_contador = 17. "11.111.111.111,11 CONCATENATE p_bwwrt(2) p_bwwrt+3(3) p_bwwrt+7(3) p_bwwrt+11(3) INTO lv_num_aux. ELSEIF lv_contador = 18. "111.111.111.111,11 CONCATENATE p_bwwrt(3) p_bwwrt+4(3) p_bwwrt+8(3) p_bwwrt+12(3) INTO lv_num_aux. ENDIF. lv_num = lv_num_aux. ELSE. "-----------------------------> Negativo "Algo parecido a lo anterior pero concatenando el "-" delante... juega un poco con los 2 ejemplos ENDIF. ENDFORM.
__________________
Consultor técnico SAP Úlima edición por vic3 fecha: 30/01/19 a las 13:41:53. |
#3
|
|||
|
|||
Te paso este código fácil y sencillo para escribir/almacenar negativos y millares.
Úlima edición por Astaroth_SA fecha: 03/04/19 a las 09:07:42. |
Herramientas | Buscar en Tema |
Desplegado | |
|
|