This article was created in response to a support issue logged with K2. The content may include typographical errors and may be revised at any time without notice This article is not considered official documentation for K2 software and is provided "as is" with no warranties.
When making use of K2 Connect for SAP, there is a parameter in the K2 Connect Service Instance named "UseCache".
With UseCache set to True, K2 caches the structure of the BAPI and does not request it again for every Connect SmartObject execution. This speeds up the overall execution and gets rid of repetitive SAP queries to reflect the structure of every BAPI.
When executing a Connect SmartObject with no input properties, and the SAP BAPI has a default value defined, results are returned on the first execution. When the SmartObject is executed subsequent times with no input properties, no results are returned.
Before You Begin
The "UseCache" feature is a function of the ERPConnect client SDK, used to cache information about BAPIs (Tables, Structures, Fields). It does not cache data. The caching option helps with lowering the amount of calls to SAP to retrieve information about a BAPI. E.g. if a BAPI consists of 10 inner structures and tables we would have to make 11 calls to SAP to get information about the BAPI. This would have to be repeated every time the SmartObject is executed with caching disabled. With caching on, we only need to get the information once per connection session.
When the information about the BAPI is retrieved, ERPConnect constructs a local object. That object might then also have any default values set on its properties obtained from the BAPI. When we use ERPConnect to execute that BAPI, it will overwrite the property values with anything we specify and using the cached object, construct a Netweaver RFC object to execute against SAP. After execution, any property values are set back to null by ERPConnect to be ready for the next call. This will also include any default values that was previously set.
On the next execution, if no value is assigned as an input property, an empty value will be sent to SAP (current state of the cached metadata object) and no data will be returned by SAP.
There are a couple of options that work with this scenario:
1. Make sure that an Input Property value is always supplied to the SmartObject and sent to the BAPI for the field from K2.
2. Change the BAPI to check if the field is null, then set the Default value again.
3. It is minimally intrusive and considered good practice in ABAP developments. Adding the following lines to the BAPI source fixes the issue:
IF [SAP PROPERTY] IS INITIAL.
[SAP PROPERTY] = '[Default Value]'.