on ‎2024 Sep 05 9:46 PM
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?
Request clarification before answering.
Hi Arushi,
you can try the ALPHA format option of the string templates. Maybe this works for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
data :s1 type string.
s1 = |{ '1234' ALPHA = IN WIDTH = 10 }|. "add 0
s1 = |{ '00001234' ALPHA = OUT }|. "1234. "remove 0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.