‎2008 Apr 10 4:19 PM
Hi Friends!
Well I have 2 materials . One has a colour tied to it and one does not . I need to compare them and exclude the color while comparing . Please advise .
mat1 = 99825
matc1 = 99825-0
In this eg I should only compare 99825.
mat2 = 99825-R
matc2 = 99825-R-0 .
In this eg I should only compare 99825-R .
Thanks !!
Teresa
‎2008 Apr 10 4:59 PM
Teresa,
This process will make the decision on which is the coloured one and work better then my previous suggestion.
DATA: matnr1 TYPE matnr VALUE '12345',
matnr2 TYPE matnr VALUE '12345-R',
len_matnr1 TYPE i,
len_matnr2 TYPE i.
len_matnr1 = strlen( matnr1 ).
len_matnr2 = strlen( matnr2 ).
IF len_matnr1 GT len_matnr2.
IF matnr1+0(len_matnr2) = matnr2.
* Must be the same material
* we know that Material 1 is the coloured one
ELSE.
* different materials.
ENDIF.
ELSE.
IF matnr2+0(len_matnr1) = matnr1.
* Must be the same material
* we know that Material 2 is the coloured one
ELSE.
* different materials.
ENDIF.
ENDIF.
‎2008 Apr 10 4:23 PM
‎2008 Apr 10 4:23 PM
compare with :
in the first Ex: with mat1 ..
if matc1 CS mat1.<-- here u'll compare with 99825
*coding
endif.
in the second Ex: with mat2 ..
if matc2 CS mat2. <-- here u'll compare with 99825-R
*coding
endif.
‎2008 Apr 10 4:27 PM
Hi,
You can use CS for string comparison.
Thanks,
Sriram Ponna.
‎2008 Apr 10 4:47 PM
Hi Teresa,
Seems that the the fields can vary in length. Perhaps testing for length on both of them would resolve this issue.
len_mtch1 = strlen( mtch1 ).
len_mtch2 = strlen( mtch2 ).
if math2+0(len_mtch1) = mtch1.
* We know we're testing the same material.
if len_mtch1 LT len_mtch2.
* Special Coding
endif.
endif.
The greater of the 2 values would be your coloured one.
Edited by: Paul Chapman on Apr 10, 2008 5:48 PM
‎2008 Apr 10 4:59 PM
Teresa,
This process will make the decision on which is the coloured one and work better then my previous suggestion.
DATA: matnr1 TYPE matnr VALUE '12345',
matnr2 TYPE matnr VALUE '12345-R',
len_matnr1 TYPE i,
len_matnr2 TYPE i.
len_matnr1 = strlen( matnr1 ).
len_matnr2 = strlen( matnr2 ).
IF len_matnr1 GT len_matnr2.
IF matnr1+0(len_matnr2) = matnr2.
* Must be the same material
* we know that Material 1 is the coloured one
ELSE.
* different materials.
ENDIF.
ELSE.
IF matnr2+0(len_matnr1) = matnr1.
* Must be the same material
* we know that Material 2 is the coloured one
ELSE.
* different materials.
ENDIF.
ENDIF.
‎2008 Apr 10 5:22 PM
This is what I have in my code .
CLEAR L_MATNR .
Loop at itab .
IF L_MATNR <> ITAB-MATNR .
Read table ztable with KEY MATNR = ITAB-MATNR .
ENDIF.
L_MATNR = ITAB-MATNR .
....
...
...
ENDLOOP.
When I am doing the read can I use 'CS' as comparison ?
My ztable matnr say is 715-R.
and my itab-matnr is 715-R-0.
Thanks Paul !!
‎2008 Apr 10 5:42 PM
Hi Teresa,
The issue I would have with using CS (Contains String) that it tests the entire string for the presence of your second oprehand.
For example.
V1 = '12345'.
V2 = '012345'.
Now.. testing IF V2 CS V1. You will get a true condtion. An that is likely bad for your issue.
Another example.
V1 = '123-R'.
V2 = '546123-R'.
Again.. you'll get a True condition.
This is why I went a bit further to test based on Length. If when in my code I test for V2+0(5) to V1, and this is true, then I know I have the same material number based on the criteria you provided.
I hope this answered the question based on CS.
Edited by: Paul Chapman on Apr 10, 2008 6:43 PM
‎2008 Apr 10 6:13 PM
Another thing I didn't think of is the field you have for MATNR, the data in the field may be Right Justified. It's hard for me to tell on our system as every material is number and they are left filled with 0's.
You may have to move the MATNR fields to work fields prior to going into my code and then use
SHIFT c LEFT DELETING LEADING c1.
such as:
w_matnr1 = matnr1.
SHIFT w_matnr1 LEFT DELETING LEADING '0'.
w_matnr2 = matnr2.
SHIFT w_matnr2 LEFT DELETING LEADING '0'.
then change the code I provide to deal with these fields instead.