Fetch Data from SAP Application Interface Framework Custom Entity Example

CLASS zcl_sd_aif_err_return_orders DEFINITION
  PUBLIC
  INHERITING FROM zcl_sd_get_aif_log_mess_super
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.

    METHODS get_data
        REDEFINITION .

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_SD_AIF_ERR_RETURN_ORDERS IMPLEMENTATION.


  METHOD get_data.
    DATA:
      lv_msgguid          TYPE sxmsguid,
      ls_sales_order      TYPE sdsls_esr_sales_order_bulk_req,
      ls_xmlparse_paramts TYPE /aif/xmlparse_data,
      ls_interface_keys   TYPE /aif/ifkeys,
      lt_logs             TYPE /aif/tt_msg_log,
      lt_result           TYPE TABLE OF zsd_i_aif_err_return_orders,
      lo_data             TYPE REF TO data.
    CONSTANTS:
      lc_ns     TYPE  /aif/ns VALUE '/SDSLS',
      lc_ifname TYPE /aif/ifname VALUE 'SO_BULK_I',
      lc_ifver  TYPE  /aif/ifversion VALUE '1'.

    SELECT msgguid
      FROM sdsls_bussys_idx
      WHERE ns = @lc_ns
      AND ifname = @lc_ifname
      AND ifver = @lc_ifver
      INTO TABLE @DATA(lt_msgguid).

    IF sy-subrc = 0.

      DATA(lif_appl_engine) = /aif/cl_aif_engine_factory=>get_engine(
                               iv_ns            = lc_ns
                               iv_ifname        = lc_ifname
                               iv_ifversion     = lc_ifver
                                    ).

      ls_interface_keys-ns = lc_ns.
      ls_interface_keys-ifname = lc_ifname.
      ls_interface_keys-ifver = lc_ifver.


      LOOP AT lt_msgguid ASSIGNING FIELD-SYMBOL().
        TRY.
            DATA(lif_ws)     = cl_wsm_access_factory=>create_monitor( iv_no_auth_check  = abap_true ).
          ##NO_HANDLER         CATCH cx_wsm_access_authority.
        ENDTRY.
        DATA(lo_id)    = NEW srt_persistency_access_id_t( ( message_id = -msgguid location = 'C' )
                                                           ( message_id = -msgguid location = 'P' ) ).
        DATA(lo_filter) = NEW srt_mselect_filter( ).
        lo_filter->access_id_list = lo_id->*.
        DATA(lo_result) = NEW srt_mselect_result_t( ).
        TRY.
            lo_result->* = lif_ws->select_messages( filter = lo_filter->* ).
          ##NO_HANDLER CATCH cx_wsm_access_authority cx_wsm_access_monitor.
        ENDTRY.
        IF lines( lo_result->* ) <> 0.

          TRY.
              TRY.
                  cl_system_uuid=>convert_uuid_c32_static( EXPORTING uuid     = -msgguid
                                                           IMPORTING uuid_x16 = lv_msgguid ).
                ##NO_HANDLER CATCH cx_uuid_error.
              ENDTRY.

              CLEAR : lo_data,
                      ls_xmlparse_paramts.

              lif_appl_engine->read_msg_from_persistency(
                                 EXPORTING
                                   iv_msgguid    = lv_msgguid
                                   iv_ns         = lc_ns
                                   iv_ifname     = lc_ifname
                                   iv_ifver      = lc_ifver
                                   iv_read_access_logging = abap_true
                                 CHANGING
                                   cref_data     = lo_data
                                   cs_xmlparse   = ls_xmlparse_paramts ).
            CATCH /aif/cx_error_handling_general.
              CONTINUE.
          ENDTRY.

          ls_sales_order = lo_data->*.

          DATA(lo_log) = NEW /aif/cl_logging_engine_app_log( ).

          LOOP AT ls_sales_order-sales_order_bulk_request-sales_order FROM 1 TO 2 ASSIGNING FIELD-SYMBOL(). "#EC CI_NESTED

            lo_log->/aif/if_logging_engine~retrieve_log( EXPORTING is_interface_key = ls_interface_keys
                                                                   iv_msgguid =  -msgguid
                                                         IMPORTING et_msg_log = lt_logs ).

            LOOP AT -item FROM 1 TO 2 ASSIGNING FIELD-SYMBOL(). "#EC CI_NESTED
              LOOP AT lt_logs FROM 1 TO 2 ASSIGNING FIELD-SYMBOL(). "#EC CI_NESTED

                APPEND INITIAL LINE TO lt_result ASSIGNING FIELD-SYMBOL().

                -salesordernumber = -sales_order_id.
                -salesorderitem = -sales_order_item_id.
                -msgguid = -msgguid.
                -plant = -plant.
                -storagelocation = -storage_location.
                -article = -material.
                -stockquantity = -requested_quantity-content.
                -meins = -requested_quantity-unit_code.
                -externaldocumentid = -external_document_id.
                -referencedocument = -zzreference_document.
                -salesorderdate = -customer_purchase_order_date.
                -movement_action = -action_code.
                "-wmstimestamp = cl_abap_tstmp=>move_to_short( -external_doc_last_change_date ).

                MESSAGE ID -msgid TYPE -msgty NUMBER -msgno WITH   -msgv1
                                                                                              -msgv2
                                                                                              -msgv2
                                                                                              -msgv2
                                                                                       INTO -errormessage.
              ENDLOOP.
            ENDLOOP.
          ENDLOOP.
        ENDIF.
      ENDLOOP.

      DELETE lt_result FROM 10 TO lines( lt_result ).    "#EC CI_STDSEQ

      CREATE DATA co_result LIKE lt_result.

      SELECT * FROM @lt_result AS result ##ITAB_KEY_IN_SELECT "#EC CI_SUBRC
         WHERE (iv_filter_string)                              "#EC CI_DYNWHERE
         INTO CORRESPONDING FIELDS OF TABLE @lt_result.

      co_result->* = lt_result.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

CLASS zcl_sd_get_aif_log_mess_super DEFINITION
  PUBLIC
  CREATE PUBLIC .

  PUBLIC SECTION.
    INTERFACES  if_rap_query_provider .
    METHODS get_data
      IMPORTING iv_filter_string TYPE string
      CHANGING  co_result        TYPE REF TO data
      RAISING
                /aif/cx_error_handling_general
                /aif/cx_aif_engine_not_found
                /aif/cx_bal_log_strategy.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS ZCL_SD_GET_AIF_LOG_MESS_SUPER IMPLEMENTATION.


  METHOD if_rap_query_provider~select .
    DATA: lo_result TYPE REF TO data.
    FIELD-SYMBOLS:
     TYPE STANDARD TABLE.

    TRY.
        TRY.
            IF io_request->is_data_requested( ).
              io_request->get_paging( ).
              io_request->get_filter( ).
              DATA(lv_sql_filter) = io_request->get_filter( )->get_as_sql_string( ).
              TRY.
                  get_data( EXPORTING iv_filter_string = lv_sql_filter CHANGING co_result = lo_result ).
                ##NO_HANDLER CATCH /aif/cx_error_handling_general /aif/cx_aif_engine_not_found /aif/cx_bal_log_strategy.
              ENDTRY.
              ASSIGN lo_result->* TO .
              IF  IS ASSIGNED.
                IF lines(   ) > 10.
                  DELETE  FROM 10 TO lines(  ).
                ENDIF.

                io_response->set_total_number_of_records( lines(   ) ).
                io_response->set_data(   ).

              ENDIF.
            ENDIF.
          ##NO_HANDLER CATCH cx_rap_query_provider.
        ENDTRY.
      ##NO_HANDLER CATCH cx_rfc_dest_provider_error.
    ENDTRY.
  ENDMETHOD.


     METHOD get_data.
     ENDMETHOD.
ENDCLASS.

@EndUserText.label: 'Get AIF Log Messages Goods Receipt'
@ObjectModel.query.implementedBy  : 'ABAP:ZCL_SD_AIF_ERR_RETURN_ORDERS'
define custom entity zsd_i_aif_err_return_orders
{
      @UI                :{lineItem:       [{ position:50,importance: #HIGH }]}
      @EndUserText.label : 'Article'
  key Article            : zsd_snapshot_article;
      Plant              : zsd_snapshot_plant;
      StorageLocation    : zsd_snapshot_sloc;
      @UI                :{lineItem:       [{ position:70,importance: #HIGH }]}
      @EndUserText.label : 'Purchase Order'
      SalesOrderNumber   : zsd_sales_order_number;
      SalesOrderItem     : zsd_snapshot_sales_order_item;
      @Consumption.semanticObject: 'AIFMessage'
      @UI                :{lineItem:       [{ position:10,importance: #HIGH },
      {type              : #FOR_INTENT_BASED_NAVIGATION, semanticObjectAction: 'startMessageMonitoring'}]}
      @EndUserText.label : 'Message ID'
      MsgGuid            : sxmsguid;
      @UI                :{lineItem:       [{ position:20,importance: #HIGH }]}
      @EndUserText.label : 'Error Information'
      ErrorMessage       : char100;
      @UI                :{lineItem:       [{ position:30,importance: #HIGH }]}
      @EndUserText.label : 'WMS Time Stamp'
      WMSTimeStamp       : zsd_snapshot_sap_timestamp;
      @UI                :{lineItem:       [{ position:40,importance: #HIGH }]}
      @EndUserText.label : 'Movement Action'
      Movement_Action    : char02;
      @UI                :{lineItem:       [{ position:60,importance: #HIGH }]}
      @Semantics.quantity.unitOfMeasure : 'Meins'
      @EndUserText.label : 'Quantity'
      StockQuantity      : sdesr_quantity_v2_gfn_content;
      @UI                :{lineItem:       [{ position:80,importance: #HIGH }]}
      @EndUserText.label : 'Reference Document'
      ExternalDocumentId : sdesr_external_ref_key_id;
      ReferenceDocument  : char12;
      ShippingType       : sdesr_shipping_type_gfn;
      Meins              : meins;
      ErrorInformation   : char100;
      SalesOrderDate     : datum;
}

Добавить комментарий