2015 Apr 27 10:50 AM
Dear forumers,
I have some difficulty in trying to manipulate string contents. Hope you can help me out~
As an example, a material number may have the following values:
i) CM123 4567 890
ii) CM123 4567 890-01
iii) CM9876543210
iv) CM9876543210-17
Examples i) and ii) contain blank spaces in between, while examples iii) and iv) does not contain any blank spaces.
How may I extract only the values, '123 4567 890' and '9876543210' in these cases?
I struggle when it comes to checking for the '-' sign.
Please help. Many thanks.
Deborah
2015 Apr 27 11:23 AM
Hi Deborah,
please check the following with all your possible material numbers:
REPORT ztestmat.
DATA: m_len TYPE i.
DATA: m_off TYPE i.
DATA: result TYPE string.
CONSTANTS: c_regex TYPE string VALUE `[0-9\s]+`.
PARAMETERS: p_mat TYPE string DEFAULT `CM123 4567 890-01`.
START-OF-SELECTION.
FIND REGEX c_regex IN p_mat
MATCH OFFSET m_off
MATCH LENGTH m_len.
IF m_len > 0.
result = p_mat+m_off(m_len).
ELSE.
result = `No material number found`.
ENDIF.
write: /1 result.
Regards,
Klaus
2015 Apr 27 11:35 AM
Hi Deborah ,
If you want to capture only numeric field from material code.
I think this will help
DATA : mat1 type matnr VALUE 'CM123 4567 890',
mat2 type matnr VALUE 'CM123 4567 890-01',
mat3 type matnr VALUE 'CM9876543210',
mat4 type matnr VALUE 'CM9876543210-17'.
data : num1(18) TYPE n,
num2(18) TYPE n,
num3(18) TYPE n,
num4(18) TYPE n.
num1 = mat1.
num2 = mat2.
num3 = mat3.
num4 = mat4.
WRITE : / num1 , num2 , num3 , num4 .
Regards
Yogendra Bhaskar
2015 Apr 27 11:47 AM
if "CM" constant in your requirement then you can try below logic to get the remaining string or number
DATA : str(20) TYPE c VALUE 'CM12345'.
DATA : len TYPE i,
str2(20) type c.
len = strlen( str ).
str2 = str+2(6).
WRITE : str2.
Thanks & Regards-
Vishal