Closed ynnoig closed 2 months ago
Update: after reading the usage documentation of gkralik/php7-sapnwrfc it seems that this change was also there performed https://github.com/gkralik/php7-sapnwrfc/blob/main/docs/usage.rst https://github.com/gkralik/php7-sapnwrfc/commit/9073bdfb74c3a9a683fd3bfa4a2e6fef3ee4dadf
But i don't know if it is correct that this numeric fields like price (CURR) or quantity (QUAN) are handles/casted to string.
explanation
According to SAP documentation BCD
is a numerical value of up to 16 digits:
RFCTYPE_BCD = 2, /* packed number, any length between 1 and 16 bytes */
source: https://help.sap.com/doc/saphelp_em92/9.2/en-US/48/a862055135307ce10000000a42189b/frameset.htm
Contrary to that PHPs float
is a numerical value of up to 14 digits:
The size of a float is platform-dependent, although a maximum of approximately 1.8e308 with a precision of roughly 14 decimal digits is a common value (the 64 bit IEEE format).
source: https://www.php.net/manual/en/language.types.float.php
Using Kraliks SAPNWRFC module prior to 2.0.0 would cause an error if the SAP BCD value exceeded PHP float. Version 2.0.0 of SAPNWRFC therefore introduced a breaking change:
- Map RFC type BCD to string BC break
source: https://github.com/gkralik/php7-sapnwrfc/releases/tag/2.0.0
conclusion
Treating BCD values as string, bypasses the issue of exceeding bytes in PHP. Therefore no fix will be issued.
In the latest version (5.x) of the
php-sap/saprfc-kralik
library, theRFCTYPE_BCD
SAP Netweaver RFC type has been mapped toIValue::TYPE_STRING
. This is a change from the previous version (4.x), whereRFCTYPE_BCD
was mapped to afloat
.This change introduces significant issues when working with certain SAP data types such as
CURR
(Currency) andQUAN
(Quantity), which represent monetary values and quantities respectively. Instead of being parsed as floats, they are now being returned as strings.This behavior is inconsistent with the underlying SAP RFC type definition, where
RFCTYPE_BCD
should correspond to a float value, as seen in the officialgkralik/php7-sapnwrfc
library:RFCTYPE_BCD
is treated as a float.Affected Code:
The change in the
php-sap/saprfc-kralik
library is located in the\phpsap\saprfc\Traits\ApiTrait::mapType
method, where theRFCTYPE_BCD
is mapped toIValue::TYPE_STRING
instead ofIValue::TYPE_FLOAT
:Problematic Behavior:
In the previous version (4.x), fields like
CURR
andQUAN
were returned as floats, which is the expected behavior. However, after the update in version 5.x, these fields are now returned as strings, leading to inaccurate handling of numeric values in downstream processes.Here are examples of the data before and after the change:
Version 4.x Output (Correct):
Version 5.x Output (Incorrect):
Impact:
KWMENG
,GROSS_VAL
,NETWR
, andMWSBP
are now returned as strings instead of floats, which causes issues with calculations and data validation.Suggested Fix: The
RFCTYPE_BCD
should be mapped back to a float (IValue::TYPE_FLOAT
) to ensure consistency with the SAP RFC type definition and the correct handling of numeric values.Reference to the correct behavior:
RFCTYPE_BCD
is a float as per thephp7-sapnwrfc
library implementation: RFC Parameters - gkralik/php7-sapnwrfc.Please investigate and restore the correct handling of
RFCTYPE_BCD
to a float.