Tip

Writing fixed length text files

I hope my experience will save some time for some programmers who never experienced this scenario before.

When sending a fixed length text file with spaces at the end of the file;

Trailing blanks are truncated when writing in text mode.

To create fixed length records, use binary mode to write each record and append your own line break(CRLF-Hex ODOA).

File-type 'BIN' gives you the option of defining the file_size while using the ws_download function to download the file.

For an 80 character fixed length file, The internal table should be defined with the 2 extra one character type x fields.


data: begin of intab occurs 10,             
      field1(01) type c, 
      bkacct(03) type c, 
      field3(02) type n, value '00',         
      acount(10) type c ,
      field5(01) type c value ' ',          
      ttype(01) type c, 
      indicator(01),(
      field8(01) type c, 
     chect(10) type n ,                                          
      trwbtr(10),                           
      laufd(6) type c,                      
      znme1(20),                            
      filler(14) type c value '  '.           
      cr(1) type x value '0D',              
      lf(1) type x value '0A',              
      end of intab.   

calling the function module with filetype bin with the specific file size.                      

form download_filetab. 
                          
* Check

    Requires Free Membership to View

that data exists describe table intab lines sy-tfill. ws_size = sy-tfill * 82. call function 'WS_DOWNLOAD' exporting bin_filesize = ws_size filename = ws_file filetype = 'BIN' tables data_tab = intab exceptions file_open_error = 1 file_write_error = 2 invalid_filesize = 3 invalid_table_width = 4 invalid_type = 5 others = 6. Hope it helps!

This was first published in May 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.