BRFplus connected to a simple IoT dev 😉
The coffeemachine is a really high sophisticated one, if there is a change in the sensors (usually when somebody takes a coffee) the machine sends the data to the SAP ERP system. The SAP ERP system calls the BRFplus function where the maintenance people define how the sensor data should be evaluated.
Nothing special, just straightforward how you can use BRFplus. With only one differences before the BRFplus function is called the SAP ERP System gets the context data of the BRFplus function - particularly the defined input data (sensors) and propagates to the BRFplus function only that sensor data received from the coffeemachine that is also defined in the function.
The configuration of BRFplus would look something like this. Well the two screenshots shown below to not cover the entire configuration of the BRFplus function. But I am sure you get fast some useful ideas how to convert the input values BEANS and WATER to valuable maintenance messages.
Signature of the BRFplus function
Rules added to the BRFplus function
class ZCL_BRFPLUS_METADATA definition
public
final
create public .
public section.
CLASS-METHODS:
getFunctionContextParams
importing pFunctionId type if_fdt_types=>id
returning value(pContextParams) type ZT_CONTEXT_PARAMS,
protected section.
private section.
ENDCLASS.
CLASS ZCL_BRFPLUS_METADATA IMPLEMENTATION.
method getFunctionContextParams.
DATA: contextParam like line of pContextParams.
* get all context Ids
DATA(contextObjectIds) = CL_FDT_FACTORY=>get_instance(
)->get_function( pFunctionId )->get_context_data_objects( ).
LOOP AT contextObjectIds assigning FIELD-SYMBOL(<contextObjectId>).
* get instance by context id
CL_FDT_FACTORY=>get_instance_generic(
EXPORTING iv_id = <contextObjectId>
IMPORTING eo_instance = DATA(lo_instance) ).
* populate result table
contextParam-name = lo_instance->get_name( ).
contextParam-type = CONV string( CAST if_fdt_element( lo_instance )->get_element_type( ) ).
append contextParam to pContextParams.
ENDLOOP.
endmethod.
ENCLASS.
ENDCLASS.
class ZCL_BRFPLUS_METADATA_UNIT definition FOR TESTING.
"#AU Risk_Level Harmless
PUBLIC SECTION.
private section.
CONSTANTS:
sitWdfFunctionId type if_fdt_types=>id
VALUE '0241750C32391EE6B4D8A1790D2D5E0C',
sitWdfFunctionName type IF_FDT_TYPES=>NAME
VALUE 'COFFEE_MACHINE_STATUS'.
METHODS: testGetFunctionContextParams FOR TESTING.
ENDCLASS.
CLASS ZCL_BRFPLUS_METADATA_UNIT IMPLEMENTATION.
method testGetFunctionContextParams.
DATA(contextParams) = ZCL_BRFPLUS_METADATA=>getFunctionContextParams(
pFunctionId = sitWdfFunctionId ).
CL_AUNIT_ASSERT=>assert_equals( EXP = 2 ACT = lines( contextParams ) ).
read table contextParams with key name = 'ZSENSOR_FILL_QUANTITY_BEANS' into DATA(contextParam).
CL_AUNIT_ASSERT=>assert_equals( EXP = 'T' ACT = contextParam-type ).
clear contextParam.
read table contextParams with key name = 'SENSOR_NOT_EXISTING' into contextParam.
CL_AUNIT_ASSERT=>assert_initial( contextParam ).
endmethod.
.
ENDCLASS.
class zcl_brfplus_function definition
public
final
create public .
public section.
class-methods process
importing pFunctionname type IF_FDT_TYPES=>NAME
pSensorValues type ref to ZCL_SENSOR_VALUES
returning
value(pMaintenanceMessages) type ZT_MAINTENANCE_MESSAGES.
protected section.
private section.
endclass.
class zcl_brfplus_function implementation.
method process.
DATA: contextParams TYPE abap_parmbind_tab,
contextparam like line of contextParams.
FIELD-SYMBOLS <resultDataAny> TYPE any.
GET TIME STAMP FIELD DATA(currentTimestamp).
"get defined context params of brfplus function
DATA(functionId) = zcl_brfplus_metadata=>getFunctionId( pFunctionname ).
DATA(definedContextParams) = zcl_brfplus_metadata=>getfunctioncontextparams( functionId ).
"build context information by matching defined context params and sensor values
pSensorValues->getSensorValues( importing pSensorValues = DATA(sensorValues) ).
loop at definedContextParams assigning field-symbol(<definedContextParam>).
loop at sensorValues assigning field-symbol(<sensorvalue>).
if <definedContextParam>-name = <sensorvalue>-name.
"move definedcontextParams into context params format for BRFplus call.
contextparam-name = <definedContextParam>-name.
GET REFERENCE OF <sensorvalue>-value INTO contextparam-value.
INSERT contextparam INTO TABLE contextparams.
endif.
endloop.
endloop.
"prepare and process BRFplus function
cl_fdt_function_process=>get_data_object_reference( EXPORTING iv_function_id = functionId
iv_data_object = 'ZTABLE_MAINTAINANCE_MESSAGES'
iv_timestamp = currentTimestamp
iv_trace_generation = abap_false
IMPORTING er_data = DATA(resultData) ).
ASSIGN resultData->* TO <resultDataAny>.
cl_fdt_function_process=>process( EXPORTING iv_function_id = functionId
iv_timestamp = currentTimestamp
IMPORTING ea_result = <resultDataAny>
CHANGING ct_name_value = contextParams ).
"return result of brfplus function
pMaintenanceMessages = <resultDataAny>.
endmethod.
endclass.
class ltcl_ definition final for testing
duration short
risk level harmless.
private section.
DATA brfplusFunction type ref to zcl_brfplus_function.
methods:
setup,
okTest2Sensors for testing raising cx_static_check,
okTest3Sensors for testing raising cx_static_check,
okTest2SensorsWithInputFrom3 for testing raising cx_static_check,
failTest2Sensors for testing raising cx_static_check,
generateDataFor2Sensors
importing pSensorFillQuantityBeans type int2
pSensorFillQuantityWater type int2
returning value(pSensorValues) type ref to ZCL_SENSOR_VALUES,
generateDataFor3Sensors
importing pSensorFillQuantityBeans type int2
pSensorFillQuantityWater type int2
pSensorFillQuantityTrash type int2
returning value(pSensorValues) type ref to ZCL_SENSOR_VALUES.
endclass.
class ltcl_ implementation.
method setup.
create object brfplusFunction.
endmethod.
method okTest2Sensors.
DATA(sensorValues) = generateDataFor2Sensors( exporting pSensorFillQuantityBeans = 80
pSensorFillQuantityWater = 80 ).
DATA(maintenanceMessages) = brfplusFunction->process( exporting pFunctionName = `COFFEE_MACHINE_STATUS` pSensorValues = sensorValues ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( maintenanceMessages ) ).
endmethod.
method okTest3Sensors.
DATA(sensorValues) = generateDataFor3Sensors( exporting pSensorFillQuantityBeans = 80
pSensorFillQuantityWater = 80
pSensorFillQuantityTrash = 20 ).
DATA(maintenanceMessages) = brfplusFunction->process( exporting pFunctionName = `COFFEE_MACHINE_STATUS_3SENSORS` pSensorValues = sensorValues ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( maintenanceMessages ) ).
endmethod.
method okTest2SensorsWithInputFrom3.
DATA(sensorValues) = generateDataFor3Sensors( exporting pSensorFillQuantityBeans = 80
pSensorFillQuantityWater = 80
pSensorFillQuantityTrash = 80 ).
DATA(maintenanceMessages) = brfplusFunction->process( exporting pFunctionName = `COFFEE_MACHINE_STATUS` pSensorValues = sensorValues ).
cl_abap_unit_assert=>assert_equals( exp = 0 act = lines( maintenanceMessages ) ).
endmethod.
method failTest2Sensors.
DATA(sensorValues) = generateDataFor2Sensors( exporting pSensorFillQuantityBeans = 20
pSensorFillQuantityWater = 80 ).
DATA(maintenanceMessages) = brfplusFunction->process( exporting pFunctionName = `COFFEE_MACHINE_STATUS` pSensorValues = sensorValues ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( maintenanceMessages ) ).
sensorValues = generateDataFor2Sensors( exporting pSensorFillQuantityBeans = 80
pSensorFillQuantityWater = 10 ).
maintenanceMessages = brfplusFunction->process( exporting pFunctionName = `COFFEE_MACHINE_STATUS` pSensorValues = sensorValues ).
cl_abap_unit_assert=>assert_equals( exp = 1 act = lines( maintenanceMessages ) ).
endmethod.
method generateDataFor2Sensors.
create object pSensorValues.
pSensorValues->addSensorValue( pSensorname = `ZSENSOR_FILL_QUANTITY_BEANS`
pSensorValue = pSensorFillQuantityBeans ).
pSensorValues->addSensorValue( pSensorname = `ZSENSOR_FILL_QUANTITY_WATER`
pSensorValue = pSensorFillQuantityWater ).
endmethod.
method generateDataFor3Sensors.
create object pSensorValues.
pSensorValues->addSensorValue( pSensorname = `ZSENSOR_FILL_QUANTITY_BEANS`
pSensorValue = pSensorFillQuantityBeans ).
pSensorValues->addSensorValue( pSensorname = `ZSENSOR_FILL_QUANTITY_WATER`
pSensorValue = pSensorFillQuantityWater ).
pSensorValues->addSensorValue( pSensorname = `ZSENSOR_FILL_QUANTITY_TRASH`
pSensorValue = pSensorFillQuantityTrash ).
endmethod.
endclass.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 |