Application Development 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: 

Add trailing space to text

tharaka_fernando
Contributor
0 Kudos

Hi All,

I need to write a text file into application server values with spaces. I know this has been mentioned several times but I am unable to find a solution yet.

below is the coding;


DATA :  lv_rec(1) TYPE c,

         lv_source(4) TYPE c,

         lv_seq_number(4) TYPE c,

         lv_cutt(8) TYPE c,

         lv_res(779) TYPE c.

DATA : lv_file_name TYPE string,

          lv_space TYPE string,

          lv_raw TYPE string.

lv_rec = 'M'.

lv_reserved = ' ' .

lv_source = 'TEST'.

lv_cutt = sy-datum.

lv_reserved =  ' '.

lv_space = cl_abap_conv_in_ce=>uccp( '00a0' ).

OPEN DATASET lv_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

WRITE  lv_space TO lv_reserved+778(1).

CONCATENATE lv_rec lv_source  lv_cutt lv_res INTO lv_raw

TRANSFER:  lv_raw  TO lv_file_name.

CLOSE DATASET lv_file_name.

I dont see the file getting created as per the requirement . Variable LV_RES should have 779 SPACES.

Could anyone plz explain the satement "WRITE  lv_space TO lv_reserved+100(1)".... specially what specially "+100(1)"

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

"+100(1)" is <position>(<No of Characters>).

So it means starting on 100th position with 1 Character .

You should try what has already said. but instead of "WINDOWS LINEFEED" I would use "SMART LINEFEED" or "NATIVE LINEFEED" as it will be OS independent .

R



9 REPLIES 9

former_member223133
Active Participant
0 Kudos

Hi,

Below statement will solve your issue.

OPEN DATASET lv_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH WINDOWS LINEFEED.

BR

Gangadhar

Former Member
0 Kudos

Hi,

"+100(1)" is <position>(<No of Characters>).

So it means starting on 100th position with 1 Character .

You should try what has already said. but instead of "WINDOWS LINEFEED" I would use "SMART LINEFEED" or "NATIVE LINEFEED" as it will be OS independent .

R



0 Kudos

Thanks for the reply..

is there a limitation of the charachters ? Cos If I use ;

WRITE  lv_space TO lv_reserved+100(1).


then File is created with 100 spaces.


but If I use WRITE  lv_space TO lv_reserved+778(1).


File has no SPACES...

0 Kudos

Did you mean lv_res? Cause I could not find lv_reserved in your code. What is the data type you used for lv_reserved?

Also how do you know it is not working when WRITE  lv_space TO lv_reserved+778(1)? Via AL11?

Note AL11 only shows up to 255 characters but in the OS level the file will be created with more than 255 characters.


R

0 Kudos

Thanks for the reply.

Yes.it is Lv_res.

Data type: lv_res (779) type c.

Im using Tcode 'CG3Y' to check the file. (Download into Local PC)

Note : OS is OS400

0 Kudos

There was a limitation of 1500 characters per line . Not sure if it still holds true.

Does not look like you have more than 1500 characters.

WITH SMART/NATIVE LINEFEED You can try to append CL_ABAP_CHAR_UTILITIES=>CR_LF at the end .

R

0 Kudos

Hi Rudra,

Thank you for the reply..

I still can write a file with character length (including SPACE) around 200 - 256.

But how to write the text file with more than 700 ?

0 Kudos

Hi,

Did you check downloading the file via CG3Y in Binary mode? Please check that once.

In order to check if the spaces are being written correctly I would put a dummy character(Put * or $ or something) at the end of the string and then download.

R

0 Kudos

Not sure if your issue is fixed. Just came to my mind. One thing also you could try.

While concatenating, use addition RESPECTING BLANKS.

R