[ABAP] OData: Keys einer Entität auswerten

* Groß-/Kleinschreibung beachten
* Variablennamen durch Komma getrennt, keine Leerzeichen
* Datumswerte mit VarDate=datetime'yyyy-mm-ddThh:mm:ss' konvertieren
* Sonderzeichen/Umlaute konvertieren

* Abfrage-URL
URL/SERVICENAME/ItemCollection(Matnr='000000000001',Date1=datetime'2013-09-04T00%3A00%3A00')?$format=xml

* Variante 1 (get_converted_keys)
METHOD xyz_get_entity.

  DATA: lv_carr TYPE /iwbep/s_mgw_name_value_pair-value.
  DATA: lv_conn TYPE /iwbep/s_mgw_name_value_pair-value.

  io_tech_request_context->get_converted_keys( IMPORTING es_key_values = er_entity ).

  TRY.
      lv_carr = er_entity-carrid.
      lv_conn = er_entity-connid.

      ...
    CATCH cx_root.
  ENDTRY.

  er_entity = ...
ENDMETHOD.

* Variante 2 (Navigation z.B.: Header -> Position, get_converted_source_keys)
METHOD xyz_get_entityset.

* Typen in MPC definert
  DATA: lv_pos TYPE zcl_abc_mpc=>ts_pos.
  DATA: lv_matnr TYPE /iwbep/s_mgw_name_value_pair-value.
  
  DATA(lv_source_entity_type_name) = io_tech_request_context->get_source_entity_type_name( ).
  
  CASE lv_source_entity_type_name.
* Konstanten in der MPC definiert
     WHEN zcl_abc_mpc=>gc_head.
* Key-Werte in Struktur des Typs zcl_abc_mpc=>ts_pos wandeln
       io_tech_request_context->get_converted_source_keys( IMPORTING es_key_values = lv_pos ).

       lv_matnr = |{ lv_pos-matnr WIDTH = 18 ALPHA = IN }|.
  ENDCASE.
  
  er_entity = ...
ENDMETHOD.

* Variante 3 (get_keys)
METHOD xyz_get_entity.

  DATA(it_keys) = io_tech_request_context->get_keys( ).

  DATA: lv_key_matnr TYPE /iwbep/s_mgw_tech_pair.
  DATA: lv_key_date1 TYPE /iwbep/s_mgw_tech_pair.

  TRY.
      lv_key_matnr = it_keys[ name = 'MATNR' ].
      lv_key_date1 = it_keys[ name = 'DATE1' ].

      DATA(lv_matnr) = lv_key_matnr-value.
      DATA(lv_date1) = lv_key_date1-value.

      ...
    CATCH cx_root.
  ENDTRY.

  er_entity = ...
ENDMETHOD.