Email content from a text file

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
jshurak
Participant
Posts: 74
Joined: Mon Jan 09, 2006 12:39 pm

Email content from a text file

Post 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.
Last edited by jshurak on Tue Sep 12, 2006 6:54 am, edited 1 time in total.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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.
Mamu Kim
jshurak
Participant
Posts: 74
Joined: Mon Jan 09, 2006 12:39 pm

GoTo Read

Post 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.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post 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.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
jshurak
Participant
Posts: 74
Joined: Mon Jan 09, 2006 12:39 pm

Kcbland

Post by jshurak »

You're a genius! Thanks. after all that, it was one line of code!
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Not a genius, just been around awhile.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply