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: 

How to insert spaces for a charatcer filed?

Former Member
0 Kudos

Hi Guys,

Can anybody tell me how to insert trailing spaces for a character field which is already having a value?

Thanks,

Gopi.

18 REPLIES 18

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

If the value is right adjusted, then you can simply shift it left. but if the value is already left adjusted, then there are already trailing spaces.

If the value is right adjusted.

shift <field> left deleting leading space.

Regards,

RIch Heilman

0 Kudos

Hi Rich,

But when i am downloading that data into aplication server, suppose if the filed length is 20 and the data is of only 10 and for the rest 10 digits spaces is not getting inserted .so how to insert spaces into the filed.

Thanks,

Gopi.

0 Kudos

Hi Gopi,

Use WRITE ......TO with offset to write into an internal table.

like:

WRITE dobj TO itab[+off][(len)]

Try this..

Regards

Subramanian

0 Kudos

Hi, are you using TRANSFER to write to application server? Are you transfering the entire structure at one time? If so, then the spaces should be there.

Can you post your code.

Regards,

RIch Heilman

0 Kudos

Hi Gopi,

When you download the data on application server and that field is the last field then the spaces are automatically removed.

Just try with END of line character at end, may you get the spaces in application server after that.

Regards,

Atish

0 Kudos

Hi Rich ,

I am using Transfer statement like what u told .

"TRANSFER ls_EBKN_temp TO wa_PurchReq_AcntAssgmnt_file length 450 ."

but also not solved the problem.

Thanks,

Gopi.

Former Member
0 Kudos

Check with below links :

if you use concatenate command ,it will remove spaces,

http://www.sapfans.com/forums/viewtopic.php?t=200517&highlight=filedownloadspace

http://www.sapfans.com/forums/viewtopic.php?t=123275&highlight=filedownloadspace

Thanks

Seshu

0 Kudos

Hi Seshu,

In the reply u send me Links.There they told not to use Concatenate ,Then how can i transfer the data with Trailing Spaces.He told me to use

" move: fieldval1 to string+0(500),

fieldval2 to string+500(12) *field2 consists of 12 characters "

but the Q'n is how to insert Tab delimited Spaces ?can u plz help.

Thanks,

Gopi.

0 Kudos

<i>but the Q'n is how to insert Tab delimited Spaces</i>

Ok, so you want to put tabs in between the fields? You can do so, like this.




report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.

constants: con_tab type x value '09'.

* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.

itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.

  open dataset d1 for output in text mode.
  loop at itab.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    transfer str to d1.
  endloop.
  close dataset d1.

Regards,

RIch Heilman

0 Kudos

Hi Rich,

The logic which u gave doesn't worked.There was no trailing spaces in the fineal output.Can u suggest me the alternate solution?

Thanks,

Gopi.

0 Kudos

You mean at the very end of the line?

Regards,

RIch Heilman

0 Kudos

Hi Rich ,

I mean b/w the columns there must be Trailing spaces for each filed like 17 spaces (becoz u meantioned size as 20 and only 3 characters are used)u must have b/w each column and also tab delimiter.

the output is

ABC DEF DEF

123 456 456

Thanks,

Gopi

0 Kudos

Ok, this will work, but if there are any spaces in any fields, it will be a problem.



report zrich_0001.
 
parameters: d1 type localfile default '/usr/sap/TST/SYS/Test.txt'.
 
data: begin of itab occurs 0,
      field1(20) type c,
      field2(20) type c,
      field3(20) type c,
      end of itab.
data: str type string.
 
constants: con_tab type x value '09'.
 
* if you have a newer version, then you can use this instead.
*constants:
*    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
 
start-of-selection.
 
itab-field1 = 'ABC'.
itab-field2 = 'DEF'.
itab-field3 = 'GHI'.
append itab.
 
itab-field1 = '123'.
itab-field2 = '456'.
itab-field3 = '789'.
append itab.
 
  open dataset d1 for output in text mode.
  loop at itab.
    translate itab using '# '.
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    translate str using ' #'.
    transfer str to d1.
  endloop.
  close dataset d1.


You need to translate the spaces and use a placeholder, then after the concatenation, translate it back.

0 Kudos

Hi rich,

I got data in this format for the logic which u told

"ABC##DEF##GHI#######################################################################################

123##467##798#######################################################################################

"

Thanks,

Gopi.

0 Kudos

Ooops.. Sorry. I had it backwards.



    translate itab using ' #'.    "<- Adjust this
    concatenate itab-field1 itab-field2 itab-field2 into str
                  separated by con_tab.
    translate str using '# '.       "<- And adjust this


Regards,

RIch Heilman

0 Kudos

Hi rich ,

It worked well i got spaces ,But how to include in my program?

Thanks,

Gopi.

former_member196280
Active Contributor
0 Kudos

This may help you.

WRITE 'ABC' To char Right-justified.

Reward points if useful.

Regards,

SaiRama

Former Member
0 Kudos

try with this in your program

*   Download internal table to Application server file(Unix)
DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.      

  open dataset e_file for output in text mode.
  lOOP AT it_datatab......
    transfer it_datatab to e_file.
  ENDLOOP.
 
  close dataset e_file.

reward points if it is usefull ...

Girish