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

Trailing Blank spaces in the string

Former Member
0 Likes
3,488

Hi All,

I have to write a file on the application server. I've used CONDENSE for the data to be written but there is always a blank space after every field( before the added delimiter) . A delimiter has also been used after every field. The output is coming in the below format:-

EAR_LCR , ,0006036387,EXTERNAL ,0001, , , ,Y,EUR ,

I need to suppress these spaces. Please suggest.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,979

Hi,

pass the values to string type variable and do condence the check .

i think this may helps,

Srini.

17 REPLIES 17
Read only

Former Member
0 Likes
2,980

Hi,

pass the values to string type variable and do condence the check .

i think this may helps,

Srini.

Read only

0 Likes
2,979

Hi,

Try to use SHIFT LEFT <variable_name> DELETING LEADING SPACE.

Regards,

Pranav

Read only

0 Likes
2,979

I cannot use shift-left as the I need to modify an existing program with more than 100 variables.

Is there any command which I can use

Read only

0 Likes
2,979

Hi neha,

please post a couple of code lines so that we know how you proceed with creation aof application server (text?) file..

You may use REPLACE ALL OCCURRENCES OF ` ,` WITH `,` IN <output> - Note: ` ,` means space followed by comma delimiter enclosed in back hyphens to be replaced by comma delimiter only.

Regards

Clemens

Read only

0 Likes
2,979

This is the code for the program

OPEN DATASET l_fname FOR OUTPUT IN TEXT MODE. " ENCODING DEFAULT.

LOOP AT it_custtemplate .

MOVE: g_delim TO it_custtemplate-dl1,

g_delim TO it_custtemplate-dl2,

g_delim TO it_custtemplate-dl3,

g_delim TO it_custtemplate-dl4,

CONDENSE it_custtemplate.

TRANSFER it_custtemplate TO l_fname.

CLEAR it_custtemplate.

ENDLOOP.

CLOSE DATASET l_fname.

Read only

0 Likes
2,979

I am working with 4.6C version SAP and I did not find ' Replace all occurrences'. Only replace is available

Read only

0 Likes
2,979

Hi

Try condesing the individual fields of the internal field , concatenate them and then write to file, writing the complete work area is resulting in spaces. I am not sure if the mentioned result is for the same piece of code ?.

Regards

Pawan

Read only

0 Likes
2,979

Hi neha jindal,

it seems that your DL1, DL2, etc. fields contain 2 characters. Otherwise, it means the other fields of your internal table contain an erroneous leading space. Use debug to make sure what is the exact reason.

BR

Sandra

Read only

0 Likes
2,979

Hi neja,

how do you fill the fields of it_custtemplate? Transfer statement will copy the fields in full length.

You could

data:
  lv_string type string.
CONCATENATE  
  it_custtemplate-value01
  it_custtemplate-value02
...
  it_custtemplate-valuenn
INTO lv_string
SEPARATED BY ','
TRANSFER lv_string TO l_fname.

Regards,

Clemens

Read only

0 Likes
2,979

Hello Pawan,

The problem why I am not condensing or concatenating individual fields is there are more than 30 programs with 100 fields in each program in my case.

So , please let me know if there is any command which can remove these trailing spaces from the entire work area. but, In case there is no work around available I'll try and do it with the concatenation of individual fields.

The structure of it_custtemplate is like below:-

DATA : BEGIN OF it_custtemplate OCCURS 0,

name1 LIKE kna1-name1, " LIKE kna1-name1,

dl1 TYPE c,

stceg LIKE kna1-stceg,

dl2 TYPE c,

kunnr LIKE kna1-kunnr,

dl3(1),

kdgrp(10), " LIKE KNVV-KDGRP,

dl4(1),

brsch LIKE kna1-brsch,

dl5(1),

Thanks for your help.

Read only

0 Likes
2,979

Neha Jindal,

I believe you can REPLACE atleast, so try below solution.

Before your loop write the below code.

-


data: lt_comp type TABLE OF RSTRUCINFO,

lv_count type i.

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'IT_CUSTTEMPLATE'

tables

components = lt_comp

.

DESCRIBE TABLE lt_comp lines lv_count. "no. of fields in internal table

lv_count = lv_count / 2. "only half are delimiters

-


Then, just after your condense statement, use

do lv_count times.

replace ' ,' in it_custtemplate WITH ','. "space, into ,

enddo.

-


This should solve your problem as it can be pasted directly in any number of programs. Let me know in case of any issue.

Regards,

Diwakar

Edited by: Diwakar Aggarwal on Jul 21, 2011 1:18 PM

Read only

0 Likes
2,979

Thank you so much Diwakar. The problem is solved now. I won't have to change all the fields in all the programs now .

Read only

0 Likes
2,979

Hi Neha

I would then suggest you to code the replace all occurences logic (as advised by Clemens) self in a subroutine and reuse it in ur programs. Something like this :

n = strlen( l_string ).

data : offset1 type i value is initial,

offset2 type i value is initial,

l_char_prev type c,

l_char_curr type c.

l_char_curr = l_string+offset1(1).

offset1 = offset1 + 1.

While offset1 le n.

l_char_prev = l_char_curr.

l_char_curr = l_string+offset1(1).

if l_char_curr = ',' and l_char_prev = ' '.

offset2 = offset1 - 1.

REPLACE SECTION OFFSET offset2 LENGTH 2 OF l_string WITH ','.

offset1 = offset2.

else.

offset1 = offset1 + 1.

Endif.

Endwhile.

Write 😕 l_string.

Offcourse this does not handle the pattern ' ,' present in a variable but neither does the SAP standard replace all occurences.

Regards

Pawan

Read only

kiran_k8
Active Contributor
0 Likes
2,979

Try using the below statement before the open dataset statement.

PERFORM set_trail_blanks(saplgrap) USING 'X'.

Thanks,

K.Kiran.

Read only

Former Member
0 Likes
2,979

Hello Kiran,

I tried using the suggested Perform but , there was no chnage in the output format

Read only

Clemenss
Active Contributor
0 Likes
2,979

Hi neha jindal,

you may try [CONDENSE addition NO-GAPS|http://help.sap.com/abapdocu_702/en/abapcondense.htm].

This will remove all blanks.

Regards,

Clemens

Read only

Former Member
0 Likes
2,979

Hello Clemens,

Condense with no gaps will remove all spaces i. in between the words also. So, I cannot use it.

Thanks