Reading Input File Issue

rajendran

Member
i am reading an email file in linux server.i am reading the file line by line and extracting the data which i need from the file.i am using an state machine to process these files.My current desing is based on a particular orde of the data.

code snippet.
Code:
  input from value(v-File).
  vState = "Undefined".

  doparse:

  repeat while vState <> "Uncompliant":

   import unformatted vRow.
  
   case vState:
       when "Undefined" then
       do:
          if entry(1,vRow,":") = "Date" then
          do:
             run GetDateInfo( input vRow,
                              output v-ComplianceDate,
                              output v-ComplianceTime,
                              output vState
                            ).
          end.
       end.
  
       when "HaveDate" then
       do:
          if entry(1,vRow," ") = "Thread-topic:" and
             entry(2,vRow," ") = "COMPLAINT:" then
          do:
             run GetSubject( input vRow,
                             output v-ProductID,
                             output v-DispatchID,
                             output vState
                           ).
          end.
        
          else if entry(1,vRow," ") = "Thread-topic:" and
                  entry(2,vRow," ") <> "COMPLAINT:" then
          
            vState = "UnCompliant".
       end.
    
            
       when "HaveSubject" then
       do:
          if vRow = "Comply" then vState = "Compliant".
       end.
    
       when "Compliant" then do:
         v-ComplianceRemarks = trim(vRow).
         leave doparse.
       end.
     end. /* end case */

  end.
  input close.

This state machine works only when the "Date" line comes first and "Thread-Topic" comes next.
if the order changes like "Thread-Topic" comes first and "Date" comes next then it fails.

please help me to work it for any order in the email file.
Based on email client the order of data gets changed.
I have attached an sample file.
 

Attachments

  • Sample.docx
    13.2 KB · Views: 2
Last edited by a moderator:

Cringer

ProgressTalk.com Moderator
Staff member
You could use COPY-LOB to copy the file into a LONGCHAR variable. Then you can loop through it like you would any character variable, so there's no problem looping through many times to find the info you want. Not necessarily the cleanest solution but you could make it work.
 

rajendran

Member
Even if i have copy-lob form the file.
i have to read it by line by line to get my data.
so whats the difference in that.
could you show some code snippet how to loop through longchar variable to get my data.
so in every state machne do i need to loop though longchar variable.
 

RealHeavyDude

Well-Known Member
You don't disclose much of your code, but I'll bet that the get* procedures check for a pattern in the line and extract the data use string functions like index, entry, substring etc.

With a CLOB the difference is that you can use function like index, entry, substring, etc. to directly work directly on the whole content instead of reading the lines sequentially.

Heavy Regards, RealHeavyDude.
 

rajendran

Member
Yes Rhd all the Get Prodcedures use entry,substring,index functions to extract the data from the line.
But with Clob its not easy to use that functions to extract as its a huge file and cannot predict the positions of the string unless its a line.
Is ther any other way to make this work.
 

RealHeavyDude

Well-Known Member
I don't understand why you couldn't use the index function to locate the desired patterns in the longchar. Maybe you should tell us more about the logic that you have to identify the patterns.

Heavy Regards, RealHeavyDude.
 

rajendran

Member
Thanks RHD ,i have designed it by using the index function and located what all i need to Extract.
Thanks very much for you help.
 
Top