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 Grid Display

Former Member
0 Likes
2,554

Kindly tell me how do I display a report in the ALV grid display in the easiest possible way and using the least number of fumctions ....

it would always be helpful if a particular flow of the code is given ....

thanks...

paul

Kindly tell me how do I display a report in the ALV grid display in the easiest possible way and using the least number of fumctions ....

it would always be helpful if a particular flow of the code is given ....

thanks...

paul

14 REPLIES 14
Read only

peter_atkin
Active Contributor
0 Likes
1,671

Paul,

Can't remember where I got this...

Don't even know if it works??

-


DATA: l_alv TYPE REF TO cl_gui_alv_grid,

lt_sflight TYPE TABLE OF sflight.

SELECT * FROM sflight INTO TABLE lt_sflight.

  • Creation of the ALV object, when we use cl_gui_container=>screen0 as parent, the ALVGrid control will

  • automatically use the full screen to display the grid, NO CONTAINER DEFINITION IS REQUIRED !

CREATE OBJECT l_alv EXPORTING i_parent = cl_gui_container=>screen0.

  • calling the display of the grid, the system will automatically create the fieldcatalog based

  • on the table name you pass in parameter

CALL METHOD l_alv->set_table_for_first_display

EXPORTING i_structure_name = 'SFLIGHT'

CHANGING it_outtab = lt_sflight.

  • You have to create an EMPTY screen, put NOTHING in the layout and this is going to work

CALL SCREEN 100.

Read only

Former Member
0 Likes
1,671

Hi pradipta

try this code . this is the simplest method to display ALV Grid

REPORT zdemo_alvgrid .

TABLES: ekko.

type-pools: slis. "ALV Declarations

*Data Declaration

*----


TYPES: BEGIN OF t_ekko,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

statu TYPE ekpo-statu,

aedat TYPE ekpo-aedat,

matnr TYPE ekpo-matnr,

menge TYPE ekpo-menge,

meins TYPE ekpo-meins,

netpr TYPE ekpo-netpr,

peinh TYPE ekpo-peinh,

END OF t_ekko.

DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,

wa_ekko TYPE t_ekko.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

gd_tab_group type slis_t_sp_group_alv,

gd_layout type slis_layout_alv,

gd_repid like sy-repid.

************************************************************************

*Start-of-selection.

START-OF-SELECTION.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

&----


*& Form BUILD_FIELDCATALOG

&----


  • Build Fieldcatalog for ALV Report

----


form build_fieldcatalog.

  • There are a number of ways to create a fieldcat.

  • For the purpose of this example i will build the fieldcatalog manualy

  • by populating the internal table fields individually and then

  • appending the rows. This method can be the most time consuming but can

  • also allow you more control of the final product.

  • Beware though, you need to ensure that all fields required are

  • populated. When using some of functionality available via ALV, such as

  • total. You may need to provide more information than if you were

  • simply displaying the result

  • I.e. Field type may be required in-order for

  • the 'TOTAL' function to work.

fieldcatalog-fieldname = 'EBELN'.

fieldcatalog-seltext_m = 'Purchase Order'.

fieldcatalog-col_pos = 0.

fieldcatalog-outputlen = 10.

fieldcatalog-emphasize = 'X'.

fieldcatalog-key = 'X'.

  • fieldcatalog-do_sum = 'X'.

  • fieldcatalog-no_zero = 'X'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'EBELP'.

fieldcatalog-seltext_m = 'PO Item'.

fieldcatalog-col_pos = 1.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'STATU'.

fieldcatalog-seltext_m = 'Status'.

fieldcatalog-col_pos = 2.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.

fieldcatalog-seltext_m = 'Item change date'.

fieldcatalog-col_pos = 3.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material Number'.

fieldcatalog-col_pos = 4.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.

fieldcatalog-seltext_m = 'PO quantity'.

fieldcatalog-col_pos = 5.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.

fieldcatalog-seltext_m = 'Order Unit'.

fieldcatalog-col_pos = 6.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.

fieldcatalog-seltext_m = 'Net Price'.

fieldcatalog-col_pos = 7.

fieldcatalog-outputlen = 15.

fieldcatalog-do_sum = 'X' "Display column total

fieldcatalog-datatype = 'CURR'.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

fieldcatalog-fieldname = 'PEINH'.

fieldcatalog-seltext_m = 'Price Unit'.

fieldcatalog-col_pos = 8.

append fieldcatalog to fieldcatalog.

clear fieldcatalog.

endform. " BUILD_FIELDCATALOG

&----


*& Form BUILD_LAYOUT

&----


  • Build layout for ALV grid report

----


form build_layout.

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-totals_text = 'Totals'(201).

  • gd_layout-totals_only = 'X'.

  • gd_layout-f2code = 'DISP'. "Sets fcode for when double

  • "click(press f2)

  • gd_layout-zebra = 'X'.

  • gd_layout-group_change_edit = 'X'.

  • gd_layout-header_text = 'helllllo'.

endform. " BUILD_LAYOUT

&----


*& Form DISPLAY_ALV_REPORT

&----


  • Display report using ALV grid

----


form display_alv_report.

gd_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = gd_repid

  • i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM

  • i_callback_user_command = 'USER_COMMAND'

  • i_grid_title = outtext

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

  • it_special_groups = gd_tabgroup

  • IT_EVENTS = GT_XEVENTS

i_save = 'X'

  • is_variant = z_template

tables

t_outtab = it_ekko

exceptions

program_error = 1

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.

endform. " DISPLAY_ALV_REPORT

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


form data_retrieval.

select ebeln ebelp statu aedat matnr menge meins netpr peinh

up to 10 rows

from ekpo

into table it_ekko.

endform. " DATA_RETRIEVAL

regards

kishore

Read only

kvenkatesh-in
Explorer
0 Likes
1,671

Hi,

There are two ways to dispaly the report in alv grid.

1. Function module method

ex. BALVSD02_GRID

BALVST03_GRID

2. Objects method

ex : BCALV_GRID_01

BCALV_GRID_02

BCALV_GRID_03

BCALV_GRID_04

BCALV_GRID_05

venkatesh

For more examples go through the programs in Package SLIS from se80

Read only

0 Likes
1,671

HI,

have a look at the following link to know how to implement ALV grid using Classes..

<a href="http://www.sapgenie.com/abap/controls/alvgrid.htm">ALV Grid control</a>

which is recommended to be used over the REUSE_ALV* function modules ..

regards

satesh

Read only

Former Member
0 Likes
1,671

Hi,

Here is a sample code, for ALV, including Top of page.


REPORT zad_test_alv
       NO STANDARD PAGE HEADING
       MESSAGE-ID zcs_cs_001.

************************************************************************
*                    DATA DECLARATIONS
************************************************************************

************************************************************************
* Table Declarations:
************************************************************************
TABLES: mara.


************************************************************************
* Internal Tables:
************************************************************************
DATA:  i_fieldcat    TYPE lvc_t_fcat,
       i_fieldrows   TYPE lvc_t_row,
       i_output      TYPE STANDARD TABLE OF mara,


************************************************************************
* Work Areas:
************************************************************************
      w_fieldrows   LIKE LINE OF i_fieldrows,
      w_output      TYPE mara.

************************************************************************
* Constants Declarations:
************************************************************************
CONSTANTS:    c_x                        TYPE c VALUE 'X'.


*----------------------------------------------------------------------*
*             SELECTION SCREEN FIELDS
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b_0 WITH FRAME TITLE text-000.
SELECT-OPTIONS: s_mara FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK b_0.



*----------------------------------------------------------------------*
*                   CLASS DECLARATIONS                                 *
*----------------------------------------------------------------------*

INCLUDE <icon>.
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA : o_alvgrid          TYPE REF TO cl_gui_alv_grid ,
       o_dockingcontainer TYPE REF TO cl_gui_docking_container ,
       o_eventreceiver    TYPE REF TO lcl_event_receiver,
       v_split            TYPE REF TO cl_gui_easy_splitter_container,
       v_contnr_top       TYPE REF TO cl_gui_container,
       v_contnr_bot       TYPE REF TO cl_gui_container,
       v_grid_02          TYPE REF TO cl_gui_alv_grid,
       v_html             TYPE REF TO cl_dd_document,
       v_text01(255)      TYPE c VALUE 'This is the heading',
       v_font(50)         TYPE c VALUE '30',
*---------------------------------------------------------------------*
*       Work Area
*---------------------------------------------------------------------*
       w_layout TYPE lvc_s_layo ,
       w_variant TYPE disvariant.
*---------------------------------------------------------------------*
*       Constants
*---------------------------------------------------------------------*

CONSTANTS : c_a(1) TYPE c VALUE 'A' .                     " All Layouts
*---------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.
    CLASS-METHODS:
* Hot Spot Click
       handle_hotspot
         FOR EVENT hotspot_click OF cl_gui_alv_grid
            IMPORTING e_row_id
                      e_column_id
                      es_row_no,
      handle_print_top_of_page
            FOR EVENT print_top_of_page OF
                      cl_gui_alv_grid,

      handle_top_of_page
           FOR EVENT top_of_page OF
                      cl_gui_alv_grid.
ENDCLASS.
* Implementation
CLASS lcl_event_receiver IMPLEMENTATION.
*&---------------------------------------------------------------------*
*&      Method handle_hotspot
*&---------------------------------------------------------------------*
* This method is called when the user clicks on a hotspot to drill down.
* The following types are exported from the ALV
* LVC_S_ROW
* LVC_S_COL
* LVC_S_ROID
*&---------------------------------------------------------------------*
  METHOD handle_hotspot.
* The hotspot processing coded in the form below.
    PERFORM f9802_handle_hotspot USING e_row_id
                                       e_column_id
                                       es_row_no.

  ENDMETHOD.
  METHOD handle_print_top_of_page.
    IF sy-pagno = 1.
      PERFORM f9803_top_of_page.
    ENDIF.
  ENDMETHOD.
  METHOD handle_top_of_page.
    PERFORM f9803_top_of_page.
  ENDMETHOD.
ENDCLASS.


***********************************************************************
* START-OF-SELECTION
***********************************************************************
START-OF-SELECTION.

  PERFORM f5000_get_data.

************************************************************************
** END-OF-SELECTION
************************************************************************

END-OF-SELECTION.
************************************************************************
  IF NOT i_output[] IS INITIAL.
    CALL SCREEN 9001.
  ELSE.
    MESSAGE i001 WITH text-051.
    " No documents were found for the selection
    LEAVE LIST-PROCESSING.
  ENDIF.


*----------------------------------------------------------------------*
*                           FORMS                                      *
*----------------------------------------------------------------------*
* This part has the various forms used in the program
************************************************************************

*&---------------------------------------------------------------------*
*&      Form  f5000_get_totals
*&---------------------------------------------------------------------*
*       To get Data
*----------------------------------------------------------------------*
FORM f5000_get_data.

  SELECT *
         INTO TABLE i_output UP TO 5 ROWS
         FROM mara.


ENDFORM.                    " f5000_get_data

*&---------------------------------------------------------------------*
*&      Form  f9000_objects_create
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM f9000_objects_create.

  IF cl_gui_alv_grid=>offline( ) IS INITIAL.
    CREATE OBJECT o_dockingcontainer
      EXPORTING
        ratio                       = '95'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        others                      = 6.
    IF sy-subrc NE 0.
      MESSAGE i001 WITH text-e01."Error in creating Docking container
      LEAVE LIST-PROCESSING.
    ENDIF.
    CREATE OBJECT v_split
         EXPORTING
           parent            = o_dockingcontainer
*          ORIENTATION       = 0
           sash_position     = 25
           with_border       = 0
         EXCEPTIONS
           cntl_error        = 1
           cntl_system_error = 2
           others            = 3.
    IF sy-subrc NE 0.
      MESSAGE i000 WITH text-e01."Error in creating Docking container
      LEAVE LIST-PROCESSING.
    ENDIF.
*   Get the containers of the splitter control
    v_contnr_top = v_split->top_left_container.
    v_contnr_bot = v_split->bottom_right_container.

    CREATE OBJECT o_alvgrid
   EXPORTING
     i_parent = o_dockingcontainer.

*   Create an instance of alv control
    CREATE OBJECT o_alvgrid
         EXPORTING i_parent = v_contnr_bot.

*   Object for display of selection parameters in HTML top container
    CREATE OBJECT v_html
         EXPORTING
           style = 'ALV_GRID'.


*   Must be after the SET HANDLER for TOP_OF_PAGE and foreground only
    CALL METHOD o_alvgrid->list_processing_events
                     EXPORTING i_event_name = 'TOP_OF_PAGE'
                               i_dyndoc_id  = v_html.
    CLEAR v_text01.

    v_text01     = 'Heading'.


    v_font = 'HEADING'.
    CALL METHOD v_html->add_gap
                EXPORTING
                  width         = 120.
    CALL METHOD v_html->add_text
           EXPORTING
             text           = v_text01
             sap_style      = v_font.

    CALL METHOD v_html->new_line.
* Display the data
    CALL METHOD v_html->display_document
      EXPORTING
         parent             = v_contnr_top.

*   Handle the event
    CALL METHOD o_alvgrid->list_processing_events
                        EXPORTING i_event_name = 'PRINT_TOP_OF_PAGE'.
  ENDIF.

* IF Program Running in Background, place a container.
  IF sy-batch = 'X'.
    CREATE OBJECT o_alvgrid
 EXPORTING
   i_parent = o_dockingcontainer.
  ENDIF.

ENDFORM.                    " f9000_objects_create

*&---------------------------------------------------------------------*
*&      Form  f9001_build_field_cat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_FIELDCAT  text
*      -->P_0021   text
*----------------------------------------------------------------------*
FORM f9001_build_field_cat TABLES   p_fieldcat STRUCTURE lvc_s_fcat
                      USING value(p_structure).

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name       = p_structure
       CHANGING
            ct_fieldcat            = p_fieldcat[]
       EXCEPTIONS
            inconsistent_interface = 1
            program_error          = 2
            OTHERS                 = 3.
  IF sy-subrc <> 0.
    MESSAGE i001 WITH text-e05."Error in ALV field catalogue creation
    LEAVE LIST-PROCESSING.
  ENDIF.

ENDFORM.                    " f9001_build_field_cat
*&---------------------------------------------------------------------*
*&      Form  f9002_modify_field_cat
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_FIELDCAT  text
*----------------------------------------------------------------------*
FORM f9002_modify_field_cat TABLES p_fieldcat STRUCTURE lvc_s_fcat.

  FIELD-SYMBOLS : <lfs_fieldcat> TYPE lvc_s_fcat.


ENDFORM.                    " f9002_modify_field_cat
*&---------------------------------------------------------------------*
*&      Form  f9003_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SY_TITLE  text
*      -->P_0030   text
*      -->P_0031   text
*      -->P_0032   text
*----------------------------------------------------------------------*
FORM f9003_layout USING  value(ptitle)
                         value(pzebra)
                         value(pmode)
                         value(pwidth).

  w_layout-grid_title  = ptitle.
  w_layout-zebra       = pzebra.
  w_layout-sel_mode    = pmode.
  w_layout-cwidth_opt  = pwidth.
  w_variant-report     = sy-repid.

ENDFORM.                    " f9003_layout
*&---------------------------------------------------------------------*
*&      Form  f9004_display_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_I_OUTPUT  text
*      -->P_I_FIELDCAT  text
*----------------------------------------------------------------------*
FORM f9004_display_data TABLES   p_output
                                 p_fieldcat.

  IF sy-batch = 'X'.
    CREATE OBJECT o_eventreceiver.
    SET HANDLER o_eventreceiver->handle_print_top_of_page FOR o_alvgrid.
  ENDIF.

  CALL METHOD o_alvgrid->set_table_for_first_display
    EXPORTING
       is_variant                    = w_variant
       i_save                        = c_a
       is_layout                     = w_layout
    CHANGING
       it_outtab                     = p_output[]
       it_fieldcatalog               = p_fieldcat[]
    EXCEPTIONS
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 3
       OTHERS                        = 4.

  IF sy-subrc <> 0.
    MESSAGE i128 WITH text-e06."Error in ALV report display
    LEAVE LIST-PROCESSING.
  ENDIF.

  IF sy-batch NE 'X'.
    CREATE OBJECT o_eventreceiver.
    SET HANDLER o_eventreceiver->handle_print_top_of_page FOR o_alvgrid.
    SET HANDLER o_eventreceiver->handle_top_of_page FOR o_alvgrid.
  ENDIF.

ENDFORM.                    " f9004_display_data
*&---------------------------------------------------------------------*
*&      Form  f9005_free_objects
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_O_ALVGRID  text
*      -->P_0056   text
*      -->P_TEXT_E02  text
*----------------------------------------------------------------------*
FORM f9005_free_objects USING pobject
                        value(ptype)
                        value(ptext).
  CASE ptype.

    WHEN 'ALV'.
      DATA lobjectalv TYPE REF TO cl_gui_alv_grid.
      lobjectalv = pobject.
      IF NOT ( lobjectalv IS INITIAL ).
        CALL METHOD lobjectalv->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject ,
               lobjectalv.
        PERFORM f9006_error_handle USING ptext.
      ENDIF.

    WHEN 'DOCKING'.
      DATA lobjectdock TYPE REF TO cl_gui_docking_container.
      lobjectdock = pobject.
      IF NOT ( lobjectdock IS INITIAL ).
        CALL METHOD lobjectdock->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject ,
               lobjectdock.
        PERFORM f9006_error_handle USING ptext.
      ENDIF.

    WHEN 'CONTAINER'.
      DATA lobjectcontainer TYPE REF TO cl_gui_container.
      lobjectcontainer = pobject.
      IF NOT ( lobjectcontainer IS INITIAL ).
        CALL METHOD lobjectcontainer->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
        CLEAR: pobject ,
               lobjectcontainer.
        PERFORM f9006_error_handle USING ptext.
      ENDIF.

    WHEN OTHERS.
      sy-subrc = 1.
      PERFORM f9006_error_handle USING text-e04.
  ENDCASE.
ENDFORM.                    " f9005_free_objects
*&---------------------------------------------------------------------*
*&      Form  f9006_error_handle
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_PTEXT  text
*----------------------------------------------------------------------*
FORM f9006_error_handle USING value(ptext).

  IF sy-subrc NE 0.
    CALL FUNCTION 'POPUP_TO_INFORM'
         EXPORTING
              titel = text-e03
              txt2  = sy-subrc
              txt1  = ptext.
  ENDIF.

ENDFORM.                    " f9006_error_handle
*&---------------------------------------------------------------------*
*&      Form  f9802_handle_hotspot
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_E_ROW_ID  text
*      -->P_E_COLUMN_ID  text
*      -->P_ES_ROW_NO  text
*----------------------------------------------------------------------*
FORM f9802_handle_hotspot USING    p_row_id
                                   p_column_id
                                   p_row_no.


ENDFORM.                    " f9802_handle_hotspot
*&---------------------------------------------------------------------*
*&      Form  f9803_top_of_page
*&---------------------------------------------------------------------*
*      TOP-OF-PAGE
*----------------------------------------------------------------------*
FORM f9803_top_of_page.
* List heading
  WRITE:/ v_text01.
ENDFORM.                    " f9803_top_of_page



*----------------------------------------------------------------------*
*   INCLUDE ZCSGM_MFRECON_SUMMRPT_LD_SCRN                              *
************************************************************************
*&---------------------------------------------------------------------*
*&      Module  STATUS_1001  OUTPUT
*&---------------------------------------------------------------------*
*       This performs PBO
*----------------------------------------------------------------------*
MODULE  status_9001 OUTPUT.

  IF o_dockingcontainer IS INITIAL.
    SET PF-STATUS 'ZSTATUS'.
    SET TITLEBAR  'ZTITLE'.
*   Creating Object
    PERFORM f9000_objects_create.

*   Building the field catalog
    PERFORM f9001_build_field_cat TABLES i_fieldcat
                            USING 'MARA'.
  ENDIF.
*   Modifying the field catalog
  PERFORM f9002_modify_field_cat TABLES i_fieldcat.

*   For Layout
  PERFORM f9003_layout USING sy-title 'X' 'B' 'X' .
*   To display output
  PERFORM f9004_display_data TABLES i_output
                                    i_fieldcat.
* Set handlers for events
  SET HANDLER o_eventreceiver->handle_hotspot       FOR o_alvgrid.

ENDMODULE.                 " STATUS_9001  OUTPUT

*&---------------------------------------------------------------------
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------
*       This performs PAI
*----------------------------------------------------------------------*

MODULE user_command_9001 INPUT.

  CASE sy-ucomm.
    WHEN 'EXIT' OR  'CANC'.
      PERFORM f9005_free_objects :
              USING o_alvgrid 'ALV' text-e02 ,
              USING o_dockingcontainer 'DOCKING' text-e01.
      LEAVE PROGRAM.
    WHEN 'BACK'.
      PERFORM f9005_free_objects :
              USING o_alvgrid 'ALV' text-e02 ,
              USING o_dockingcontainer 'DOCKING' text-e01.
      SET SCREEN '0'.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_9001  INPUT

Hope that solves your query.

Best Regards,

Anjali

Read only

Former Member
0 Likes
1,671

Hi Paul,

REPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .

************************************************************************

*data definition

tables:

marav. "Table MARA and table MAKT

----


  • Data to be displayed in ALV

  • Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-

  • matically determine the fieldstructure from this source program

Data:

begin of imat occurs 100,

matnr like marav-matnr, "Material number

maktx like marav-maktx, "Material short text

matkl like marav-matkl, "Material group (so you can test to make

" intermediate sums)

ntgew like marav-ntgew, "Net weight, numeric field (so you can test to

"make sums)

gewei like marav-gewei, "weight unit (just to be complete)

end of imat.

----


  • Other data needed

  • field to store report name

data i_repid like sy-repid.

  • field to check table length

data i_lines like sy-tabix.

----


  • Data for ALV display

TYPE-POOLS: SLIS.

data int_fcat type SLIS_T_FIELDCAT_ALV.

----


select-options:

s_matnr for marav-matnr matchcode object MAT1.

----


start-of-selection.

  • read data into table imat

select * from marav

into corresponding fields of table imat

where

matnr in s_matnr.

  • Check if material was found

clear i_lines.

describe table imat lines i_lines.

if i_lines lt 1.

  • Using hardcoded write here for easy upload

write: /

'No materials found.'.

exit.

endif.

end-of-selection.

----


*

  • Now, we start with ALV

*

----


*

*

  • To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.

  • The fieldcatalouge can be generated by FUNCTION

  • 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any

  • report source, including this report.

  • The only problem one might have is that the report and table names

  • need to be in capital letters. (I had it )

*

*

----


  • Store report name

i_repid = sy-repid.

  • Create Fieldcatalogue from internal table

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = i_repid

I_INTERNAL_TABNAME = 'IMAT' "capital letters!

I_INCLNAME = i_repid

CHANGING

CT_FIELDCAT = int_fcat

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 2

OTHERS = 3.

*explanations:

  • I_PROGRAM_NAME is the program which calls this function

*

  • I_INTERNAL_TABNAME is the name of the internal table which you want

  • to display in ALV

*

  • I_INCLNAME is the ABAP-source where the internal table is defined

  • (DATA....)

  • CT_FIELDCAT contains the Fieldcatalouge that we need later for

  • ALV display

IF SY-SUBRC <> 0.

write: /

'Returncode',

sy-subrc,

'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.

ENDIF.

*This was the fieldcatlogue

----


*

  • And now, we are ready to display our list

  • Call for ALV list display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'

I_CALLBACK_PROGRAM = i_repid

IT_FIELDCAT = int_fcat

I_SAVE = 'A'

TABLES

T_OUTTAB = imat

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

*

*explanations:

  • I_CALLBACK_PROGRAM is the program which calls this function

*

  • IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains

  • now the data definition needed for display

*

  • I_SAVE allows the user to save his own layouts

*

  • T_OUTTAB contains the data to be displayed in ALV

IF SY-SUBRC <> 0.

write: /

'Returncode',

sy-subrc,

'from FUNCTION REUSE_ALV_LIST_DISPLAY'.

ENDIF.

*

with regards,

Manikandan R

Read only

Former Member
0 Likes
1,671

Hi,

try this code...

in the call screen 100.

write this code...

PROCESS BEFORE OUTPUT.

MODULE STATUS_0100.

module create_object.

module display_data.

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

tables vbak.

DATA: it_vbak TYPE STANDARD TABLE OF vbak.

DATA: v_container TYPE REF TO cl_gui_custom_container,

v_alv TYPE REF TO cl_gui_alv_grid.

START-OF-SELECTION.

SELECT * FROM vbak INTO TABLE it_vbak.

CALL SCREEN 100.

&----


*& Module STATUS_0100 OUTPUT

&----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'STAT'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module create_object OUTPUT

&----


MODULE create_object OUTPUT.

CREATE OBJECT v_container

EXPORTING

container_name = 'ALV_CONTAINER'.

CREATE OBJECT v_alv

EXPORTING

i_parent = v_container.

ENDMODULE. " create_object OUTPUT

&----


*& Module display_data OUTPUT

&----


module display_data output.

CALL METHOD v_alv->set_table_for_first_display

EXPORTING

I_STRUCTURE_NAME = 'vbak'

IT_TOOLBAR_EXCLUDING = lt_exclude

CHANGING

it_outtab = it_vbak[].

endmodule. " display_data OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


module USER_COMMAND_0100 input.

case sy-ucomm.

when 'BACK'.

leave program.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

hope this helps u...

regards

raghu

Read only

Former Member
0 Likes
1,671

Hi Pradipta,

Tell me your e-mail id so that I can give u the program for displaying ALV in the easiest manner...

I can give you some documents associated with ALV too...

Bye.

Sylendra.

Read only

Former Member
0 Likes
1,671

Hi,

Look at the link you will fing no.of examples.will help you a lot.

http://www.geocities.com/mpioud/Abap_programs.html

Thanks.

If this helps you reward with points.

Read only

Former Member
0 Likes
1,671

Hi pradiptha,

Here is the solution using OOP.

Data: container type ref to CL_GUI_CUSTOM_CONTAINER,

grid type ref to CL_GUI_ALV_GRID.

DATA: ITAB type table of sflight with header line.

call screen 100.

  • in the screen, create a custom container named

  • ALV_CONTAINER.

if container is initial.

  • checking if container is being used or not

create object container

exporting container_name = 'ALV_CONTAINER'

exceptions -


.

  • the above stmt initializes the container for ALV.

create object grid

exporting

i_parent = container

exceptions -


.

  • this statement initializes the ALV Grid

select * from sflight into table itab.

call method grid->set_table_for_first_display

exporting

I_STRUCTURE_NAME = 'SFLIGHT'

changing

it_outtab = itab[]

exceptions ---.

endif.

THis is the easiest way to display ALV .

Regards,

Sylendra.

Read only

Former Member
0 Likes
1,671

i need to find subtotals in alv

Read only

0 Likes
1,671

Kalyan,

would it not be better, if you started a new thread?(for more visiblity) and gave more details of the way you are getting your ALV. if you are using the Fn. Mod. you can get subtotals (on numeric fields) very easily. Read the documentation of the Fn. Modules.

Read only

Former Member
0 Likes
1,671

The easiest by miles is either REUSE_ALV_GRID_DISPLAY or its near identical cousin REUSE_ALV_LIST_DISPLAY, I personally prefer the GRID cos' when you press preview, it give you a LIST display anyway.

The easiest way to get the column headers is to create a structureidentical to the list of fields in your internal tablein the dic. and pass this as a parameter to the fn. mod. [This stru. can then be used to define your internal table, makes sense].

Pass the internal table as a parameter to the fn. mod. and Enjoy!

Read the doc. of the Fn. Mod., surprisingly, it is quite well documented and believe me, this one Fn. Mod. can do almost anything that you'd do using cumbersome methods.

Read only

Former Member
0 Likes
1,671

Hi Paul,

&----


*& Report Z_REPORTFROMKNA1ANDT005T

*&

&----


*&

*&

&----


REPORT Z_REPORTFROMKNA1ANDT005T

LINE-SIZE 180

MESSAGE-ID ZZ.

TABLES:EKKO.

TYPE-POOLS : SLIS.

&----


  • Internal table for ALV

----


DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, "Field catalog

WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV, "WA for Field catalog

IT_EVENT TYPE SLIS_T_EVENT, "events

WA_EVENT TYPE SLIS_ALV_EVENT, "WA for events

IT_COMMENT TYPE SLIS_T_LISTHEADER, "Header details

WA_COMMENT TYPE SLIS_LISTHEADER, "WA for header details

WA_LAYOUT TYPE SLIS_LAYOUT_ALV, "Layout

IT_SORT TYPE SLIS_T_SORTINFO_ALV, "Sort table

WA_SORT TYPE SLIS_SORTINFO_ALV, "WA for sort table

IT_KEYINFO TYPE SLIS_KEYINFO_ALV. "Pass key value

DATA : V_REPID LIKE SY-REPID.

V_REPID = SY-REPID.

DATA : V_DATE LIKE SY-DATUM.

    • color management.

DATA : IT_COLOR TYPE TABLE OF LVC_S_SCOL. "Color management.

&----


  • Internal table declearation

----


DATA:BEGIN OF IT_EKKO OCCURS 0,

EBELN LIKE EKKO-EBELN,

BUKRS LIKE EKKO-BUKRS,

AEDAT LIKE EKKO-AEDAT,

END OF IT_EKKO.

DATA : BEGIN OF IT_EKPO OCCURS 0,

EBELN LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

MATNR LIKE EKPO-MATNR,

MENGE LIKE EKPO-MENGE,

MEINS LIKE EKPO-MEINS,

NETPR LIKE EKPO-NETPR,

NETWR LIKE EKPO-MENGE,

chk(1) type c,

END OF IT_EKPO.

DATA : BEGIN OF IT_EKBE OCCURS 0,

EBELN LIKE EKBE-EBELN,

EBELP LIKE EKBE-EBELP,

BELNR LIKE EKBE-BELNR,

MENGE LIKE EKBE-MENGE,

MATNR LIKE EKBE-MATNR,

END OF IT_EKBE.

DATA : BEGIN OF IT_FINAL OCCURS 0,

EBELN LIKE EKPO-EBELN,

EBELP LIKE EKPO-EBELP,

MATNR LIKE EKPO-MATNR,

MENGE LIKE EKPO-MENGE,

MEINS LIKE EKPO-MEINS,

NETPR LIKE EKPO-NETPR,

NETWR LIKE EKPO-NETWR,

LINE_COLOR(4) TYPE C, "Used to store row color attributes

END OF IT_FINAL.

SELECTION-SCREEN BEGIN OF BLOCK BLK WITH FRAME TITLE TEXT-001.

SELECT-OPTIONS:S_EBELN FOR EKKO-EBELN.

SELECTION-SCREEN END OF BLOCK BLK.

START-OF-SELECTION.

PERFORM GET_DETAILS.

PERFORM GET_ALV.

&----


*& Form GET_DETAILS

&----


  • Get the details

----


FORM GET_DETAILS .

DATA: LD_COLOR(1) TYPE C.

SELECT EBELN

BUKRS

AEDAT

FROM EKKO

INTO TABLE IT_EKKO

WHERE EBELN IN S_EBELN.

IF SY-SUBRC = 0.

SORT IT_EKKO BY EBELN.

ELSE.

MESSAGE E000 WITH 'DATA NOT FOUND'.

ENDIF.

IF NOT IT_EKKO[] IS INITIAL.

SELECT EBELN

EBELP

MATNR

MENGE

MEINS

NETPR

NETWR

  • chk

FROM EKPO

INTO TABLE IT_EKPO

FOR ALL ENTRIES IN IT_EKKO

WHERE EBELN = IT_EKKO-EBELN.

IF SY-SUBRC = 0.

SORT IT_EKPO BY EBELN.

ENDIF.

ENDIF.

LOOP AT IT_EKPO.

IT_FINAL-EBELN = IT_EKPO-EBELN.

IT_FINAL-EBELP = IT_EKPO-EBELP.

IT_FINAL-MATNR = IT_EKPO-MATNR.

IT_FINAL-MENGE = IT_EKPO-MENGE.

IT_FINAL-MEINS = IT_EKPO-MEINS.

IT_FINAL-NETPR = IT_EKPO-NETPR.

IT_FINAL-NETWR = IT_EKPO-NETWR.

ON CHANGE OF IT_FINAL-EBELN.

LD_COLOR = 7.

CONCATENATE 'C' LD_COLOR '10' INTO IT_FINAL-LINE_COLOR.

ENDON.

APPEND IT_FINAL.

CLEAR IT_FINAL.

ENDLOOP.

ENDFORM. " GET_DETAILS

&----


*& Form GET_ALV

&----


  • text

----


FORM GET_ALV .

PERFORM GENERATE_FIELDCAT.

PERFORM GENERATE_LAYOUT.

PERFORM GENERATE_EVENTS.

PERFORM GENERATE_SORT.

PERFORM ALV_GRID_DISPLAY.

ENDFORM. " GET_ALV

&----


*& Form GENERATE_FIELDCAT

&----


  • Field catalog

----


FORM GENERATE_FIELDCAT .

WA_FIELDCAT-FIELDNAME = 'EBELN'.

WA_FIELDCAT-COL_POS = '1'.

WA_FIELDCAT-JUST = 'R'.

WA_FIELDCAT-SELTEXT_L = 'PO Number'.

WA_FIELDCAT-LOWERCASE = 'X'.

WA_FIELDCAT-DO_SUM = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'EBELP'.

WA_FIELDCAT-COL_POS = '2'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'Item Number'.

WA_FIELDCAT-LOWERCASE = 'X'.

WA_FIELDCAT-edit = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MATNR'.

WA_FIELDCAT-COL_POS = '3'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'Material Number'.

WA_FIELDCAT-LOWERCASE = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MENGE'.

WA_FIELDCAT-COL_POS = '4'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'PO Quantity'.

WA_FIELDCAT-LOWERCASE = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'MEINS'.

WA_FIELDCAT-COL_POS = '5'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'Order unit'.

WA_FIELDCAT-LOWERCASE = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'NETPR'.

WA_FIELDCAT-COL_POS = '6'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'Net price'.

WA_FIELDCAT-LOWERCASE = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

WA_FIELDCAT-FIELDNAME = 'NETWR'.

WA_FIELDCAT-COL_POS = '7'.

WA_FIELDCAT-JUST = 'C'.

WA_FIELDCAT-SELTEXT_L = 'Net order value'.

WA_FIELDCAT-LOWERCASE = 'X'.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

ENDFORM. " GENERATE_FIELDCAT

*&----


*& Form GENERATE_EVENTS

*&----


  • Generate Events

*----


FORM GENERATE_EVENTS .

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

IMPORTING

ET_EVENTS = IT_EVENT

EXCEPTIONS

LIST_TYPE_WRONG = 1

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.

IF NOT IT_EVENT[] IS INITIAL.

READ TABLE IT_EVENT INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.

IF SY-SUBRC = 0.

WA_EVENT-FORM = 'TOP_OF_PAGE'.

MODIFY IT_EVENT FROM WA_EVENT INDEX SY-TABIX.

ENDIF.

READ TABLE IT_EVENT INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.

IF SY-SUBRC = 0.

WA_EVENT-FORM = 'IT_USER_COMMAND'.

MODIFY IT_EVENT FROM WA_EVENT INDEX SY-TABIX.

ENDIF.

ENDIF.

ENDFORM. " GENERATE_EVENTS

*&----


*& Form TOP_OF_PAGE

*&----


  • TOP_OF_PAGE

*----


FORM TOP_OF_PAGE.

DATA : V_CONCATE(50) TYPE C.

DATA : V_SPACE(10) TYPE C.

CONCATENATE 'VIKRANTH' 'rajesh' INTO V_CONCATE.

WA_COMMENT-TYP = 'S'.

WA_COMMENT-KEY = 'USER :'.

WA_COMMENT-INFO = V_CONCATE.

APPEND WA_COMMENT TO IT_COMMENT.

WA_COMMENT-TYP = 'S'.

WA_COMMENT-KEY = 'DATE:'.

WA_COMMENT-INFO = SY-DATUM.

APPEND WA_COMMENT TO IT_COMMENT.

WA_COMMENT-TYP = 'S'.

WA_COMMENT-KEY = 'TIME:'.

WA_COMMENT-INFO = SY-TIMLO.

APPEND WA_COMMENT TO IT_COMMENT.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = it_comment.

CLEAR IT_COMMENT.

ENDFORM. "TOP_OF_PAGE

&----


*& Form ALV_GRID_DISPLAY

&----


  • Grid display

----


FORM ALV_GRID_DISPLAY .

PERFORM GRID_DISPLAY.

ENDFORM. " ALV_GRID_DISPLAY

&----


*& Form GENERATE_LAYOUT

&----


  • LAYOUT

----


FORM GENERATE_LAYOUT .

WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "OPTIMIZING FIELD WIDTH

WA_LAYOUT-ZEBRA = 'X'. "PUTTING ZEBRA COLORS

WA_LAYOUT-TOTALS_TEXT = 'Total'.

<b> WA_LAYOUT-SUBTOTALS_TEXT = 'SUB TOTAL'.</b>

WA_LAYOUT-INFO_FIELDNAME = 'LINE_COLOR'.

ENDFORM. " GENERATE_LAYOUT

&----


*& Form GENERATE_SORT

&----


  • SORT

----


FORM GENERATE_SORT .

WA_SORT-FIELDNAME = 'EBELN'.

WA_SORT-SPOS = '1'.

WA_SORT-UP = 'X'.

<b> WA_SORT-SUBTOT = 'X'.</b>

APPEND WA_SORT TO IT_SORT.

ENDFORM. " GENERATE_SORT

&----


*& Form GRID_DISPLAY

&----


  • GRID DISPLAY

----


FORM GRID_DISPLAY .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = 'IT_USER_COMMAND'

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

I_GRID_TITLE = 'Purchase Order Details'

  • I_GRID_SETTINGS = I_GRID_SETTINGS

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT

  • IT_EXCLUDING = IT_EXCLUDING

  • IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS

IT_SORT = IT_SORT

  • IT_FILTER = IT_FILTER

  • IS_SEL_HIDE = IS_SEL_HIDE

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT = IS_VARIANT

IT_EVENTS = IT_EVENT

  • IT_EVENT_EXIT = IT_EVENT_EXIT

  • IS_PRINT = IS_PRINT

  • IS_REPREP_ID = IS_REPREP_ID

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS = IT_ALV_GRAPHICS

  • IT_HYPERLINK = IT_HYPERLINK

  • IT_ADD_FIELDCAT = IT_ADD_FIELDCAT

  • IT_EXCEPT_QINFO = IT_EXCEPT_QINFO

  • IR_SALV_FULLSCREEN_ADAPTER = IR_SALV_FULLSCREEN_ADAPTER

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER = E_EXIT_CAUSED_BY_CALLER

  • ES_EXIT_CAUSED_BY_USER = ES_EXIT_CAUSED_BY_USER

TABLES

T_OUTTAB = IT_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

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.

ENDFORM. " GRID_DISPLAY

Thanks

Vikranth khimavath

Message was edited by:

Khimavath Vikranth