CDS

Unit Conversion in CDS

Open SQL and CDS now both support unit conversion for the quantity directly in the select statement using in-built functions. Here is a sample code for CDS.

 define view Zunit_conversion_Example
 as select from mara as a
 {
    key a.matnr as Material,
     a.brgew as MatQuan,
     a.meins as SrcUnit,
     a.gewei as TgtUnit, 
     unit_conversion( quantity => brgew, 
                   source_unit => meins, 
                   target_unit => gewei ) as ConvF1
 } 

Looks simple and useful at times. But quantity conversion for specific material may have separate conversion saved in Material master. Or it may be saved as factors in the transaction table for example – EKPO. I think preference should be given to these factors. If you want to convert quantity using factors maintained either in material master or transaction tables then you need to use plain arithmetic. Here is a sample code for that. However in this example, denominators are not zeroes, is not ensured. Can you figure out how to do that?

Please join our LinkedIn page for updates on new blogs and training sessions.

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share