This example describes how you can extend the Manage Customer Line Items app by adding a new field (called “MyField1” in this example).
This is what the extended app looks like: The “MyField1” field has been added to the UI.
You are familiar with the extensibility options of the app whose UI you want to extend, for example, the Manage Customer Line Items app.
For more information, see App Extensibility: Manage Customer Line Items
You have checked if the ABAP structures of the OData model nodes can be extended.
In the SAP system, choose transaction SE11.
The ABAP Dictionary: Initial Screen opens.
Select the Data type radio button, enter INCL_EEW_FAR_CLI_ITEM_MD, and choose (Display).
On the Dictionary: Display Structure screen, select Append Structure...
Enter an append name and choose (xxxAccept (Enter)).
Enter a short description and choose (Save).
Enter the new field: Under Component, enter MYFIELD1, under Data Type, enter CHAR, and under Length, the value 10.
In the Create Object Directory Entry dialog, select a package and choose (Save).
Activate the append and the field.
In the SAP system, choose transaction SEGW (Gateway Service Builder).
On the SAP NetWeaver Gateway Service Builder screen, choose (Open).
In the Open Project dialog, choose FAR_CUSTOMER_LINE_ITEMS and (Execute).
Choose (Create Project).
In the Create Project dialog, enter a name and description and select a package.
Select the new service, right-click Data Model, choose Redefine, and then OData Service (GW).
In the Redefine Service step of the wizard, enter the technical service name (FAR_CUSTOMER_LINE_ITEMS) and version and choose (Next)
Select
and double-click Properties.Choose (Append line)
Enter the required data, for example:
Field | Entry |
---|---|
Name: | MyField1 |
Edm Core Type: | Edm.String |
Prec. (Precision): | 10 |
Scale: | 0 |
Max Length: | 0 |
Label: | MyField1 |
ABAP Field Name: | MyField1 |
Make sure that the Sortable and Filterable fields are not selected.
Choose (Save) and then (Generate Runtime Objects).
Confirm the Model and Service Definition dialog, select a package, and save your data.
In the SAP NetWeaver Gateway Client, select
and double-click LOCAL.Choose Register, select the system alias, and save your data.
Choose Gateway Client, then Add URI Option, and then $metadata.
Choose Execute.
You should now see the correct metadata:
<Property Name="MyField1" sap_filterable="false" sap=sortable="false" sap:updatable="false" sap:creatable="false" MaxLength="10" Nullable="false" Type="Edm.String"/>
In the SAP NetWeaver Gateway Client, select
and double-click CL_MYFIELD1_DPC_EXT.Choose (Display<->Change) and double-click ZCL_[Your service]_DPC_EXT.
Make sure that the Filter field is not selected.
Select the IF_SADL_GW_QUERY_CONTROL~SET_QUERY_OPTIONS method and choose (Redefine).
Copy the following coding:
Example
METHOD if_sadl_gw_query_control-set_query_options.
DATA:
lt_req_elements TYPE if_sadl_public_types=>tt_requested_elements,
lv_changed TYPE abap_bool.
call super method
*
CALL METHOD super ->if_sadl_gw_query_control-set_query_options
EXPORTING
iv_entity_set = iv_entity_set
io_query_options = io_query_options.
* check if fields required for calculation are already selected. Add them, if they are not.
io_query_ooptions->get_requested_elements( IMPORTING et_elements = lt_req_elements ).
LOOP AT lt_req_elements ASSIGNING FIELD-SYMBOL(<ls_req_element>).
CASE <ls_req_element>.
WHEN 'MYFIELD1'.
READ TABLE lt_req_elements WITH KEY table_line = 'DMBTR' TRANSPORTING NO FIELDS.
If sy-subrc <> 0.
APPEND 'DMBTR' TO lt_req_elements.
lv_changed = abap_true.
ENDIF.
ENDIF.
ENDCASE.
ENDLOOP.
IF lv_changed = abap_true.
io_query_options->set_requested_elements( EXPORTING it_elements = lt_req_elements ).
ENDIF.
ENDMETHOD.
Choose (Activate).
Repeat the steps above for the ITEMSET_GET_ENTITYSET method and use the following coding:
Example
METHOD itemset_get_entityset.
* call super method
CALL METHOD super->itemset_get_entityset
EXPORTING
iv_entity_name = iv_entity_name
iv_entity_set_name = iv_entity_set_name
iv_entity_set_name = iv_entity_set_name
iv_source_name = iv_source_name
it_filter_select_options = it_filter_select_options
is_paging = is_paging
it_key_tab = it_key_tab
it_navigation_path = it_navigation_path
it_order = it_order
iv_filter_string = iv_filter_string
io_tech_request_context = io_tech_request_context
IMPORTING
et_entityset = et_entityset
es_response_context = es_response_context
*loop at result set and calculate the new field(s)
IF abs( <ls_entity>-dmbtr ) > 10000.
<ls_entity>-myfield1 = 'Large'.
ELSEIF abs( <ls_entity>-dmbtr ) > 1000.
<ls_entity>-myfield1 = 'Medium'.
ELSE.
<ls_entity>-myfield1 = 'Small'.
ENDIF.
ENDLOOP.
ENDMETHOD.
You can now perform a test in transaction /IWFND/GW_CLIENT to see if the new field is filled correctly.
As the front-end system uses an analytical table, you need to make some changes to ensure that the UI gets the right metadata. Here, we show you how to define an annotation for a dimension:
In the DEFINE method of ZCL_[Your service]_DPC_EXT, define a dimension annotation using the following coding:
Example
super->define().
DATA(lo_entity_type) = model->get_entity_type( 'Item' ).
lo_entity_type->set_semantic( /iwbep/if_ana_odata_types->gcs_ana_odata_semantic_value-query-aggregate ).
DATA(lo_property) = lo_entity_type->get_property( 'MyField1' ).
DATA(lo_annotation) =
lo_property->/iwbep/if_mgw_odata_annotatabl-create_annotation(
/iwbep/if_mgw_med_odata_types->gc_sap_namespace ).
lo_annotation->add(
iv_key = /iwbep/if_ana_odata_types->gcs_ana_odata_annotation_key-aggregatation_role
iv_value = /iwbep/if_ana_odata_types->gcs_ana_odata_annotation_value-dimension-dimension ).
For a description of what you need to do in the front-end system, please see Example: How to extend "Manage Customer Line Items" (Part 2).
For general information about the extensibility of Fiori apps, please see Extending SAP Fiori Applications.