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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cobol an Email 2

Status
Not open for further replies.

landei

Programmer
Apr 28, 2005
20
DE
Hi,

I look for a solution, to send Email with a Cobol-Programm. My Compiler is ACUCOBOL Version 4.2. I know, it is not the newest Version!!!

Thank you for help.
 
Hi Frederico,

the platform is WINDOWS (NT.... 2000....)

Regards

Helmut Langguth
Germany

 
If that does not work, you are welcome to use this. It was written for Micro Focus COBOL and so might need some minor modifications. It does require that you have an email client (e.g. outlook etc.) on your machine.

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 ACUCOBOL 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.  [URL unfurl="true"]www.tubularity.com[/URL]
       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=ø[URL unfurl="true"]http://www.tubularity.comø>".[/URL]
       02 FILLER PIC X(36) VALUE "[URL unfurl="true"]http://www.tubularity.com</a>[/URL]       ".
       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.

Clive
 
Hi Clive,

it is a complete other way for the solution of my problem. I don´t fight with "MAPI", I use the "mailto-Method". It is a greate idea, thank you for help. I will try it.

Regards
Helmut
 
Hi Clive,

it works!!!!! And it looks good as HTML-Page on target site.

Thank you for the good idea. Now I will make a little "cosmetic". It was not a problem, to convert to ACUCOBOL. My problem now is the multiuser-working at the same time in a great network with 100 user. You will send the wrong text to the right recipient!!! I will hang up on the next tree. This is a problem with unique file-names. But this is not really a problem.

That was a great idea.

Thanks from
Edermünde / Germany
 
Clive -

A star for you!

I think you could eliminate the dependence on the location of Internet Explorer (or use another browser completely) by simply passing the html file to the command line and letting the system's file association logic invoke the browser.

Regards.

Glenn
 
Thanks Guys,

Using the command line opens up lots of possiblities. It might be useful to make a faq of it for how different compilers pass something to the command line.

I would be glad to compile the list if people with different compilers would post their methods.

Maybe a new thread: PC COBOL to Command Line.

Clive
 
Just another possibility. I have a cobol program that writes a vbscript which sends any where from a few to a few hundred emails with file attachments. Once I have built the script with the cobol program I use a system call to the command line and using cscript launch the VBscript which sends the emails. I use MAPI to script the email.vbs.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top