cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Remove and add zeroes in S4 HANA

Arushi
Explorer
0 Likes
2,598

Hi,

I am trying to remove and add zeroes in S4 HANA, Call function 'CONVERSION_EXIT_ALPHA_INPUT' is throwing error - Not permitted in restricted scope, what is the other way to remove zeroes and then add zeroes as per the data type?

Accepted Solutions (1)

Accepted Solutions (1)

M-K
Active Participant

Hi Arushi,

you can try the ALPHA format option of the string templates. Maybe this works for you.

Arushi
Explorer
0 Likes
Thank you, this worked for me..

Answers (2)

Answers (2)

junwu
SAP Champion
SAP Champion
data :s1 type string.
s1 = |
{ '1234' ALPHA = IN WIDTH = 10 }|. "add 0
s1 = |{ '00001234' ALPHA = OUT }|. "1234.  "remove 0
 

 

Arushi
Explorer
0 Likes
this worked for me, thank you so much
gabriel_redware
Explorer
You can try too
gabriel_redware
Explorer
You can try too ALPHA = IN to add left zeros following data domain or ALPHA = OUT to delete left zeros
Arushi
Explorer
0 Likes
thank you everyone this worked for me
chelseafair01
Explorer
0 Likes

In SAP S/4HANA, the use of function modules like CONVERSION_EXIT_ALPHA_INPUT and CONVERSION_EXIT_ALPHA_OUTPUT is restricted in some cases, especially when working in a restricted or cloud-based environment. Since you're getting the error "Not permitted in restricted scope," it means you're not allowed to use these function modules in your context.

To handle the removal and addition of leading zeros without using these function modules, you can manually manipulate the strings in ABAP code. 

Here's an alternative approach:

1. Remove Leading Zeros

You can use the SHIFT statement to remove leading zeros from a string.

DATA(lv_field) = '000123456'. " Example value with leading zeros
SHIFT lv_field LEFT DELETING LEADING '0'.
WRITE: lv_field. " Output: 123456

2. Add Leading Zeros Based on Data Type Length

To add leading zeros back, you can use the CONDENSE and FORMAT options, or pad it using the WRITE statement.

DATA: lv_output TYPE string,
lv_length TYPE i.

lv_output = '123456'. " Example value after removing zeros
lv_length = 10. " Desired length with leading zeros

" Add leading zeros to match the required length
lv_output = lv_output+0(lv_length).
WRITE lv_output LEFT-JUSTIFIED TO lv_output.

WRITE: lv_output. " Output: 0000123456 if length is 10

Explanation:

- SHIFT: Removes leading zeros from the string.
- lv_length: Represents the target length of the field after adding zeros.
- Padding: The lv_output = lv_output+0(lv_length) ensures that the string is padded with leading zeros to match the desired length.