You are on page 1of 10

Report : how to male an interactive alv report with first

alv display employee detail and second by clicking of
employee id , there salary details.

*&---------------------------------------------------------------------*
*& Report ZINTERACTIVE_ALV
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZINTERACTIVE_ALV_BY_ME.

*----------------------------------------------------------------------*
*-& This is an Interactive ALV report, where on line slection we can see
*& the secondry list
*& *
*&---------------------------------------------------------------------*

TYPE-POOLS: SLIS.

TABLES: ZEMPLOYEE, ZSALARY.

DATA: BEGIN OF ITAB_EMPLOY OCCURS 0,

EMPID TYPE ZEMPLOYEE-EMPID,
EMPNAME TYPE ZEMPLOYEE-EMPNAME,

AGE TYPE ZEMPLOYEE-AGE,
JOB TYPE ZEMPLOYEE-JOB,

END OF ITAB_EMPLOY.

DATA: WA_EMPLOY TYPE ZEMPLOYEE.

DATA: BEGIN OF ITAB_SALARY OCCURS 0,

EMPID TYPE ZSALARY-EMPID,
EMPNAME TYPE ZSALARY-EMPNAME,
BASIC TYPE ZSALARY-BASIC,
HRA TYPE ZSALARY-HRA,
DA TYPE ZSALARY-DA,
OT TYPE ZSALARY-OT,

END OF ITAB_SALARY.
DATA: WA_SALARY TYPE ZSALARY.

DATA: V_REPID LIKE SY-REPID.
DATA: ITAB_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA: ITAB_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.

DATA: ITAB_EVENTS TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT.

DATA: ITAB_LAYOUT TYPE SLIS_LAYOUT_ALV.

DATA: I_TITLE_EMPLOY TYPE LVC_TITLE VALUE 'EMPLOYEE LIST'.
DATA: I_TITLE_SALARY TYPE LVC_TITLE VALUE 'EMPLOYEE SALARY LIST'.

DATA: POS TYPE I VALUE 0,
INFO(40),
INFO1(50).

DATA: ID LIKE ZEMPLOYEE-EMPID.
DATA: FIELDNAME TYPE STRING,
VALUENAME TYPE STRING.
*--------------------------------------------------------------------*
*--------------------------FOR ZEMPLOYEE-----------------------------*
*--------------------------------------------------------------------*

INITIALIZATION.
V_REPID = SY-REPID.
PERFORM BUILD_FIELDCATLOG. "FIELDCATLOG FOR TABLE ZEMPLOYEE"
perform layout.
PERFORM EVENT_CALL. "EVENT FOR ZEMPLOYEE TABLE"
PERFORM POPULATE_EVENT. "HERE WE READ LINE FROM ZEMPLOYEE "

START-OF-SELECTION.
PERFORM DATA_RETRIEVAL. "DATA RETRIEVING FROM ZEMPLOYEE"

PERFORM DISPLAY_ALV_REPORT. "DISPLAY ALV REPORT"

*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG.

CLEAR ITAB_FIELDCAT.
CLEAR WA_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_EMPLOY'.
WA_FIELDCAT-FIELDNAME = 'EMPID'.
WA_FIELDCAT-SELTEXT_M = 'ID'.
WA_FIELDCAT-HOTSPOT = 'X'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_EMPLOY'.
WA_FIELDCAT-FIELDNAME = 'EMPNAME'.
WA_FIELDCAT-SELTEXT_M = 'NAME'.
WA_FIELDCAT-HOTSPOT = ''.

APPEND WA_FIELDCAT TO ITAB_FIELDCAT.
CLEAR WA_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_EMPLOY'.
WA_FIELDCAT-FIELDNAME = 'AGE'.
WA_FIELDCAT-SELTEXT_M = 'AGE'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.
CLEAR WA_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_EMPLOY'.
WA_FIELDCAT-FIELDNAME = 'JOB'.
WA_FIELDCAT-SELTEXT_M = 'JOB OCCUPATION'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.
CLEAR WA_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG

*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM LAYOUT.

ITAB_LAYOUT-ZEBRA = 'X'.
ITAB_LAYOUT-BOX_FIELDNAME = 'EMPID'.
ITAB_LAYOUT-BOX_FIELDNAME = 'EMPNAME'.
ITAB_LAYOUT-GROUP_BUTTONS = 'X'.
* ITAB_LAYOUT-hotspot_fieldname = 'ITAB_EMPLOY-EMPID'.

* itab_layout-def_status = 'A'. "(1) type c, " default status space or 'A'
* ITAB_LAYOUT-item_text = 'MENU-BAR'. " Text for item button
* ITAB_LAYOUT-countfname = 'D'.

*ITAB_LAYOUT-NUMC_SUM = 'X'.

*
ENDFORM. "LAYOUT

*&--------------------------------------------------------------------*
*& Form EVENT_CALL
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE =0
IMPORTING
ET_EVENTS = ITAB_EVENTS
* 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.
ENDFORM. "EVENT_CALL

*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT.

READ TABLE ITAB_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY ITAB_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.
IF ITAB_EMPLOY-EMPID NE ''.
READ TABLE ITAB_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND'.
MODIFY ITAB_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-NAME.
ENDIF.
ENDIF.
ENDFORM. "POPULATE_EVENT

*&--------------------------------------------------------------------*
*& Form data_retrieval
*&--------------------------------------------------------------------*
* retreiving values from the database table ZEMPLOYEE
*---------------------------------------------------------------------*
FORM DATA_RETRIEVAL.

SELECT EMPID EMPNAME AGE JOB FROM ZEMPLOYEE INTO TABLE ITAB_EMPLOY.

ENDFORM. "data_retrieval
*

*&--------------------------------------------------------------------*
*& Form display_alv_report
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
* I_CALLBACK_PF_STATUS_SET =''
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = I_TITLE_EMPLOY
* I_GRID_SETTINGS =
IS_LAYOUT = itab_LAYOUT
IT_FIELDCAT = ITAB_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT = ITAB_EMPLOY
* IT_FILTER =
* IS_SEL_HIDE = 'C'
* i_default = 'ZLAY1'
* I_SAVE = 'A'
* is_variant = i_variant
IT_EVENTS = ITAB_EVENTS
TABLES
T_OUTTAB = ITAB_EMPLOY
* 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 TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.

CLEAR ITAB_HEADER.
* CLEAR WA_HEADER.

POS = POS + 1.
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'EMPLOYEE DETAIL'.
APPEND WA_HEADER TO ITAB_HEADER.

POS = POS + 1.
WA_HEADER-TYP = 'S'.
CONCATENATE 'SYSTEM DATE :- ' SY-DATUM INTO INFO1.
WA_HEADER-INFO = INFO1.
APPEND WA_HEADER TO ITAB_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ITAB_HEADER
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.

ENDFORM. "TOP_OF_PAGE

*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*&--------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
*
* -->IT IS REQUIRE FOR DISPLAY RESULTING TABLE
* -->RS_SLEFIEL INDIACTE TO SELECT FIELD
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD. " INDICATE FOR
CURSUR POSITION "
CASE R_UCOMM.
WHEN '&IC1'. "Cosntants: c_Alv_Double_Click type syucomm
value '&IC1'." "FUNCTION CODE"
READ TABLE ITAB_EMPLOY INTO WA_EMPLOY INDEX RS_SELFIELD-TABINDEX.
"TABINDEX = SYTABIX "

*BREAK-POINT.
* GET CURSOR FIELD FIELDNAME VALUE VALUENAME.
*
* IF FIELDNAME = 'ITAB_EMPLOY-EMPID'.
PERFORM BUILD_FIELDCATLOG_SALARY.
perform layout_salary.
PERFORM EVENT_CALL_SALARY.
PERFORM POPULATE_EVENT_SALARY.
PERFORM DATA_RETRIEVAL_SALARY.
* PERFORM FIELDCATLOG_SALARY.
PERFORM DISPLAY_ALV_SALARY.
* ENDIF.
ENDCASE.
ENDFORM. "user_command

*------------------END PORTION OF ZEMPLOYEE-----------*
*---------------------------------------------------------------------*

*-------------------ZSALARY TABLE ----------------------*

*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG_SALARY
*&--------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG_SALARY.

CLEAR ITAB_FIELDCAT.
CLEAR WA_FIELDCAT.
POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'EMPID'.
WA_FIELDCAT-SELTEXT_M = 'ID'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'EMPNAME'.
WA_FIELDCAT-SELTEXT_M = 'NAME'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'BASIC'.
WA_FIELDCAT-SELTEXT_M = 'BASIC SALARY(Rs)'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'HRA'.
WA_FIELDCAT-SELTEXT_M = 'HRA(Rs)'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'DA'.
WA_FIELDCAT-SELTEXT_M = 'DAILY ALLOWENCE(Rs)'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

POS = POS + 1.
WA_FIELDCAT-TABNAME = 'ITAB_SALARY'.
WA_FIELDCAT-FIELDNAME = 'OT'.
WA_FIELDCAT-SELTEXT_M = 'OVER TIME(Rs)'.
APPEND WA_FIELDCAT TO ITAB_FIELDCAT.

ENDFORM. "BUILD_FIELDCATLOG_SALARY

FORM LAYOUT_salary.

ITAB_LAYOUT-ZEBRA = 'X'.
ITAB_LAYOUT-BOX_FIELDNAME = 'EMPID'.
ITAB_LAYOUT-BOX_FIELDNAME = 'EMPNAME'.
ITAB_LAYOUT-GROUP_BUTTONS = 'X'.
*ITAB_LAYOUT-NUMC_SUM = 'X'.

*
ENDFORM. "LAYOUT

*&--------------------------------------------------------------------*
*& Form event_call_SALARY
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table ITAB_events
*---------------------------------------------------------------------*
FORM EVENT_CALL_SALARY.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE =0
IMPORTING
ET_EVENTS = ITAB_EVENTS
* 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.
ENDFORM. "event_call_SALARY

*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT_SALARY
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT_SALARY.
READ TABLE ITAB_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY ITAB_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.

ENDIF.

ENDFORM. "POPULATE_EVENT

*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM F_TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ITAB_HEADER
* I_logo = ''
* I_END_OF_LIST_GRID =
.

ENDFORM. "TOP_OF_PAGE

*---------------------------------------------------------------------*

*retreiving values from the database table ZSALARY

FORM DATA_RETRIEVAL_SALARY.
*BREAK-POINT.
SELECT EMPID EMPNAME BASIC HRA DA OT FROM ZSALARY INTO TABLE ITAB_SALARY WHERE
EMPID = wa_EMPLOY-EMPID.

ENDFORM. "DATA_RETRIEVAL_SALARY

*&---------------------------------------------------------------------*
*& Form BUILD_LISTHEADER_SALARY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->ITAB_LISTHEADER text
*----------------------------------------------------------------------*
FORM BUILD_LISTHEADER_SALARY USING ITAB_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA: HLINE1 TYPE SLIS_LISTHEADER.
HLINE1-TYP = 'H'.
HLINE1-INFO = 'CHECKING PGM'.
ENDFORM. "BUILD_LISTHEADER_SALARY

*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_SALARY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV_SALARY.
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 = 'F_USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = '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_TITLE_SALARY
* I_GRID_SETTINGS =
IS_LAYOUT = itab_layout
IT_FIELDCAT = ITAB_FIELDCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT =
* I_SAVE = 'A'
* IS_VARIANT =
IT_EVENTS = ITAB_EVENTS
TABLES
T_OUTTAB = ITAB_SALARY
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_SALARY