SAP Fiori applications are pretty useful and user-friendly right out of the box.  Side-by-side with this initial usefulness is a set of tools and process that you can use to enhance and extend the delivered services with your own business logic.  As a developer, the first thing I wanted to do was mess around with stuff anyway – so it’s nice to know that SAP built in ways for me to do that.

My colleague Gavin Quinn got our development environment set up with the available Fiori apps, and I just looked at one of them to try some enhancement stuff.  This is a very very simple example, but I wanted to present what I’ve done so folks can either learn for themselves or critique my work.  Hopefully a little of both. 🙂

Things you should note:

  • In this example, I’m using the Track Purchase Order application.  I’m tackling the service enhancements first, and will post later about the Fiori UI enhancement process. 
  • SAP publishes an overview of the apps.  Note that most of these ERP apps have separate pages detailing their extensibility and identify the specific enhancement points. 
  • This app is part of the first wave of Fiori apps.  I can’t make any promises that this process will fit all next-gen apps, and in fact future releases of Fiori will probably follow a bit more standardized process for extensions – which I’ll make sure to blog about when we get our hands on the next wave. 
  • I am following some of the things on this SAP page, but I have added some steps of my own as I discovered how to get this done.
  • To do the play-at-home version you need the appropriate Fiori installation set up in your ECC system.
  • After every step in enhancing things, I made sure to clean up cache on both my ECC and my Gateway systems.  I found that sometimes I didn’t see the changes I wanted until I ran /IWBEP/CACHE_CLEANUP on both systems.  I recommend this as a general step in creating enhancement to the services – it seems to be something that comes up occasionally enough that it saved me time to just keep clearing it.

Scenario

The Track Purchase Order app lets you view PO/items/item detail for selected POs.  In the screenshot below, I have chosen the first item from one of our test POs and navigated to the item detail page.  You can see that the item is delivered to one of the plants in our system.  I am going to enhance the backend logic to include the distribution channel for that plant.

PO item detail.PNG

Enhancing the entity

If you navigate to SEGW in your ERP system and open project SRA020_PO_TRACKING, you’ll see all the entity types available to this service.  The item detail page has its basis in the POItemDetailData entity, which is the entity we’ll enhance.

po item detail entity.PNG

Instead of redefining the service and editing the entity directly like you would probably do for a custom-developed scenario, we have to edit a data dictionary structure and implement a couple of BAdIs.

The ABAP dictionary structure that defines this entity is SRA020_S_PO_ITEM_DETAILED.  If you open that structure and scroll to the bottom of the components list, you’ll see that SAP has provided an append SRA020_S_PO_ITEM_DETAILED_INCL.  For my purposes I opened this include and created a customer append that held the field I wanted (vtweg, the distribution channel).

append structure for PO thing.PNG

Next, you’ll need to create an implementation of BAdI SRA020_PO_TRACKING_MPC.  This provides the code hooks to update the runtime definition of the structures of the service.  Go to t-code SE18 and enter the BAdI name in the “BAdI Name” field.

Create an implementation with whatever naming conventions your organization uses.  Eventually you’ll be led to implement method ENHANCE_GW_SERVICE_ENTITY_MPC in your implementation class.  The simple code I used below will accomplish adding the field to the entity at runtime.

METHOD if_sra020_po_tracking_mpc~enhance_gw_service_entity_mpc. 

  DATA: lo_property TYPE REF TO /iwbep/if_mgw_odata_property. 

  IF iv_entity_type_name = ‘POItemDetailData’. 

   lo_property = io_entity_type->create_property( 

           iv_property_name = ‘VTWEG’ 

           iv_abap_fieldname = ‘VTWEG’ ). 

   lo_property->set_nullable( abap_true ). 

  ENDIF. 

ENDMETHOD.

At this point, you should be able to see a (blank) VTWEG field in your Gateway service.  As part of getting the Fiori application installed you will end up with a service you can test in Gateway from t-code /IWFND/GW_CLIENT.


Getting data at runtime

Now that there’s a field in the entity to be a placeholder for the data you want to add, you can implement a different BAdI to fill the live system data you want to into this field.  Once again, t-code SE18 is your friend; enter BAdI SRA020_PO_TRACKING_DPC and do the same stuff.

When it’s time to implement your code, you’ll notice that this BAdI has a lot more available methods.  For the data we want to monkey around with, method CHANGE_POITEMDETAILDATA_API suits our needs.  Code I used:

METHOD if_sra020_po_tracking_dpc~change_poitemdetaildata_api. 

  TYPES: BEGIN OF ltyp_vtweg, 

       werks TYPE werks_d, 

       vtweg TYPE vtwiv, 

      END OF ltyp_vtweg. 

  DATA: lt_vtweg TYPE TABLE OF ltyp_vtweg, 

     ls_vtweg TYPE ltyp_vtweg, 

     lv_vtweg TYPE vtwiv, 

     lt_werks TYPE RANGE OF werks_d, 

     ls_werks LIKE LINE OF lt_werks. 

  FIELD-SYMBOLS: <ls_po_items_details> LIKE LINE OF ct_po_items_details. 

  LOOP AT ct_po_items_details ASSIGNING <ls_po_items_details>. 

   CLEAR ls_werks. 

   ls_werks-sign = ‘I’. 

   ls_werks-option = ‘EQ’. 

   ls_werks-low = <ls_po_items_details>-plant. 

   APPEND ls_werks TO lt_werks. 

  ENDLOOP. 

  CHECK lt_werks IS NOT INITIAL. 

  SELECT werks vtweg INTO CORRESPONDING FIELDS OF TABLE lt_vtweg 

   FROM t001w 

   WHERE werks IN lt_werks. 

  CHECK lt_vtweg IS NOT INITIAL. 

  SORT lt_vtweg BY werks. 

  LOOP AT ct_po_items_details ASSIGNING <ls_po_items_details>. 

   READ TABLE lt_vtweg INTO ls_vtweg WITH KEY 

    werks = <ls_po_items_details>-plant BINARY SEARCH. 

   IF sy-subrc IS INITIAL. 

    <ls_po_items_details>-vtweg = ls_vtweg-vtweg. 

   ENDIF. 

  ENDLOOP. 

ENDMETHOD. 

I hope it’s obvious here that I’m just taking the PO items’ plant (werks) and using that to select on T100W to get the plant’s associated distribution channel.  The changing parameter CT_PO_ITEMS_DETAILS has the fields we need to change.

After implementing the DPC BAdI you’re all done.  You should see the field come into the service data and filled with the appropriate distribution channel.  Proof:

vtweg proof.PNG

Hope this helps!  Remember, this doesn’t get you all the way there – you still have to update your UI5 to reveal that field on your screen.  I’ll be researching that soon and presenting what I find. 

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. SASIKANTH SM

      Hi Masa & Paul, We have implemented sap fiori wave 1 application and turned on purchase requisition approval and its working fine in production. Now our clients want us to implement Track purchase order application. In the launch page, we can see the  Track PO tile. When I click on teh tile its taking me to initial screen of Track PO and I am not seeing any PO in the initial screen even though I have PO’s in the backend ECC system. Do I need to turn on anything else? How to trace the issue? Regards, Sasi

      (0) 
  1. Kishore Gokara

    This is very informative blog post. I have a question on this. The MPC BAdis are used to add new properties to an existing entity type. Do we have an option to add a new entity type and set altogether.

    Say example: I need to add a custom field with value help on the screen. For adding custom field I will do an implementation. But for value help I need list of values for which I need to go for entity type and set which calls for a service redefinition.

    (0) 

Leave a Reply