Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

MATERIAL_UNIT_CONVERSION produces incorrect output for a specific material

abo
Active Contributor
0 Likes
5,002

For a specific material, a call to this function in a custom report will always return the input value unchanged, that is a 1:1 conversion regardless of the direction requested and, arguably, the wrong one since the units are hours (int. HO / ext. H.) and days (int. 10 / ext. GG). Don't ask me why such units are material-specific, I honestly have no answer to that.

Here is the sample code I used to avoid running the original report each time:

REPORT zborandtestconversion.

CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
METHOD main.

DATA: matnr TYPE mara-matnr VALUE 'FRE0009',
meinh TYPE mara-meins VALUE 'H.',
meins TYPE mara-meins VALUE 'GG',
output TYPE f.

cl_demo_input=>request( CHANGING field = matnr ).
cl_demo_input=>request( CHANGING field = meinh ).
cl_demo_input=>request( CHANGING field = meins ).

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = meinh
language = sy-langu
IMPORTING
output = meinh
EXCEPTIONS
unit_not_found = 1.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = meins
language = sy-langu
IMPORTING
output = meins
EXCEPTIONS
unit_not_found = 1.


* By default, it converts INPUT from MEINS to MEINH (KZMEINH = space).
* To do the opposite, pass KZMEINH = 'X'.
* ( See https://answers.sap.com/answers/316524/view.html )
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = 8
kzmeinh = 'X' "MEINH (H.) -> MEINS (GG) - Z report
* kzmeinh = space "MEINS (GG) -> MEINH (H.) - default
matnr = matnr
meinh = meinh
meins = meins
IMPORTING
output = output
EXCEPTIONS
conversion_not_found = 1
input_invalid = 2
material_not_found = 3
meinh_not_found = 4
meins_missing = 5
no_meinh = 6
output_invalid = 7
overflow = 8.

cl_demo_output=>display( output ).

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
demo=>main( ).

(for input 8, report returns 8 regardless of kzmeinh)

And here is the conversion table for the offending material:

By comparison, here is another material which behaves as expected:

One thing I noticed is that the "bad" material has hours as base unit whereas the "good" one has pieces but the MM people tell me that this should be of no consequence given the conversion tables above.

I'm stumped... on the face of it, I'm still inclined to believe something is wrong in the master data since I've found nothing in the correction notes, but I have no clues.

Any tips?

For a specific material, a call to this function in a custom report will always return the input value unchanged, that is a 1:1 conversion regardless of the direction requested and, arguably, the wrong one since the units are hours (int. HO / ext. H.) and days (int. 10 / ext. GG). Don't ask me why such units are material-specific, I honestly have no answer to that.

Here is the sample code I used to avoid running the original report each time:

REPORT zborandtestconversion.

CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
METHOD main.

DATA: matnr TYPE mara-matnr VALUE 'FRE0009',
meinh TYPE mara-meins VALUE 'H.',
meins TYPE mara-meins VALUE 'GG',
output TYPE f.

cl_demo_input=>request( CHANGING field = matnr ).
cl_demo_input=>request( CHANGING field = meinh ).
cl_demo_input=>request( CHANGING field = meins ).

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = meinh
language = sy-langu
IMPORTING
output = meinh
EXCEPTIONS
unit_not_found = 1.

CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
EXPORTING
input = meins
language = sy-langu
IMPORTING
output = meins
EXCEPTIONS
unit_not_found = 1.


* By default, it converts INPUT from MEINS to MEINH (KZMEINH = space).
* To do the opposite, pass KZMEINH = 'X'.
* ( See https://answers.sap.com/answers/316524/view.html )
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
input = 8
kzmeinh = 'X' "MEINH (H.) -> MEINS (GG) - Z report
* kzmeinh = space "MEINS (GG) -> MEINH (H.) - default
matnr = matnr
meinh = meinh
meins = meins
IMPORTING
output = output
EXCEPTIONS
conversion_not_found = 1
input_invalid = 2
material_not_found = 3
meinh_not_found = 4
meins_missing = 5
no_meinh = 6
output_invalid = 7
overflow = 8.

cl_demo_output=>display( output ).

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
demo=>main( ).

(for input 8, report returns 8 regardless of kzmeinh)

And here is the conversion table for the offending material:

By comparison, here is another material which behaves as expected:

One thing I noticed is that the "bad" material has hours as base unit whereas the "good" one has pieces but the MM people tell me that this should be of no consequence given the conversion tables above.

I'm stumped... on the face of it, I'm still inclined to believe something is wrong in the master data since I've found nothing in the correction notes, but I have no clues.

Any tips?

4 REPLIES 4
Read only

Jeansy
Active Contributor
4,656

Hi c5e08e0478aa4727abc4482f5be390b2 ,

can you check if the following function module brings the same result?

MD_CONVERT_MATERIAL_UNIT

Kind regards
Jens

Read only

abo
Active Contributor
0 Likes
4,656

Well, both are unreleased functions so at least it's not going to be worse because of that 😄

With those two test cases it seems to behave correctly, thanks.

It bothers me that I can't find a released function for such a basic task, though.

EDIT: half of our custom programs use one function, half the other one... so much for consistency 😄

Read only

Oenedoef
Explorer
0 Likes
4,656

I ran into the exact same issue with 'MATERIAL_UNIT_CONVERSION'.

The answer from Jens Zähringer below, using the FM 'MD_CONVERT_MATERIAL_UNIT', fixed my issue as well, therefore a good solution!

jzaehringerApr 11, 2022 at 06:36 PM

Hi c5e08e0478aa4727abc4482f5be390b2 ,

can you check if the following function module brings the same result?

MD_CONVERT_MATERIAL_UNIT

Kind regards
Jens

Read only

abo
Active Contributor
0 Likes
4,656

I no longer have access to the system where I had that problem and that material, so I cannot really test. Still, no released function for such a task is... disappointing, let's leave it at that.