0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【ABAP】統合データアクセス(IDA)を備えたALVでCDS Viewのデータを表示する(CL_SALV_GUI_TABLE_IDA)

Last updated at Posted at 2021-04-30

#やること
統合データアクセス(IDA)を備えたALVで、CDS Viewのデータを表示する。
CL_SALV_GUI_TABLE_IDAを使用。

参考:
SAP List Viewer with Integrated Data Access (ALV with IDA)
ABAP Development: Work with Core Data Services (CDS)

CDS Viewではなく、テーブルデータを出力する方法についてはこちら
統合データアクセス(IDA)を備えたALVでテーブルデータを表示する(CL_SALV_GUI_TABLE_IDA)

#実行結果
※CDS Viewのデータを表示。
###CDS Viewの定義
※テーブルEKKOとEKPOを結合しただけ
image.png

Y_PO_ITEM_01
@AbapCatalog.sqlViewName: 'Y_PO_ITEM'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS View Demo'
define view Y_PO_ITEM_01 
  as select from ekko
  join ekpo
    on ekko.ebeln = ekpo.ebeln
    {
    ekko.lifnr, 
    ekko.ebeln,
    ekko.bsart,
    ekko.ekorg,
    ekko.ekgrp,
    ekpo.ebelp,
    ekpo.matnr
    }

###選択画面
image.png

###ALV画面(CDS Viewのデータ)
image.png

#ソースコード

Y_CL_SALV_GUI_TABLE_IDA_CDS
*&---------------------------------------------------------------------*
*& Report Y_CL_SALV_GUI_TABLE_IDA_CDS
*&---------------------------------------------------------------------*
*& CDS ViewのデータをALV画面で出力
*&---------------------------------------------------------------------*
REPORT y_cl_salv_gui_table_ida_cds.

* 選択画面定義
DATA w_ebeln TYPE ekko-ebeln.

PARAMETERS p_lifnr TYPE ekko-lifnr.
SELECT-OPTIONS s_ebeln FOR w_ebeln.

*----------------------------------------------------------------------*
*       CLASS DEFINITION
*----------------------------------------------------------------------*
*----- メイン
CLASS lcl_main DEFINITION CREATE PRIVATE.

  PUBLIC SECTION.
    CLASS-METHODS run.
  PRIVATE SECTION.

ENDCLASS.
*----------------------------------------------------------------------*
*       CLASS IMPLEMENTATION
*----------------------------------------------------------------------*
*----- メイン
CLASS lcl_main IMPLEMENTATION.

  METHOD run.
* IDA作成
    DATA(o_ida) = cl_salv_gui_table_ida=>create_for_cds_view( 'Y_PO_ITEM_01' ).

* 抽出条件の設定
* PARAMETERSの場合
    DATA lr_lifnr TYPE RANGE OF ekko-lifnr.
    DATA(o_sel) = NEW cl_salv_range_tab_collector( ).
    IF p_lifnr IS NOT INITIAL.
      lr_lifnr = VALUE #(
        ( sign = 'I' option = 'EQ' low = p_lifnr )
      ).
      o_sel->add_ranges_for_name( iv_name = 'LIFNR' it_ranges = lr_lifnr[] ).
    ENDIF.
*  SELECT-OPTIONSの場合
    o_sel->add_ranges_for_name( iv_name = 'EBELN' it_ranges = s_ebeln[] ).

    o_sel->get_collected_ranges( IMPORTING et_named_ranges = DATA(lt_named_ranges) ).
    o_ida->set_select_options( it_ranges = lt_named_ranges ).

* ALV出力
    o_ida->fullscreen( )->display( ).
  ENDMETHOD.
ENDCLASS.
*----------------------------------------------------------------------*
*       START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  lcl_main=>run( ).

#検証中の事象
CDS ViewにParameterオプションが設定されている場合、エラーとなる。。。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?