Nifriz
Nifriz

Reputation: 1234

Writing into IFS file a variable size string

I'm writing a file in iSeries IFS.

My variable File_Data is a 32000A, so when I use

CallP     Write(FileD           :  
               %Addr(File_Data) : 
               %Size(File_Data) )  

I find some unuseful spaces when the Variable is not filled for 32K chars. I try with a %Trim but I get an Error.

To bypass the problem I do this:

 For       Counter = 1 To %Len(%Trim(File_Data))        
 Eval      SingleChar = %SubSt(File_Data : Counter : 1) 
 CallP     Write(FileD           :                      
                %Addr(SingleChar) :                     
                %Size(SingleChar) )                     
 EndFor                                                 

Is there a better way to do this? Becasue is very slow.

Upvotes: 2

Views: 334

Answers (1)

nfgl
nfgl

Reputation: 3212

Considering your solution uses %trim (trim both sides) but writes file_data from char 1 then there must be no space at the beginning. So you can use %trimr instead, that simplifies the problem.

What you want is tell write() the length of data to write : this should do the work

CallP     Write(FileD           :  
               %Addr(File_Data) : 
               %len(%trimr(File_Data))
          )  

But if the program you write also builds the content, then maybe you can declare file_data as varchar. It will keep track of the actual length of data and in the end you can write

CallP     Write(FileD           :  
               %Addr(File_Data:*data) : 
               %len(File_Data)
          )  

Upvotes: 4

Related Questions