Cobol Foro

Cobol Foro (https://www.cobolforo.es/index.php)
-   WinDev (https://www.cobolforo.es/forumdisplay.php?f=76)
-   -   [Sintaxis] Convertir DECIMAL a NUMERO para COBOL (https://www.cobolforo.es/showthread.php?t=1035)

Dasije 11 de agosto de 2019 23:44

Convertir DECIMAL a NUMERO para COBOL
 
Hola buenas.

Comparto el código para convertir un campo decimal/currency a campos numéricos legible para COBOL de IBM, muy útil para importación de archivos generados desde Windev.

Código WinDev:
  1. PROCEDURE PUBLIC  convertir_DECIMAL_PIC_COBOL(IMPORTE is numeric(15,2), NUMERO_ENTEROS is int, SIGNO is boolean)
  2.  
  3. IMPORTE_FINAL is numeric(15,2)
  4.  
  5. CARACTER_SIGNO is fixed string on 1 = ""
  6.  
  7. RESULTADO is UNICODE string = ""
  8.  
  9. SWITCH IMPORTE
  10.     CASE < 0
  11.         IMPORTE_FINAL = IMPORTE * (-1)
  12.         CARACTER_SIGNO = "N"
  13.     OTHER CASE
  14.         IMPORTE_FINAL = IMPORTE
  15.         CARACTER_SIGNO = "0"
  16. END
  17.  
  18. SWITCH SIGNO
  19.     CASE True
  20.         NUMERO_ENTEROS-=1
  21.         RESULTADO = CARACTER_SIGNO+NumToString((IMPORTE_FINAL * 100),"0"+NUMERO_ENTEROS+".0F")     
  22.     CASE False
  23.         RESULTADO = NumToString((IMPORTE_FINAL * 100),"0"+NUMERO_ENTEROS+".0F")
  24. END
  25.  
  26. RESULT RESULTADO

Sí el número fuera -4.85 donde tiene 15 enteros y 2 decimales, el resultado sería así : N00000000000485

Saludos y espero que os sirvan para aquellos que trabajen desde la plataforma de IBM.


La franja horaria es GMT +2. Ahora son las 17:54.

Powered by: vBulletin, Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.