Page 1 of 1

Email content from a text file

Posted: Tue Sep 12, 2006 6:20 am
by jshurak
I'm trying to create the content for an email from a text file. The email contains an output from an SQL statement. The statement returns multiple rows. In the actual email only the last line from the file is displayed.

The code is as follows:

Code: Select all


      Reportdate = OConv(@DATE-1, "D-DMY[,A3,]")
      LineData = ""
      Error_output = ""
*


*
* Setup Load_error_check, run it, wait for it to finish, and test for success
      hJob2 = DSAttachJob("Load_error_check", DSJ.ERRFATAL)
      If NOT(hJob2) Then
         Call DSLogFatal("Job Attach Failed: Load_error_check", "JobControl")
         Abort
      End
      ErrCode = DSSetParam(hJob2, "Reportdate", Reportdate)
      ErrCode = DSRunJob(hJob2, DSJ.RUNNORMAL)
      ErrCode = DSWaitForJob(hJob2)
      Status = DSGetJobInfo(hJob2, DSJ.JOBSTATUS)
      Begin Case
         Case Status = DSJS.RUNFAILED
            Call DSLogWarn("Job Failed: Load_error_check", "JobControl")
         Case Status = DSJS.RUNWARN
            Call DSLogWarn("Job ran with warning: Load_error_check","JobControl")
         Case Status = DSJS.RUNOK
            Call DSLogInfo("Load_error_check completed successfully.", "JobControl")
         Case 1
            Call DSLogInfo("Load_error_check ran with status ":Status, "JobControl")
      End Case

      InputDataFile = "G:\DataStage\Outbox\load_error.txt"

      OpenSeq InputDataFile To InputData Then
      READ:   	

      ReadSeq LineData from InputData Then
      End

      Closeseq InputData

     *
            EMail = ''
            EMail<1> = "To:whatever_email@abc123.com\n"

*
* Construct the e-mail body
*
            DateDay = Oconv(Date(),"DWA")
            TimeDay = OCONV(Time(),"MTH")
            message = ""
            sender = ""
            sender = "From:Data_Staqe_Dwetl2@appliedcard.com\n"
            message = "Subject:Load Errors ":DateDay:" ":TimeDay:"\n"

            message = message:"Server:172.17.90.80\n"
            message = message:"Body:\n"
            message = message:"Failure Status of Inbound Data for v_inbound3\n"
            message = message:"---------------------------------------------\n"
            message = message:"                                               ":"\n"
            message = message:"                                               ":"\n"
            message = message:"                                               ":"\n"
            message = message:LineData:"\n"
            message = message:"                                                ":"\n"
            message = message:"                                               ":"\n"
            message = message:"                                                 ":"\n"
            message = message:"Have a nice day!":"\n"
*
* Send the e-mail's
*
            For L = 1 to COUNT(EMail,@AM)+1
               EMailMessage = ""
               EMailMessage = sender
               EMailMessage = EMailMessage:EMail<L>
               EMailMessage = EMailMessage:message
               code = ''
               code = DSSendMail(EMailMessage)
               If code = 0 Then
                  Call DSLogInfo("E-mail sent successfully.",'Job Control')
               End Else
                  Call DSLogInfo("E-mail NOT sent.",'Job Control')
               End
            Next L
            RETURN


Originally I had Error_output equating to LineData, but that seemed unecessary.

Posted: Tue Sep 12, 2006 6:50 am
by kduke
Please edit your post and put code tags around it so we can see the indentation.

It looks like at first glace you only read one line from the sequential file.

GoTo Read

Posted: Tue Sep 12, 2006 7:04 am
by jshurak

Code: Select all

OpenSeq InputDataFile To InputData Then
      READ:      

      ReadSeq LineData from InputData Then
      End 

I've tried different variations of GoTos and also tried arrays, but just can't seem to figure this one out.

Posted: Tue Sep 12, 2006 7:24 am
by kcbland
The "best" way to read small files is to simply do this:
CALL DSExecute("NT", "type /here/there/yourfile.txt", ScreenOutput, ReturnCode)
The variable ScreenOutput will be a dynamic array of the file contents, each line in the screen output will be a row in the array.

If you're on Unix, just switch NT to UNIX and type to cat.

Kcbland

Posted: Tue Sep 12, 2006 7:42 am
by jshurak
You're a genius! Thanks. after all that, it was one line of code!

Posted: Tue Sep 12, 2006 8:03 am
by kcbland
Not a genius, just been around awhile.