Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Creating a Fixed Length File

Former Member
0 Likes
2,528

Greetings,

I'm creating an application that need to create a fixed length file on a UNIX system and need help. I have an internal table(s) which contain structures with fields of different lengths (type c) and so I have a routine that concatenates these fields into a single record to be sent to a file using the open dataset. This process is squeezing out all my spaces and so my fixed length file is lost. Can someone assist in creating a fixed length file from an internal table without using delimiters?

Thanks!

Greetings,

I'm creating an application that need to create a fixed length file on a UNIX system and need help. I have an internal table(s) which contain structures with fields of different lengths (type c) and so I have a routine that concatenates these fields into a single record to be sent to a file using the open dataset. This process is squeezing out all my spaces and so my fixed length file is lost. Can someone assist in creating a fixed length file from an internal table without using delimiters?

Thanks!

5 REPLIES 5
Read only

Former Member
0 Likes
1,457

Joseph,

Please read the online help on CONCATENATE statement and you will find that it is designed to remove spaces.

If your internal table structure contains only text fields, then just don't concatenate individual fields. Just output the entire record to the file like below. Then you will get a file of fixed width.

TRANSFER itab_header TO dataset.

Read only

former_member194669
Active Contributor
0 Likes
1,457

Something like this way


Data : begin of itab.
        Field1(1) type c,
        Field2(2) type c.,
        Field3(3) type c,
        Field4(4) type c.
Data : end of itab.

Data : begin of itab1 occurs 0.
        Field(20) type c.
Data : end of itab1.

Loop at itab.
     Move itab to itab1.
     Append itab1.
Endloop.

Open dataset  ........

Loop at itab1.
   Transfer itab1 TO dataset.
Endloop.

Read only

0 Likes
1,457

This seems work only if my table record has a value of some kind in the last field.

So to use your example if Field1 and Field4 has data my fixed lengths are preserved however if only Field1 has data and 2,3,4 are empty then record ends right after Field1.

Ideas?

Read only

0 Likes
1,457

ABAP statement TRANSFER has an addition LENGTH that can be used to specify the width of the line.

Read only

0 Likes
1,457

" May be placing a carriage return end of each records 
" will solve your problem

class cl_abap_char_utilities definition load.
data : begin of itab,
        field1(1) type c,
        field2(2) type c,
        field3(3) type c,
        field4(4) type c,
crlf(2) type c value cl_abap_char_utilities=>cr_lf. "<<<See this line<<<
data : end of itab.

Data : begin of itab1 occurs 0.
        Field(20) type c.
Data : end of itab1.

Loop at itab.
     Move itab to itab1.
     Append itab1.
Endloop.

Open dataset  ........

Loop at itab1.
   Transfer itab1 TO dataset.
Endloop.