Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I eMail a report from PC COBOL

COBOL Weblers

How do I eMail a report from PC COBOL

by  CliveC  Posted    (Edited  )
This was written for Micro Focus COBOL and so might need some minor modifications for other compilers. It does require that you have an email client (e.g. outlook etc.) on your machine.

You can call or chain to eREPORT from the program that produces the report.

1. In the program that puts out the report that you want to email, put the report out to disk and call it eREPORT.DAT. Sample:

Code:
                           Training Instructor Report

          CLIENT:      Deloitte Touche
          INSTRUCTOR:  CliveC                          DATE: 19990821
          ------------------------------------------------------------

                                   EXPENSES

                      Sun 19990815 110 Taxi          22.00
                      Sun 19990815 220 Dinner        12.00
                      Sun 19990815 800 Lodging      109.91
                      Mon 19990816 200 Breakfast      6.22
                      Mon 19990816 210 Lunch          5.50
                      Mon 19990816 220 Dinner        36.49
                      Mon 19990816 310 Telephone     13.28
                      Mon 19990816 800 Lodging      109.91
                      Tue 19990817 200 Breakfast      6.20
                      Tue 19990817 210 Lunch          5.48
                      Tue 19990817 220 Dinner        35.95
                      Tue 19990817 310 Telephone      5.28
                      Tue 19990817 310 Telephone      6.70
                      Tue 19990817 800 Lodging      109.91
                      Wed 19990818 200 Breakfast      6.80
                      Wed 19990818 210 Lunch          6.67
                      Wed 19990818 220 Dinner        12.50
                      Wed 19990818 310 Telephone      6.42
                      Wed 19990818 310 Telephone      5.20
                      Wed 19990818 900 Car Rental   153.08
                      Wed 19990818 110 Taxi          22.00
                                       TOTAL        697.50

2. In the same program put out a parm file eReport.prm that specifies the new html file path, the report file, the recipients email and the Subject.

Code:
C:\eREPORT\eREPORT.htm
C:\eREPORT\eREPORT.dat
accounting@employer.com
Expenses

3. Modify the provided program eREPORT.cbl to do what your COBOL product does to write to the command line (paragraph 9000-submit-report and associated working storage).

4. Check the paths to your browser in WS item SYSTEM-COMMAND-LINE.

5. Check the path to the parm file in WS item PARM-FILE-ID.

6. Compile and Run.

Code:
      ******************************************************************

       IDENTIFICATION DIVISION.

      ******************************************************************

       PROGRAM-ID.    eREPORT.
       AUTHOR.        Clive Cummins.
       INSTALLATION.  www.tubularity.com
       DATE-WRITTEN.  Nov 23,2001.

      *-****************************************************************
      *-                          eREPORT
      *-
      *-    SEND A GIVEN REPORT TO THE GIVEN RECIPIENTS E-MAIL ID.
      *-****************************************************************

      ******************************************************************
      *    MODIFICATION LOG
      *    CCYYMMDD MODIFICATION
      ******************************************************************

      ******************************************************************

       ENVIRONMENT DIVISION.

      ******************************************************************

      ******************************************************************
       INPUT-OUTPUT SECTION.
      ******************************************************************

       FILE-CONTROL.

           SELECT PARM-FILE ASSIGN TO PARM-FILE-ID
                  FILE STATUS  IS PARM-RETURN-CODE
                  ACCESS MODE  IS SEQUENTIAL
                  ORGANIZATION IS LINE SEQUENTIAL.

           SELECT HTML-FILE ASSIGN TO HTML-FILE-ID
                  FILE STATUS  IS HTML-RETURN-CODE
                  ACCESS MODE  IS SEQUENTIAL
                  ORGANIZATION IS LINE SEQUENTIAL.

           SELECT DATA-FILE ASSIGN TO DATA-FILE-ID
                  FILE STATUS  IS DATA-RETURN-CODE
                  ACCESS MODE  IS SEQUENTIAL
                  ORGANIZATION IS LINE SEQUENTIAL.

      ******************************************************************

       DATA DIVISION.

      ******************************************************************

      ******************************************************************
       FILE SECTION.
      ******************************************************************

       FD  PARM-FILE.
       01  PARM-RECORD            PIC X(80).

       FD  HTML-FILE.
       01  HTML-RECORD            PIC X(80).

       FD  DATA-FILE.
       01  DATA-RECORD            PIC X(80).

      ******************************************************************
       WORKING-STORAGE SECTION.
      ******************************************************************

       01  PROGRAM-DETAILS.
           05  PROGRAM-RELEASE.
               10  PROGRAM-NAME PIC X(08) VALUE 'eREPORT'.
               10  PROGRAM-REL  PIC X(08) VALUE '  1.0.00'.
           05  PROGRAM-COPYRIGHT.
               10  PROGRAM-COPY PIC X(16) VALUE 'COPYRIGHT: 2001'.
               10  PROGRAM-AUTH PIC X(16) VALUE ' Clive Cummins.'.

      ******************************************************************
       01 EREPORT.
      ******************************************************************
       02 FILLER PIC X(36) VALUE "<html><head><title>                 ".
       02 FILLER PIC X(36) VALUE "Tubularity - eREPORT                ".
       02 FILLER PIC X(36) VALUE "</title></head>                     ".
       02 FILLER PIC X(36) VALUE "<body bgcolor=°yellow°><b>TO:       ".
       02 E-ID1  PIC X(36) VALUE "                                    ".
       02 FILLER PIC X(36) VALUE "&nbsp;&nbsp;&nbsp;&nbsp;SUBJECT:    ".
       02 E-SUB1 PIC X(36) VALUE "                                    ".
       02 FILLER PIC X(36) VALUE "</b><form method=°POST°             ".
       02 FILLER PIC X(36) VALUE "action=°mailto:                     ".
       02 E-ID2  PIC X(36) VALUE "                                    ".
       02 FILLER PIC X(36) VALUE "?subject=                           ".
       02 E-SUB2 PIC X(36) VALUE "                                    ".
       02 FILLER PIC X(36) VALUE "°enctype=°text/plain° target=_blank>".
       02 FILLER PIC X(36) VALUE "<textarea name=°Data° rows=°20°     ".
       02 FILLER PIC X(36) VALUE "cols=°80° readonly>                 ".
       02 FILLER PIC X(36) VALUE "                                    ".
       02 FILLER PIC X(36) VALUE "</textarea><br><br><b>              ".
       02 FILLER PIC X(36) VALUE "<input type=°submit° value=°Submit°>".
       02 FILLER PIC X(36) VALUE "&nbsp;&nbsp;eREPORT by Tubularity:  ".
       02 FILLER PIC X(36) VALUE "<a href=°http://www.tubularity.com°>".
       02 FILLER PIC X(36) VALUE "http://www.tubularity.com</a>       ".
       02 FILLER PIC X(36) VALUE "</b></form></body></html>           ".
       01 FILLER REDEFINES EREPORT.
       02 EREPORT-ENTRY PIC X(36) OCCURS 022 INDEXED BY EREPORT-IDX.
      * MUST INSPECT REPLACING hF8 WITH h22 AND hFB WITH h27

      ******************************************************************
       01  FILE-DETAILS.
      ******************************************************************

           05  PARM-FILE-ID            PIC X(80) VALUE
               "C:\eREPORT\eREPORT.prm".
           05  PARM-RETURN-CODE        PIC X(02).
           05  HTML-FILE-ID            PIC X(80).
           05  HTML-RETURN-CODE        PIC X(02).
           05  DATA-FILE-ID            PIC X(80).
           05  DATA-RETURN-CODE        PIC X(02).

      ******************************************************************
       01  SYSTEM-COMMAND-LINE.
      ******************************************************************

           05  MY-BROWSER              PIC X(49)  VALUE
           '"C:\Program Files\Internet Explorer\iexplore.exe"'.
           05  FILLER                  PIC X(01)  VALUE SPACE.
           05  MY-HTML-FILE            PIC X(80).

      ******************************************************************
       01  EREPORT-PARAMETERS.
      ******************************************************************

           05  EREPORT-HTML-FILESPEC   PIC X(80) VALUE
               "C:\eREPORT\eREPORT.htm".
           05  EREPORT-DATA-FILESPEC   PIC X(80) VALUE
               "C:\eREPORT\eREPORT.dat".
           05  EREPORT-RECIPIENT-EMAIL PIC X(80) VALUE
               "accounting@employer.com".
           05  EREPORT-SUBJECT         PIC X(80) VALUE
               "Report".
       01 FILLER REDEFINES EREPORT-PARAMETERS.
           05  PARM-ENTRY PIC X(80) OCCURS 4 INDEXED BY PARM-IDX.

      ******************************************************************
       01  CALL9135-PARAMETERS.
      ******************************************************************

           05  CALL9135-CALL-FUNCTION  PIC X(01) VALUE 35 COMP-X.
           05  CALL9135-RETURN-CODE    PIC X(01) VALUE  0 COMP-X.
           05  CALL9135-COMMAND-LENGTH PIC X(01) VALUE  0 COMP-X.

      ******************************************************************

       PROCEDURE DIVISION.

      ******************************************************************

           PERFORM 1000-INITIALIZATION.

           OPEN INPUT  DATA-FILE
                OUTPUT HTML-FILE.

           IF DATA-RETURN-CODE EQUAL ZERO
               PERFORM 2000-PROCESS-DATA.

           CLOSE DATA-FILE.

           GOBACK.

      ******************************************************************
       1000-INITIALIZATION.
      ******************************************************************

           OPEN INPUT PARM-FILE.

           IF PARM-RETURN-CODE EQUAL ZERO
               PERFORM VARYING PARM-IDX FROM 1 BY 1
                         UNTIL PARM-IDX GREATER THAN 4
                 READ PARM-FILE INTO PARM-ENTRY (PARM-IDX)
               END-PERFORM
           ELSE
               DISPLAY "eREPORT.prm FILE NOT FOUND"
               STOP RUN
           END-IF.

           CLOSE PARM-FILE.

           MOVE EREPORT-HTML-FILESPEC   TO HTML-FILE-ID.
           MOVE EREPORT-HTML-FILESPEC   TO MY-HTML-FILE.
           MOVE EREPORT-DATA-FILESPEC   TO DATA-FILE-ID.
           MOVE EREPORT-RECIPIENT-EMAIL TO E-ID1  E-ID2.
           MOVE EREPORT-SUBJECT         TO E-SUB1 E-SUB2.

      ******************************************************************
       2000-PROCESS-DATA.
      ******************************************************************

           PERFORM 3000-OUTPUT-BEG-HTML.

           PERFORM 4900-READ-DATA-FILE.

           PERFORM 4000-OUTPUT-EREPORT
             UNTIL DATA-RETURN-CODE NOT EQUAL ZERO.

           PERFORM 5000-OUTPUT-END-HTML.

           CLOSE HTML-FILE.

           PERFORM 9000-SUBMIT-REPORT.

      ******************************************************************
       3000-OUTPUT-BEG-HTML.
      ******************************************************************

           PERFORM VARYING EREPORT-IDX FROM 1 BY 1
                     UNTIL EREPORT-IDX GREATER THAN 16
             MOVE EREPORT-ENTRY (EREPORT-IDX)
               TO HTML-RECORD
             INSPECT HTML-RECORD REPLACING ALL X"F8" BY X"22"
             INSPECT HTML-RECORD REPLACING ALL X"FB" BY X"27"
             PERFORM 5900-WRITE-HTML-RECORD
           END-PERFORM.

      ******************************************************************
       4000-OUTPUT-EREPORT.
      ******************************************************************

           MOVE DATA-RECORD TO HTML-RECORD.

           PERFORM 5900-WRITE-HTML-RECORD.

           PERFORM 4900-READ-DATA-FILE.

      ******************************************************************
       4900-READ-DATA-FILE.
      ******************************************************************

           READ DATA-FILE.

      ******************************************************************
       5000-OUTPUT-END-HTML.
      ******************************************************************

           PERFORM VARYING EREPORT-IDX FROM 17 BY 1
                     UNTIL EREPORT-IDX GREATER THAN 22
             MOVE EREPORT-ENTRY (EREPORT-IDX)
               TO HTML-RECORD
             INSPECT HTML-RECORD REPLACING ALL X"F8" BY X"22"
             INSPECT HTML-RECORD REPLACING ALL X"FB" BY X"27"
             PERFORM 5900-WRITE-HTML-RECORD
           END-PERFORM.

      ******************************************************************
       5900-WRITE-HTML-RECORD.
      ******************************************************************

           WRITE HTML-RECORD.

      ******************************************************************
       9000-SUBMIT-REPORT.
      ******************************************************************

           DISPLAY SYSTEM-COMMAND-LINE UPON COMMAND-LINE.
           CALL x'91' USING CALL9135-RETURN-CODE
                            CALL9135-CALL-FUNCTION
                            CALL9135-COMMAND-LENGTH.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top