Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

sample alv program using classes & methods ..but not using container

Former Member
0 Kudos

hai ,

my requirement is : sample alv program using classes & methods ..but not using container ..

it's urgent ..plz send me sample program with classes & methods but not to use container ...

thanks in advance ..

5 REPLIES 5

Former Member
0 Kudos

Hi,

Check this link by using a docking container not a fixed container..

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-7StepstocreateOOPSALV(forbeginners)&

Thanks

Naren

harimanjesh_an
Active Participant
0 Kudos

hi suddu,

sample code:

<b>TYPE-POOLS: slis.

TABLES ydb_emp. ,</b>"ydb_emp is custom table

<b>

DATA:

BEGIN OF tp_emp OCCURS 0,

empid LIKE ydb_emp-emdid

fname LIKE ydb_emp-efname,

lname LIKE ydb_emp-elname,

sal LIKE ydb_emp-esal,

END OF tp_emp.

DATA int_fcat TYPE slis_t_fieldcat_alv.

DATA i_repid LIKE sy-repid.

START-OF-SELECTION.

SELECT emdid efname elname esal FROM ydb_emp INTO TABLE tp_emp.

IF sy-subrc <> 0.

WRITE / 'No rows selected'.

ENDIF.

i_repid = sy-repid.

END-OF-SELECTION.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = i_repid

i_internal_tabname = 'TP_EMP'

i_inclname = i_repid

CHANGING

ct_fieldcat = int_fcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE: /

'Returncode',

sy-subrc,

'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.

ENDIF.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = i_repid

it_fieldcat = int_fcat

  • I_SAVE = 'A'

TABLES

t_outtab = tp_emp

EXCEPTIONS

program_error = 1

OTHERS = 2.

IF sy-subrc <> 0.

WRITE: /

'Returncode',

sy-subrc,

'from FUNCTION REUSE_ALV_LIST_DISPLAY'.

ENDIF.</b>

check this link for other code example:

ABAP Code Sample for Data Browser Using ALV Grid:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/925ae990-0201-0010-fb88-f073bd31...

ALV Object Model:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/acdefb13-0701-0010-f1a2-8eeefa7d...

Display Flat file data in ALV Grid:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/afb1e590-0201-0010-f6b6-a6314f0f...

7 steps to create ALV :

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-7StepstocreateOOPS+ALV

Reward me if useful..........

Harimanjesh AN

uwe_schieferstein
Active Contributor
0 Kudos

Hello Suddu

The new ALV object model does not need a container anymore. For the classical ALV (CL_GUI_ALV_GRID) I rarely use a custom container but <b>link </b>(e.g.) a docking container to the target dynpro.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_CL_SALV_TABLE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
 
REPORT  zus_sdn_cl_salv_table.
 
 
DATA:
  gt_knb1        TYPE STANDARD TABLE OF knb1.
 
 
DATA:
  go_table       TYPE REF TO cl_salv_table.
*  go_layout      type ref to CL_SALV_LAYOUT,
*  go_display     type ref to CL_SALV_DISPLAY_SETTINGS,
*  go_columns     type ref to CL_SALV_COLUMNS_TABLE.
 
 
 
 
START-OF-SELECTION.
 
 
START-OF-SELECTION.
 
  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = '1000'.
 
 
  TRY.
      CALL METHOD cl_salv_table=>factory
*    EXPORTING
*      LIST_DISPLAY   = IF_SALV_C_BOOL_SAP=>FALSE
*      R_CONTAINER    =
*      CONTAINER_NAME =
        IMPORTING
          r_salv_table   = go_table
        CHANGING
          t_table        = gt_knb1.
    CATCH cx_salv_msg .
  ENDTRY.
 
  go_table->display( ).
 
 
END-OF-SELECTION.

<b>(2)</b> If you are using the "classical" OO-approach then you always need a container but not necessarily a custom container. The following sample report displays two ALV lists on a screen without any dynpro elements.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
 
REPORT  zus_sdn_two_alv_grids.
 
 
 
 
DATA:
  gd_okcode        TYPE ui_func,
*
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_splitter      TYPE REF TO cl_gui_splitter_container,
  go_cell_top      TYPE REF TO cl_gui_container,
  go_cell_bottom   TYPE REF TO cl_gui_container,
  go_grid1         TYPE REF TO cl_gui_alv_grid,
  go_grid2         TYPE REF TO cl_gui_alv_grid.
 
 
DATA:
  gt_knb1          TYPE STANDARD TABLE OF knb1,
  gt_knvv          TYPE STANDARD TABLE OF knvv.
 
 
 
 
 
*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
 
  PUBLIC SECTION.
    CLASS-METHODS:
      handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
        IMPORTING
          e_row
          e_column
          es_row_no
          sender.
 
 
ENDCLASS.                    "lcl_eventhandler DEFINITION
 
 
 
*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.
 
  METHOD handle_double_click.
*   define local data
    DATA:
      ls_knb1      TYPE knb1.
 
    CHECK ( sender = go_grid1 ).
 
    READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row-index.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).
 
    CALL METHOD go_grid1->set_current_cell_via_id
      EXPORTING
*        IS_ROW_ID    =
*        IS_COLUMN_ID =
        is_row_no    = es_row_no.
 
 
*   Triggers PAI of the dynpro with the specified ok-code
    CALL METHOD cl_gui_cfw=>set_new_ok_code( 'DETAIL' ).
 
 
 
  ENDMETHOD.                    "handle_double_click
 
ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
 
 
 
 
 
 
START-OF-SELECTION.
 
  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = '1000'.
 
 
* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
* Create splitter container
  CREATE OBJECT go_splitter
    EXPORTING
      parent            = go_docking
      rows              = 2
      columns           = 1
*      NO_AUTODEF_PROGID_DYNNR =
*      NAME              =
    EXCEPTIONS
      cntl_error        = 1
      cntl_system_error = 2
      OTHERS            = 3.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
* Get cell container
  CALL METHOD go_splitter->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = go_cell_top.
  CALL METHOD go_splitter->get_container
    EXPORTING
      row       = 2
      column    = 1
    RECEIVING
      container = go_cell_bottom.
 
* Create ALV grids
  CREATE OBJECT go_grid1
    EXPORTING
      i_parent          = go_cell_top
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
* Set event handler
  SET HANDLER: lcl_eventhandler=>handle_double_click FOR go_grid1.
 
 
  CREATE OBJECT go_grid2
    EXPORTING
      i_parent          = go_cell_bottom
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
* Display data
  CALL METHOD go_grid1->set_table_for_first_display
    EXPORTING
      i_structure_name = 'KNB1'
    CHANGING
      it_outtab        = gt_knb1
    EXCEPTIONS
      OTHERS           = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
  CALL METHOD go_grid2->set_table_for_first_display
    EXPORTING
      i_structure_name = 'KNVV'
    CHANGING
      it_outtab        = gt_knvv  " empty !!!
    EXCEPTIONS
      OTHERS           = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
* Link the docking container to the target dynpro
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      OTHERS                      = 4.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
* NOTE: dynpro does not contain any elements
  CALL SCREEN '0100'.
* Flow logic of dynpro (does not contain any dynpro elements):
*
*PROCESS BEFORE OUTPUT.
*  MODULE STATUS_0100.
**
*PROCESS AFTER INPUT.
*  MODULE USER_COMMAND_0100.
 
 
 
END-OF-SELECTION.
 
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
*  SET TITLEBAR 'xxx'.
 
 
* Refresh display of detail ALV list
  CALL METHOD go_grid2->refresh_table_display
*    EXPORTING
*      IS_STABLE      =
*      I_SOFT_REFRESH =
    EXCEPTIONS
      OTHERS         = 2.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
 
 
ENDMODULE.                 " STATUS_0100  OUTPUT
 
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
 
  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.
 
*   User has pushed button "Display Details"
    WHEN 'DETAIL'.
      PERFORM entry_show_details.
 
    WHEN OTHERS.
  ENDCASE.
 
  CLEAR: gd_okcode.
 
ENDMODULE.                 " USER_COMMAND_0100  INPUT
 
*&---------------------------------------------------------------------*
*&      Form  ENTRY_SHOW_DETAILS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM entry_show_details .
* define local data
  DATA:
    ld_row      TYPE i,
    ls_knb1     TYPE knb1.
 
  CALL METHOD go_grid1->get_current_cell
    IMPORTING
      e_row = ld_row.
 
  READ TABLE gt_knb1 INTO ls_knb1 INDEX ld_row.
  CHECK ( syst-subrc = 0 ).
 
  SELECT        * FROM  knvv INTO TABLE gt_knvv
         WHERE  kunnr  = ls_knb1-kunnr.
 
 
 
ENDFORM.                    " ENTRY_SHOW_DETAILS

In summary, I do rarely use a custom container on a dynpro to display my controls. In contrast, I link my containers to the dynpro (using method LINK) which allows for much more flexibility.

Regards

Uwe

Former Member
0 Kudos

All right then - very simple (I added some functions anyway:-):

REPORT z_alv_simple.

TABLES: .....

SELECT ......

INTO CORRESPONDING FIELDS OF TABLE etab

FROM ..... .

LOOP AT etab INTO we.

ENDLOOP.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = gr_table

CHANGING

t_table = etab.

gr_functions = gr_table->get_functions( ).

gr_functions->set_all( 'X' ).

gr_table->display( ).

Just replace .... with your own input.

Former Member
0 Kudos

Sorry, I forgot this part:

DATA: gr_table TYPE REF TO cl_salv_table.

DATA: gr_functions TYPE REF TO cl_salv_functions_list,

gr_stripped TYPE REF TO cl_salv_display_settings.