Application Development and Automation 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: 
Read only

alv oops

Former Member
0 Likes
642

I want sample code for simple ALV display in oops.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
587

Hi,

pls find the following program of ALV using oops.


* data declarations
data : itab       type standard table of mara,"Output Internal table
       i_fieldcat type standard table of lvc_s_fcat,"Field catalog
       wa         type mara,
       w_variant  type disvariant,
       o_docking  type ref to cl_gui_docking_container,
                                                  "Docking Container
       o_grid     type ref to cl_gui_alv_grid."Grid

select * from mara into table itab up to 100 rows.
call screen 9000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_9000 output.
  if o_docking is initial.
    set pf-status 'ZSTATUS'.
    set titlebar 'ZTITLE'.
* create the docking container
    create object o_docking
      exporting
        ratio                       = '95'
        .
    if sy-subrc eq 0.
* creating the grid
      create object o_grid
      exporting
        i_parent          = o_docking
       .
    endif.
    call function 'LVC_FIELDCATALOG_MERGE'
      exporting
        i_structure_name       = 'MARA'
      changing
        ct_fieldcat            = i_fieldcat
      exceptions
        inconsistent_interface = 1
        program_error          = 2
        others                 = 3.
    w_variant-report = sy-repid.
* display the output
    call method o_grid->set_table_for_first_display
      exporting
        is_variant                    = w_variant
        i_save                        = 'A'
      changing
        it_outtab                     = itab
        it_fieldcatalog               = i_fieldcat
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        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.
  endif.
endmodule.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_9000 input.
  data lv_ucomm type sy-ucomm.
  lv_ucomm = sy-ucomm.
  case lv_ucomm.
    when 'CANCEl' or 'EXIT'.
      perform free_objects.
      leave program.
    when 'BACK'.
      perform free_objects.
      set screen '0'.
      leave screen.
  endcase.
endmodule.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  free_objects
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form free_objects .
  call method o_grid->free
    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.

  call method o_docking->free
    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.
endform.                    " free_objects

<REMOVED BY MODERATOR>

teja.

Edited by: Alvaro Tejada Galindo on Feb 27, 2008 3:10 PM

4 REPLIES 4
Read only

Former Member
0 Likes
587

Hi

Refer the program BCALV_TEST_LIST

Thanks

Vijay

Read only

Former Member
0 Likes
588

Hi,

pls find the following program of ALV using oops.


* data declarations
data : itab       type standard table of mara,"Output Internal table
       i_fieldcat type standard table of lvc_s_fcat,"Field catalog
       wa         type mara,
       w_variant  type disvariant,
       o_docking  type ref to cl_gui_docking_container,
                                                  "Docking Container
       o_grid     type ref to cl_gui_alv_grid."Grid

select * from mara into table itab up to 100 rows.
call screen 9000.
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_9000 output.
  if o_docking is initial.
    set pf-status 'ZSTATUS'.
    set titlebar 'ZTITLE'.
* create the docking container
    create object o_docking
      exporting
        ratio                       = '95'
        .
    if sy-subrc eq 0.
* creating the grid
      create object o_grid
      exporting
        i_parent          = o_docking
       .
    endif.
    call function 'LVC_FIELDCATALOG_MERGE'
      exporting
        i_structure_name       = 'MARA'
      changing
        ct_fieldcat            = i_fieldcat
      exceptions
        inconsistent_interface = 1
        program_error          = 2
        others                 = 3.
    w_variant-report = sy-repid.
* display the output
    call method o_grid->set_table_for_first_display
      exporting
        is_variant                    = w_variant
        i_save                        = 'A'
      changing
        it_outtab                     = itab
        it_fieldcatalog               = i_fieldcat
      exceptions
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        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.
  endif.
endmodule.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_9000 input.
  data lv_ucomm type sy-ucomm.
  lv_ucomm = sy-ucomm.
  case lv_ucomm.
    when 'CANCEl' or 'EXIT'.
      perform free_objects.
      leave program.
    when 'BACK'.
      perform free_objects.
      set screen '0'.
      leave screen.
  endcase.
endmodule.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Form  free_objects
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form free_objects .
  call method o_grid->free
    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.

  call method o_docking->free
    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.
endform.                    " free_objects

<REMOVED BY MODERATOR>

teja.

Edited by: Alvaro Tejada Galindo on Feb 27, 2008 3:10 PM

Read only

Former Member
0 Likes
587

Hi,

Check the below code....

&----


*& Report ZZZ_TEST_501

*&

&----


*&

*&

&----


REPORT zzz_test_501.

TYPES:BEGIN OF ty_vbak,

vbeln LIKE vbak-vbeln,

auart LIKE vbak-auart,

kunnr LIKE vbak-kunnr,

vkorg LIKE vbak-vkorg,

vtweg LIKE vbak-vtweg,

spart LIKE vbak-spart,

END OF ty_vbak,

BEGIN OF ty_vbap,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

werks LIKE vbap-werks,

lgort LIKE vbap-lgort,

ntgew LIKE vbap-ntgew,

END OF ty_vbap.

DATA:i_vbak TYPE STANDARD TABLE OF ty_vbak,

i_vbap TYPE STANDARD TABLE OF ty_vbap,

w_vbak TYPE ty_vbak,

w_vbap TYPE ty_vbap.

SELECT-OPTIONS:s_vbeln FOR w_vbak-vbeln.

PARAMETERS:s_date LIKE sy-datum.

*Declarations for ALV

CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA:grid1 TYPE REF TO cl_gui_alv_grid,

container TYPE REF TO cl_gui_docking_container,

i_fieldcat TYPE lvc_t_fcat,

w_fieldcat TYPE lvc_s_fcat,

disvar TYPE disvariant,

gs_toolbar TYPE stb_button,

eventreceiver TYPE REF TO lcl_event_receiver,

w_layout TYPE lvc_s_layo.

  • invariant TYPE disvariant,

  • i_event TYPE slis_t_event,

  • w_event TYPE slis_alv_event,

  • i_header TYPE slis_t_listheader,

  • w_header TYPE slis_listheader.

----


  • CLASS lcl_event_receiver DEFINITION

----


*

----


CLASS lcl_event_receiver DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_toolbar

FOR EVENT toolbar OF cl_gui_alv_grid

IMPORTING e_object e_interactive,

handle_user_command

FOR EVENT user_command OF cl_gui_alv_grid

IMPORTING e_ucomm,

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row

e_column

es_row_no.

ENDCLASS. "lcl_event_receiver DEFINITION

----


  • CLASS lcl_event_receiver IMPLEMENTATION

----


*

----


CLASS lcl_event_receiver IMPLEMENTATION.

----


  • METHOD HANDLE_USER_COMMAND

----


METHOD handle_user_command.

DATA:lt_rows TYPE lvc_t_row,

w_row TYPE lvc_s_row.

CASE e_ucomm.

WHEN 'CLICK'.

CLEAR lt_rows.

  • get selected row

CALL METHOD grid1->get_selected_rows

IMPORTING

et_index_rows = lt_rows.

READ TABLE lt_rows INTO w_row INDEX 1.

READ TABLE i_vbak INTO w_vbak INDEX w_row-index.

SET PARAMETER ID 'AUN' FIELD w_vbak-vbeln.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

  • CLEAR w_cust_detadd3.

  • PERFORM f1900_get_selectedrows TABLES lt_rows.

  • PERFORM f2000_modify_message.

  • ls_stable-row = 'X'.

  • ls_stable-col = 'X'.

*

  • CALL METHOD o_alvgrid->refresh_table_display

  • EXPORTING

  • is_stable = ls_stable.

*

  • CALL METHOD cl_gui_cfw=>flush.

  • CALL METHOD o_alvgrid->get_selected_rows

  • IMPORTING et_index_rows = lt_rows.

*

  • CLEAR w_cust_detadd3.

  • PERFORM f1900_get_selectedrows TABLES lt_rows.

  • PERFORM f2000_modify_message.

  • ls_stable-row = 'X'.

  • ls_stable-col = 'X'.

*

  • CALL METHOD o_alvgrid->refresh_table_display

  • EXPORTING

  • is_stable = ls_stable.

*

  • CALL METHOD cl_gui_cfw=>flush.

ENDCASE.

ENDMETHOD. "HANDLE_USER_COMMAND

----


  • METHOD HANDLE_TOOLBAR

----


METHOD handle_toolbar.

  • append a separator to normal toolbar

CLEAR gs_toolbar.

MOVE 3 TO gs_toolbar-butn_type.

APPEND gs_toolbar TO e_object->mt_toolbar.

CLEAR gs_toolbar.

MOVE 'CLICK' TO gs_toolbar-function.

MOVE 'CLICK' TO gs_toolbar-text.

  • --> This function code is evaluated in 'handle_menu_button'

MOVE 0 TO gs_toolbar-butn_type.

MOVE space TO gs_toolbar-disabled.

APPEND gs_toolbar TO e_object->mt_toolbar.

LOOP AT e_object->mt_toolbar INTO gs_toolbar.

IF gs_toolbar-function = '&MB_SUM'.

gs_toolbar-disabled = space.

MODIFY e_object->mt_toolbar FROM gs_toolbar INDEX sy-tabix.

ENDIF.

ENDLOOP.

ENDMETHOD. "HANDLE_TOOLBAR

----


  • METHOD DOUBLE_CLICK

----


METHOD handle_double_click.

READ TABLE i_vbak INTO w_vbak INDEX e_row-index.

SET PARAMETER ID 'AUN' FIELD w_vbak-vbeln.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

ENDMETHOD. "HANDLE_DOUBLE_CLICK

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

START-OF-SELECTION.

SELECT vbeln

auart

kunnr

vkorg

vtweg

spart FROM vbak

INTO TABLE i_vbak

WHERE vbeln IN s_vbeln.

IF sy-subrc = 0.

ENDIF.

END-OF-SELECTION.

IF NOT i_vbak IS INITIAL.

CALL SCREEN 9001.

ENDIF.

&----


*& Module STATUS_9001 OUTPUT

&----


  • text

----


MODULE status_9001 OUTPUT.

  • IF NOT container IS INITIAL.

SET PF-STATUS 'GRID'.

  • if cl_gui_alv_grid=>offline() is initial.

CREATE OBJECT container

EXPORTING

ratio = 95

name = 'ALV'.

CREATE OBJECT grid1

EXPORTING

i_parent = container

EXCEPTIONS

error_cntl_create = 1

error_cntl_init = 2

error_cntl_link = 3

error_dp_create = 4

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.

  • ENDIF.

SET HANDLER eventreceiver->handle_user_command

eventreceiver->handle_toolbar

eventreceiver->handle_double_click FOR grid1.

w_fieldcat-col_pos = 1.

w_fieldcat-fieldname = 'VBELN'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Sales Document #'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = 2.

w_fieldcat-fieldname = 'AUART'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Order Type'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = 3.

w_fieldcat-fieldname = 'KUNNR'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Customer #'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = 4.

w_fieldcat-fieldname = 'VKORG'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Sales Org'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = 5.

w_fieldcat-fieldname = 'VTWEG'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Distribution Channel'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = 6.

w_fieldcat-fieldname = 'SPART'.

w_fieldcat-tabname = 'I_VBAK'.

w_fieldcat-reptext = 'Division'.

APPEND w_fieldcat TO i_fieldcat.

CLEAR w_fieldcat.

CALL METHOD grid1->set_table_for_first_display

  • EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

it_outtab = i_vbak

it_fieldcatalog = i_fieldcat

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

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.

*endif.

ENDMODULE. " STATUS_9001 OUTPUT

&----


*& Module USER_COMMAND_9001 INPUT

&----


  • text

----


MODULE user_command_9001 INPUT.

CASE sy-ucomm.

WHEN 'EXIT' OR 'CANC'.

SET SCREEN '0'.

WHEN 'BACK'.

SET SCREEN '0'.

WHEN 'DISP'.

  • <Enter code for handling the display option>

WHEN OTHERS.

ENDCASE.

ENDMODULE. " USER_COMMAND_9001 INPUT

Cheers,

Bujji

Read only

Former Member
0 Likes
587

RESOLVED