본문 바로가기
ERP-SAP/ABAP

<ABAP> SALV 01. Hierarchical List

by 행복한워니의 기록 2012. 8. 29.
728x90
반응형

기본적인 소스인것 같은데....
난 하이어라키 하기 싫었는데.....-_- 그냥 연습해본거...
보다보면 클래스가 어떻게 구동되는지도 살짝 핥아 볼 수 있다...
이거 그냥 붙여넣고 테스트 해봐라... 그럼 된다.
 

  *&---------------------------------------------------------------------*
*& This code snippet will show how to use the CL_SALV_HIERSEQ_TABLE to
*&generate the simplest Hierarchical (Sequential) ALV
*&---------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
  PUBLIC SECTION.
*   Final Header output table
    TYPESBEGIN OF ty_vbak,
            vbeln TYPE vbak-vbeln,
            erdat TYPE erdat,
            auart TYPE auart,
            kunnr TYPE kunnr,
            expand   TYPE char01,    "Column for Expand / Collapse
           END   OF ty_vbak.

*   FInal Item output table

    TYPESBEGIN OF ty_vbap,
            vbeln TYPE vbap-vbeln,
            posnr TYPE vbap-posnr,
            matnr TYPE vbap-matnr,
            arktx TYPE vbap-arktx,
           END   OF ty_vbap.

*   Standard internal tables
    DATAt_vbak TYPE STANDARD TABLE OF ty_vbak,
          t_vbap TYPE STANDARD TABLE OF ty_vbap.

*   Hierarchical ALV reference
    DATAo_hs_alv TYPE REF TO cl_salv_hierseq_table.

    METHODS:
*  data selection
      get_data,
*generating output
      generate_output.
**$*$*.....CODE_ADD_1 - Begin..................................1..*$*$
***    In this section we will define the private methods which can
*      be implemented to set the properties of the ALV and can be
*      called in the GENERATE_OUTPUT method
**$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
ENDCLASS.                    "lcl_report DEFINITION
*
START-OF-SELECTION.
  DATAlo_report TYPE REF TO lcl_report.
*
  CREATE OBJECT lo_report.
*
  lo_report->get_data).
*
  lo_report->generate_output).
*
*
*----------------------------------------------------------------------*
*       CLASS lcl_report IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
  METHOD get_data.
*   data selection - Header
    SELECT vbeln erdat auart kunnr
     INTO  TABLE t_vbak
       FROM  vbak
        UP TO 10 ROWS.
*
*   data selection - Item
    SELECT vbeln posnr matnr arktx
      INTO  TABLE t_vbap
      FROM  vbap
      FOR   ALL ENTRIES IN t_vbak
      WHERE vbeln t_vbak-vbeln.
*
  ENDMETHOD.                    "get_data
*
*.......................................................................
  METHOD generate_output.
* New ALV instance
*   We are calling the static Factory method which will give back
*   the ALV object reference.
*
    DATAlx_data_err   TYPE REF TO cx_salv_data_error,
     lx_not_found  TYPE REF TO cx_salv_not_found.
*
*   Fill the Binding table. Here we hae to provide the relationship
*     between all the Common Key fields in the Master and Slave
*     table. Based on this relationship, we will get the output.
    DATAlt_bind TYPE salv_t_hierseq_binding,
          la_bind LIKE LINE OF lt_bind.
*
    la_bind-master 'VBELN'.    " VBELN as field of my T_VBAK
    la_bind-slave  'VBELN'.    " VBELN as field of my T_VBAP
    APPEND la_bind TO lt_bind.

*
*   call factory method to generate the output
    TRY.
        CALL METHOD cl_salv_hierseq_table=>factory
          EXPORTING
            t_binding_level1_level2 lt_bind
          IMPORTING
            r_hierseq               o_hs_alv
          CHANGING
            t_table_level1          t_vbak
            t_table_level2          t_vbap.

      CATCH cx_salv_data_error INTO lx_data_err.
      CATCH cx_salv_not_found  INTO lx_not_found
     .
    ENDTRY.
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
*    In this area we will call the methods which will set the
*      different properties to the ALV
*
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
* Displaying the ALV
*   Here we will call the DISPLAY method to get the output on the screen
    o_hs_alv->display).
*
  ENDMETHOD.                    "generate_output
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
*    In this area we will implement the methods which are defined in
*      the class definition
*
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*
*
ENDCLASS.                    "lcl_report IMPLEMENTATION

728x90
반응형