Skip to Content

MDG: Using the Read API

In MDG-projects it is always necessary to read some data. This can be done in a convenient way using the Read-API. From my point of view it is easier to use that the Model API or the Governance API.

Princpally you only need the required Entity Type, the key structure for the selection criiterea and the structure of the expected result. The structures are the generated ones from the MDGIMG.

  • Fill the key table
  • Call the required method.

The following methods are provided:

 

The following example shows how to read the active relationships of a Contact Person (Data Model BP, Entity Type BP_REL):


    DATA:
      lt_relations_key     TYPE SORTED TABLE OF /mdgbp/_s_bp_ky_bp_rel
                                WITH UNIQUE KEY partner1
                                                partner2
                                                bp_rel,
      ls_relation_key      LIKE LINE OF lt_relations_key,
      lt_contact_relations TYPE SORTED TABLE OF /mdgbp/_s_bp_pp_bp_rel
                                WITH UNIQUE KEY partner1
                                                partner2
                                                bp_rel,
      lo_read_api          TYPE REF TO if_usmd_read_api.

*--------------------------------------------------------------------*

    CHECK iv_contact_id IS NOT INITIAL.

    ls_relation_key-partner2 = lv_contact_id.
    ls_relation_key-bp_rel   = if_mdg_bp_constants=>gc_relation-contact_person.
    INSERT ls_relation_key INTO TABLE lt_relations_key.

    lo_read_api = cl_usmd_read_api=>get_instance( iv_model_name = if_mdg_bp_constants=>gc_bp_model ).
    CHECK lo_read_api IS BOUND.

    lo_read_api->read_active_data(
      EXPORTING
        iv_entity_type = if_mdg_bp_constants=>gc_bp_model_entity-relation
        it_entity_key  = lt_relations_key
      IMPORTING
        et_data        = lt_contact_relations
    ).

 

To be honest until today I only used it once to read custom entity type data during the outbound processing. So feel free to post your experiences with this API in the comments!

 

Have fun!

Markus

/
4 Comments
You must be Logged on to comment or reply to a post.
  • Hi Markus,

    This is great info.

    At anytime there is saved data and unsaved data.

    What is the purpose of the other ones?

    i assume: active = saved = confirmed

    current = unsaved

    Does that makes sense?

    Thank you

    • Hi Ritam,

      thank you for your comment. Unfortunately I do not remember the details of the methods as it is a long time ago when I used it. Just try them, the debugger is your friend.

      Best regards,
      Markus

  • Great Posting!

    I used this API for WBF parepare-context BAdI.

    as sample class, the Material Entity and Labor was used.

    Our requirement use Ztable value as the context.

    I use read-api(method read_current_data) so custom entity(key matnr) was read without problem.

    Thanks.