Description
Get conversion factor between two UoM for an item.
Parameters
icItemCode | input | character | |
icFromUoMCode | input | character | |
icToUoMCode | input | character | |
odConversionFactor | output | decimal | Conversion factor between From UoM and To UoM |
oiReturnStatus | output | integer | Return status of the method. |
Internal usage
QadFinancials
program code (program3/bmfguomconv.p)
/* ========================================================================= */
/* This procedure calculates conversion between two unit of measure */
/* ========================================================================= */
/* Input: ItemCode Code of item for which conversion factor is */
/* calculated */
/* FromUoMCode Unit of Measure we want to calculate from */
/* ToUoMCode Unit of Measure we want to calculate to */
/* Output: ConversionFactor Conversion factor */
/* ToUom = FromUoM * ConversionFactor */
/* ========================================================================= */
/* See gpumcnv.p */
/* ========================================================================= */
assign oiReturnStatus = -98
odConversionFactor = ?.
/* ValCodeate input parameters */
if icItemCode = '':U then assign icItemCode = ?.
if icFromUoMCode = '':U then assign icFromUoMCode = ?.
if icToUoMCode = '':U then assign icToUoMCode = ?.
if icFromUoMCode = ? or
icToUoMCode = ?
then do:
assign oiReturnStatus = 0.
return.
end.
/* if booth unit of measures are the same */
if lc(icFromUoMCode) = lc(icToUoMCode)
then do:
assign odConversionFactor = 1
oiReturnStatus = 0.
return.
end.
/* Start query for retrieving of conversion factor */
<Q-1 run UoMConvByItemFromTo
(Start) in BMfgUoMConv >
/* Try to find conversion factor for item first */
if icItemCode <> ?
then do:
<Q-2 run UoMConvByItemFromTo (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input icItemCode, (ItemId)
input icFromUoMCode, (FromUoMId)
input icToUoMCode, (ToUoMId)
output dataset tqUoMConvByItemFromTo) in BMfgUoMConv >
find first tqUoMConvByItemFromTo no-lock.
if available tqUoMConvByItemFromTo
then assign odConversionFactor = tqUoMConvByItemFromTo.tdum_conv.
else do:
/* if not find try to find reverse conversion factor */
<Q-3 run UoMConvByItemFromTo (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input icItemCode, (ItemId)
input icToUoMCode, (FromUoMId)
input icFromUoMCode, (ToUoMId)
output dataset tqUoMConvByItemFromTo) in BMfgUoMConv >
find first tqUoMConvByItemFromTo no-lock.
if available tqUoMConvByItemFromTo
then assign odConversionFactor = 1 / tqUoMConvByItemFromTo.tdum_conv.
end.
end.
/* if conversion factor is not found try to look into global conversion */
/* factor table */
if odConversionFactor = ?
then do:
<Q-4 run UoMConvByItemFromTo (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input '':U, (ItemId)
input icFromUoMCode, (FromUoMId)
input icToUoMCode, (ToUoMId)
output dataset tqUoMConvByItemFromTo) in BMfgUoMConv >
find first tqUoMConvByItemFromTo no-lock.
if available tqUoMConvByItemFromTo
then assign odConversionFactor = tqUoMConvByItemFromTo.tdum_conv.
else do:
/* if not find try to find reverse conversion factor */
<Q-5 run UoMConvByItemFromTo (all) (Read) (NoCache)
(input vcDomainCode, (Domain)
input '':U, (ItemId)
input icToUoMCode, (FromUoMId)
input icFromUoMCode, (ToUoMId)
output dataset tqUoMConvByItemFromTo) in BMfgUoMConv >
find first tqUoMConvByItemFromTo no-lock.
if available tqUoMConvByItemFromTo
then assign odConversionFactor = 1 / tqUoMConvByItemFromTo.tdum_conv.
end.
end.
/* Stop query for retrieving of conversion factor */
<Q-6 run UoMConvByItemFromTo
(Stop) in BMfgUoMConv >
if oiReturnStatus = -98 then assign oiReturnStatus = 0.
Sample code: how to call this method through RPCRequestService (QXtend Inbound)
define temp-table ttContext no-undo
field propertyQualifier as character
field propertyName as character
field propertyValue as character
index entityContext is primary unique
propertyQualifier
propertyName
index propertyQualifier
propertyQualifier.
define dataset dsContext for ttContext.
define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.
/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
ttContext.propertyValue = "BMfgUoMConv".
create ttContext.
assign ttContext.propertyName = "methodName"
ttContext.propertyValue = "ApiGetConversionFactor".
create ttContext.
assign ttContext.propertyName = "applicationId"
ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
ttContext.propertyValue = "".
/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bmfguomconv.apigetconversionfactor.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icItemCode = <parameter value>
vhParameter::icFromUoMCode = <parameter value>
vhParameter::icToUoMCode = <parameter value>.
/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").
if not vhServer:connected()
then do:
message "Could not connect AppServer" view-as alert-box error title "Error".
return.
end.
/* Run */
assign vhContextDS = dataset dsContext:handle.
run program/rpcrequestservice.p on vhServer
(input-output dataset-handle vhContextDS by-reference,
output dataset-handle vhExceptionDS,
input dataset-handle vhInputDS by-reference,
input-output dataset-handle vhInputOutputDS by-reference,
output dataset-handle vhOutputDS).
/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).
if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).
/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.
if valid-handle(vhInputDS)
then delete object vhInputDS.
if valid-handle(vhOutputDS)
then delete object vhOutputDS.
if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.