Show TOC

 Example: How to extend “Manage Customer Line Items” (Part 1) Locate this document in the navigation structure

 

This example describes how you can extend the Manage Customer Line Items app by adding a new field (called “MyField1” in this example).

This graphic is explained in the accompanying text.

This is what the extended app looks like: The “MyField1” field has been added to the UI.

Prerequisites

  • 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.

Here is what you need to do in the back-end system:

Extend the extension include in the structure of the OData service node

  1. In the SAP system, choose transaction SE11.

    The ABAP Dictionary: Initial Screen opens.

  2. Select the Data type radio button, enter INCL_EEW_FAR_CLI_ITEM_MD, and choose (Display).

  3. On the Dictionary: Display Structure screen, select Append Structure...

  4. Enter an append name and choose (xxxAccept (Enter)).

  5. Enter a short description and choose (Save).

  6. Enter the new field: Under Component, enter MYFIELD1, under Data Type, enter CHAR, and under Length, the value 10.

  7. In the Create Object Directory Entry dialog, select a package and choose (Save).

  8. Activate the append and the field.

Create a new OData Service

  1. In the SAP system, choose transaction SEGW (Gateway Service Builder).

  2. On the SAP NetWeaver Gateway Service Builder screen, choose (Open).

  3. In the Open Project dialog, choose FAR_CUSTOMER_LINE_ITEMS and (Execute).

  4. Choose (Create Project).

  5. In the Create Project dialog, enter a name and description and select a package.

  6. Select the new service, right-click Data Model, choose Redefine, and then OData Service (GW).

  7. In the Redefine Service step of the wizard, enter the technical service name (FAR_CUSTOMER_LINE_ITEMS) and version and choose (Next)

  8. Select   [Your service]   Entity Types   Item   and double-click Properties.

  9. Choose (Append line)

  10. 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.

  11. Choose (Save) and then (Generate Runtime Objects).

  12. Confirm the Model and Service Definition dialog, select a package, and save your data.

Perform a smoke test

  1. In the SAP NetWeaver Gateway Client, select   [Your service]   Service Maintenance.   and double-click LOCAL.

  2. Choose Register, select the system alias, and save your data.

  3. Choose Gateway Client, then Add URI Option, and then $metadata.

  4. Choose Execute.

  5. 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"/>

Fill the new field using ABAP coding

  1. In the SAP NetWeaver Gateway Client, select   [Your service]   Runtime Artifacts.   and double-click CL_MYFIELD1_DPC_EXT.

  2. Choose (Display<->Change) and double-click ZCL_[Your service]_DPC_EXT.

  3. Make sure that the Filter field is not selected.

  4. Select the IF_SADL_GW_QUERY_CONTROL~SET_QUERY_OPTIONS method and choose (Redefine).

  5. Copy the following coding:

    Example 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.

    End of the example.

    Choose (Activate).

Fill the new field using a loop over the result set

Repeat the steps above for the ITEMSET_GET_ENTITYSET method and use the following coding:

Example 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.

End of the example.

Test the coding

You can now perform a test in transaction /IWFND/GW_CLIENT to see if the new field is filled correctly.

Provide analytical annotations for entity types and properties

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 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 ).

End of the example.

More Information

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.