2008 Aug 27 8:36 AM
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
2008 Aug 27 8:39 AM
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
2008 Aug 27 8:38 AM
hi
move that variable to another variable of data type Character
else use Conversion_Exits
regards
Deva
2008 Aug 27 8:39 AM
2008 Aug 27 8:40 AM
2008 Aug 27 8:41 AM
2008 Aug 27 8:42 AM
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 : 12345Or
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
2008 Aug 27 8:42 AM
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.
2008 Aug 27 8:43 AM
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.
2008 Aug 27 8:44 AM
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.
2008 Aug 27 8:49 AM
Hi,
Check this sample code,
DATA:var TYPE int4.
var = '0000012434'.
WRITE: var NO-ZERO.
" output = 12434.Regards
Adil
2008 Aug 27 8:50 AM
check this..
data:var type int4.
var = '0000012434'.
field-symbols:<var1> type int4.
assign var to <var1>.
write <var1>.
2008 Aug 27 8:56 AM
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
2008 Aug 27 9:01 AM
>
> 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
2008 Aug 27 9:04 AM
2008 Aug 27 9:14 AM
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.
2008 Oct 15 6:24 AM
2008 Oct 15 8:05 AM
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.