Ver Mensaje Individual
  #6
Antiguo 9 de mayo de 2017, 00:23
Dasije
Forero Senior
Última Actividad 06.03.2022 17:04
Posts Posts: 173
Likes enviados Enviados: 1
Likes recibidos Recibidos: 79

Código COBOL:
  1. @OPTIONS BINARY(BYTE)
  2.  IDENTIFICATION DIVISION.
  3.  PROGRAM-ID     PRINT-RAW.
  4.  AUTHOR.        Doug Brown.
  5.  INSTALLATION.  FUJITSU COBOL (GENERIC).
  6.  SECURITY.      COPYRIGHT (C) 1999 FUJITSU SOFTWARE CORPORATION.
  7. *
  8. * Program is passed a text file and printer name and prints the
  9. *  file to the printer. It is assumed that the text file may contain
  10. *  printer control characters and should be passed to the printer
  11. *  "as is" i.e. it is read as a sequential file and passed to the
  12. *  printer in blocks.
  13. * The program is designed to be invoked from the command line, or
  14. *  from the Windows CreateProcess function, so that it executes
  15. *  asynchronously.
  16. * Command line format is:
  17. *
  18. * FSC-SPOOL-FILE.EXE "Text file name" "Printer name"
  19. *
  20. * The quotes are only required if the text file or printer name
  21. *  includes spaces.
  22. *-----------------------------------------------------------------
  23.  ENVIRONMENT DIVISION.
  24.  CONFIGURATION SECTION.
  25.  SOURCE-COMPUTER. WINDOWS.
  26.  OBJECT-COMPUTER. WINDOWS.
  27.  SPECIAL-NAMES.
  28.      ARGUMENT-NUMBER IS ARGUMENT-NUMBER
  29.      ARGUMENT-VALUE  IS ARGUMENT-VALUE
  30.      SYMBOLIC CONSTANT
  31.  
  32.         *> Program Copyright Information
  33.         PROGRAM-NAME             IS "CBLEXEC"
  34.         PROGRAM-SOURCE-DATE      IS "April 5 1999"
  35.         PROGRAM-SERIAL-NUMBER    IS "DAB/FSC/000001"
  36.         PROGRAM-DESCRIPTION      IS
  37.         "Fujitsu COBOL Spool Print File"
  38.         PROGRAM-COPYRIGHT        IS
  39.         "Copyright (C) 1999 Fujitsu Software Corporation"
  40.         PROGRAM-AUTHOR           IS "Doug Brown"
  41.         PROGRAM-BUILD-TYPE       IS "PRODUCTION"
  42.         PROGRAM-CHARACTER-SET    IS "ASCII"
  43.         PROGRAM-CHARACTER-TYPE   IS "SBCS".
  44. *-----------------------------------------------------------------
  45.  INPUT-OUTPUT SECTION.
  46.  FILE-CONTROL.
  47.      SELECT Print-File ASSIGN TO Print-File-Name
  48.        ORGANIZATION SEQUENTIAL
  49.        FILE STATUS IS Print-File-Status
  50.      .
  51.  DATA DIVISION.
  52.  
  53.  FILE SECTION.
  54.  
  55.  FD Print-File.
  56.  01 Print-Record        PIC X(16384).
  57.  
  58.  WORKING-STORAGE SECTION.
  59.  
  60. * Note: Ensure that Print-Buffer is always the same size
  61. *  as Print-Record
  62.  01 Print-Buffer        PIC X(16384).
  63.  
  64.  01 Print-File-Name PIC X(255) VALUE SPACES.
  65.  
  66.  01 Print-File-Status   PIC X(2).
  67.  
  68.  01 Record-Bytes        PIC 9(9) COMP-5.
  69.  
  70.  01 Bytes-Written       PIC 9(9) COMP-5.
  71.  
  72.  01 Printer-Name          PIC X(255) VALUE SPACES.
  73.  
  74.  01 Printer-Handle  PIC 9(9) COMP-5.
  75.  
  76.  01 Return-Value        PIC S9(9) COMP-5.
  77.  
  78.  01 Doc-Info.
  79.     03 pDocName    USAGE POINTER.
  80.     03 pOutputFile USAGE POINTER VALUE NULL.
  81.     03 pDatatype   USAGE POINTER.
  82.  
  83.  01 Datatype.
  84.    03 PIC X(3) VALUE "RAW".
  85.    03 PIC X    VALUE X"00".
  86.  
  87.  01 Number-of-Arguments   PIC 9(2) COMP-5.
  88.  
  89.  01 End-of-File-Flag    PIC 9 VALUE ZERO.
  90.  88 END-OF-FILE VALUE 1.
  91.  
  92.  01 Offset      PIC 9(5) COMP-5.
  93.  
  94.  01 PRINTER-d.                                            
  95.           05 pDatatyp pic x(4) value low-value.                                            
  96.           05 pDevMod  pic x(4) value low-value.                                            
  97.           05 DesiredAccess pic s9(9) comp-5 value 8.
  98. *------------------------------------------------------------------
  99.  PROCEDURE DIVISION.
  100.  
  101.       ACCEPT Number-of-Arguments FROM ARGUMENT-NUMBER
  102. *     DISPLAY Number-of-Arguments
  103.  
  104.       IF Number-of-Arguments NOT = 2
  105. * <<Check what action is appropriate to notify user of an error>>
  106.          DISPLAY "Argumentos incorrectos"
  107.          EXIT PROGRAM
  108.       END-IF
  109.  
  110.       ACCEPT Print-File-Name FROM ARGUMENT-VALUE
  111.       ACCEPT Printer-Name FROM ARGUMENT-VALUE
  112. * Find end of printer name and place a null byte to terminate
  113. *  the string.
  114.       MOVE FUNCTION LENG (Printer-Name) TO Offset
  115.       PERFORM UNTIL Printer-Name (Offset:1) NOT = SPACE
  116.         SUBTRACT 1 FROM Offset
  117.       END-PERFORM
  118.       ADD 1 TO Offset
  119.       MOVE X"00" TO Printer-Name (Offset:1)
  120.  
  121. * Set up the Doc-Info structure for use with the StartDocPrinter
  122. *  function.
  123.       MOVE FUNCTION ADDR (Print-File-Name) TO pDocName
  124.       MOVE FUNCTION ADDR (Datatype)        TO pDatatype  
  125.  
  126. * Open the printer.
  127. *  <<Insert explanation as to why some functions are called with the
  128. *   "A" appended and others are not.>>
  129.       CALL "OpenPrinterA" WITH STDCALL
  130.           USING BY REFERENCE Printer-Name
  131.                 BY REFERENCE Printer-Handle
  132.                 BY VALUE     0
  133.           RETURNING Return-Value.
  134.  
  135.       IF Return-Value = 0
  136.         DISPLAY "Error en la apertura de la impresora"
  137.         EXIT PROGRAM
  138.       END-IF
  139.    
  140.       CALL "StartDocPrinterA" WITH STDCALL
  141.           USING BY VALUE     Printer-Handle
  142.                 BY VALUE     1
  143.                 BY REFERENCE Doc-Info
  144.           RETURNING Return-Value
  145.       IF Return-Value = 0
  146.         DISPLAY "Problema de iniciar el documento a imprimir"
  147.         EXIT PROGRAM
  148.       END-IF
  149.  
  150.       CALL "StartPagePrinter" WITH STDCALL
  151.           USING BY VALUE Printer-Handle
  152.           RETURNING Return-Value
  153.       IF Return-Value = 0
  154.         DISPLAY "Problema iniciar página de impresión"
  155.         EXIT PROGRAM
  156.       END-IF
  157.  
  158.       OPEN INPUT Print-File
  159.       IF Print-File-Status NOT = "00"
  160.         DISPLAY "No se puede abrir el archivo de impresión"
  161.         EXIT PROGRAM
  162.       END-IF
  163.  
  164. *     Ensure Print-Record area is initialized to nulls
  165.       MOVE LOW-VALUES TO Print-Record
  166.  
  167.       MOVE FUNCTION LENG (Print-Buffer) TO Record-Bytes
  168. *     Read ahead so that last record can be detected
  169.       READ Print-File
  170.         AT END
  171.           DISPLAY "No hay datos para imprimir en el fichero"
  172.           EXIT PROGRAM
  173.       END-READ
  174.       IF Print-File-Status NOT = "00"
  175.          DISPLAY "Error lectura archivo de impresión (1): " Print-File-Status
  176.          EXIT PROGRAM
  177.       END-IF
  178. *     Move record to buffer so that Print-Record is available for
  179. *      the next read
  180.       MOVE Print-Record TO Print-Buffer
  181.  
  182.       PERFORM UNTIL END-OF-FILE
  183. *        Set Print-Record to LOW-VALUES before reading
  184.          MOVE LOW-VALUES TO Print-Record
  185.          READ Print-File
  186.            AT END
  187. *            Last read had the last record, so find last non-null
  188. *             byte in record (only want to pass the data in the file
  189. *             not the padding nulls at the end of the buffer)
  190.              SET END-OF-FILE TO TRUE
  191.              MOVE FUNCTION LENG (Print-Buffer) TO Offset
  192.              PERFORM UNTIL Print-Buffer (Offset:1) NOT = X"00"
  193.                SUBTRACT 1 FROM Offset
  194.              END-PERFORM
  195.              MOVE Offset TO Record-Bytes
  196.          END-READ
  197.          IF Print-File-Status = "00"
  198.                OR
  199.             Print-File-Status = "10" *> At end status
  200.            CALL "WritePrinter" WITH STDCALL
  201.              USING BY VALUE     Printer-Handle
  202.                    BY REFERENCE Print-Buffer
  203.                    BY VALUE     Record-Bytes
  204.                    BY REFERENCE Bytes-Written
  205.              RETURNING Return-Value
  206.            IF Return-Value = 0
  207.              DISPLAY "Error imprimir en la impresora"
  208.              SET END-OF-FILE TO TRUE
  209.            END-IF
  210.          ELSE
  211.            DISPLAY "Error lectura archivo de impresión (2): " Print-File-Status
  212.            SET END-OF-FILE TO TRUE
  213.          END-IF
  214.          IF NOT END-OF-FILE
  215. *          Set up next record to print
  216.            MOVE Print-Record TO Print-Buffer
  217.          END-IF
  218.       END-PERFORM
  219.  
  220.       CLOSE Print-File
  221.  
  222.       CALL "EndPagePrinter" WITH STDCALL
  223.           USING BY VALUE Printer-Handle
  224.           RETURNING Return-Value
  225.                
  226.       CALL "EndDocPrinter" WITH STDCALL
  227.           USING BY VALUE Printer-Handle
  228.           RETURNING Return-Value
  229.                
  230.       CALL "ClosePrinter" WITH STDCALL
  231.           USING BY VALUE Printer-Handle
  232.           RETURNING Return-Value
  233.  
  234.       STOP RUN.



Empresa de desarrollo de aplicaciones en COBOL.

DASIJE INFORMATICA, S.L.
C/ TOMAS BRETON 20
11406 JEREZ DE LA FRONTERA
CADIZ

Teléfono : 956 11 21 11
Web: http://www.dasije.es / DASIJE INFORMATICA
E-m@il: clientes(@)dasije.es
Dasije is offline   Responder Con Cita