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: 

alv report

Former Member
0 Kudos
166

Hi,

Can anyone send a simple alv report program?

Regards,

Hema

8 REPLIES 8

Former Member
0 Kudos
132

hi

see this example :

PROGRAM TEST.

DATA: OK_CODE LIKE SY-UCOMM,

GT_SFLIGHT TYPE TABLE OF SFLIGHT,

G_CONTAINER TYPE SCRFNAME VALUE 'BCALV_GRID_DEMO_0100_CONT1',

GRID1 TYPE REF TO CL_GUI_ALV_GRID,

G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

----


  • MAIN *

----


SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT.

CALL SCREEN 100.

----


  • MODULE PBO OUTPUT *

----


MODULE PBO OUTPUT.

SET PF-STATUS 'MAIN100'.

IF G_CUSTOM_CONTAINER IS INITIAL.

CREATE OBJECT G_CUSTOM_CONTAINER

EXPORTING CONTAINER_NAME = G_CONTAINER.

CREATE OBJECT GRID1

EXPORTING I_PARENT = G_CUSTOM_CONTAINER.

CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'

CHANGING IT_OUTTAB = GT_SFLIGHT.

ENDIF.

ENDMODULE.

----


  • MODULE PAI INPUT *

----


MODULE PAI INPUT.

  • to react on oi_custom_events:

call method cl_gui_cfw=>dispatch.

CASE OK_CODE.

WHEN 'EXIT'.

PERFORM EXIT_PROGRAM.

WHEN OTHERS.

  • do nothing

ENDCASE.

CLEAR OK_CODE.

ENDMODULE.

----


  • FORM EXIT_PROGRAM *

----


FORM EXIT_PROGRAM.

  • CALL METHOD G_CUSTOM_CONTAINER->FREE.

  • CALL METHOD CL_GUI_CFW=>FLUSH.

LEAVE PROGRAM.

ENDFORM.

Regards,

Prasant

*reward if useful

Former Member
0 Kudos
132

REPORT ZALV .

TABLES : VBAP.

TYPE-POOLS : SLIS.

DATA : BEGIN OF ITAB OCCURS 0,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

ERNAM LIKE VBAP-ERNAM,

ERDAT LIKE VBAP-ERDAT.

DATA : END OF ITAB.

DATA : IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV.

SELECT-OPTIONS : S_VBELN FOR VBAP-VBELN.

START-OF-SELECTION.

SELECT VBELN

POSNR

ERNAM

ERDAT

FROM VBAP

INTO CORRESPONDING FIELDS OF TABLE ITAB

WHERE VBELN IN S_VBELN.

PERFORM MODIFY_CAT.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

  • I_CALLBACK_PROGRAM = ' '

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_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 =

  • I_GRID_SETTINGS =

IS_LAYOUT = WA_LAYOUT

IT_FIELDCAT = IT_FIELDCAT

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = ITAB

  • 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.

*END-OF-SELECTION.

*LOOP AT ITAB.

*WRITE : / ITAB-VBELN,

  • ITAB-POSNR,

  • ITAB-ERNAM,

  • ITAB-ERDAT.

*ENDLOOP.

&----


*& Form MODIFY_CAT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM MODIFY_CAT .

WA_FIELDCAT-TABNAME = 'ITAB'..

WA_FIELDCAT-FIELDNAME = 'VBELN'.

WA_FIELDCAT-SELTEXT_L = 'SALES DOC'.

WA_FIELDCAT-COL_POS = 1.

WA_FIELDCAT-OUTPUTLEN = 10.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'ITAB'..

WA_FIELDCAT-FIELDNAME = 'POSNR'.

WA_FIELDCAT-SELTEXT_L = 'ITEM'.

WA_FIELDCAT-COL_POS = 2.

WA_FIELDCAT-OUTPUTLEN = 6.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'ITAB'..

WA_FIELDCAT-FIELDNAME = 'ERNAM'.

WA_FIELDCAT-SELTEXT_L = 'PERSON NAME'.

WA_FIELDCAT-COL_POS = 3.

WA_FIELDCAT-OUTPUTLEN = 12.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'ITAB'..

WA_FIELDCAT-FIELDNAME = 'ERDAT'.

WA_FIELDCAT-SELTEXT_L = 'DATE'.

WA_FIELDCAT-COL_POS = 4.

WA_FIELDCAT-OUTPUTLEN = 8.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

WA_LAYOUT-ZEBRA = 'X'.

*WA_LAYOUT-INFO_FIELDNAME = 'COLOR'.

ENDFORM. " MODIFY_CAT

Regards

vasu

0 Kudos
132

*&---------------------------------------------------------------------*
*& Report  ZFIRSTMETHOD                                            *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZFIRSTMETHOD                        .

TABLES: SFLIGHT.
*--------------------------------------------------------------------
* G L O B A L   I N T E R N  A L   T A B L E S
*--------------------------------------------------------------------
DATA: GI_SFLIGHT TYPE STANDARD TABLE OF SFLIGHT.

*--------------------------------------------------------------------
* G L O B A L   D A T A
*--------------------------------------------------------------------
DATA: OKCODE LIKE SY-UCOMM,
      G_WA_SFLIGHT LIKE SFLIGHT.

* Declare reference variables to the ALV grid and the container
DATA:
  GO_GRID             TYPE REF TO CL_GUI_ALV_GRID,
  GO_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------
START-OF-SELECTION.
  SET SCREEN '0100'.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  CASE OKCODE.
    WHEN 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* Create objects
  IF GO_CUSTOM_CONTAINER IS INITIAL.
    CREATE OBJECT GO_CUSTOM_CONTAINER
      EXPORTING CONTAINER_NAME = 'ALV_CONTAINER'.
    CREATE OBJECT GO_GRID
      EXPORTING
        I_PARENT = GO_CUSTOM_CONTAINER.
    PERFORM LOAD_DATA_INTO_GRID.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Form  load_data_into_grid
*&---------------------------------------------------------------------*
FORM LOAD_DATA_INTO_GRID.

* Read data from table SFLIGHT
  SELECT *
    FROM SFLIGHT
    INTO TABLE GI_SFLIGHT.

* Load data into the grid and display them
  CALL METHOD GO_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      I_STRUCTURE_NAME = 'SFLIGHT'
    CHANGING
      IT_OUTTAB        = GI_SFLIGHT.
ENDFORM.                    " load_data_into_grid

0 Kudos
132

*&---------------------------------------------------------------------*
*& Report  ZSECONDMETHOD                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZSECONDMETHOD                       .


DATA: ITAB TYPE SFLIGHT OCCURS 0,

TABNAME LIKE DD02L-TABNAME VALUE 'sflight'.

SELECT * FROM SFLIGHT INTO TABLE ITAB.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                = ' '
*   I_BUFFER_ACTIVE                   = ' '
   I_CALLBACK_PROGRAM                = 'SY-REPID'
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  =  'sflight' "tabname
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT                         =
*   IT_FIELDCAT                       =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
*   IT_SORT                           =
*   IT_FILTER                         =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT                          =
*   IS_REPREP_ID                      =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   IT_ALV_GRAPHICS                   =
*   IT_HYPERLINK                      =
*   IT_ADD_FIELDCAT                   =
*   IT_EXCEPT_QINFO                   =
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
 "IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB                          = ITAB
* 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.

0 Kudos
132

Hi,

BCALV_FULLSCREEN_DEMO ALV Demo

BCALV_FULLSCREEN_DEMO_CLASSIC

BCALV_GRID_DEMO

regards

ket

Former Member
0 Kudos
132

Hello,

ALV Demo programs

<b>BCALV_DEMO_HTML

BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode

BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode

BCALV_GRID_DEMO Simple ALV Control Call Demo Program

BCALV_TREE_DEMO Demo for ALV tree control

BCALV_TREE_SIMPLE_DEMO

BC_ALV_DEMO_HTML_D0100</b>

Reward if helpful,

Regards,

LIJO

Former Member
0 Kudos
132

Hi refer this,

REPORT ZRS_SIMPLE_ALV.

tables:mara.

data itab like mara occurs 0 with header line.

select * from mara into table itab up to 25 rows.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_structure_name = 'MARA'

i_grid_title = 'GENERAL MATERIAL DATA'

  • i_sort = 'X'

  • i_fieldname = 'matnr'

  • i_grid_settings = 'X'

tables

t_outtab = itab.

This report takes data from MARA table.

Reward if useful.

Former Member
0 Kudos
132

hi

good

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.

*

----


*

  • yes, it is that simple. Go ahead and try yourself!

*

thanks

mrutyun^