Creating Entity Sets (OData Service)

Using FAB Workbench Entity Set Designer


The Entity Set Designer allows you to define Entity Sets and corresponding Service Model from within the FAB Workbench

 Start a new Form or use Existing Form

 

Design Entity Set(s)

Let’s say we want an Entity called Plant and an Entity Set called Plants.

In the Fields section of the workbench, press the  button (Entity Sets)

Design the Entity and Entity Sets as follows:

 


(tip: use Data Element Finder to help find the appropriate Data Element to use)

(tip: use Wizard to generate the entity name and set based on a list of fields from available table/structure)
 

Create Model Provider and Data Provider Classes

The following are one-off steps required to prepare the Model and Service for use.

Model Provider

Create a sub-class of /IQX/CL_FAB_MODEL_PROVIDER by entering a class name under Model Class and click on . This will create and activate the class and will automatically assign the form name in the method SET_FORM_NAME.

Data Provider

Create a sub-class of /IQX/CL_FAB_DATA_PROVIDER by entering a class name unde Data Class and click on . This will create and activate the class and will automatically assign the form name in the method SET_FORM_NAME.

Create Model and Service

Maintain Model

Enter the Model Name and Version and click on  to open the Maintan Model screen

Set the Model Provider Class to the one just created.

Press Save

You may also Check Model

Maintain Service

Enter the Service Name and Version and click on  to open the Maintan Service screen

Set the Data Provider Class to the one created above.

Save

Assign Model to Service

Press Assign Model

Enter the Model Name created above (eg ZIQX_MY_DEMO_MODEL)

Save

Activate and Maintain Service

Press  from the Entity Set designer to open up the Activate and Maintain Services screen

Press Add Service 

 

Choose the appropriate System Alias (eg LOCAL) and enter Service created above (eg ZIQZ_MY_DEMO_SERVICE)

 

Press Get Services 

 


The Service should be located

 



Select Service and press Add Selected Service 

 Assign Package and press Tick 

Press Back

 

Locate the Service and ensure the SICF Node is activated and System Alias is assigned


Take note of the SICF Node path (choose ICF Node->Configure (ICF) )

Here it is: /sap/opu/odata/sap/ziqz_my_demo_service


 

Clear the Cache

Press  from the Entity Set designer to clear the cache of the service. Additionaly, the transaction /IWFND/CACHE_CLEANUP can be used to clear the cache further

Utilize Model in FAB Form


Now that the one-off set up has been completed, the Service can be prepared for use in the Form.

Add a Model Node to the Form

Set the SICF Node to the one created above: (eg : /sap/opu/odata/sap/ziqz_my_demo_service)

Set the Gateway Service (use F4 help)

Give the model an identifier (eg demo)

Provide the Data Provider Class (optional) – [use F4 help]


Implement the Service Logic

Implement GET_ENTITY_SET


Tip: press the  button in the Entity Set Designer to navigate to the method GET_ENTITY_SET of the Data Provider Class implementation


Use the iv_entity_name variable to code the logic for each Entity Set.

Example:

   CASE iv_entity_name.
  
      WHEN 'Plant'.

        DATA: lv_bukrs TYPE bukrs.

        TYPES: BEGIN OF t_t001k,
                bwkey TYPE t001k-bwkey,
                bukrs TYPE t001k-bukrs,
                name1 TYPE t001w-name1,
              END OF t_t001k.

        DATA: lt_t001k TYPE STANDARD TABLE OF t_t001k.

        FIELD-SYMBOLS: <fs_results> TYPE any,
                       <fs_t001k> TYPE t_t001k.


        READ TABLE it_filter_select_options INTO ls_filter WITH KEY property = 'Bukrs'.
        IF sy-subrc EQ 0.
          READ TABLE ls_filter-select_options INTO ls_so WITH KEY sign = 'I' option = 'EQ'.
          IF sy-subrc EQ 0.
            lv_bukrs = ls_so-low.
          ENDIF.
        ENDIF.

        IF lv_bukrs IS NOT INITIAL.

          SELECT t001k~bwkey bukrs name1 FROM t001k INNER JOIN t001w ON t001w~bwkey = t001k~bwkey
            INTO CORRESPONDING FIELDS OF TABLE lt_t001k
            WHERE bukrs = lv_bukrs.

        ELSE.

          SELECT t001k~bwkey bukrs name1 FROM t001k INNER JOIN t001w ON t001w~bwkey = t001k~bwkey
          INTO CORRESPONDING FIELDS OF TABLE lt_t001k.

        ENDIF.

        FIELD-SYMBOLS: <fs_bukrs> TYPE any,
                       <fs_werks> TYPE any,
                       <fs_name1> TYPE any.

        DEFINE move_field.
          ASSIGN COMPONENT &1 of STRUCTURE <fs_results> to &2.
          &2 = &3.
        END-OF-DEFINITION.


        LOOP AT lt_t001k ASSIGNING <fs_t001k>.
          APPEND INITIAL LINE TO et_entityset ASSIGNING <fs_results>.

          move_field 'BUKRS' <fs_bukrs> <fs_t001k>-bukrs.
          move_field 'WERKS' <fs_werks> <fs_t001k>-bwkey.
          move_field 'NAME1' <fs_name1> <fs_t001k>-name1.

        ENDLOOP.
    
    ENDCASE.


Note that since ET_ENTITY_SET is a dynamic variable (TYPE STANDARD TABLE), it is sometimes required to use field symbols to set fields. A macro such as the following may be useful


        DEFINE move_field.
          ASSIGN COMPONENT &1 of STRUCTURE <fs_results> to &2.
          &2 = &3.
        END-OF-DEFINITION.

With

        FIELD-SYMBOLS: <fs_bukrs> TYPE any,
                       <fs_werks> TYPE any,
                       <fs_name1> TYPE any.

And


          move_field 'BUKRS' <fs_bukrs> <fs_t001k>-bukrs.
          move_field 'WERKS' <fs_werks> <fs_t001k>-bwkey.
          move_field 'NAME1' <fs_name1> <fs_t001k>-name1.


Verify Service


Verify the Entity Set is working as expected by using it in the Form.

Here we use it is the basis of a Custom Search Help

 



It works.


Design More Entity Sets


The real power of the Entity Set Designer is apparent when you need to now design more Entity Sets.

Say an Entity Set for MaterialStockBalances is required. Open the Entity Set Designer again with the   button and design the Entity and Entity Set as follows:


Save and then Save the Form

Refresh Metadata Cache


When you add a new Entity Set, it is likely that you will need to clear the Metadata of the model before the new Entity Set becomes available in the Form.

To do this, use transaction /IWBEP/REG_SERVICE (Maintain Service) again. Select your service and press  Cleanup Cache.

 



Implement GET_ENTITYSET


Example:

    WHEN 'MaterialStockBalance'.

        READ TABLE it_filter_select_options INTO ls_filter WITH KEY property = 'Werks'.
        IF sy-subrc EQ 0.
          READ TABLE ls_filter-select_options INTO ls_so WITH KEY sign = 'I' option = 'EQ'.
          IF sy-subrc EQ 0.
            lv_werks = ls_so-low.
          ENDIF.
        ENDIF.

        READ TABLE it_filter_select_options INTO ls_filter WITH KEY property = 'Matnr'.
        IF sy-subrc EQ 0.
          READ TABLE ls_filter-select_options INTO ls_so WITH KEY sign = 'I' option = 'EQ'.
          IF sy-subrc EQ 0.
            lv_matnr = ls_so-low.
          ENDIF.
        ENDIF.

        IF lv_werks IS NOT INITIAL AND lv_matnr IS NOT INITIAL.

          CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
            EXPORTING
              input        = lv_matnr
            IMPORTING
              output       = lv_matnr
            EXCEPTIONS
              length_error = 1
              OTHERS       = 2.
          IF sy-subrc <> 0.
          ENDIF.


          SELECT mard~lgort mard~matnr mard~werks labst vmlab mara~meins lgobe
               FROM mard INNER JOIN mara ON mara~matnr = mard~matnr
                         INNER JOIN t001l ON ( t001l~lgort = mard~lgort AND t001l~werks = mard~werks )
               INTO CORRESPONDING FIELDS OF TABLE et_entityset
               WHERE mard~werks = lv_werks
                 AND mard~matnr = lv_matnr.

        ENDIF.


Note in this case it is simple to select INTO CORRESPONDING FIELDS OF TABLE et_entityset


Let’s create a Table based on this Entity Set

 



Note: for demo, also added Page->onLoad function init()

function init(){


    refreshList("StockBalancesTable");


};

And defaulted Plant = 1000, Material = 100-100


 Adding new Entities / Changes to existing Entities

 When a new entity is added or changed, the oData cache needs to be run in both ECC and Gateway systems:

  • In FAB → Entity Sets screen, ensure that the "Save" button at the top of the pop up is clicked:

  • Then click the "Save" button at the bottom of the screen to close the pop up
  • "Save" the whole FAB App
  • Update the Model to reflect the new changes
    • While in the app, re-open the EntitySet screen and click on the "Model" button
    •  
    •  In the "Change Model" screen, click on the "Save" button
    • Then click on the "Check model" button


  • Update the Service
    • Close the "Change Model" screen and go back to the FAB Entity Set 
  • Clear the Model Cache
    1. Run transaction 

      /IWFND/CACHE_CLEANUP

      Enter the model and click "Save"

      Then click on the "
  • Update the Service



 














 




IQX Business Solutions - FAB 2.40