Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Jacques Nomssi
Submitted: 2014-01-21
Related Links:

Description Code:

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT ysdnblog_jnn.
DATA: BEGIN OF gs_sel,
        matnr TYPE matnr,
        mtart TYPE mtart,
        matkl TYPE matkl,
      END OF gs_sel.
SELECTION-SCREEN BEGIN OF SCREEN 200.
SELECT-OPTIONS:
  so_matnr FOR gs_sel-matnr,
  so_mtart FOR gs_sel-mtart,
  so_matkl FOR gs_sel-matkl.
PARAMETERS p_rows TYPE count DEFAULT '100'.
SELECTION-SCREEN END OF SCREEN 200.
INTERFACE lif_unit_test.
ENDINTERFACE.
CLASS lcl_param DEFINITION FRIENDS lif_unit_test.
  PUBLIC SECTION.
    TYPES:
      tt_matnr_range TYPE RANGE OF matnr,
      tt_mtart_range TYPE RANGE OF mtart,
      tt_matkl_range TYPE RANGE OF matkl.
    CLASS-METHODS factory
      RETURNING value(ro_param) TYPE REF TO lcl_param.
    DATA mv_rows TYPE count READ-ONLY.
    DATA mt_matnr_range TYPE tt_matnr_range READ-ONLY.
    DATA mt_mtart_range TYPE tt_mtart_range READ-ONLY.
    DATA mt_matkl_range TYPE tt_matkl_range READ-ONLY.
  PRIVATE SECTION.
    METHODS get_selection.
ENDCLASS.                    "lcl_param DEFINITION
INTERFACE lif_data_source.
  METHODS get RETURNING value(rr_data) TYPE REF TO data.
ENDINTERFACE.                    "lif_data_source DEFINITION
CLASS lcl_mara DEFINITION FRIENDS lif_unit_test.
  PUBLIC SECTION.
    INTERFACES lif_data_source.
    ALIASES get FOR lif_data_source~get.
    CLASS-METHODS factory
      IMPORTING io_param TYPE REF TO lcl_param
      RETURNING value(ro_mara) TYPE REF TO lcl_mara.
  PRIVATE SECTION.
    METHODS query
      IMPORTING io_param TYPE REF TO lcl_param.
    DATA mt_mara TYPE mara_tt.
ENDCLASS.                    "lcl_mara DEFINITION
CLASS lcl_view DEFINITION CREATE PRIVATE FRIENDS lif_unit_test.
  PUBLIC SECTION.
    CLASS-METHODS factory
      IMPORTING ii_source TYPE REF TO lif_data_source
      RETURNING value(ro_view) TYPE REF TO lcl_view
      RAISING cx_salv_msg.
    METHODS display.
  PRIVATE SECTION.
    METHODS alv_init
      CHANGING ct_data TYPE STANDARD TABLE
      RAISING cx_salv_msg.
    DATA mo_alv TYPE REF TO cl_salv_table.
ENDCLASS.                    "lcl_view DEFINITION
CLASS lcl_ctrl DEFINITION FRIENDS lif_unit_test.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    CLASS-METHODS create_view
      RETURNING value(ro_view) TYPE REF TO lcl_view
      RAISING cx_salv_msg.
ENDCLASS.
CLASS lcl_ctrl IMPLEMENTATION.
  METHOD create_view.
    DATA lo_param TYPE REF TO lcl_param.
    DATA lo_mara TYPE REF TO lcl_mara.
    CALL SELECTION-SCREEN 200.
    lo_param = lcl_param=>factory( ).
    lo_mara = lcl_mara=>factory( lo_param ).
    ro_view = lcl_view=>factory( lo_mara ).
  ENDMETHOD.                    "create_view
  METHOD main.
    DATA lo_view TYPE REF TO lcl_view.
    DATA lx_error TYPE REF TO cx_static_check.
    TRY.
        lo_view = create_view( ).
        lo_view->display( ).
      CATCH cx_static_check INTO lx_error.
        MESSAGE lx_error TYPE 'E' DISPLAY LIKE 'I'.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
  lcl_ctrl=>main( ).

CLASS lcl_param IMPLEMENTATION.
  METHOD factory.
    CREATE OBJECT ro_param.
    ro_param->get_selection( ).
  ENDMETHOD.                    "factory
  METHOD get_selection.
    mv_rows = p_rows.
    mt_matnr_range[] = so_matnr[].
    mt_matkl_range[] = so_matkl[].
    mt_mtart_range[] = so_mtart[].
  ENDMETHOD.                    "get_selection
ENDCLASS.                    "lcl_param IMPLEMENTATION
CLASS lcl_mara IMPLEMENTATION.
  METHOD factory.
    CREATE OBJECT ro_mara.
    ro_mara->query( io_param ).
  ENDMETHOD.                    "factory
  METHOD query.
    CLEAR mt_mara[].
    SELECT * FROM mara
      INTO CORRESPONDING FIELDS OF TABLE mt_mara
      UP TO io_param->mv_rows ROWS
      WHERE matnr IN io_param->mt_matnr_range
        AND mtart IN io_param->mt_mtart_range
        AND matkl IN io_param->mt_matkl_range.
  ENDMETHOD.                    "query
  METHOD get.
    GET REFERENCE OF mt_mara INTO rr_data.
  ENDMETHOD.                    "get_ref
ENDCLASS.                    "lcl_mara IMPLEMENTATION
CLASS lcl_view IMPLEMENTATION.
  METHOD factory.
    FIELD-SYMBOLS <lt_table> TYPE STANDARD TABLE.
    DATA lr_data TYPE REF TO data.
    CREATE OBJECT ro_view.
    lr_data = ii_source->get( ).
    ASSIGN lr_data->* TO <lt_table>.
    ro_view->alv_init( CHANGING ct_data = <lt_table> ).
  ENDMETHOD.                    "factory
  METHOD display.
    mo_alv->display( ).
  ENDMETHOD.                    "display
  METHOD alv_init.
    DATA lo_functions TYPE REF TO cl_salv_functions.
    cl_salv_table=>factory(
      IMPORTING r_salv_table   = mo_alv
      CHANGING  t_table        = ct_data ).
    lo_functions = mo_alv->get_functions( ).
    lo_functions->set_all( abap_true ).
  ENDMETHOD.                    "alv_init
ENDCLASS.                    "lcl_view IMPLEMENTATION
  • No labels

2 Comments

  1. That escalated quickly!

    Seems like a very complicated way to show an ALV, but it sure looks good!!

    Regards,
    Bruno 

  2. Former Member

    Different thought!!!! Really good One...

     

    Regards,

    Joyjit