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

Drill down ALV

Former Member
0 Likes
1,795

Hi There,

Could someone tell me what are the FM's to be used for drill down ALV's.

regards,

kavitha

4 REPLIES 4
Read only

Former Member
0 Likes
994

Hi,

Reprots

http://www.sapgenie.com/abap/reports.htm

http://www.allsaplinks.com/material.html

http://www.sapdevelopment.co.uk/reporting/reportinghome.htm

ALV

1. Please give me general info on ALV.

http://www.sapfans.com/forums/viewtopic.php?t=58286

http://www.sapfans.com/forums/viewtopic.php?t=76490

http://www.sapfans.com/forums/viewtopic.php?t=20591

http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.

2. How do I program double click in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=11601

http://www.sapfans.com/forums/viewtopic.php?t=23010

3. How do I add subtotals (I have problem to add them)...

http://www.sapfans.com/forums/viewtopic.php?t=20386

http://www.sapfans.com/forums/viewtopic.php?t=85191

http://www.sapfans.com/forums/viewtopic.php?t=88401

http://www.sapfans.com/forums/viewtopic.php?t=17335

4. How to add list heading like top-of-page in ABAP lists?

http://www.sapfans.com/forums/viewtopic.php?t=58775

http://www.sapfans.com/forums/viewtopic.php?t=60550

http://www.sapfans.com/forums/viewtopic.php?t=16629

5. How to print page number / total number of pages X/XX in ALV? http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)

6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.

http://www.sapfans.com/forums/viewtopic.php?t=64320

http://www.sapfans.com/forums/viewtopic.php?t=44477

7. How can I set the cell color in ALV? http://www.sapfans.com/forums/viewtopic.php?t=52107

8. How do I print a logo/graphics in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=81149

http://www.sapfans.com/forums/viewtopic.php?t=35498

http://www.sapfans.com/forums/viewtopic.php?t=5013

9. How do I create and use input-enabled fields in ALV?

http://www.sapfans.com/forums/viewtopic.php?t=84933

http://www.sapfans.com/forums/viewtopic.php?t=69878

10. How can I use ALV for reports that are going to be run in background?

http://www.sapfans.com/forums/viewtopic.php?t=83243

http://www.sapfans.com/forums/viewtopic.php?t=19224

11. How can I display an icon in ALV? (Common requirement is traffic light icon).

http://www.sapfans.com/forums/viewtopic.php?t=79424

http://www.sapfans.com/forums/viewtopic.php?t=24512

12. How can I display a checkbox in ALV? http://www.sapfans.com/forums/viewtopic.php?t=88376

http://www.sapfans.com/forums/viewtopic.php?t=40968

http://www.sapfans.com/forums/viewtopic.php?t=6919

Check this for basic concepts of OOPS

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Tabstrip

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Editable ALV

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20...

Tree

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_usrint.htm

General Tutorial for OOPS

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/an%20ea...

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

http://www.sap-img.com/abap/what-is-alv-programming.htm

http://www.sap-img.com/abap-function.htm

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

http://www.sapdevelopment.co.uk/reporting/alv/alvtree%5Calvtree_basic.htm

http://esnips.com/doc/ad20dca9-6182-4903-8d8f-96a66dc8590c/ALV.pdf

http://www.sap-img.com/abap-function.htm

Read only

Former Member
0 Likes
994

Hi

Please go thru this link. This should help you to build Interactive ALV report.

You need to handle Double Click on At user command event. '&IC1' is the okcode for Double click. Please handle this in your program. I have given you links earlier to see events in ALV report. They are also using Function modules.

Here is a sample code -

1.) Declare user_command in events:

DATA: ls_event type slis_alv_event.

move 'USER_COMMAND' to ls_event-form.

append ls_event to gt_events.

2.) Getting cell value ." within the form USER_COMMAND:

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

  • Check function code

CASE R_UCOMM.

WHEN '&IC1'. "--> check your own sy-ucomm once you double click the line item

  • Check field clicked on within ALVgrid report

IF RS_SELFIELD-FIELDNAME = 'EBELN'.

  • Read data table, using index of row user clicked on

READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.

ENDIF.

ENDCASE.

ENDFORM.

Read only

Former Member
0 Likes
994

Hi Kavitha,

This is kiran Kumar.G.(working in SAP).Generally we use only 3 FUNCTION MODULES used to display output.I will mention these function modules below check it once ok.

if u r satisfy with my answer give me REWARD POINTS.

HAVE A NICE DAY..

FUNCTION MODULES:

1.REUSE_ALV_LIST_DISPLAY

2.REUSE_ALV_GRID_DISPLAY

3.REUSE_ALV_BLOCK_LIST_DISPLAY

Read only

Former Member
0 Likes
994

Hi

<b>drill down alv </b>

TABLES: vbak .
TABLES: mara .

TYPES: BEGIN OF tp_vbak ,
vbeln TYPE vbak-vbeln,
erdat TYPE vbak-erdat,
erzet TYPE vbak-erzet,
ernam TYPE vbak-ernam,
vbtyp TYPE vbak-vbtyp,
trvog TYPE vbak-trvog,
auart TYPE vbak-auart,
lifsk TYPE vbak-lifsk,
faksk TYPE vbak-faksk,
waerk TYPE vbak-waerk,
vkorg TYPE vbak-vkorg,
kunnr TYPE vbak-kunnr,
vgbel TYPE vbak-vgbel,
vgtyp TYPE vbak-vgtyp,
END OF tp_vbak .


TYPES: BEGIN OF tp_mara ,
matnr TYPE mara-matnr,
END OF tp_mara .

TYPES: BEGIN OF tp_alv1_data.
INCLUDE TYPE tp_vbak .
TYPES: END OF tp_alv1_data.

TYPES: BEGIN OF tp_alv2_data.
INCLUDE TYPE tp_mara .
TYPES: END OF tp_alv2_data.

TYPE-POOLS: slis.


DATA: gt_vbak TYPE STANDARD TABLE OF tp_vbak WITH HEADER LINE.
DATA: gt_mara TYPE STANDARD TABLE OF tp_mara WITH HEADER LINE.
DATA: gs_variant LIKE disvariant.

DATA: gt_alv1_data TYPE STANDARD TABLE OF tp_alv1_data WITH HEADER LINE.

DATA: gt_alv2_data TYPE STANDARD TABLE OF tp_alv2_data WITH HEADER LINE.

*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* BLOCK b0 *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b0 WITH FRAME.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. "<field not defined?>
PARAMETERS: p_matnr LIKE mara-matnr. "<field not defined?>
SELECTION-SCREEN END OF BLOCK b0.

*----------------------------------------------------------------------*
* BLOCK bvar *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bvar WITH FRAME.
PARAMETERS: p_vari LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK bvar.

*----------------------------------------------------------------------*
* BLOCK bbox *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bbox WITH FRAME.
PARAMETERS: p_box_up RADIOBUTTON GROUP b1,
p_box_do RADIOBUTTON GROUP b1 DEFAULT 'X',
p_box_no RADIOBUTTON GROUP b1.
SELECTION-SCREEN END OF BLOCK bbox.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN ON P_VARI *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_vari.
PERFORM alv_variant_existence USING p_vari
CHANGING gs_variant.

*---------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE REQUEST FOR P_VARI *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
PERFORM alv_variant_f4 CHANGING p_vari
gs_variant.

*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.

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

PERFORM authority_check.

PERFORM get_control_data.
PERFORM get_transaction_data.
PERFORM process_transaction_data.

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

PERFORM output_data.

*----------------------------------------------------------------------*
* F O R M S *
*----------------------------------------------------------------------*


*---------------------------------------------------------------------*
* FORM AUTHORITY_CHECK *
*---------------------------------------------------------------------*
* Perform authority checks for the report *
*---------------------------------------------------------------------*
FORM authority_check.

* !!! Note: authorisation checks are application-dependent.
* !!! Some common cases are listed below - please select one of them
* !!! or add new authorisation checks.
* !!! If the report is creating batch input session or using LDB
* !!! it may be sufficient to use automatic SAP auth.checks.

* Authorisation for displaying documents in a single company code
* ---------------------------------------------------------------
* authority-check object 'F_BKPF_BUK'
* id 'BUKRS' field p_bukrs
* id 'ACTVT' field '03'.
* if sy-subrc <> 0.
* message e001(z9) with 'No authorisation to display documents'
* 'in company code' p_bukrs.
* endif.

* Displaying documents from a list of company codes (select-options)
* ------------------------------------------------------------------
* call function 'Y_BUKRS_AUTHORITY_CHECK'
* EXPORTING
* ACTVT = '03'
* NOMESSAGE = ' '
* tables
* s_bukrs = s_bukrs.

ENDFORM. " AUTHORITY_CHECK

*---------------------------------------------------------------------*
* FORM GET_CONTROL_DATA *
*---------------------------------------------------------------------*
* Read configuration etc. *
*---------------------------------------------------------------------*
FORM get_control_data.

ENDFORM. " GET_CONTROL_DATA

*---------------------------------------------------------------------*
* FORM GET_TRANSACTION_DATA *
*---------------------------------------------------------------------*
* Read documents etc. *
*---------------------------------------------------------------------*
FORM get_transaction_data.

* !!! Data selection statement below has been generated automatically.
* !!! Please check if it is correct and complete.
* !!! Use table joins or 'SELECT FOR ALL ENTRIES' when selecting data
* !!! from related tables.

SELECT
vbeln
erdat
erzet
ernam
FROM vbak
INTO CORRESPONDING FIELDS OF TABLE gt_vbak
.

CHECK NOT gt_vbak[] IS INITIAL.

SELECT
matnr
FROM mara
INTO CORRESPONDING FIELDS OF TABLE gt_mara
FOR ALL ENTRIES IN gt_vbak
WHERE ernam = gt_vbak-ernam
.

ENDFORM. " GET_TRANSACTION_DATA

*---------------------------------------------------------------------*
* FORM PROCESS_TRANSACTION_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM process_transaction_data.

LOOP AT gt_vbak .
MOVE-CORRESPONDING gt_vbak TO gt_alv1_data .
APPEND gt_alv1_data .
ENDLOOP.

FREE gt_vbak .

LOOP AT gt_mara .
MOVE-CORRESPONDING gt_mara TO gt_alv2_data .
APPEND gt_alv2_data .
ENDLOOP.

FREE gt_mara .

ENDFORM. " PROCESS_TRANSACTION_DATA

*---------------------------------------------------------------------*
* FORM OUTPUT_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM output_data.

PERFORM alv_list_display.

ENDFORM. " OUTPUT_DATA

*---------------------------------------------------------------------*
* FORM DISPLAY_RECORD *
*---------------------------------------------------------------------*
* Display object associated with the current ALV line *
*---------------------------------------------------------------------*
FORM display_record USING is_selfield TYPE slis_selfield.

READ TABLE gt_alv1_data INDEX is_selfield-tabindex.
CHECK sy-subrc = 0.

* !!! SAMPLE IMPLEMENTATION FOR DISPLAYING FI DOCUMENTS:
SET PARAMETER ID 'BUK' FIELD gt_alv1_data-vbeln.
* set parameter id 'BLN' field gt_alv1_data-belnr.
* set parameter id 'GJR' field gt_alv1_data-gjahr.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.

ENDFORM. " DISPLAY_RECORD

*---------------------------------------------------------------------*
* FORM ALV_LIST_DISPLAY *
*---------------------------------------------------------------------*
* Invoke main ALV function to format and show the report *
*---------------------------------------------------------------------*
FORM alv_list_display.

DATA: ls_layout TYPE slis_layout_alv,
ls_print TYPE slis_print_alv,
ls_keyinfo TYPE slis_keyinfo_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_exctab TYPE slis_t_extab,
lt_sorttab TYPE slis_t_sortinfo_alv,
lt_events TYPE slis_t_event.

PERFORM alv_init_report_events TABLES lt_events.

PERFORM alv_init_report_layout TABLES lt_fieldcat
lt_exctab
lt_sorttab
CHANGING ls_layout
ls_print
ls_keyinfo.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_interface_check = ' '
i_callback_program = sy-cprog
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_excluding = lt_exctab
* IT_SPECIAL_GROUPS =
it_sort = lt_sorttab
* IT_FILTER =
* IS_SEL_HIDE =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_DEFAULT = 'X'
i_save = 'A'
is_variant = gs_variant
it_events = lt_events
* IT_EVENT_EXIT =
i_tabname_header = 'GT_ALV1_DATA'
i_tabname_item = 'GT_ALV2_DATA'
* I_STRUCTURE_NAME_HEADER =
* I_STRUCTURE_NAME_ITEM =
is_keyinfo = ls_keyinfo
is_print = ls_print
* IS_REPREP_ID =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab_header = gt_alv1_data
t_outtab_item = gt_alv2_data.
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2

ENDFORM. " ALV_LIST_DISPLAY

*---------------------------------------------------------------------*
* FORM ALV_INIT_REPORT_LAYOUT *
*---------------------------------------------------------------------*
* Set up report layout definition for ALV_LIST_DISPLAY *
*---------------------------------------------------------------------*
* <-- OT_FIELDCAT list of fields *
* <-- OT_EXCTAB excluded menu options *
* <-- OT_SORTTAB sorting/grouping definition *
* <-- OS_LAYOUT global report layout settings *
* <-- OS_PRINT global report printout settings *
* <-- OS_KEYINFO itab key fields (required only for hier.lists) *
*---------------------------------------------------------------------*
FORM alv_init_report_layout TABLES ot_fieldcat TYPE slis_t_fieldcat_alv
ot_exctab TYPE slis_t_extab
ot_sorttab TYPE slis_t_sortinfo_alv
CHANGING cs_layout TYPE slis_layout_alv
cs_print TYPE slis_print_alv
cs_keyinfo TYPE slis_keyinfo_alv.

* add menu items to be excluded to ot_exctab.
REFRESH ot_exctab.
REFRESH ot_fieldcat.
REFRESH ot_sorttab.

* !!!
* !!! List all ALV data fields for display here:
* !!!
* DD-struct = data dictionary structure name
* DD-field = field of data dictionary structure
* itab = internal table for output data
* itab-field = internal table field name
* key = set to 'X' if key field
* sum = set to 'X' for totals
* hid = set to 'X' if field is initially hidden
* row = list row number (multi-line list if >1)
*
* DD-struct DD-field itab itab-field key sum hid row
* ------------------------------------------------------------------

PERFORM alv_build_fieldcat TABLES ot_fieldcat USING:
'VBAK' 'VBELN' 'GT_ALV1_DATA' 'VBELN' ' ' ' ' ' ' 1 ,
'VBAK' 'ERDAT' 'GT_ALV1_DATA' 'ERDAT' ' ' ' ' ' ' 1 ,
'VBAK' 'ERZET' 'GT_ALV1_DATA' 'ERZET' ' ' ' ' ' ' 1 ,
'VBAK' 'ERNAM' 'GT_ALV1_DATA' 'ERNAM' ' ' ' ' ' ' 1.

PERFORM alv_build_fieldcat TABLES ot_fieldcat USING:
'MARA' 'MATNR' 'GT_ALV2_DATA' 'MATNR' ' ' ' ' ' ' 1 .

* !!!
* !!! List all ALV data fields for sorting/grouping here
* !!!
* itab = internal table for output data
* itab-field = internal table field name
* up = sort ascending
* down = sort descending
* grp = group by
* comp = group initially compressed
* pos = field position in sort sequence
*
* itab field up down grp comp pos
* ---------------------------------------------------------------------

PERFORM alv_build_sorttab TABLES ot_sorttab USING:
'GT_ALV1_DATA' 'VBELN' 'X' ' ' ' ' ' ' 1.

PERFORM alv_build_sorttab TABLES ot_sorttab USING:
'GT_ALV2_DATA' 'MATNR' 'X' ' ' ' ' ' ' 1.

* !!! key definition - required only for hierarchical display (2 itabs)
cs_keyinfo-header01 = 'VBELN' .
cs_keyinfo-item01 = 'MATNR' .

* !!! See the declaration of type SLIS_LAYOUT_ALV and set the fields
* !!! of OS_LAYOUT record to change list-level attributes

* os_layout-no_colhead = 'X'. " no headings
cs_layout-zebra = 'X'. " stripped pattern
* os_layout-no_vline = 'X'. " columns separated by space
* os_layout-totals_only = 'X'. " show only totals
* os_layout-totals_text = 'Total'. " totals line label
* os_layout-subtotals_text = 'Subtotal'. " subtotals line label
* os_layout-subtotals_text = 'Subtotal'. " subtotals line label
* os_layout-key_hotspot = 'X'. " keys as hotspot
* os_layout-expand_all = 'X'. " Expand all positions
* os_layout...

cs_print-no_print_selinfos = 'X'. " Skip selection statistics
cs_print-no_print_listinfos = 'X'. " Skip list statistics
* os_print-...

ENDFORM. " INIT_REPORT_LAYOUT

*---------------------------------------------------------------------*
* FORM ALV_BUILD_FIELDCAT *
*---------------------------------------------------------------------*
* Format a single line for ALV_INIT_REPORT_LAYOUT *
*---------------------------------------------------------------------*
FORM alv_build_fieldcat TABLES ot_fieldcat
USING iv_ref_tabname "ref to a table/field
iv_ref_fieldname
iv_tabname "actual table/field name
iv_fieldname
iv_key
iv_do_sum
iv_no_out
iv_row_pos.

* status variables for auto-numbering of field column position
* (column number reset when a new table or row begins)
STATICS: sv_last_tabname TYPE slis_tabname,
sv_last_row_pos TYPE i,
sv_current_col TYPE i.
IF sv_last_tabname <> iv_tabname OR sv_last_row_pos <> iv_row_pos.
sv_current_col = 1.
ELSE.
ADD 1 TO sv_current_col.
ENDIF.
sv_last_tabname = iv_tabname.
sv_last_row_pos = iv_row_pos.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.
DATA: lv_fieldname TYPE slis_fieldname.

lv_fieldname = iv_fieldname.

* !!!
* !!! List all the special formatting requirements in cases below
* !!!
* case lv_fieldname.
* when 'WRBTR'. "<-- link with currency required
* ls_fieldcat-cfieldname = 'WAERS'.
* ls_fieldcat-ctabname = iv_tabname.
*
* when 'HKONT'. "<-- change default column header
* ls_fieldcat-seltext_s = 'GL Acc.'.
* ls_fieldcat-ddictxt = 'S'. " (S)hort (M)iddle (L)ong
*
* when 'SOME_NUMBER' "<-- change number formatting
* ls_fieldcat-nosign = 'X'.
* ls_fieldcat-nozero = 'X'.
* ls_fieldcat-just = 'L'. " (L)eft (R)ight (C)enter
* endcase.

ls_fieldcat-ref_tabname = iv_ref_tabname.
ls_fieldcat-ref_fieldname = iv_ref_fieldname.
ls_fieldcat-tabname = iv_tabname.
ls_fieldcat-fieldname = iv_fieldname.
ls_fieldcat-key = iv_key.
ls_fieldcat-do_sum = iv_do_sum.
ls_fieldcat-no_out = iv_no_out.
ls_fieldcat-row_pos = iv_row_pos.
ls_fieldcat-col_pos = sv_current_col.

APPEND ls_fieldcat TO ot_fieldcat.

ENDFORM. " ALV_BUILD_FIELDCAT

*---------------------------------------------------------------------*
* FORM ALV_BUILD_SORTTAB *
*---------------------------------------------------------------------*
* Set up sorting information for ALV_INIT_REPORT_LAYOUT *
*---------------------------------------------------------------------*
FORM alv_build_sorttab TABLES ot_sorttab TYPE slis_t_sortinfo_alv
USING iv_tabname TYPE slis_fieldname
iv_fieldname TYPE slis_fieldname
iv_up TYPE c
iv_down TYPE c
iv_subtot TYPE c
iv_comp TYPE c
iv_spos TYPE n.

ot_sorttab-spos = iv_spos.
ot_sorttab-fieldname = iv_fieldname.
ot_sorttab-tabname = iv_tabname.
ot_sorttab-up = iv_up.
ot_sorttab-down = iv_down.
ot_sorttab-subtot = iv_subtot.
ot_sorttab-comp = iv_comp.
APPEND ot_sorttab.

ENDFORM. " ALV_BUILD_SORTTAB

*---------------------------------------------------------------------*
* FORM ALV_INIT_REPORT_EVENTS *
*---------------------------------------------------------------------*
* Set up program events for ALV_LIST_DISPLAY *
*---------------------------------------------------------------------*
* <-- OT_EVENTS list of events and associated report subroutines *
*---------------------------------------------------------------------*
FORM alv_init_report_events TABLES ot_events TYPE slis_t_event.

CLEAR ot_events.
REFRESH ot_events.

ot_events-name = slis_ev_user_command.
ot_events-form = 'USER_COMMAND'.
APPEND ot_events.

ot_events-name = slis_ev_pf_status_set.
ot_events-form = ''. "'PF_STATUS_SET'.
APPEND ot_events.

ot_events-name = slis_ev_top_of_list.
ot_events-form = 'TOP_OF_LIST'.
APPEND ot_events.

ot_events-name = slis_ev_end_of_list.
ot_events-form = 'END_OF_LIST'.
APPEND ot_events.

ot_events-name = slis_ev_top_of_page.
ot_events-form = 'TOP_OF_PAGE'.
APPEND ot_events.

ot_events-name = slis_ev_end_of_page.
ot_events-form = 'END_OF_PAGE'.
APPEND ot_events.

ot_events-name = slis_ev_foreign_top_of_page.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_foreign_end_of_page.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_top_of_coverpage.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_end_of_coverpage.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_before_line_output.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_after_line_output.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_caller_exit_at_start.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_list_modify.
ot_events-form = ''.
APPEND ot_events.

ot_events-name = slis_ev_subtotal_text.
ot_events-form = ''.
APPEND ot_events.

ENDFORM. " ALV_INIT_REPORT_EVENTS

*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer *
* --> UCOMM - user command code passed from ALV *
* --> SELFIELD - information record describing current line/field *
*---------------------------------------------------------------------*
FORM user_command USING value(iv_ucomm) LIKE sy-ucomm
is_selfield TYPE slis_selfield.

CASE iv_ucomm.
WHEN '&IC1'. "ALV record selection
PERFORM display_record USING is_selfield.
* when ...
* ...
ENDCASE.

ENDFORM. " USER_COMMAND

*---------------------------------------------------------------------*
* FORM PF_STATUS_SET *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer, *
* allows setting alternative menu. If necessary: *
* 1. Copy 'STANDARD' menu from SAPLKKBL and modify as required, *
* 2. Activate callback *
*---------------------------------------------------------------------*
FORM pf_status_set USING it_exctab TYPE slis_t_extab.

* set pf-status 'STANDARD' excluding it_exctab.

ENDFORM. " PF_STATUS_SET

*---------------------------------------------------------------------*
* FORM TOP_OF_LIST *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer, *
* executed once at the start of list output. *
*---------------------------------------------------------------------*
FORM top_of_list.

DATA: lt_seltab TYPE STANDARD TABLE OF rsparams WITH HEADER LINE.
DATA: lv_report LIKE sy-repid.
lv_report = sy-repid. "do not pass sy-repid to function!


IF p_box_up = 'X'. "display select options at report start

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = lv_report
TABLES
selection_table = lt_seltab.

* remove 'technical' parameters with 'DELETE LT_SELTAB WHERE...'
* before display, if necessary
CALL FUNCTION 'RS_LIST_SELECTION_TABLE'
EXPORTING
report = lv_report
seltext = 'X'
* dyn_range =
newpage = ' '
* screennr = 1000
TABLES
sel_tab = lt_seltab
EXCEPTIONS
sel_tab_empty = 1.

ENDIF. "p_box_up = 'X'

ENDFORM. " TOP_OF_LIST

*---------------------------------------------------------------------*
* FORM END_OF_LIST *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer *
* executed once at the end of list output. *
*---------------------------------------------------------------------*
FORM end_of_list.

DATA: lt_seltab TYPE STANDARD TABLE OF rsparams WITH HEADER LINE.
DATA: lv_report LIKE sy-repid.
lv_report = sy-repid. "do not pass sy-repid to function!

IF p_box_do = 'X'. "display select options at report end

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
EXPORTING
curr_report = lv_report
TABLES
selection_table = lt_seltab.

* remove 'technical' parameters with 'DELETE LT_SELTAB WHERE...'
* before display, if necessary
CALL FUNCTION 'RS_LIST_SELECTION_TABLE'
EXPORTING
report = lv_report
seltext = 'X'
* dyn_range =
newpage = ' '
* screennr = 1000
TABLES
sel_tab = lt_seltab
EXCEPTIONS
sel_tab_empty = 1.

ENDIF. "p_box_do = 'X'

ENDFORM. " END_OF_LIST

*---------------------------------------------------------------------*
* FORM TOP_OF_PAGE *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer *
*---------------------------------------------------------------------*
FORM top_of_page.

* standard Ingram Micro report page heading
DATA: lv_coco_pos TYPE i, "CurPos of 'Company confidential'
lv_title_pos TYPE i, "CurPos of report title
lv_title(70) TYPE c, "Truncated report title
lv_page_pos TYPE i, "CurPos of page number
lv_date_pos TYPE i, "CurPos of date and time
lv_page_no(10) TYPE c,
lv_date(25) TYPE c,
lv_time(20) TYPE c,
lv_page(10) TYPE c.

* We may need to truncate title if the line size is < 81.
IF sy-linsz < 81.
lv_title = sy-title+0(50).
ELSE.
lv_title = sy-title.
ENDIF.

* Decide on positioning of text depending on width of page
lv_title_pos = ( sy-linsz / 2 ) - ( STRLEN( lv_title ) / 2 ).
lv_coco_pos = sy-linsz - 20.

FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: / 'Ingram Micro',
AT lv_title_pos lv_title,
AT lv_coco_pos 'Company Confidential'.

* Setup data correctly in the correct format for the display fields.
lv_page = sy-pagno.
SHIFT lv_page LEFT DELETING LEADING ' '.
CONCATENATE sy-datum+6(2) sy-datum+4(2) sy-datum+0(4)
INTO lv_date SEPARATED BY '.'.
CONCATENATE sy-uzeit+0(2) ':' sy-uzeit+2(2) INTO lv_time.
CONCATENATE lv_date lv_time INTO lv_date SEPARATED BY ' '.
CONCATENATE 'Page' lv_page INTO lv_page_no SEPARATED BY ' '.

* Decide on positioning of text depending on width of page.
lv_page_pos = sy-linsz - ( STRLEN( lv_page_no ) ).

WRITE: / lv_date,
AT lv_page_pos lv_page_no.

ULINE.

ENDFORM. " TOP_OF_PAGE

*---------------------------------------------------------------------*
* FORM END_OF_PAGE *
*---------------------------------------------------------------------*
* Subroutine attached as callback form to ABAP List Viewer *
*---------------------------------------------------------------------*
FORM end_of_page.

ENDFORM. " END_OF_PAGE

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

* Form ALV_VARIANT_EXISTENCE

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

* Reads ALV variant definition

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

FORM alv_variant_existence USING iv_variant LIKE disvariant-variant
CHANGING os_variant LIKE disvariant.

CHECK NOT iv_variant IS INITIAL.
os_variant-report = sy-repid.
os_variant-variant = iv_variant.

IF iv_variant CP '/*'. "user-specific variants begin with slash
os_variant-username = sy-uname.
ENDIF.

CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = os_variant
EXCEPTIONS
wrong_input = 1
not_found = 2
program_error = 3
OTHERS = 4.

IF sy-subrc <> 0.
MESSAGE e001(z9) WITH 'Please select a valid display variant.'.
ENDIF.

ENDFORM. " ALV_VARIANT_EXISTENCE

*---------------------------------------------------------------------*
* FORM ALV_VARIANT_F4 *
*---------------------------------------------------------------------*
* Display list of layout variants on report selection screen *
*---------------------------------------------------------------------*
FORM alv_variant_f4 CHANGING cv_varname LIKE disvariant-variant
cs_variant LIKE disvariant.

DATA: lv_exit(1) TYPE c.
cs_variant-report = sy-repid.

CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = cs_variant
i_save = 'A'
* it_default_fieldcat =
IMPORTING
e_exit = lv_exit
es_variant = cs_variant
EXCEPTIONS
not_found = 2.

IF sy-subrc = 2.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF lv_exit = space.
cv_varname = cs_variant-variant.
ENDIF.
ENDIF. 

<b><i>or check this coding too</b></i>

 * Global ALV Data Declarations
type-pools: slis.
 
* Internal Tables
data: begin of itab occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of itab.
 
start-of-selection.
 
  perform get_data.
  perform call_alv.
 
*********************************************************************
*      Form  GET_DATA
*********************************************************************
form get_data.
 
  select mara~matnr makt~maktx
          into corresponding fields of table itab
               from mara
                 inner join makt
                  on mara~matnr = makt~matnr
                             up to 20 rows.
 
endform.
 
************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.
 
  data: ifc type slis_t_fieldcat_alv.
  data: xfc type slis_fieldcat_alv.
  data: repid type sy-repid.
 
  repid = sy-repid.
 
  clear xfc. refresh ifc.
 
  clear xfc.
  xfc-reptext_ddic = 'Material Number'.
  xfc-fieldname    = 'MATNR'.
  xfc-tabname      = 'ITAB'.
  xfc-outputlen    = '18'.
  append xfc to ifc.
 
  clear xfc.
  xfc-reptext_ddic = 'Material Description'.
  xfc-fieldname    = 'MAKTX'.
  xfc-tabname      = 'ITAB'.
  xfc-outputlen    = '40'.
  append xfc to ifc.
 
* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            i_callback_program      = repid
            i_callback_user_command = 'HANDLE_USER_COMMAND'
            it_fieldcat             = ifc
       tables
            t_outtab                = itab.
 
endform.
 
***********************************************************************
*       FORM handle_User_Command                                      *
***********************************************************************
form handle_user_command using r_ucomm     like sy-ucomm
                               rs_selfield type slis_selfield.
 
  case r_ucomm.
    when '&IC1'.
 
    case rs_selfield-FIELDNAME.
      when 'MATNR'.
         set parameter id 'MAT' field rs_selfield-value.
         call transaction 'MD04' and skip first screen.
 
 
      endcase.
 
 
  endcase.
 
endform.
 
 

<b>Reuse_alv_list_display</b>

 type-pools: slis.
 
data: fieldcat type slis_t_fieldcat_alv,
fieldcat_ln like line of fieldcat,
fs_layout type slis_layout_alv,
t_layoout like standard table
of fs_layout.
 
data: begin of fs_spfli,
carrid type spfli-carrid,
connid type spfli-connid,
countryfr type spfli-countryfr,
cityfrom type spfli-cityfrom,
airpfrom type spfli-airpfrom,
countryto type spfli-countryto,
cityto type spfli-cityto,
airpto type spfli-airpto,
fltime type spfli-fltime,
deptime type spfli-deptime,
arrtime type spfli-arrtime,
distance type spfli-distance,
distid type spfli-distid,
fltype type spfli-fltype,
period type spfli-period,
checkbox,
color(3),
end of fs_spfli.
data:
begin of fs_table,
carrid type spfli-carrid,
connid type spfli-connid,
end of fs_table.
 
 
data: begin of fs_sflight,
check,
color(3).
include type sflight.
data:end of fs_sflight.
 
data:
begin of fs_table1,
carrid type sflight-carrid,
connid type sflight-connid,
fldate type sflight-fldate,
end of fs_table1.
 
data:
t_spfli like standard table
of fs_spfli.
 
data:
t_table like standard table
of fs_table.
 
data:
t_table1 like standard table
of fs_table1.
 
data:
t_sflight like standard table
of fs_sflight.
 
data:
t_sbook like standard table
of sbook.
 
 
data t_layout type slis_layout_alv.
 
select *
into corresponding fields of table t_spfli
from spfli.
 
perform start_list_viewer.
perform get_spfli_details.
 
*&--------------------------------------------------------------------*
*& Form SUB1
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
 
form sub1 using rt_extab type slis_t_extab.
 
data: flight type slis_extab.
flight-fcode = 'SFLIGHT'.
append flight to rt_extab.
set pf-status 'SFLIGHT'. " EXCLUDING RT_EXTAB.
 
endform. "SUB1
 
*&---------------------------------------------------------------------*
*& Form START_LIST_VIEWER
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
 
form start_list_viewer .
 
data: pgm like sy-repid.
pgm = sy-repid.
 
fs_layout-box_fieldname = 'CHECKBOX'.
fs_layout-info_fieldname = 'COLOR'.
 
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_callback_pf_status_set = 'SUB1'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SPFLI'
is_layout = fs_layout
tables
t_outtab = t_spfli
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. " START_LIST_VIEWER
 
 
********Process Call Back Events (Begin)***************************
 
form user_command using ucomm like sy-ucomm
selfield type slis_selfield.
 
case ucomm.
when 'SFLIGHT'.
selfield-refresh = 'X'.
perform get_spfli_details.
select *
from sflight
into corresponding fields of table t_sflight
for all entries in t_table
where carrid eq t_table-carrid
and connid eq t_table-connid.
 
perform display_sflight.
 
when 'SBOOK'.
selfield-refresh = 'X'.
perform get_sflight_details.
select *
from sbook
into corresponding fields of table t_sbook
for all entries in t_table1
where carrid eq t_table1-carrid
and connid eq t_table1-connid
and fldate eq t_table1-fldate.
 
perform display_sbook.
 
endcase.
endform. "USER_COMMAND
 
*&--------------------------------------------------------------------*
*& Form SUB2
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->RT_EXTAB text
*---------------------------------------------------------------------*
 
form sub2 using rt_extab type slis_t_extab.
 
data: flight type slis_extab.
flight-fcode = 'SBOOK'.
append flight to rt_extab.
set pf-status 'SBOOK'. " EXCLUDING RT_EXTAB.
 
endform. "SUB2
 
*&---------------------------------------------------------------------*
*& Form DISPLAY_SFLIGHT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
 
form display_sflight .
 
data: pgm like sy-repid.
pgm = sy-repid.
 
clear t_layout.
fs_layout-box_fieldname = 'CHECK'.
fs_layout-info_fieldname = 'COLOR'.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_callback_pf_status_set = 'SUB2'
i_callback_user_command = 'USER_COMMAND'
i_structure_name = 'SFLIGHT'
is_layout = fs_layout
tables
t_outtab = t_sflight
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_SFLIGHT
 
*&---------------------------------------------------------------------*
*& Form GET_SPFLI_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
 
form get_spfli_details .
 
loop at t_spfli into fs_spfli.
if fs_spfli-checkbox = 'X'.
fs_spfli-color = 'C51'.
fs_spfli-checkbox = '1'.
fs_table-carrid = fs_spfli-carrid.
fs_table-connid = fs_spfli-connid.
append fs_table to t_table.
modify t_spfli from fs_spfli.
endif.
endloop.
endform. " GET_SFLIGHT_DETAILS
 
*&---------------------------------------------------------------------*
*& Form GET_SFLIGHT_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
 
form get_sflight_details .
 
loop at t_sflight into fs_sflight.
if fs_sflight-check = 'X'.
fs_sflight-color = 'C71'.
fs_sflight-check = '1'.
fs_table1-carrid = fs_sflight-carrid.
fs_table1-connid = fs_sflight-connid.
fs_table1-fldate = fs_sflight-fldate.
append fs_table1 to t_table1.
modify t_sflight from fs_sflight.
endif.
endloop.
 
endform. " GET_SFLIGHT_DETAILS
 
*&---------------------------------------------------------------------*
*& Form DISPLAY_SBOOK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
 
form display_sbook .
 
data: pgm like sy-repid.
pgm = sy-repid.
 
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = pgm
i_structure_name = 'SBOOK'
tables
t_outtab = t_sbook
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_SBOOK


<b> Reuse_alv_fieldcatalog_merge</b>

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

<b> Reuse_alv_events_get</b>

By using this function module called 'REUSE_ALV_EVENTS_GET' where u get all the events like PF_STATUS_SET, TOP_OF_LIST, END_OF_PAGE,END_OF_LIST etc populated into an internal table So u can read this internal table and call the appropriate form to print the content at the end of the list. Below is the sample code for ur reference.


FORM build_events USING flag
CHANGING pa_events TYPE slis_t_event.

*Get all possible events
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = pa_events
EXCEPTIONS
list_type_wrong = 1
OTHERS = 2.

IF sy-subrc <> 0.
ENDIF.
* Specify events used in selection screen
READ TABLE pa_events WITH KEY name = slis_ev_top_of_page
INTO ls_events.
IF sy-subrc = 0.
IF flag = 1.
ls_events-form = 'TOP_OF_PAGE1'.
ELSEIF flag = 2.
ls_events-form = 'TOP_OF_PAGE2'.
ELSE.
ls_events-form = 'TOP_OF_PAGE3'.
ENDIF.
MODIFY pa_events FROM ls_events INDEX sy-tabix.
CLEAR ls_events.
ENDIF.

ENDFORM. "build_events

*&---------------------------------------------------------------------*
*& Form top_of_page1
*&---------------------------------------------------------------------*
FORM top_of_page1.

WRITE: 'Last Year'.

ENDFORM. "TOP_OF_PAGE1

*&---------------------------------------------------------------------*
*& Form top_of_page2
*&---------------------------------------------------------------------*
FORM top_of_page2.

WRITE: 'Budget'.

ENDFORM. "TOP_OF_PAGE2


*&---------------------------------------------------------------------*
*& Form top_of_page3
*&---------------------------------------------------------------------*
FORM top_of_page3.

WRITE: 'This year'.
ENDFORM. "TOP_OF_PAGE3  

<b>Reuse_alv_commentary_write </b>

*&---------------------------------------------------------------------*
*& Report  ZALV                                                        *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
Report  ZALV  .

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,
      gt_events     type slis_t_event,
      gd_prntparams type slis_print_alv.


************************************************************************
*Start-of-selection.
START-OF-SELECTION.

perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
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-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_events
            is_print                = gd_prntparams
            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


*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
      wa_header type slis_listheader,
      t_line like wa_header-info,
      ld_lines type i,
      ld_linesc(10) type c.

* Title
  wa_header-typ  = 'H'.
  wa_header-info = 'EKKO Table Report'.
  append wa_header to t_header.
  clear wa_header.

* Date
  wa_header-typ  = 'S'.
  wa_header-key = 'Date: '.
  CONCATENATE  sy-datum+6(2) '.'
               sy-datum+4(2) '.'
               sy-datum(4) INTO wa_header-info.   "todays date
  append wa_header to t_header.
  clear: wa_header.

* Total No. of Records Selected
  describe table it_ekko lines ld_lines.
  ld_linesc = ld_lines.
  concatenate 'Total No. of Records Selected: ' ld_linesc
                    into t_line separated by space.
  wa_header-typ  = 'A'.
  wa_header-info = t_line.
  append wa_header to t_header.
  clear: wa_header, t_line.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            it_list_commentary = t_header.
*            i_logo             = 'Z_LOGO'.
endform.


*------------------------------------------------------------------*
*       FORM USER_COMMAND                                          *
*------------------------------------------------------------------*
*       --> R_UCOMM                                                *
*       --> RS_SELFIELD                                            *
*------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                  rs_selfield TYPE slis_selfield.

* Check function code
  CASE r_ucomm.
    WHEN '&IC1'.
*   Check field clicked on within ALVgrid report
    IF rs_selfield-fieldname = 'EBELN'.
*     Read data table, using index of row user clicked on
      READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
*     Set parameter ID for transaction screen field
      SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
*     Sxecute transaction ME23N, and skip initial data entry screen
      CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDCASE.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Build events table
*----------------------------------------------------------------------*
form build_events.
  data: ls_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = gt_events[].
  read table gt_events with key name =  slis_ev_end_of_page
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_PAGE' to ls_event-form.
    append ls_event to gt_events.
  endif.

    read table gt_events with key name =  slis_ev_end_of_list
                           into ls_event.
  if sy-subrc = 0.
    move 'END_OF_LIST' to ls_event-form.
    append ls_event to gt_events.
  endif.
endform.                    " BUILD_EVENTS


*&---------------------------------------------------------------------*
*&      Form  BUILD_PRINT_PARAMS
*&---------------------------------------------------------------------*
*       Setup print parameters
*----------------------------------------------------------------------*
form build_print_params.
  gd_prntparams-reserve_lines = '3'.   "Lines reserved for footer
  gd_prntparams-no_coverpage = 'X'.
endform.                    " BUILD_PRINT_PARAMS


*&---------------------------------------------------------------------*
*&      Form  END_OF_PAGE
*&---------------------------------------------------------------------*
form END_OF_PAGE.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  write: sy-uline(50).
  skip.
  write:/40 'Page:', sy-pagno .
endform.


*&---------------------------------------------------------------------*
*&      Form  END_OF_LIST
*&---------------------------------------------------------------------*
form END_OF_LIST.
  data: listwidth type i,
        ld_pagepos(10) type c,
        ld_page(10)    type c.

  skip.
  write:/40 'Page:', sy-pagno .
endform. 

<b>Reuse_alv_grid_display</b>

*&---------------------------------------------------------------------*
*& Report  ZALVTEST                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZALVTEST.

TABLES: mara, makt.

TYPE-POOLS: slis.

TYPES: BEGIN OF tab,
          matnr TYPE matnr,
          matkl TYPE matkl,
          maktx TYPE maktx,
       END OF tab.

DATA: itab TYPE TABLE OF tab,
      wa LIKE LINE OF itab.



*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   = 'MATNR'.
  fieldcatalog-seltext_m   = 'Material No'.
  fieldcatalog-col_pos     = 0.
  fieldcatalog-outputlen   = 10.
  fieldcatalog-emphasize   = 'X'.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MATKL'.
  fieldcatalog-seltext_m   = 'Group'.
  fieldcatalog-col_pos     = 2.
   fieldcatalog-outputlen   = 5.
  append fieldcatalog to fieldcatalog.
  clear  fieldcatalog.

  fieldcatalog-fieldname   = 'MAKTX'.
  fieldcatalog-seltext_m   = 'Description'.
  fieldcatalog-col_pos     = 1.
  fieldcatalog-outputlen   = 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'.
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                = 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.
endform.                    " DISPLAY_ALV_REPORT


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.

SELECT F~matnr F~matkl P~maktx
    INTO table itab
    FROM mara AS F INNER JOIN makt AS P
           ON F~matnr = P~matnr.

endform.                    " DATA_RETRIEVAL

Regards

Pavan