Convert Units of Measurement using ABAP Function Module for Weight
Using ABAP function modules, SAP programmers can convert measurement unit values into other units of measurements. Weight, currency, lengths, and such measurement units are stored in SAP tables as value and corresponding measurement unit. ABAP programmer can easily convert a value in a given measurement unit into an other unit of measurement using ABAP MC_UNIT_CONVERSION function module.
In the following ABAP code, as SAP developers can easily understand a delivery document is read from SAP LIKP table.
The delivery header mass measurements, the total weight and net weight of all delivery items is read in the document measurement unit.
These values are stored in btgew, ntgew and gewei fields of LIKP table in SAP.
Then I display these weight amounts and unit of measurement on the screen.
In the second part of the sample ABAP program, I read all mass related measurement units into an internal table temporarily.
The units of measurements used in SAP system are stored in T006 transparent ABAP table.
For the unit texts in desired languages, ABAP programmer will find the translations or measurement unit texts in T006A SAP transparent table.
The last part of the sample ABAP code contains the code block where unit conversion takes place.
As programmers can see, in an ABAP Loop command I use ABAP function module MC_UNIT_CONVERSION to convert the source unit of measurement with the target measurement unit I got in the referenced Loop structure.
MC_UNIT_CONVERSION ABAP function module returns a multiplication factor which is used to calculate the new weight amount in the target unit of measurement.
To summarize:
target amount (in target measurement unit) = source amount (in source unit) * factor (returned in umref parameter)
Below is the overall representation of fragmented ABAP source codes to see the SAP program easily.
And the above example ABAP program generates following output.
As you see, the initial line has the source values (mass in KG) read from the delivery document header. And in the ABAP Loop statement using ABAP MC_UNIT_CONVERSION function module, the source weight is converted into every possible mass unit defined in the SAP system.