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

removing zeros at the begining

Former Member
0 Likes
2,725

hi,

How to remove zeros at the begining of a variable value irrespective of the length of that number

for example,

data:var type int4.

var = '0000012434'.

var= '0003423365'

var= '0436509843'.

I want to remove all zeros at the beginning.

the purpose is I am passing this to a function module which can not allow intial zeros.

Please help me with code

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,692

Hi,

Use FM CONVERSION_EXIT_ALPHA_OUTPUT .

Regards,

Raju

16 REPLIES 16
Read only

Former Member
0 Likes
2,692

hi

move that variable to another variable of data type Character

else use Conversion_Exits

regards

Deva

Read only

Former Member
0 Likes
2,693

Hi,

Use FM CONVERSION_EXIT_ALPHA_OUTPUT .

Regards,

Raju

Read only

Former Member
0 Likes
2,692

Hi,

check this link, you will get the solution-

Read only

Former Member
0 Likes
2,692

Press F1 on SHIFT left deleting leading zero

Read only

Former Member
0 Likes
2,692

Hi ,

we can use :

" CONVERSION_EXIT_ALPHA_OUTPUT " fm

or use " SHIFT" statement.

example :

data a(9) value '000012345'.
SHIFT a LEFT DELETING LEADING '0'.
write:/ a.

Output will be : 12345

Or

data a(9) value '000012345'.

Call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
Exporting
input = a
Importing
output = a.

write a.

output:
12345.

thanx.

Edited by: Dhanashri Pawar on Aug 27, 2008 9:42 AM

Read only

Former Member
0 Likes
2,692

Hi,

CONVERSION_EXIT_ALPHA_OUTPUT

converts any number with zeroes right into a simple integer.

Ex:

'00001234'-->1234

CONVERSION_EXIT_ALPHA_INPUT

converts any number into a string fill with zeroes, with the number at the extreme right

ALPHA conversion is used especially with account numbers. During conversion from the external to the internal format, the system checks to see if input in the INPUT field is purely numeric, that is, if this input consists only of numbers, possibly with spaces before and after them. If this is the case, then the number string is inserted right- justified in the display field OUTPUT and all spaces to the left of the value are filled with zeroes ('0'). If the input is not purely numeric, it is inserted in the display field from left to right and all extra spaces are filled with blanks.

Example:

(Input field and output field are both eight characters in length)

'1234 ' --> '00001234'

Regards,

Omkaram.

Read only

vinodh_arumugam
Explorer
0 Likes
2,692

hi friend,

you want to remove all zeros at the beginning for output.

Use the function call mentioned here that will be useful to you

call function 'conversion_exit_alpha_output'

for ex.

here

input = 0000000123

then the function call will return the output as

output = 123.

Read only

Former Member
0 Likes
2,692

You could also use the following piece of code to achieve it.

data:var1 type int4.

var1 = '0000000134'.

DATA: var2(10) TYPE C.

var2 = var1.

CONDENSE var2.

WRITE:/ var2.

Read only

Former Member
0 Likes
2,692

Hi,

Check this sample code,

DATA:var TYPE int4.
var = '0000012434'.
WRITE: var NO-ZERO.
" output = 12434.

Regards

Adil

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,692

check this..

data:var type int4.

var = '0000012434'.

field-symbols:<var1> type int4.

assign var to <var1>.

write <var1>.

Read only

0 Likes
2,692

Do not use anything other than the conversion exit FM CONVERSION_EXIT_ALPHA_OUTPUT, as suggested by S Raju Shanigar

To do so would be bad programming practice.

matt

Read only

0 Likes
2,692

>

> Do not use anything other than the conversion exit FM CONVERSION_EXIT_ALPHA_OUTPUT, as suggested by S Raju Shanigar

>

> To do so would be bad programming practice.

>

> matt

any particular reason why?

pk

Read only

0 Likes
2,692

The type is INT4.

That FM only supports character types....

Read only

0 Likes
2,692

As Keshu Thekkillam said FM only supports clike types.

DATA:
  var TYPE int4.
  var = '0000012434'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input         = var
    IMPORTING
   OUTPUT        = var.
  write: var.
" The function module interface allows you to specify only
" fields of a particular type under "INPUT".
" The field "VAR" specified here is a different
" field type.

DATA:
  var(10) TYPE c.
  var = '0000012434'.

"The field "VAR" should be of type clike.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
  EXPORTING
    input  = var
  IMPORTING
    output = var.
WRITE: var.

Read only

Former Member
0 Likes
2,692

thanks

Read only

Former Member
0 Likes
2,692

Hi..

Find the following example:

DATA : BEGIN OF ITAB OCCURS 0,

NAME(10) TYPE C,

AGE(9) TYPE C,

END OF ITAB.

ITAB-NAME = 'NAME1'.

ITAB-AGE = '000028'.

APPEND ITAB.

ITAB-NAME = 'NAME2'.

ITAB-AGE = '000027'.

APPEND ITAB.

ITAB-NAME = 'NAME3'.

ITAB-AGE = '000029'.

APPEND ITAB.

ITAB-NAME = 'NAME4'.

ITAB-AGE = '000026'.

APPEND ITAB.

LOOP AT ITAB.

SHIFT ITAB-AGE LEFT DELETING LEADING '0'.

WRITE:/ ITAB-NAME,ITAB-AGE.

ENDLOOP.