본문 바로가기
Fiori/Odata

OData (get_expanded_entityset)

by clode 2023. 2. 21.
728x90
반응형
 METHOD /iwbep/if_mgw_appl_srv_runtime~get_expanded_entityset.

    TYPES : BEGIN OF ts_main_entity.
              INCLUDE TYPE zcl_ztest3gw_so_mpc=>ts_soheader.
    TYPES:  navi_so_item TYPE STANDARD TABLE OF vbap WITH DEFAULT KEY,
            END OF ts_main_entity.

    DATA : ls_main TYPE ts_main_entity.
    DATA : lt_main LIKE TABLE OF ls_main.

    DATA : ls_head TYPE zcl_ztest3gw_so_mpc=>ts_soheader.

    DATA : ls_so_item TYPE vbap.
    DATA : lt_so_item TYPE TABLE OF vbap.

    DATA : lo_filter TYPE  REF TO /iwbep/if_mgw_req_filter.
    DATA : lt_filter_select_options TYPE /iwbep/t_mgw_select_option.
    DATA : ls_filter TYPE /iwbep/s_mgw_select_option.
    DATA : ls_option TYPE /iwbep/t_cod_select_options.
    DATA : r_vbeln TYPE /iwbep/t_cod_select_options.


    DATA : l_vbeln TYPE vbeln.


    DATA: lv_top  TYPE i,
          lv_skip TYPE i.

    lv_top  = io_tech_request_context->get_top( ).
    lv_skip = io_tech_request_context->get_skip( ).

    FIELD-SYMBOLS <ls_options> TYPE /iwbep/s_cod_select_option.

    lo_filter = io_tech_request_context->get_filter( ).
    lt_filter_select_options = lo_filter->get_filter_select_options( ).

    CASE iv_entity_set_name.
      WHEN 'SOheaderSet'.
        READ TABLE lt_filter_select_options INTO ls_filter WITH KEY property = 'Vbeln'.
        IF sy-subrc = 0.
          r_vbeln[] = ls_filter-select_options.

          LOOP AT r_vbeln ASSIGNING <ls_options>.
            IF <ls_options>-low IS NOT INITIAL.
              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  input  = <ls_options>-low
                IMPORTING
                  output = l_vbeln.
              IF sy-subrc EQ 0.
                <ls_options>-low = l_vbeln.
              ENDIF.
            ENDIF.
            IF <ls_options>-high IS NOT INITIAL.
              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  input  = <ls_options>-high
                IMPORTING
                  output = l_vbeln.
              IF sy-subrc EQ 0.
                <ls_options>-high = l_vbeln.
              ENDIF.
            ENDIF.
          ENDLOOP.
        ENDIF.


        DATA: ls_rows TYPE i.
        IF is_paging-top IS INITIAL.
          ls_rows = 500.
        ELSE.
          ls_rows = is_paging-top.
        ENDIF.
        ls_rows = ls_rows + is_paging-skip.


        SELECT * FROM vbak
          WHERE vbeln IN @r_vbeln
          ORDER BY vbeln ASCENDING
          INTO CORRESPONDING FIELDS OF TABLE @lt_main
          UP TO @ls_rows ROWS.


        IF is_paging-skip IS NOT INITIAL.
          DO is_paging-skip TIMES.
            DELETE lt_main INDEX 1.
          ENDDO.
        ENDIF.


        IF lt_main IS INITIAL.
          EXIT.
        ENDIF.


        SELECT * FROM vbap
          INTO CORRESPONDING FIELDS OF TABLE @lt_so_item
          FOR ALL ENTRIES IN @lt_main
          WHERE vbeln = @lt_main-vbeln.
        SORT lt_so_item ASCENDING BY vbeln posnr.


        LOOP AT lt_main INTO ls_main.
          MOVE-CORRESPONDING lt_so_item[] TO ls_main-navi_so_item[].
          ls_so_item-vbeln = ls_main-vbeln.
          DELETE ls_main-navi_so_item[] WHERE vbeln NE ls_so_item-vbeln.
          MODIFY lt_main FROM ls_main.
        ENDLOOP.
    ENDCASE.

    APPEND 'NAVI_SO_ITEM' TO et_expanded_tech_clauses.

    copy_data_to_ref(
    EXPORTING
      is_data = lt_main
    CHANGING
      cr_data = er_entityset ).


  ENDMETHOD.
728x90
반응형

'Fiori > Odata' 카테고리의 다른 글

Create Odata  (0) 2023.02.24
OData (create_deep_entity)  (0) 2023.02.21

댓글