Question
· May 10, 2018

how to read a batch line by line and write that to a file

I have a batch that uses the record mapper class .I would like to have a custom operation that will write this batch to a csv file .My operation has a batch as its request and I would like to read that batch data to a csv.So far here is  what I have.

Method BatchFile(pRequest As ResponseRBAT, Output pResponse As EnsLib.RecordMap.BatchResponse) As %Status
{
 #dim status as %Status=$$$OK
 #dim inrec as HSCIC.DBS.ResponseRMAP.Record=##class(ResponseRMAP.Record).%New()
 set x=0
    set:$$$ISOK(status) status=  ..Adapter.PutLine(pRequest.%Source,pRequest.BatchHeader)
    //set pRequest.Records.Count()
    while (x<pRequest.Records.Count())
    {
     set inrec.ResponseCode=pRequest.Records.GetAt(1)
     set inrec.PatientID =pRequest.Records.GetAt(2)
      set inrec.MultiMatch =pRequest.Records.GetAt(3)
 
   set:$$$ISOK(status) status=  ..Adapter.PutLine(pRequest.%Source,inrec)
   set x=$INCREMENT(x)
 }
     
 
 
   set:$$$ISOK(status) status=  ..Adapter.PutLine(pRequest.%Source,pRequest.BatchTrailer)
 $$$TRACE($System.Status.GetErrorText(status))
 return status
} 

The GETAT method only write this  5@ResponseRMAP.Record to a file. I am just missing something any help please. I am aware of the built in record mapper that can produce the CSV file but that built in functionality is not doing the job for me as it prints extra characters that make my file not readable by the receiving system 

Discussion (1)2
Log in or sign up to continue

I'd suggest contacting the WRC to help look at the problem you're seeing with unwanted characters in the output. EnsLib.RecordMap.Operation.BatchFileOperation does what you've described, so it would be best to get this working for your use case if possible.

Looking at the code you posted...

pRequest.Records.GetAt(1)

This will just get you the first record from the batch. If you want to get a specific field from a record you would want to use something like:

pRequest.Records.GetAt(1).FieldName