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

Fill empty field by space

Former Member
0 Likes
5,081

i have an internal table

field1 field2 field3 field4

-


c1 c2 c3 c4

c5 c6 c7 c8

i am concatenating each row into a string separated by space.

my problem is this: if c3 or c4 is empty, it should be filled with space. The downloaded file should be like this.

length of c3 is 16 and length of c4 is 50

1900000094 23/05/2008 IBM INDIA LTD Purchase the LAPTOP

1900000096 23/05/2008 Training SAP

1 ACCEPTED SOLUTION
Read only

Former Member
3,088

Try this:


data: space1 type CL_ABAP_CHAR_UTILITIES=>SPACE_STR. 
l_length = strlen (itab-field1).
Do l_length times.
 concatenate itab-field1 space1 into itab-field1.
enddo.

11 REPLIES 11
Read only

Former Member
3,089

Try this:


data: space1 type CL_ABAP_CHAR_UTILITIES=>SPACE_STR. 
l_length = strlen (itab-field1).
Do l_length times.
 concatenate itab-field1 space1 into itab-field1.
enddo.

Read only

0 Likes
3,088

Hi Sourav Bhaduri,

Thanks for ur reply.. I tried this code.

data : space1 type CL_ABAP_CHAR_UTILITIES=>SPACE_STR.

I got this error : The type "SPACE_STR" is unknown.

Read only

0 Likes
3,088

Hi Christy,

CL_ABAP_CHAR_UTILITIES=>SPACE_STR

The Visibility for SPACE_STR is a PRIVATE, hence it cannot be used for declaration.

Regards,

Rafi

Read only

0 Likes
3,088

yes you are right,

but this is public.

CL_SCSM_XML_WRITER=>SPACE_STR

Read only

0 Likes
3,088

CL_SCSM_XML_WRITER=>SPACE_STR

Read only

JozsefSzikszai
Active Contributor
0 Likes
3,088

hi,

I think there are two ways to go:

1.

CONCATENATE field1 field2 ... INTO string SEPARATED BY space RESPECTING BLANKS.

However this works only in 6.0 (because of the RESPECTING BLANKS)

2. Use offsets:

string+n(16) = field3. (n will be the starting position of field3 minus 1)

string+x(50) = field4.

hope this helps

ec

Read only

0 Likes
3,088

Thanks Eric,

could you pls explain it? below is my code. this is not working.

if wa_linedata-xblnr = ' '.

  • here i want to fill wa_linedata-xblnr by space.

string+n(16) = wa_linedata-xblnr.

endif.

Read only

0 Likes
3,088

hi check this...use this..

data: filler(16) TYPE c VALUE cl_abap_char_utilities=>HORIZONTAL_TAB.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,088

if u r facing the problem using normal concatenate statement then do some thing like this.

loop at itab.

if itab-c1 is not initial.

wk_string = itab-c1.

elseif itab-c2 is not initial.

concatenate wk_string itab-c2 into wk_string separated by space.

elseif itab-c3 is not initial.

concatenate wk_string itab-c3 into wk_string separated by space..

elseif itab-c4 is not initial.

concatenate wk_string itab-c4 into wk_string separated by space.

endif.

write wk_string.

endloop.

do find out whether there is any better way than this

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
3,088

i have replied wrongly i guess...

Read only

Former Member
0 Likes
3,088

Why are you concatenating everything into a string?  Can't you just download your structured itab since all the components seem to be character type?  If you actually need a space between each field then declare another work area with the same fields plus a CHAR1 field between each and download from that structure.

JIm