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

Delete leading space in integer

Former Member
0 Likes
8,611

Hello,

i have a requirement where I need to pass integer value only and do not need leading spaces. Can someone please help me to get this issue resolved?

I have tried using "shift"/condense and many more options. None of them works as they are for type C,N,D,T.

Plese help.

1 ACCEPTED SOLUTION
Read only

vinod_vemuru2
Active Contributor
4,907

Hi Michael,

u can't use CONDENSE for deleting leading spaces of TYPE I fields. MOVE THIS DATA to character/String Variable and then CONDENSE this.

eg:

DATA: w_num TYPE I VALUE 8,

w_char TYPE string.

MOVE w_num TO w_char.

CONDENSE w_char.

WRITE :/1 w_num

/1 w_char.

Thanks,

Vinod.

29 REPLIES 29
Read only

former_member156446
Active Contributor
0 Likes
4,907

u need to use convert_exit_apha_output FM

in se37 chek for Convertalphaoutput FM

Read only

Former Member
0 Likes
4,907

Hi Michael ,

INtegers wont have leading spaces , what exactly do want to acheive .

Regards

Arun

Edited by: Arun R on May 14, 2008 8:44 PM

Read only

Former Member
0 Likes
4,907

Hello,

Did you used the command UNPACK and CONDENSE.

Regards,

Read only

vinod_vemuru2
Active Contributor
4,908

Hi Michael,

u can't use CONDENSE for deleting leading spaces of TYPE I fields. MOVE THIS DATA to character/String Variable and then CONDENSE this.

eg:

DATA: w_num TYPE I VALUE 8,

w_char TYPE string.

MOVE w_num TO w_char.

CONDENSE w_char.

WRITE :/1 w_num

/1 w_char.

Thanks,

Vinod.

Read only

Former Member
0 Likes
4,907

An interger field can not have spaces. So passing the field would have leading zeroes.

Read only

Former Member
0 Likes
4,907

DATA : lv_num TYPE i VALUE '123'.

data : lv_num1(10) type c .

lv_num1(10) = lv_num.

SHIFT lv_num1 LEFT DELETING LEADING space.

WRITE:/ lv_num1.

hope this helps..

regds

Read only

Former Member
0 Likes
4,907

Thanks for the prompt reply.

but my question is to remove space in integer.

Condense/ covertalphainput/output will all be applied on char type. These will not resolve my problem.

my problem is like I have an integer whose value is ' 8' (do not refer quote, it is used to show leading space). I have to get only 8 and that to in integer.

Read only

0 Likes
4,907

Micheal,

Integers are stored as Binary. So you can't have a space.

To prove this, put a breakpoint in your program at the field with the value in it. Then when in debug, double click on the

field. Where it shows the value, yes you will see ' 8'. however, if you push the Magnifying glass with the + in it, you will see the true

value of the field in HEX.

Passing this field should pass the integer in binary. You must make sure that the sizes are the same in the sending and receiving fields of what ever you are attempting to pass it to.

Read only

0 Likes
4,907

Hi Michael ,

You cannot acheive it using int data type , you need to move it to a variable of type n and then use shift to acheive the result.

Here is a sample code for the same

data v1 type i.
data v2(10) type n.

v1 = 8.
v2 = v1.
shift v2  left deleting leading '0'.

Regards

Arun

Read only

0 Likes
4,907

Hi

your issue is not very clear, I can't understand where u have the integer and where u have to put the integer, anyway try to see if this sample is helpfull for you:

DATA: V_CHAR(10) TYPE C,
        I          TYPE I VALUE 8,
        LEN        TYPE I.

  WRITE I TO V_CHAR.

  CONDENSE V_CHAR NO-GAPS.

  LEN = STRLEN( V_CHAR ).

  WRITE V_CHAR(LEN).

Max

Read only

0 Likes
4,907

Hi,

What is every material number also have few zero infront, like some is 0000001000 and another once is 00123456 , how to remove the front zero for matnr field?

Thanks

Read only

Former Member
0 Likes
4,907

Here is a sample code. i tried to replicate the same case,

data : v_int type i.

v_int = 56.

write v_int.

Here you will get the spaces. How to remove spaces in integer(i do not want ouput in any other data type).

Read only

0 Likes
4,907

Hi

DATA : V_INT TYPE I.

V_INT = 56.

WRITE V_INT LEFT-JUSTIFIED.

Max

Read only

0 Likes
4,907

check the post of Max for the solution to your problem , it would have been great if you had mentioned that you want to acheive it in write statement .

use LEFT-JUSTIFIED along with the write statement

data v1 type i.

v1 = 8.
write v1.
skip 1 .
write v1 LEFT-JUSTIFIED.
skip 1.

Read only

0 Likes
4,907

Then if you are not passing it to a FM, or another program etc...

Max's suggestion is the best solution.

Or

You can move it to a character type field as many here have suggested and use the SHIFT LEFT deleteing leading zeros.

Then, print the Character field.

Read only

0 Likes
4,907

form alpha_input using p_var.

call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
exporting
input = p_var
importing
output = p_var.

endform. " alpha_input
Read only

4,907

Ok..

Try like this:


data : v_int type i,
v_len type i,
v_char type char10.


v_int = 356.
v_char = v_int.
condense v_char.
v_len = strlen( v_char ).
write at (v_len)v_int.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
4,907

I have to use this variable containing no spaces furher. So "left-justified' will not work. Anyways good one. Please help me in this requirement.

Read only

0 Likes
4,907

Writing Left justified does NOT effect the original value. It's simply the displaying of it.

Read only

0 Likes
4,907

then the only option is to use type N.

Read only

Former Member
0 Likes
4,907

n type will also not help me in resolving the issue.

It is like i have to pass integer value in BDC and it is not accepting value in any other data type and even spaces in front of integer will not fetch me my result in BDC. Only option for me is to remove spaces in front of integer.

need help

Read only

0 Likes
4,907

what about this


data: l_v type i value 36,
      l_n(6) type n.
l_n = l_v.
write l_n to l_n no-zero.
condense l_n.
write l_n.

Read only

0 Likes
4,907

try using data type n in BDC ; i dont thnik BDC has an issue with data type till the data you are passing to field is correct.

Try it and tell the result .

Read only

0 Likes
4,907

Hi

If you're creating a BDC report, the BDC structure has only char field, so u can use the statament:

WRITE <INTEGER> LEFT-JUSTIFIED TO BDCDATA-FVAL.

Max

Read only

Former Member
0 Likes
4,907

Hello everybody,

i have recorded transaction ML81 and have to make changes in the Service entry sheet. When making changes into the same i have to pass line no. which needs to be modified as i have to modify quantity. In order to pass line no. I have read data using sy-tabix and then passed the same into a temporary integer value which signifies line no. But due to spaces present in it BDC is not capturing the line no. So it skips this step and move further without amendment

Read only

0 Likes
4,907

When you pass your line number to BDC table use CONDENSE to remove the leading space from the BDC field.

Like:


BDCDATA-FVAL  = L_INDEX.
condense BDCDATA-FVAL.
APPEND BDCDATA.

Regards,

Naimesh Patel

Read only

0 Likes
4,907

Hi

I don't know that trx, but if you're speaking about a tablecontrol, u should transfer the line value beetween ()

Max

Read only

0 Likes
4,907

May be try this RegEx


report zars.
data: l_v type i value '       36',
      l_c(13) type c.

data : regex    type c length 120 value '^[ 	]+|[ 	]+$'.

write l_v to l_c.
replace regex  regex in l_c
                      with space ignoring case.

write l_c.

a®

Read only

Former Member
0 Likes
4,907

This message was moderated.