Skip to Content
author's profile photo
Former Member

alv report

hi,

can any one give me an example of simple alv report with little explanation.

i do always give points for the good answers

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Sep 29, 2007 at 05:39 AM

    This is a simple ALV report example. code is self explanatory. Please let me know what questions do you have.

    see this example.

    REPORT ZBHALV_LIST_GRID2.

    TABLES:MARA.

    DATA:BEGIN OF ITAB OCCURS 0,

    MATNR LIKE MARA-MATNR,

    ERSDA LIKE MARA-ERSDA,

    ERNAM LIKE MARA-ERNAM,

    MBRSH LIKE MARA-MBRSH,

    END OF ITAB.

    TYPE-POOLS:SLIS.

    DATA:FIELDCAT1 TYPE SLIS_T_FIELDCAT_ALV.

    DATA:EVE TYPE SLIS_T_EVENT WITH HEADER LINE.

    DATA:HEAD TYPE SLIS_T_LISTHEADER WITH HEADER LINE.

    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

    EXPORTING

    I_PROGRAM_NAME = SY-REPID

    I_INTERNAL_TABNAME = 'ITAB'

    • I_STRUCTURE_NAME = 'ITAB'

    • I_CLIENT_NEVER_DISPLAY = 'X'

    I_INCLNAME = SY-REPID

    • I_BYPASSING_BUFFER =

    • I_BUFFER_ACTIVE =

    CHANGING

    CT_FIELDCAT = FIELDCAT1.

    EVE-NAME = 'TOP_OF_PAGE'.

    EVE-FORM = 'HEADER'.

    APPEND EVE.

    EVE-NAME = 'END_OF_LIST'.

    EVE-FORM = 'LISTEND'.

    APPEND EVE.

    EVE-NAME = 'TOP_OF_LIST'.

    EVE-FORM = 'LISTTOP'.

    APPEND EVE.

    SELECT * FROM MARA INTO CORRESPONDING FIELDS OF TABLE ITAB UP TO 20 ROWS.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = SY-REPID

    • I_STRUCTURE_NAME = 'ITAB'

    IT_FIELDCAT = FIELDCAT1

    I_DEFAULT = 'X'

    I_SAVE = 'A'

    IT_EVENTS = EVE[]

    TABLES

    T_OUTTAB = ITAB.

    FORM HEADER.

    REFRESH HEAD.

    HEAD-TYP = 'H'.

    HEAD-INFO = 'GENERAL MATERIAL DATA'.

    APPEND HEAD.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = HEAD[].

    ENDFORM.

    FORM LISTEND.

    REFRESH HEAD.

    HEAD-TYP = 'H'.

    HEAD-INFO = 'END OF THE LIST'.

    APPEND HEAD.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = HEAD[].

    ENDFORM.

    FORM LISTTOP.

    REFRESH HEAD.

    HEAD-TYP = 'H'.

    HEAD-INFO = 'TOP OF THE LIST'.

    APPEND HEAD.

    CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

    EXPORTING

    IT_LIST_COMMENTARY = HEAD[].

    ENDFORM.

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

    this is simple alv grid with out fieldcat

    REPORT ZBHALV_LIST_GRID1.

    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'

    TABLES

    T_OUTTAB = ITAB.

    If you see documentation of function module REUSE_ALV_LIST_DISPLAY, it gives details about all parameters in detail.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 29, 2007 at 05:55 AM

    hi

    go through this simple alv

    &----


    *& Report ZPRG8 *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT ZPRG8 .

    TABLES: LFA1, EKKO, EKPO.

    SELECT-OPTIONS: S_LIFNR FOR LFA1-LIFNR.

    DATA: BEGIN OF ITAB OCCURS 0,

    LIFNR LIKE LFA1-LIFNR,

    NAME1 LIKE LFA1-NAME1,

    END OF ITAB.

    DATA: BEGIN OF JTAB OCCURS 0,

    EBELN LIKE EKKO-EBELN,

    AEDAT LIKE EKKO-AEDAT,

    END OF JTAB.

    DATA: BEGIN OF KTAB OCCURS 0,

    EBELP LIKE EKPO-EBELP,

    MATNR LIKE EKPO-MATNR,

    END OF KTAB.

    TYPE-POOLS:SLIS.

    DATA: REPID LIKE SY-REPID,

    F_LFA11 TYPE SLIS_T_FIELDCAT_ALV,

    F_LFA1 TYPE SLIS_FIELDCAT_ALV,

    F_EKKO1 TYPE SLIS_T_FIELDCAT_ALV,

    F_EKKO TYPE SLIS_FIELDCAT_ALV,

    F_EKPO1 TYPE SLIS_T_FIELDCAT_ALV,

    F_EKPO TYPE SLIS_FIELDCAT_ALV,

    I_EVENTS TYPE SLIS_T_EVENT,

    S_EVENTS TYPE SLIS_ALV_EVENT.

    REPID = SY-REPID.

    PERFORM COL_HEAD.

    START-OF-SELECTION.

    SELECT LIFNR NAME1 FROM LFA1 INTO TABLE ITAB WHERE LIFNR IN S_LIFNR.

    CALL FUNCTION 'REUSE_ALV_LIST_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_STRUCTURE_NAME =

    • IS_LAYOUT =

    IT_FIELDCAT = F_LFA11

    • IT_EXCLUDING =

    • IT_SPECIAL_GROUPS =

    • IT_SORT =

    • IT_FILTER =

    • IS_SEL_HIDE =

    • I_DEFAULT = 'X'

    • I_SAVE = ' '

    • IS_VARIANT =

    IT_EVENTS = I_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

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

    FORM COL_HEAD.

    F_LFA1-FIELDNAME = 'LIFNR'.

    *F_LFA1-TABNAME = 'ITAB'.

    F_LFA1-REF_TABNAME = 'LFA1'.

    F_LFA1-REF_FIELDNAME = 'LIFNR'.

    APPEND F_LFA1 TO F_LFA11.

    F_LFA1-FIELDNAME = 'NAME1'.

    *F_LFA1-TABNAME = 'ITAB'.

    F_LFA1-REF_TABNAME = 'LFA1'.

    F_LFA1-REF_FIELDNAME = 'NAME1'.

    APPEND F_LFA1 TO F_LFA11.

    F_EKKO-FIELDNAME = 'EBELN'.

    *F_EKKO-TABNAME = 'JTAB'.

    F_EKKO-REF_TABNAME = 'EKKO'.

    F_EKKO-REF_FIELDNAME = 'EBELN'.

    APPEND F_EKKO TO F_EKKO1.

    F_EKKO-FIELDNAME = 'AEDAT'.

    *F_EKKO-TABNAME = 'JTAB'.

    F_EKKO-REF_TABNAME = 'EKKO'.

    F_EKKO-REF_FIELDNAME = 'AEDAT'.

    APPEND F_EKKO TO F_EKKO1.

    F_EKPO-FIELDNAME = 'EBELP'.

    *F_EKPO-TABNAME = 'KTAB'.

    F_EKPO-REF_TABNAME = 'EKPO'.

    F_EKPO-REF_FIELDNAME = 'EBELP'.

    APPEND F_EKPO TO F_EKPO1.

    F_EKPO-FIELDNAME = 'MATNR'.

    *F_EKPO-TABNAME = 'KTAB'.

    F_EKPO-REF_TABNAME = 'EKPO'.

    F_EKPO-REF_FIELDNAME = 'MATNR'.

    APPEND F_EKPO TO F_EKPO1.

    S_EVENTS-NAME = 'USER_COMMAND'.

    S_EVENTS-FORM = 'VAL'.

    APPEND S_EVENTS TO I_EVENTS.

    ENDFORM.

    FORM VAL USING USER_COMMAND LIKE SY-UCOMM SEL TYPE SLIS_SELFIELD.

    DATA: V_LIFNR(10) TYPE N,

    V_EBELN(10) TYPE N,

    V_MATNR(10) TYPE C.

    IF SEL-FIELDNAME = 'LIFNR'.

    V_LIFNR = SEL-VALUE.

    SELECT EBELN AEDAT FROM EKKO INTO TABLE JTAB WHERE LIFNR = V_LIFNR.

    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING

    I_CALLBACK_PROGRAM = REPID

    IT_FIELDCAT = F_EKKO1

    IT_EVENTS = I_EVENTS

    TABLES

    T_OUTTAB = JTAB.

    ENDIF.

    IF SEL-FIELDNAME = 'EBELN'.

    V_EBELN = SEL-VALUE.

    SELECT EBELP MATNR FROM EKPO INTO TABLE KTAB WHERE EBELN = V_EBELN.

    CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'

    EXPORTING

    I_TITLE = 'ITEM DETAILS'

    I_SCREEN_START_COLUMN = 10

    I_SCREEN_START_LINE = 10

    I_SCREEN_END_COLUMN = 36

    I_SCREEN_END_LINE = 16

    I_TABNAME = 'EKPO'

    IT_FIELDCAT = F_EKPO1

    I_CALLBACK_PROGRAM = REPID

    • I_CALLBACK_USER_COMMAND =

    • IS_PRIVATE =

    IMPORTING

    ES_SELFIELD = SEL

    • E_EXIT =

    TABLES

    T_OUTTAB = KTAB.

    ENDIF.

    IF SEL-FIELDNAME = 'MATNR'.

    V_MATNR = SEL-VALUE.

    SET PARAMETER ID 'MAT' FIELD V_MATNR.

    CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.

    ENDIF.

    ENDFORM.

    reward points if u find useful

    regards

    Nagesh.Paruchuri

    Add comment
    10|10000 characters needed characters exceeded