SIMPLE LIST REPORT
REPORT ZTESTS.
type-pools:slis .
data: it_fieldcat type slis_t_fieldcat_alv ,
wa_fieldcat type slis_fieldcat_alv ,
wa_layout type slis_layout_alv .
data: begin of itab occurs 0,
name(20) type c ,
age type i ,
end of itab .
itab-name = 'venkat01'.
itab-age = '12'.
append itab .
itab-name = 'venkat02'.
itab-age = '13'.
append itab .
itab-name = 'venkat03'.
itab-age = '14'.
append itab .
itab-name = 'venkat04'.
itab-age = '15'.
append itab .
wa_fieldcat-fieldname = 'NAME'.
wa_fieldcat-reptext_ddic = 'material number'.
append wa_fieldcat to it_fieldcat.
wa_fieldcat-fieldname = 'AGE'.
wa_fieldcat-reptext_ddic = 'INDUSTRY'.
append wa_fieldcat to it_fieldcat.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
t_outtab = ITAB .
REPORT FOR HEADER DISPLAY IN GRID
REPORT ZTESTS.
type-pools:slis .
data: it_fieldcat type slis_t_fieldcat_alv ,
wa_fieldcat type slis_fieldcat_alv ,
wa_layout type slis_layout_alv ,
IT_EVENTS TYPE SLIS_T_EVENT ,
WA_EVENTS TYPE SLIS_ALV_EVENT ,
IT_HEADER TYPE SLIS_T_LISTHEADER,
WA_HEADER TYPE SLIS_LISTHEADER.
data: begin of itab occurs 0,
name(20) type c ,
age type i ,
end of itab .
itab-name = 'venkat01'.
itab-age = '12'.
append itab .
itab-name = 'venkat02'.
itab-age = '13'.
append itab .
itab-name = 'venkat03'.
itab-age = '14'.
append itab .
itab-name = 'venkat04'.
itab-age = '15'.
append itab .
wa_fieldcat-fieldname = 'NAME'.
wa_fieldcat-SELTEXT_L = 'NAME'.
append wa_fieldcat to it_fieldcat.
wa_fieldcat-fieldname = 'AGE'.
wa_fieldcat-SELTEXT_L = 'AGE'.
append wa_fieldcat to it_fieldcat.
PERFORM GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
IT_EVENTS = IT_EVENTS
TABLES
t_outtab = ITAB .
*&---------------------------------------------------------------------*
*& Form GET_EVENTS
*----------------------------------------------------------------------*
form GET_EVENTS .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
ET_EVENTS = IT_EVENTS .
READ TABLE IT_EVENTS INTO WA_EVENTS
WITH KEY NAME = SLIS_EV_TOP_OF_PAGE.
IF SY-SUBRC = 0.
WA_EVENTS-FORM = 'TOP_OF_PAGE'.
MODIFY IT_EVENTS FROM WA_EVENTS INDEX SY-TABIX.
ENDIF.
endform. " GET_EVENTS
*&---------------------------------------------------------------------*
*& Form HEADER_DISPLAY
*----------------------------------------------------------------------*
form TOP_OF_PAGE .
WA_HEADER-TYP = 'H'.
WA_HEADER-INFO = 'HEADER'.
APPEND WA_HEADER TO IT_HEADER.
WA_HEADER-TYP = 'S'..
WA_HEADER-INFO = 'SUBHEADER :'.
APPEND WA_HEADER TO IT_HEADER.
WA_HEADER-TYP = 'S'..
WA_HEADER-INFO = 'DATE : '.
APPEND WA_HEADER TO IT_HEADER.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_HEADER .
endform. " HEADER_DISPLAY
alv list totals
REPORT zdemo_alvgrid .
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
data: BEGIN OF itab occurs 0,
F1 TYPE I,
F2 TYPE I,
F3 TYPE I,
END OF itab.
data: it_fieldcatalog type slis_t_fieldcat_alv ,
wa_fieldcatalog type slis_fieldcat_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
itab-f1 = '1'.
itab-f2 = '10'.
itab-f3 = '1234'.
append itab.
itab-f1 = '2'.
itab-f2 = '400'.
itab-f3 = '1234'.
append itab.
itab-f1 = '3'.
itab-f2 = '5120'.
itab-f3 = '1343'.
append itab.
itab-f1 = '4'.
itab-f2 = '620'.
itab-f3 = '1233'.
append itab.
itab-f1 = '5'.
itab-f2 = '9430'.
itab-f3 = '234'.
append itab.
itab-f1 = '6'.
itab-f2 = '100'.
itab-f3 = '14'.
append itab.
itab-f1 = '7'.
itab-f2 = '140'.
itab-f3 = '3421'.
append itab.
wa_fieldcatalog-fieldname = 'F1'.
wa_fieldcatalog-reptext_ddic = 'field1'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
wa_fieldcatalog-fieldname = 'F2'.
wa_fieldcatalog-reptext_ddic = 'field2'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
wa_fieldcatalog-fieldname = 'F3'.
wa_fieldcatalog-reptext_ddic = 'field3'.
wa_fieldcatalog-do_sum = 'X'.
append wa_fieldcatalog to it_fieldcatalog .
clear wa_fieldcatalog .
* gd_layout-
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'.
gd_repid = sy-repid.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = gd_repid
is_layout = gd_layout
it_fieldcat = it_fieldcatalog[]
tables
t_outtab = itab .
alv total in list
REPORT ZALVTOTAL.
tables:pa0008.
type-pools:slis.
types:begin of ty_pa0008,
pernr like pa0008-pernr,
begda like pa0008-begda,
endda like pa0008-endda,
ansal like pa0008-ansal,
lga01 like pa0008-lga01,
bet01 like pa0008-bet01,
end of ty_pa0008.
data:it_pa0008 type standard table of ty_pa0008 with header line.
data:it_fieldcat type SLIS_T_FIELDCAT_ALV,
wa_fieldcat type slis_fieldcat_alv,
it_layout type slis_layout_alv .
select-options:s_pernr for pa0008-pernr.
start-of-selection.
perform get_data.
perform disp_alv.
*&---------------------------------------------------------------------*
*& Form getD_data
*----------------------------------------------------------------------*
form get_data .
select pernr
begda
endda
ansal
lga01
bet01
from pa0008
into table it_pa0008
where pernr in s_pernr.
sort it_pa0008 by pernr begda descending.
endform. " getD_data
*&---------------------------------------------------------------------*
*& Form disp_alv
*----------------------------------------------------------------------*
form disp_alv .
wa_fieldcat-fieldname = 'PERNR'.
wa_FIELDCAT-REPTEXT_DDIC = 'Personnel no'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'BEGDA'.
wa_FIELDCAT-REPTEXT_DDIC = 'Start date'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'ENDDA'.
wa_FIELDCAT-REPTEXT_DDIC = 'End date'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'ANSAL'.
wa_FIELDCAT-REPTEXT_DDIC = 'Annula salary'.
wa_fieldcat-do_sum = 'X'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'LGA01'.
wa_FIELDCAT-REPTEXT_DDIC = 'Wage Type'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = 'BET01'.
wa_FIELDCAT-REPTEXT_DDIC = 'Amount for wagetype'.
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
IT_layout-totals_text = 'total text'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IS_LAYOUT = it_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
t_outtab = it_pa0008 .
endform. " disp_alv
alv in different languages
REPORT ZVENKAT.
tables: mara,
makt.
TYPE-POOLS:SLIS.
data:begin of it_mara occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
end of it_mara.
data: begin of it_makt occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
SPRAS like makt-spras,
end of it_makt.
data:begin of it_final occurs 0,
matnr like mara-matnr,
meins like mara-meins,
mtart like mara-mtart,
maktx like makt-maktx,
end of it_final.
DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
IT_LAYOUT TYPE SLIS_LAYOUT_ALV.
select-options:s_matnr for mara-matnr.
parameters: p_lang like sy-langu.
parameters:p_rad1 radiobutton group g1 DEFAULT 'X',
p_rad2 radiobutton group g1,
p_rad3 radiobutton group g1.
AT SELECTION-SCREEN OUTPUT.
if p_rad1 = 'X'.
p_lang = 'EN'.
endif.
if p_rad2 = 'X'.
p_lang = 'DE'.
endif.
if p_rad3 = 'X'.
p_lang = 'FR'.
endif.
START-OF-SELECTION.
select matnr
meins
mtart
from mara
into table it_mara
where matnr in s_matnr.
select matnr
maktx
spras
from makt
into table it_makt
for all entries in it_mara
where matnr = it_mara-matnr
and spras = p_lang.
loop at it_mara.
it_final-matnr = it_mara-matnr.
it_final-meins = it_mara-meins.
it_final-mtart = it_mara-mtart.
read table it_makt with key matnr = it_mara-matnr.
it_final-maktx = it_makt-maktx.
append it_final.
clear it_final.
endloop.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MATNR'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MEINS'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'MTART'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MTART'.
WA_FIELDCAT-REF_TABNAME = 'MARA'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-FIELDNAME = 'MAKTX'.
WA_FIELDCAT-TABNAME = 'IT_FINAL'.
WA_FIELDCAT-REF_FIELDNAME = 'MATKX'.
WA_FIELDCAT-REF_TABNAME = 'MAKT'.
APPEND WA_FIELDCAT TO IT_FIELDCAT.
CLEAR WA_FIELDCAT.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = IT_LAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = IT_FINAL.
f4 help for alv grid display
REPORT ztest_alv.
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fcat.
DATA: it_data TYPE vbap_t.
SELECT *
FROM VBAP
INTO TABLE it_data
UP TO 20 ROWS.
wa_fcat-fieldname = 'VBELN'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-ref_fieldname = 'VBELN'.
wa_fcat-ref_tabname = 'VBAK'.
APPEND wa_fcat TO it_fcat.
clear wa_fcat .
wa_fcat-fieldname = 'POSNR'.
wa_fcat-tabname = 'IT_DATA'.
wa_fcat-seltext_l = 'Item'.
APPEND wa_fcat TO it_fcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_interface_check = sy-repid
it_fieldcat = it_fcat
TABLES
t_outtab = it_data
EXCEPTIONS
program_error = 1.
Simple interactive with list
REPORT ZALV_LIST4.
TABLES:
SPFLI.
TYPE-POOLS:
SLIS.
DATA:
T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
W_COLOR(3) ,
W_ROW TYPE I,
W_FIELDNAME(20),
W_PROG TYPE SY-REPID.
DATA:
BEGIN OF T_SPFLI OCCURS 0,
COLOR(3),
CHECKBOX ,
CELL TYPE SLIS_T_SPECIALCOL_ALV,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
CITYFROM TYPE SPFLI-CITYFROM,
CITYTO TYPE SPFLI-CITYTO,
DISTANCE TYPE SPFLI-DISTANCE,
END OF T_SPFLI.
DATA:
FS_CELL LIKE LINE OF T_SPFLI-CELL.
SELECT *
FROM SPFLI
INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
FS_FIELDCAT-FIELDNAME = 'CARRID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'CONNID'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-KEY = 'X'.
FS_FIELDCAT-HOTSPOT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT .
FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-KEY = ' '.
FS_FIELDCAT-EDIT = 'X'.
APPEND FS_FIELDCAT TO T_FIELDCAT.
CLEAR FS_FIELDCAT.
FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
FS_FIELDCAT-KEY = ' '.
APPEND FS_FIELDCAT TO T_FIELDCAT.
LOOP AT T_SPFLI WHERE DISTANCE GT 600.
W_FIELDNAME = 'DISTANCE'.
FS_CELL-FIELDNAME = W_FIELDNAME .
FS_CELL-NOKEYCOL = 'X'.
APPEND FS_CELL TO T_SPFLI-CELL.
MODIFY T_SPFLI TRANSPORTING CELL.
ENDLOOP.
FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
FS_LAYOUT-F2CODE = '&ETA'.
W_PROG = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = W_PROG
IS_LAYOUT = FS_LAYOUT
IT_FIELDCAT = T_FIELDCAT
TABLES
T_OUTTAB = T_SPFLI .
Repeatative Colors in alv reports
REPORT zdemo_alvgrid .
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) type c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
* Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
form build_fieldcatalog.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
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-info_fieldname = 'LINE_COLOR'.
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
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
i_save = 'X'
tables
t_outtab = it_ekko .
endform. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
data: ld_color(1) type c.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
ld_color = ld_color + 1.
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
modify it_ekko from wa_ekko.
endloop.
endform. " DATA_RETRIEVAL
popup in the alv program
report ztests.
TYPE-POOLS: slis.
DATA: BEGIN OF itab OCCURS 0,
a TYPE p DECIMALS 2,
b TYPE p DECIMALS 2,
c TYPE c,
END OF itab.
DATA: ls_fieldcat TYPE lvc_t_fcat WITH HEADER LINE,
it_event_exit TYPE slis_t_event_exit WITH HEADER LINE.
PERFORM build_data_tab.
PERFORM build_fcat.
PERFORM build_event_table.
PERFORM alv_display.
*&---------------------------------------------------------------------*
*& Form build_data_tab
*&---------------------------------------------------------------------*
FORM build_data_tab .
itab-a = '1.12'.
itab-b = '2.25'.
itab-c = '+'.
APPEND itab.
APPEND itab.
APPEND itab.
APPEND itab.
ENDFORM. " build_data_tab
*&---------------------------------------------------------------------*
*& Form build_fcat
*&---------------------------------------------------------------------*
FORM build_fcat .
ls_fieldcat-fieldname = 'A'.
ls_fieldcat-reptext = 'FLD1'.
APPEND ls_fieldcat.
ls_fieldcat-fieldname = 'B'.
ls_fieldcat-reptext = 'FLD2'.
APPEND ls_fieldcat.
ls_fieldcat-fieldname = 'C'.
ls_fieldcat-reptext = 'FLD3'.
APPEND ls_fieldcat.
ENDFORM. " build_fcat
*&---------------------------------------------------------------------*
*& Form build_event_table
*&---------------------------------------------------------------------*
FORM build_event_table .
it_event_exit-ucomm = '&F03'.
APPEND it_event_exit.
it_event_exit-ucomm = '&F15'.
APPEND it_event_exit.
it_event_exit-ucomm = '&F12'.
APPEND it_event_exit.
ENDFORM. " build_event_table
*&---------------------------------------------------------------------*
*& Form alv_display
*&---------------------------------------------------------------------*
FORM alv_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
it_fieldcat_lvc = ls_fieldcat[]
it_event_exit = it_event_exit[]
TABLES
t_outtab = itab[].
ENDFORM. " alv_display
*&---------------------------------------------------------------------*
*& Form user_command
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm .
WHEN '&F03'.
MESSAGE 'U are going back' TYPE 'I'.
WHEN '&F15'.
MESSAGE 'U are about to exit' TYPE 'I'.
WHEN '&F12'.
MESSAGE 'U have clicked cancel button' TYPE 'I'.
ENDCASE.
ENDFORM. "user_command
CHECKBOX IN ALV REPORTS
REPORT ZALV_CHECKBOX.
type-pools: slis.
*Table declaration
tables: vbak,vbap.
*internal table
data: begin of i_sales occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
check type c, "checkbox
end of i_sales.
data: begin of i_final occurs 0,
vbeln like vbak-vbeln,
erdat like vbak-erdat,
audat like vbak-audat,
kunnr like vbak-kunnr,
vkorg like vbak-vkorg,
matnr like vbap-matnr,
netpr like vbap-netpr,
end of i_final.
data: v_fieldcat type slis_fieldcat_alv,
gt_fieldcat type slis_t_fieldcat_alv,
gt_layout type slis_layout_alv,
gt_sort type slis_sortinfo_alv,
fieldcat like line of gt_fieldcat.
*Selection screen
parameters: p_vkorg like vbak-vkorg.
select-options: s_vbeln for vbak-vbeln.
*start of selection.
start-of-selection.
perform get_data.
perform fill_fieldcatalog.
perform write_data.
*-----------------------------------------------------------------
* get data
*-----------------------------------------------------------------
FORM get_data .
select a~vbeln
a~erdat
a~audat
a~kunnr
a~vkorg
b~matnr
b~netpr
into corresponding fields of table i_sales
from vbak as a inner join vbap as b on a~vbeln = b~vbeln
where a~vkorg = p_vkorg
and a~vbeln in s_vbeln.
ENDFORM. " get_data
*-----------------------------------------------------------------
* write_data
*-----------------------------------------------------------------
FORM write_data .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
I_CALLBACK_PF_STATUS_SET = 'GUI_SET'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IS_LAYOUT = gt_layout
IT_FIELDCAT = gt_fieldcat
TABLES
T_OUTTAB = i_sales .
ENDFORM. " write_data
*-----------------------------------------------------------------
* fill catalog
*-----------------------------------------------------------------
FORM fill_fieldcatalog .
sort i_sales by vbeln.
clear v_fieldcat.
*for check box
v_fieldcat-col_pos = 1.
v_fieldcat-fieldname = 'CHECK'.
v_fieldcat-seltext_m = 'chek'.
v_fieldcat-checkbox = 'X'.
v_fieldcat-input = 'X'.
v_fieldcat-edit = 'X'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 2.
v_fieldcat-fieldname = 'VBELN'.
v_fieldcat-seltext_m = 'Sales Document'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 3.
v_fieldcat-fieldname = 'ERDAT'.
v_fieldcat-seltext_m = 'Creation Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 4.
v_fieldcat-fieldname = 'AUDAT'.
v_fieldcat-seltext_m = 'Document Date'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 5.
v_fieldcat-fieldname = 'KUNNR'.
v_fieldcat-seltext_m = 'Customer'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 6.
v_fieldcat-fieldname = 'VKORG'.
v_fieldcat-seltext_m = 'Sales Organization'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 7.
v_fieldcat-fieldname = 'MATNR'.
v_fieldcat-seltext_m = 'Material'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
v_fieldcat-col_pos = 8.
v_fieldcat-fieldname = 'NETPR'.
v_fieldcat-seltext_m = 'Net Value'.
append v_fieldcat to gt_fieldcat.
clear v_fieldcat.
endform.
*&---------------------------------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------------------------------*
FORM GUI_SET USING RT_EXTAB TYPE SLIS_T_EXTAB .
SET PF-STATUS 'GETDATA' .
ENDFORM. "GUI_SET
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
R_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'DATA'.
CLEAR I_FINAL.
CLEAR I_SALES.
REFRESH I_FINAL.
LOOP AT i_sales .
if i_sales-check = 'X'.
i_final-vbeln = i_sales-vbeln.
i_final-erdat = i_sales-erdat.
i_final-audat = i_sales-audat.
i_final-kunnr = i_sales-kunnr.
i_final-vkorg = i_sales-vkorg.
i_final-matnr = i_sales-matnr.
i_final-netpr = i_sales-netpr.
IF NOT I_FINAL-VBELN IS INITIAL.
append i_final .
ENDIF.
endif.
ENDLOOP.
PERFORM final_display.
endcase.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form final_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form final_display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = sy-repid
IS_LAYOUT = gt_LAYOUT
IT_FIELDCAT = gt_fieldcat
TABLES
t_outtab = i_final .
endform. " final_display
Alv blocked list report
*-Demo of FM REUSE_ALV_LIST_DISPLAY - Several Lists
REPORT Z10109_ALV_SEVERAL_LISTS.
*---------------------------------------------------------------------*
* Demo of FM REUSE_ALV_LIST_DISPLAY - Several Lists *
*---------------------------------------------------------------------*
* Macro definition
DEFINE M_FIELDCAT.
LS_FIELDCAT-FIELDNAME = &1.
LS_FIELDCAT-REF_TABNAME = &2.
APPEND LS_FIELDCAT TO LT_FIELDCAT.
END-OF-DEFINITION.
DEFINE M_SORT.
LS_SORT-FIELDNAME = &1.
LS_SORT-UP = 'X'.
APPEND LS_SORT TO LT_SORT.
END-OF-DEFINITION.
*
TYPE-POOLS: SLIS. " ALV Global types
SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) V_1 FOR FIELD P_MAX. "#EC NEEDED
PARAMETERS P_MAX(2) TYPE N DEFAULT '02' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
DATA:
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
* 1st Table
BEGIN OF GT_KNA1 OCCURS 0, " Data displayed
KUNNR LIKE KNA1-KUNNR, " Customer number
ERNAM LIKE KNA1-ERNAM, " Name of Person who Created
ERDAT LIKE KNA1-ERDAT, " Creation date
NAME1 LIKE KNA1-NAME1, " Name 1
END OF GT_KNA1,
* 2nd Table
BEGIN OF GT_MARA OCCURS 0,
ERNAM LIKE MARA-ERNAM, " Name of Person who Created
MATNR LIKE MARA-MATNR, " Material number
ERSDA LIKE MARA-ERSDA, " Creation date
BRGEW LIKE MARA-BRGEW, " Gross weight
END OF GT_MARA,
* 3rd Table
BEGIN OF GT_VBAK OCCURS 0,
VKORG LIKE VBAK-VKORG, " Sales organization
KUNNR LIKE VBAK-KUNNR, " Sold-to party
VBELN LIKE VBAK-VBELN, " Sales document
NETWR LIKE VBAK-NETWR, " Net Value of the Sales Order
WAERK LIKE VBAK-WAERK, " SD document currency
END OF GT_VBAK.
*---------------------------------------------------------------------*
INITIALIZATION.
V_1 = 'Maximum of records to read'(001).
*---------------------------------------------------------------------*
START-OF-SELECTION.
* Read data
SELECT * FROM KNA1
UP TO P_MAX ROWS
INTO CORRESPONDING FIELDS OF TABLE GT_KNA1.
SELECT * FROM MARA
UP TO P_MAX ROWS
INTO CORRESPONDING FIELDS OF TABLE GT_MARA.
SELECT * FROM VBAK
UP TO P_MAX ROWS
INTO CORRESPONDING FIELDS OF TABLE GT_VBAK.
PERFORM F_DISPLAY_DATA.
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD. "#EC CALLED
CASE I_UCOMM.
WHEN '&IC1'. " Pick
CASE IS_SELFIELD-SEL_TAB_FIELD(7).
WHEN 'GT_MARA'.
WHEN 'GT_KNA1'.
WHEN 'GT_VBAK'.
READ TABLE GT_VBAK INDEX IS_SELFIELD-TABINDEX.
IF SY-SUBRC EQ 0.
SET PARAMETER ID 'AUN' FIELD GT_VBAK-VBELN.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDCASE.
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM F_DISPLAY_DATA.
DATA :
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Field catalog
LS_SORT TYPE SLIS_SORTINFO_ALV,
LT_SORT TYPE SLIS_T_SORTINFO_ALV, " Sort table
LT_EVENTS TYPE SLIS_T_EVENT,
LS_EVENT TYPE SLIS_ALV_EVENT.
GS_LAYOUT-GROUP_CHANGE_EDIT = 'X'.
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
GS_LAYOUT-ZEBRA = 'X'.
GS_LAYOUT-CELL_MERGE = 'X'.
GS_LAYOUT-DETAIL_POPUP = 'X'.
GS_LAYOUT-GET_SELINFOS = 'X'.
GS_LAYOUT-MAX_LINESIZE = '200'.
* Build field catalog and sort table
M_FIELDCAT 'KUNNR' 'KNA1'.
M_FIELDCAT 'ERNAM' 'KNA1'.
M_FIELDCAT 'ERDAT' 'KNA1'.
M_FIELDCAT 'NAME1' 'KNA1'.
M_SORT 'KUNNR'.
* Build Event Table
MOVE 'TOP_OF_PAGE' TO LS_EVENT-NAME.
MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
MOVE 'END_OF_LIST' TO LS_EVENT-NAME.
MOVE 'END_OF_LIST' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = LT_FIELDCAT
IS_LAYOUT = GS_LAYOUT
IT_EVENTS = LT_EVENTS
IT_SORT = LT_SORT
TABLES
T_OUTTAB = GT_KNA1.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM top_of_page *
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE. "#EC CALLED
ULINE.
WRITE : SY-UNAME, SY-TITLE(56) CENTERED, SY-DATUM.
ULINE.
ENDFORM. " TOP_OF_PAGE
*---------------------------------------------------------------------*
* FORM End_of_list *
*---------------------------------------------------------------------*
FORM END_OF_LIST. "#EC CALLED
DATA :
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Field catalog
LS_SORT TYPE SLIS_SORTINFO_ALV,
LT_SORT TYPE SLIS_T_SORTINFO_ALV, " Sort table
LT_EVENTS TYPE SLIS_T_EVENT,
LS_EVENT TYPE SLIS_ALV_EVENT.
* Build field catalog and sort table
M_FIELDCAT 'MATNR' 'MARA'.
M_FIELDCAT 'ERNAM' 'MARA'.
M_FIELDCAT 'ERSDA' 'MARA'.
M_FIELDCAT 'BRGEW' 'MARA'.
M_SORT 'MATNR'.
* Build Event Table
MOVE 'END_OF_LIST' TO LS_EVENT-NAME.
MOVE 'END_OF_LIST_2' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
GS_LAYOUT-LIST_APPEND = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IT_FIELDCAT = LT_FIELDCAT
IS_LAYOUT = GS_LAYOUT
IT_SORT = LT_SORT
IT_EVENTS = LT_EVENTS
TABLES
T_OUTTAB = GT_MARA.
ENDFORM. " END_OF_LIST
*---------------------------------------------------------------------*
* FORM End_of_list_2 *
*---------------------------------------------------------------------*
FORM END_OF_LIST_2. "#EC CALLED
DATA :
LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV, " Field catalog
LS_SORT TYPE SLIS_SORTINFO_ALV,
LT_SORT TYPE SLIS_T_SORTINFO_ALV, " Sort table
LT_EVENTS TYPE SLIS_T_EVENT,
LS_EVENT TYPE SLIS_ALV_EVENT.
* Build field catalog and sort table
M_FIELDCAT 'VBELN' 'VBAK'.
M_FIELDCAT 'VKORG' 'VBAK'.
M_FIELDCAT 'KUNNR' 'VBAK'.
M_FIELDCAT 'NETWR' 'VBAK'.
M_FIELDCAT 'WAERK' 'VBAK'.
M_SORT 'VBELN'.
* Build Event Table
MOVE 'TOP_OF_PAGE' TO LS_EVENT-NAME.
MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
APPEND LS_EVENT TO LT_EVENTS.
GS_LAYOUT-LIST_APPEND = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IT_FIELDCAT = LT_FIELDCAT
IS_LAYOUT = GS_LAYOUT
IT_SORT = LT_SORT
IT_EVENTS = LT_EVENTS
TABLES
T_OUTTAB = GT_VBAK.
ENDFORM. " END_OF_LIST_2
************* END OF PROGRAM Z_ALV_LIST_BLOCK_2 **********************
Simple interactive report with grid
REPORT zTESTS NO STANDARD PAGE
HEADING LINE-SIZE 225
LINE-COUNT 65 .
TYPE-POOLS: slis, icon.
TABLES: vbak, vbap.
DATA: BEGIN OF it OCCURS 0,
vbeln LIKE vbak-vbeln,
waerk LIKE vbak-waerk,
vkorg LIKE vbak-vkorg,
spart LIKE vbak-spart,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
netwr LIKE vbap-netwr,
flag,
icon TYPE icon-id,
check,
END OF it,
BEGIN OF it1 OCCURS 0,
vbeln LIKE vbak-vbeln,
waerk LIKE vbak-waerk,
vkorg LIKE vbak-vkorg,
spart LIKE vbak-spart,
END OF it1,
BEGIN OF it2 OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
netwr LIKE vbap-netwr,
END OF it2.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
it_sort TYPE slis_t_sortinfo_alv,
it_event TYPE slis_t_event,
it_header TYPE slis_t_listheader.
DATA: itab LIKE TABLE OF it WITH HEADER LINE.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.
START-OF-SELECTION.
PERFORM populating_data.
PERFORM final_data.
PERFORM populate_fieldcat.
PERFORM sort_bulding.
PERFORM events_get.
PERFORM write_headings.
PERFORM display_data.
*&---------------------------------------------------------------------*
*& Form populating_data
*&---------------------------------------------------------------------*
FORM populating_data .
SELECT vbeln waerk vkorg spart INTO TABLE it1 FROM vbak
WHERE vbeln IN s_vbeln.
IF NOT it1[] IS INITIAL.
SELECT vbeln posnr matnr netwr INTO TABLE it2 FROM vbap
FOR ALL ENTRIES IN it1 WHERE vbeln EQ it1-vbeln.
ENDIF.
ENDFORM. " populating_data
*&---------------------------------------------------------------------*
*& Form final_data
*&---------------------------------------------------------------------*
FORM final_data .
LOOP AT it2.
READ TABLE it1 WITH KEY vbeln = it2-vbeln.
it-vbeln = it1-vbeln.
it-waerk = it1-waerk.
it-vkorg = it1-vkorg.
it-spart = it1-spart.
it-posnr = it2-posnr.
it-matnr = it2-matnr.
it-netwr = it2-netwr.
APPEND it.
CLEAR it.
ENDLOOP.
LOOP AT it.
IF it-netwr = 0.
it-flag = 'X'.
MODIFY it INDEX sy-tabix.
ENDIF.
ENDLOOP.
DELETE it WHERE flag = 'X'.
LOOP AT it.
IF it-netwr < 5000.
it-icon = '@46@'.
ELSEIF it-netwr > 5000 AND it-netwr < 10000.
it-icon = '@44@'.
ELSE.
it-icon = '@45@'.
ENDIF.
MODIFY it INDEX sy-tabix.
ENDLOOP.
ENDFORM. " final_data
*&---------------------------------------------------------------------*
*& Form populate_fieldcat
*&---------------------------------------------------------------------*
FORM populate_fieldcat .
DATA ws_fieldcat TYPE slis_fieldcat_alv.
DATA l_tabix TYPE sy-tabix.
CLEAR: ws_fieldcat.
ws_fieldcat-fieldname = 'VBELN'.
ws_fieldcat-key = 'X'.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Sales Doc Number'.
ws_fieldcat-col_pos = 1.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'POSNR'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Item'.
ws_fieldcat-col_pos = 2.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'VKORG'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Sales Organization'.
ws_fieldcat-col_pos = 3.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'SPART'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Dist. Channel'.
ws_fieldcat-col_pos = 4.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'MATNR'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Material Number'.
ws_fieldcat-col_pos = 5.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'NETWR'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = 'X'.
ws_fieldcat-seltext_m = 'Amount'.
ws_fieldcat-col_pos = 6.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'WAERK'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'Currency'.
ws_fieldcat-col_pos = 7.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'ICON'.
ws_fieldcat-key = ''.
ws_fieldcat-do_sum = ''.
ws_fieldcat-seltext_m = 'ICON'.
ws_fieldcat-col_pos = 8.
ws_fieldcat-icon = 'X'.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
ws_fieldcat-fieldname = 'CHECK'.
ws_fieldcat-col_pos = 9.
APPEND ws_fieldcat TO it_fieldcat.
CLEAR ws_fieldcat.
LOOP AT it_fieldcat INTO ws_fieldcat.
l_tabix = sy-tabix.
IF ws_fieldcat-fieldname = 'CHECK'.
ws_fieldcat-key = 'X'.
ws_fieldcat-checkbox = 'X'.
ws_fieldcat-input = 'X'.
ENDIF.
MODIFY it_fieldcat FROM ws_fieldcat INDEX l_tabix.
ENDLOOP.
ENDFORM. " populate_fieldcat
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
FORM display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-cprog
i_callback_pf_status_set = 'GUI_SET'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = it_fieldcat
it_sort = it_sort
it_events = it_event
TABLES
t_outtab = it.
ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form sort_bulding
*&---------------------------------------------------------------------*
FORM sort_bulding .
DATA: ws_sort TYPE slis_sortinfo_alv.
CLEAR ws_sort.
ws_sort-fieldname = 'VBELN'. "key field
ws_sort-up = 'X'.
ws_sort-subtot = 'X'.
APPEND ws_sort TO it_sort.
ENDFORM. " sort_bulding
*&---------------------------------------------------------------------*
*& Form events_get
*&---------------------------------------------------------------------*
FORM events_get .
DATA: ws_event TYPE slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 1
IMPORTING
et_events = it_event.
READ TABLE it_event WITH KEY name = slis_ev_top_of_page
INTO ws_event.
IF sy-subrc = 0.
MOVE 'TOP-OF-PAGE' TO ws_event-form.
APPEND ws_event TO it_event.
ENDIF.
ENDFORM. " events_get
*&---------------------------------------------------------------------*
*& Form write_headings
*&---------------------------------------------------------------------*
FORM write_headings .
DATA: wa_header TYPE slis_listheader.
CLEAR wa_header.
wa_header-typ = 'H'.
wa_header-info = 'Sales Order Information'.
APPEND wa_header TO it_header.
ENDFORM. " write_headings
*&---------------------------------------------------------------------*
*& Form write_headings
*&---------------------------------------------------------------------*
FORM top-of-page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_header
i_logo = 'ENJOY'.
ENDFORM. "top-of-page
*&---------------------------------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------------------------------*
FORM gui_set USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'A000'.
ENDFORM. "GUI_SET
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
r_selfield TYPE slis_selfield.
REFRESH itab.
CASE r_ucomm.
WHEN '&IC1'.
PERFORM list_display USING r_ucomm
r_selfield.
WHEN 'LIST'.
PERFORM list_display USING r_ucomm
r_selfield.
WHEN 'REPORT'.
LEAVE TO LIST-PROCESSING.
PERFORM display_report.
ENDCASE.
ENDFORM. "USER_COMMAND
*&---------------------------------------------------------------------*
*& Form list_display
*----------------------------------------------------------------------*
FORM list_display USING r_ucomm LIKE sy-ucomm
r_selfield TYPE slis_selfield.
CLEAR itab.
LOOP AT it WHERE vbeln = r_selfield-value.
itab-vbeln = it-vbeln.
itab-waerk = it-waerk.
itab-vkorg = it-vkorg.
itab-spart = it-spart.
itab-posnr = it-posnr.
itab-matnr = it-matnr.
itab-netwr = it-netwr.
APPEND itab.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = it_fieldcat
TABLES
t_outtab = itab.
ENDFORM. " list_display
*&---------------------------------------------------------------------*
*& Form display_report
*----------------------------------------------------------------------*
FORM display_report .
LOOP AT it.
WRITE:/ it-vbeln, it-posnr, it-vkorg, it-spart,
it-matnr, it-netwr, it-waerk.
ENDLOOP.
ENDFORM. " display_report
List output in the a pop up
REPORT ZBHALV_LIST1.
TYPE-POOLS SLIS.
TABLES:MARA.
DATA:FCAT TYPE slis_t_fieldcat_alv.
DATA:LAYOUT TYPE slis_layout_alv.
DATA:EVE TYPE slis_t_event WITH HEADER LINE.
DATA:HEAD TYPE slis_t_listheader WITH HEADER LINE.
DATA:SORT TYPE slis_t_sortinfo_alv WITH HEADER LINE.
DATA:BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR,
ERSDA LIKE MARA-ERSDA,
MTART LIKE MARA-MTART,
MBRSH LIKE MARA-MBRSH,
END OF ITAB.
SELECT-OPTIONS: MATNR FOR MARA-MATNR.
start-of-selection .
SELECT * FROM MARA
INTO CORRESPONDING FIELDS OF TABLE
ITAB WHERE MATNR IN MATNR.
SORT-UP = 'X'.
SORT-SPOS = 1.
SORT-FIELDNAME = 'ERSDA'.
SORT-tabname = 'MARA'.
APPEND SORT.
SORT-SPOS = 2.
SORT-FIELDNAME = 'MTART'.
SORT-tabname = 'MARA'.
APPEND SORT.
EVE-NAME = 'TOP_OF_PAGE'.
EVE-FORM = 'TOPOFPAGE'.
APPEND EVE.
EVE-NAME = 'TOP_OF_LIST'.
EVE-FORM = 'TOPOFLIST'.
APPEND EVE.
EVE-NAME = 'END_OF_LIST'.
EVE-FORM = 'ENDOFLIST'.
APPEND EVE.
LAYOUT-ZEBRA = 'X'.
LAYOUT-no_hline = 'X'.
LAYOUT-NO_VLINE = 'X'.
LAYOUT-window_titlebar = 'MATERIAL DETAILS'.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'ITAB'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = SY-REPID
CHANGING
CT_FIELDCAT = FCAT .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = LAYOUT
IT_FIELDCAT = FCAT
IT_SORT = SORT[]
I_DEFAULT = 'X'
I_SAVE = ' '
IT_EVENTS = EVE[]
I_SCREEN_START_COLUMN = 5
I_SCREEN_START_LINE = 5
I_SCREEN_END_COLUMN = 60
I_SCREEN_END_LINE = 25
TABLES
T_OUTTAB = ITAB .
*------------------------------------------------------------------------
* form top of page
*------------------------------------------------------------------------
FORM TOPOFPAGE.
REFRESH HEAD.
HEAD-TYP = 'H'.
HEAD-INFO = 'MATERIALS'.
APPEND HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEAD[] .
ENDFORM.
*------------------------------------------------------------------------
* top of list
*------------------------------------------------------------------------
FORM TOPOFLIST.
REFRESH HEAD.
HEAD-TYP = 'H'.
HEAD-INFO = 'MATERIALS-LISTTOP'.
APPEND HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEAD[]
.
ENDFORM.
*-------------------------------------------------------------------------
* end of list
*-------------------------------------------------------------------------
FORM ENDOFLIST.
REFRESH HEAD.
HEAD-TYP = 'H'.
HEAD-INFO = 'MATERIALS-LISTEND'.
APPEND HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = HEAD[] .
ENDFORM.
Simple report in different forms
report zalv_sample .
tables vbak.
data it_vbak like vbak occurs 0 with header line.
selection-screen begin of block b1 with frame.
parameters: list radiobutton group alv, "REUSE_ALV_LIST_DISPLAY
popup radiobutton group alv, "REUSE_ALV_POPUP_TO_SELECT
grid radiobutton group alv, "REUSE_ALV_GRID_DISPLAY
clasical radiobutton group alv. " NORMAL DISPLAY
selection-screen end of block b1.
select * from vbak
into corresponding fields of table it_vbak
up to 10 rows.
if list = 'X'.
perform alv_func1.
elseif popup = 'X'.
perform alv_func2.
elseif grid = 'X'.
perform alv_func3.
elseif clasical = 'X'.
perform norm.
endif.
*&---------------------------------------------------------------------*
*& Form ALV_FUNC1
*&---------------------------------------------------------------------*
form alv_func1 .
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_structure_name = 'VBAK'
tables
t_outtab = it_vbak
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. " ALV_FUNC1
*&---------------------------------------------------------------------*
*& Form ALV_FUNC2
*&---------------------------------------------------------------------*
form alv_func2 .
call function 'REUSE_ALV_POPUP_TO_SELECT'
exporting
i_title = 'SALES ORDER INFO'
i_zebra = 'X'
i_tabname = 1
i_structure_name = 'vbak'
tables
t_outtab = it_vbak
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. " ALV_FUNC2
*&---------------------------------------------------------------------*
*& Form ALV_FUNC3
*&---------------------------------------------------------------------*
form alv_func3 .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_structure_name = 'vbak'
i_grid_title = 'SALES ORDER INFO'
tables
t_outtab = it_vbak
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. " ALV_FUNC3
*&---------------------------------------------------------------------*
*& Form NORM
*&---------------------------------------------------------------------*
form norm .
format intensified.
skip 1.
write: /'SALES DOC.',
' Created on ',
' Time',
' Created by',
' Valid from ',
' Sold-to party'.
format intensified off.
skip 2.
loop at it_vbak.
write: / it_vbak-vbeln,' ',
it_vbak-erdat,' ',
it_vbak-erzet,' ',
it_vbak-ernam,' ',
it_vbak-angdt,' ',
it_vbak-kunnr.
endloop.
endform. " NORM
Simple interactive report with grid
REPORT Zalvinteractive
NO STANDARD PAGE HEADING
LINE-SIZE 650
MESSAGE-ID ZZ .
TYPE-POOLS: SLIS.
*type declaration for values from ekko
TYPES: BEGIN OF I_EKKO,
EBELN LIKE EKKO-EBELN,
AEDAT LIKE EKKO-AEDAT,
BUKRS LIKE EKKO-BUKRS,
BSART LIKE EKKO-BSART,
LIFNR LIKE EKKO-LIFNR,
END OF I_EKKO.
DATA: IT_EKKO TYPE STANDARD TABLE OF I_EKKO INITIAL SIZE 0,
WA_EKKO TYPE I_EKKO.
*type declaration for values from ekpo
TYPES: BEGIN OF I_EKPO,
EBELN LIKE EKPO-EBELN,
EBELP LIKE EKPO-EBELP,
MATNR LIKE EKPO-MATNR,
MENGE LIKE EKPO-MENGE,
MEINS LIKE EKPO-MEINS,
NETPR LIKE EKPO-NETPR,
END OF I_EKPO.
DATA: IT_EKPO TYPE STANDARD TABLE OF I_EKPO INITIAL SIZE 0,
WA_EKPO TYPE I_EKPO .
*variable for Report ID
DATA: V_REPID LIKE SY-REPID .
*declaration for fieldcatalog
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.
* declaration for events table where user comand or set PF status will
* be defined
DATA: V_EVENTS TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT.
* declartion for layout
DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
* declaration for variant(type of display we want)
DATA: I_VARIANT TYPE DISVARIANT,
I_VARIANT1 TYPE DISVARIANT,
I_SAVE(1) TYPE C.
*PARAMETERS : p_var TYPE disvariant-variant.
*Title displayed when the alv list is displayed
DATA: I_TITLE_EKKO TYPE LVC_TITLE VALUE 'FIRST LIST DISPLAYED'.
DATA: I_TITLE_EKPO TYPE LVC_TITLE VALUE 'SECONDRY LIST DISPLAYED'.
INITIALIZATION.
V_REPID = SY-REPID.
PERFORM BUILD_FIELDCATLOG.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT.
START-OF-SELECTION.
PERFORM DATA_RETRIEVAL.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_REPORT.
*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG
*&--------------------------------------------------------------------*
* Fieldcatalog has all the field details from ekko
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'AEDAT'.
WA_FIELDCAT-SELTEXT_M = 'DATE.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'COMPANY CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'BUKRS'.
WA_FIELDCAT-SELTEXT_M = 'DOCMENT TYPE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKKO'.
WA_FIELDCAT-FIELDNAME = 'LIFNR'.
WA_FIELDCAT-NO_OUT = 'X'.
WA_FIELDCAT-SELTEXT_M = 'VENDOR CODE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG
*&--------------------------------------------------------------------*
*& 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 = V_EVENTS .
ENDFORM. "EVENT_CALL
*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-NAME.
ENDIF.
ENDFORM. "POPULATE_EVENT
*&--------------------------------------------------------------------*
*& Form data_retrieval
*&--------------------------------------------------------------------*
* retreiving values from the database table ekko
*---------------------------------------------------------------------*
FORM DATA_RETRIEVAL.
SELECT EBELN
AEDAT
BUKRS
BSART
LIFNR
FROM EKKO
INTO TABLE IT_EKKO.
ENDFORM. "data_retrieval
*&--------------------------------------------------------------------*
*& Form bUild_listheader
*---------------------------------------------------------------------*
FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA HLINE TYPE SLIS_LISTHEADER.
HLINE-INFO = 'this is my first alv pgm'.
HLINE-TYP = 'H'.
ENDFORM. "build_listheader
*&--------------------------------------------------------------------*
*& Form display_alv_report
*---------------------------------------------------------------------*
FORM DISPLAY_ALV_REPORT.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = I_TITLE_EKKO
IT_FIELDCAT = I_FIELDCAT[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_EKKO .
ENDFORM. "display_alv_report
*&--------------------------------------------------------------------*
*& Form TOP_OF_PAGE
*---------------------------------------------------------------------*
FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER
* i_logo =
* I_END_OF_LIST_GRID =
.
ENDFORM. "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'.
READ TABLE IT_EKKO INTO WA_EKKO INDEX RS_SELFIELD-TABINDEX.
PERFORM BUILD_FIELDCATLOG_EKPO.
PERFORM EVENT_CALL_EKPO.
PERFORM POPULATE_EVENT_EKPO.
PERFORM DATA_RETRIEVAL_EKPO.
PERFORM BUILD_LISTHEADER_EKPO USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_EKPO.
ENDCASE.
ENDFORM. "user_command
*&--------------------------------------------------------------------*
*& Form BUILD_FIELDCATLOG_EKPO
*---------------------------------------------------------------------*
FORM BUILD_FIELDCATLOG_EKPO.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELN'.
WA_FIELDCAT-SELTEXT_M = 'PO NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'IT_EKPO'.
WA_FIELDCAT-FIELDNAME = 'EBELP'.
WA_FIELDCAT-SELTEXT_M = 'LINE NO'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MATNR'.
WA_FIELDCAT-SELTEXT_M = 'MATERIAL NO.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MENGE'.
WA_FIELDCAT-SELTEXT_M = 'QUANTITY'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'MEINS'.
WA_FIELDCAT-SELTEXT_M = 'UOM'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
WA_FIELDCAT-TABNAME = 'I_EKPO'.
WA_FIELDCAT-FIELDNAME = 'NETPR'.
WA_FIELDCAT-SELTEXT_M = 'PRICE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.
ENDFORM. "BUILD_FIELDCATLOG_EKPO
*&--------------------------------------------------------------------*
*& Form event_call_ekpo
*&--------------------------------------------------------------------*
* we get all events - TOP OF PAGE or USER COMMAND in table v_events
*---------------------------------------------------------------------*
FORM EVENT_CALL_EKPO.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS .
ENDFORM. "event_call_ekpo
*&--------------------------------------------------------------------*
*& Form POPULATE_EVENT
*&--------------------------------------------------------------------*
* Events populated for TOP OF PAGE & USER COMAND
*---------------------------------------------------------------------*
FORM POPULATE_EVENT_EKPO.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_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 = IT_LISTHEADER .
.
ENDFORM. "TOP_OF_PAGE
*&--------------------------------------------------------------------*
*& Form USER_COMMAND
*---------------------------------------------------------------------*
*retreiving values from the database table ekko
FORM DATA_RETRIEVAL_EKPO.
SELECT EBELN EBELP MATNR MENGE MEINS NETPR FROM EKPO INTO TABLE IT_EKPO.
ENDFORM.
FORM BUILD_LISTHEADER_EKPO USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA: HLINE1 TYPE SLIS_LISTHEADER.
HLINE1-TYP = 'H'.
HLINE1-INFO = 'CHECKING PGM'.
ENDFORM.
FORM DISPLAY_ALV_EKPO.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_GRID_TITLE = I_TITLE_EKPO
IT_FIELDCAT = I_FIELDCAT[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_EKPO .
ENDFORM.
SIMPLE TREE EXAMPLE
REPORT ZTEST.
TABLES: KNVH.
TYPES: BEGIN OF WORKTYPE,
LEVEL(2),
HKUNNR LIKE KNVH-KUNNR,
KUNNR LIKE KNVH-HKUNNR,
END OF WORKTYPE.
DATA: IT_KNVH TYPE TABLE OF WORKTYPE,
WA_KNVH LIKE LINE OF IT_KNVH,
IT_TEMP TYPE TABLE OF WORKTYPE,
WA_TEMP LIKE LINE OF IT_TEMP,
IT_WORK TYPE TABLE OF WORKTYPE,
WA_WORK LIKE LINE OF IT_WORK.
DATA : BEGIN OF IT_NODES OCCURS 0.
INCLUDE STRUCTURE SNODETEXT.
DATA : END OF IT_NODES.
CONSTANTS: NUMBER_OF_LEVELS TYPE I VALUE 6.
PARAMETER: P_HKUNNR LIKE KNVH-HKUNNR.
START-OF-SELECTION.
* Parent = 1. hierarchy node
WA_TEMP-KUNNR = P_HKUNNR.
APPEND WA_TEMP TO IT_TEMP.
WA_WORK-KUNNR = WA_TEMP-KUNNR.
WA_WORK-LEVEL = 1.
APPEND WA_WORK TO IT_WORK.
* Reading customer hierarchy (max. 6 level)
DO NUMBER_OF_LEVELS TIMES.
CHECK NOT IT_TEMP IS INITIAL.
SELECT KUNNR HKUNNR
FROM KNVH
INTO CORRESPONDING FIELDS OF TABLE IT_KNVH
FOR ALL ENTRIES IN IT_TEMP
WHERE HKUNNR = IT_TEMP-KUNNR.
LOOP AT IT_KNVH INTO WA_KNVH.
WA_KNVH-LEVEL = SY-INDEX + 1.
APPEND WA_KNVH TO IT_WORK.
ENDLOOP.
IT_TEMP[] = IT_KNVH[].
ENDDO.
* Hierarchy nodes -> tree control
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 1.
PERFORM MAKE_NODE.
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 2 AND
HKUNNR = WA_WORK-KUNNR.
PERFORM MAKE_NODE.
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 3 AND
HKUNNR = WA_WORK-KUNNR.
PERFORM MAKE_NODE.
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 4 AND
HKUNNR = WA_WORK-KUNNR.
PERFORM MAKE_NODE.
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 5 AND
HKUNNR = WA_WORK-KUNNR.
PERFORM MAKE_NODE.
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 6 AND
HKUNNR = WA_WORK-KUNNR.
PERFORM MAKE_NODE.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
ENDLOOP.
* Making the tree control
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
NODETAB = IT_NODES
EXCEPTIONS
TREE_FAILURE = 1.
* Display the tree control
DATA : F15 TYPE C.
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = SY-REPID
IMPORTING
F15 = F15 .
FORM MAKE_NODE.
IT_NODES-NAME = WA_WORK-KUNNR.
IT_NODES-COLOR = 1.
IT_NODES-INTENSIV = 1.
IT_NODES-TEXT = WA_WORK-KUNNR.
IT_NODES-TLENGTH = 16.
IT_NODES-TLEVEL = WA_WORK-LEVEL.
IT_NODES-TCOLOR = 1.
IT_NODES-TINTENSIV = 1.
APPEND IT_NODES.
ENDFORM.
Wordwrap in reports
REPORT ZREAD_LINES.
data : str(40).
str = 'This the test report for the test case in word wraping'..
data : v1(20),
v2(10),
v3(10).
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
textline = str
OUTPUTLEN = 10
IMPORTING
OUT_LINE1 = v1
OUT_LINE2 = v2
OUT_LINE3 = v3 .
write : / v1.
write : / v2.
write : / v3.
Word warping in alv
REPORT zalv_multipleline .
TYPE-POOLS slis .
*----------------------------------------------------------------------*
* Data Declarations
*----------------------------------------------------------------------*
CONSTANTS : c_len TYPE i VALUE 20 .
TYPES : BEGIN OF ty_t100 ,
sprsl TYPE t100-sprsl ,
arbgb TYPE t100-arbgb ,
msgnr TYPE t100-msgnr ,
text TYPE t100-text ,
fline TYPE t100-text ,
END OF ty_t100 .
TYPES : BEGIN OF ty_wrd ,
text TYPE char20 ,
END OF ty_wrd .
DATA : it_t100 TYPE TABLE OF ty_t100 ,
it_sentence TYPE TABLE OF ty_wrd ,
wa_t100 TYPE ty_t100 ,
wa_word TYPE ty_wrd ,
v_repid TYPE syst-repid ,
v_tabix TYPE syst-tabix .
DATA : it_fld TYPE slis_t_fieldcat_alv ,
it_evt TYPE slis_t_event ,
wa_fld TYPE slis_fieldcat_alv ,
wa_evt TYPE slis_alv_event ,
wa_lay TYPE slis_layout_alv .
*----------------------------------------------------------------------*
* Initialization
*----------------------------------------------------------------------*
INITIALIZATION .
v_repid = sy-repid .
*----------------------------------------------------------------------*
* Start of Selection
*----------------------------------------------------------------------*
START-OF-SELECTION .
* Get some test data to display in ALV List
SELECT *
INTO TABLE it_t100
FROM t100
WHERE sprsl = 'EN'
AND arbgb = '00' .
LOOP AT it_t100 INTO wa_t100 .
v_tabix = sy-tabix .
CLEAR : it_sentence .
* Word Wrap the text in multiple lines
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
textline = wa_t100-text
outputlen = c_len
TABLES
out_lines = it_sentence.
IF NOT it_sentence IS INITIAL .
READ TABLE it_sentence INTO wa_word INDEX 1 .
wa_t100-fline = wa_word-text .
MODIFY it_t100 FROM wa_t100 INDEX v_tabix .
ENDIF.
ENDLOOP.
* Prepare fieldcatelog
CLEAR wa_fld .
wa_fld-fieldname = 'SPRSL' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'SPRSL' .
APPEND wa_fld TO it_fld .
CLEAR wa_fld .
wa_fld-fieldname = 'ARBGB' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'ARBGB' .
APPEND wa_fld TO it_fld .
CLEAR wa_fld .
wa_fld-fieldname = 'MSGNR' .
wa_fld-ref_tabname = 'T100' .
wa_fld-ref_fieldname = 'MSGNR' .
APPEND wa_fld TO it_fld .
CLEAR wa_fld .
wa_fld-fieldname = 'FLINE' .
wa_fld-inttype = 'CHAR' .
wa_fld-outputlen = 20 .
wa_fld-intlen = 20.
wa_fld-seltext_l = 'Text' .
wa_fld-ddictxt = 'L' .
APPEND wa_fld TO it_fld .
* Get event.. we will handle BEFORE and AFTER line output
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = it_evt.
READ TABLE it_evt INTO wa_evt
WITH KEY name = slis_ev_after_line_output .
wa_evt-form = slis_ev_after_line_output .
MODIFY it_evt FROM wa_evt INDEX sy-tabix .
READ TABLE it_evt INTO wa_evt
WITH KEY name = slis_ev_top_of_page .
wa_evt-form = slis_ev_top_of_page .
MODIFY it_evt FROM wa_evt INDEX sy-tabix .
wa_lay-no_colhead = 'X' .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = v_repid
it_fieldcat = it_fld
is_layout = wa_lay
it_events = it_evt
TABLES
t_outtab = it_t100.
*---------------------------------------------------------------------*
* FORM top_of_page *
*---------------------------------------------------------------------*
FORM top_of_page .
ULINE AT 1(58) .
FORMAT COLOR COL_HEADING .
WRITE: / sy-vline ,
02 'Header1' ,
10 sy-vline ,
11 'Header1' ,
31 sy-vline ,
32 'Header1' ,
37 sy-vline ,
38 'Header1' ,
58 sy-vline .
WRITE: / sy-vline ,
02 'Header2' ,
10 sy-vline ,
11 'Header2' ,
31 sy-vline ,
32 'Header2' ,
37 sy-vline ,
38 'Header2' ,
58 sy-vline .
ENDFORM.
*---------------------------------------------------------------------*
* FORM AFTER_LINE_OUTPUT *
*---------------------------------------------------------------------*
FORM after_line_output USING rs_lineinfo TYPE slis_lineinfo .
CLEAR : it_sentence ,
wa_t100 .
READ TABLE it_t100 INTO wa_t100 INDEX rs_lineinfo-tabindex .
CHECK sy-subrc = 0 .
CALL FUNCTION 'RKD_WORD_WRAP'
EXPORTING
textline = wa_t100-text
outputlen = c_len
TABLES
out_lines = it_sentence.
DESCRIBE TABLE it_sentence LINES v_tabix .
CHECK v_tabix > 1 .
LOOP AT it_sentence INTO wa_word FROM 2 .
WRITE: / sy-vline ,
10 sy-vline ,
31 sy-vline ,
37 sy-vline ,
38 wa_word-text ,
58 sy-vline .
ENDLOOP.
ENDFORM .
Hirarchial list display
REPORT ZVENKAT_SUBTOT_HIRARCHIAL.
"Types
TYPES:
BEGIN OF t_pa0001, "Header table type
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
abkrs TYPE pa0001-abkrs,
expand TYPE c,
END OF t_pa0001,
BEGIN OF t_pa0008, "Item table
pernr TYPE pa0008-pernr,
lga01 TYPE pa0008-lga01,
bet01 TYPE pa0008-bet01,
END OF t_pa0008.
"Work areas
DATA:
w_pa0008 TYPE t_pa0008,
w_pa0001 TYPE t_pa0001.
"Internal tables
DATA:
i_pa0008 TYPE STANDARD TABLE OF t_pa0008,
i_pa0001 TYPE STANDARD TABLE OF t_pa0001.
*&---------------------------------------------------------------------*
" ALV Declarations
*----------------------------------------------------------------------*
" Types Pools
TYPE-POOLS:
slis.
" Types
TYPES:
t_fieldcat TYPE slis_fieldcat_alv,
t_events TYPE slis_alv_event,
t_layout TYPE slis_layout_alv,
t_sort TYPE slis_sortinfo_alv,
t_keyinfo TYPE slis_keyinfo_alv.
" Workareas
DATA:
w_fieldcat TYPE t_fieldcat,
w_events TYPE t_events,
w_sort TYPE t_sort,
w_layout TYPE t_layout,
w_keyinfo TYPE t_keyinfo.
" Internal Tables
DATA:
i_fieldcat TYPE STANDARD TABLE OF t_fieldcat,
i_events TYPE STANDARD TABLE OF t_events,
i_sort TYPE STANDARD TABLE OF t_sort.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM build_fieldcatalog. "Fieldcatalog
PERFORM build_events. "Events table
PERFORM build_sort_tab. "To sort table and get subtotal
PERFORM build_relation_structure. "Making relationship between header
* and Item table
PERFORM display_data.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data.
DATA:l_0008 TYPE pa0008 OCCURS 0 WITH HEADER LINE.
SELECT *
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE i_pa0001
UP TO 50 ROWS
WHERE begda LE sy-datum
AND endda GE sy-datum.
IF i_pa0001[] IS NOT INITIAL.
SELECT pernr lga01 bet01
FROM pa0008
INTO CORRESPONDING FIELDS OF l_0008
FOR ALL ENTRIES IN i_pa0001
WHERE pernr = i_pa0001-pernr
AND begda LE sy-datum
AND endda GE sy-datum.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga01.
w_pa0008-bet01 = l_0008-bet01.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga02.
w_pa0008-bet01 = l_0008-bet02.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga03.
w_pa0008-bet01 = l_0008-bet03.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga04.
w_pa0008-bet01 = l_0008-bet04.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
ENDSELECT.
ENDIF.
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
FORM build_fieldcatalog.
PERFORM build_fcat USING:
"Field Int.Table Text
'PERNR' 'I_PA0001' 'PERNR',
'BUKRS' 'I_PA0001' 'BUKRS',
'WERKS' 'I_PA0001' 'WERKS',
'PERSG' 'I_PA0001' 'PERSG',
'PERSK' 'I_PA0001' 'PERSK',
'ABKRS' 'I_PA0001' 'ABKRS',
'PERNR' 'I_PA0008' 'PERNR', "Remove this if u dont
*want in the item table as well as it is there in the header table
'LGA01' 'I_PA0008' 'LGA01',
'BET01' 'I_PA0008' 'BET01'.
ENDFORM. "build_fieldcatalog
*&---------------------------------------------------------------------*
*& Form build_events
*----------------------------------------------------------------------*
FORM build_events.
CLEAR:
w_events, i_events[].
w_events-name = 'TOP_OF_PAGE'.
w_events-form = 'TOP_OF_PAGE'.
APPEND w_events TO i_events.
CLEAR w_events.
ENDFORM. "build_events
*&---------------------------------------------------------------------*
*& Form build_relation_structure
*----------------------------------------------------------------------*
FORM build_relation_structure.
w_keyinfo-header01 = 'PERNR'.
w_keyinfo-item01 = 'PERNR'.
ENDFORM. "build_relation_structure
*&---------------------------------------------------------------------*
*& Form display_data
*----------------------------------------------------------------------*
FORM display_data.
DATA:
l_program TYPE sy-repid VALUE sy-repid.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = l_program
it_fieldcat = i_fieldcat
it_events = i_events
it_sort = i_sort
i_tabname_header = 'I_PA0001'
i_tabname_item = 'I_PA0008'
is_keyinfo = w_keyinfo
TABLES
t_outtab_header = i_pa0001
t_outtab_item = i_pa0008.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "display_data
*&---------------------------------------------------------------------*
*& Form build_fcat
*&---------------------------------------------------------------------*
FORM build_fcat USING l_field l_tab l_text.
w_fieldcat-fieldname = l_field.
w_fieldcat-tabname = l_tab.
w_fieldcat-seltext_m = l_text.
IF l_field = 'BET01'.
w_fieldcat-do_sum = 'X'.
ENDIF.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
ENDFORM. " build_fcat
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
DATA :
i_header TYPE slis_t_listheader,
w_header LIKE LINE OF i_header.
DATA:l_date1 TYPE datum,
l_date2 TYPE datum.
w_header-typ = 'S'.
w_header-info = sy-title.
APPEND w_header TO i_header.
CLEAR w_header.
w_header-typ = 'H'.
w_header-info = sy-repid.
APPEND w_header TO i_header.
CLEAR w_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header
i_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form BUILD_sort_tab
*&---------------------------------------------------------------------*
FORM build_sort_tab .
CLEAR :i_sort[],w_sort.
w_sort-spos = 1.
w_sort-fieldname = 'PERNR'.
w_sort-tabname = 'I_PA0001'. "header table
w_sort-up = 'X'.
w_sort-subtot = 'X'.
APPEND w_sort TO i_sort.
CLEAR w_sort.
ENDFORM. " BUILD_sort_tab
Subtotals in hirarchial report
REPORT zvenkat_alv_4_hierarchi_subtot.
"Types
TYPES:
BEGIN OF t_pa0001, "Header table type
pernr TYPE pa0001-pernr,
bukrs TYPE pa0001-bukrs,
werks TYPE pa0001-werks,
persg TYPE pa0001-persg,
persk TYPE pa0001-persk,
abkrs TYPE pa0001-abkrs,
expand TYPE c,
END OF t_pa0001,
BEGIN OF t_pa0008, "Item table
pernr TYPE pa0008-pernr,
lga01 TYPE pa0008-lga01,
bet01 TYPE pa0008-bet01,
END OF t_pa0008.
"Work areas
DATA:
w_pa0008 TYPE t_pa0008,
w_pa0001 TYPE t_pa0001.
"Internal tables
DATA:
i_pa0008 TYPE STANDARD TABLE OF t_pa0008,
i_pa0001 TYPE STANDARD TABLE OF t_pa0001.
*&---------------------------------------------------------------------*
" ALV Declarations
*----------------------------------------------------------------------*
" Types Pools
TYPE-POOLS:
slis.
" Types
TYPES:
t_fieldcat TYPE slis_fieldcat_alv,
t_events TYPE slis_alv_event,
t_layout TYPE slis_layout_alv,
t_sort TYPE slis_sortinfo_alv,
t_keyinfo TYPE slis_keyinfo_alv.
" Workareas
DATA:
w_fieldcat TYPE t_fieldcat,
w_events TYPE t_events,
w_sort TYPE t_sort,
w_layout TYPE t_layout,
w_keyinfo TYPE t_keyinfo.
" Internal Tables
DATA:
i_fieldcat TYPE STANDARD TABLE OF t_fieldcat,
i_events TYPE STANDARD TABLE OF t_events,
i_sort TYPE STANDARD TABLE OF t_sort.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM build_fieldcatalog. "Fieldcatalog
PERFORM build_events. "Events table
PERFORM build_sort_tab. "To sort table and get subtotal
PERFORM build_relation_structure. "Making relationship between header
* and Item table
PERFORM display_data.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data.
DATA:l_0008 TYPE pa0008 OCCURS 0 WITH HEADER LINE.
SELECT *
FROM pa0001
INTO CORRESPONDING FIELDS OF TABLE i_pa0001
UP TO 50 ROWS
WHERE begda LE sy-datum
AND endda GE sy-datum.
IF i_pa0001[] IS NOT INITIAL.
SELECT pernr lga01 bet01
FROM pa0008
INTO CORRESPONDING FIELDS OF l_0008
FOR ALL ENTRIES IN i_pa0001
WHERE pernr = i_pa0001-pernr
AND begda LE sy-datum
AND endda GE sy-datum.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga01.
w_pa0008-bet01 = l_0008-bet01.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga02.
w_pa0008-bet01 = l_0008-bet02.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga03.
w_pa0008-bet01 = l_0008-bet03.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
w_pa0008-pernr = l_0008-pernr.
w_pa0008-lga01 = l_0008-lga04.
w_pa0008-bet01 = l_0008-bet04.
APPEND w_pa0008 TO i_pa0008.
CLEAR w_pa0008.
ENDSELECT.
ENDIF.
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form build_fieldcatalog
*&---------------------------------------------------------------------*
FORM build_fieldcatalog.
PERFORM build_fcat USING:
"Field Int.Table Text
'PERNR' 'I_PA0001' 'PERNR',
'BUKRS' 'I_PA0001' 'BUKRS',
'WERKS' 'I_PA0001' 'WERKS',
'PERSG' 'I_PA0001' 'PERSG',
'PERSK' 'I_PA0001' 'PERSK',
'ABKRS' 'I_PA0001' 'ABKRS',
'PERNR' 'I_PA0008' 'PERNR', "Remove this if u dont
*want in the item table as well as it is there in the header table
'LGA01' 'I_PA0008' 'LGA01',
'BET01' 'I_PA0008' 'BET01'.
ENDFORM. "build_fieldcatalog
*&---------------------------------------------------------------------*
*& Form build_events
*----------------------------------------------------------------------*
FORM build_events.
CLEAR:
w_events, i_events[].
w_events-name = 'TOP_OF_PAGE'.
w_events-form = 'TOP_OF_PAGE'.
APPEND w_events TO i_events.
CLEAR w_events.
ENDFORM. "build_events
*&---------------------------------------------------------------------*
*& Form build_relation_structure
*----------------------------------------------------------------------*
FORM build_relation_structure.
w_keyinfo-header01 = 'PERNR'.
w_keyinfo-item01 = 'PERNR'.
ENDFORM. "build_relation_structure
*&---------------------------------------------------------------------*
*& Form display_data
*----------------------------------------------------------------------*
FORM display_data.
DATA:
l_program TYPE sy-repid VALUE sy-repid.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = l_program
it_fieldcat = i_fieldcat
it_events = i_events
it_sort = i_sort
i_tabname_header = 'I_PA0001'
i_tabname_item = 'I_PA0008'
is_keyinfo = w_keyinfo
TABLES
t_outtab_header = i_pa0001
t_outtab_item = i_pa0008.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. "display_data
*&---------------------------------------------------------------------*
*& Form build_fcat
*&---------------------------------------------------------------------*
FORM build_fcat USING l_field l_tab l_text.
w_fieldcat-fieldname = l_field.
w_fieldcat-tabname = l_tab.
w_fieldcat-seltext_m = l_text.
IF l_field = 'BET01'.
w_fieldcat-do_sum = 'X'.
ENDIF.
APPEND w_fieldcat TO i_fieldcat.
CLEAR w_fieldcat.
ENDFORM. " build_fcat
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM top_of_page.
DATA :
i_header TYPE slis_t_listheader,
w_header LIKE LINE OF i_header.
DATA:l_date1 TYPE datum,
l_date2 TYPE datum.
w_header-typ = 'S'.
w_header-info = sy-title.
APPEND w_header TO i_header.
CLEAR w_header.
w_header-typ = 'H'.
w_header-info = sy-repid.
APPEND w_header TO i_header.
CLEAR w_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_header
i_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "top_of_page
*&---------------------------------------------------------------------*
*& Form BUILD_sort_tab
*&---------------------------------------------------------------------*
FORM build_sort_tab .
CLEAR :i_sort[],w_sort.
w_sort-spos = 1.
w_sort-fieldname = 'PERNR'.
w_sort-tabname = 'I_PA0001'. "header table
w_sort-up = 'X'.
w_sort-subtot = 'X'.
APPEND w_sort TO i_sort.
CLEAR w_sort.
ENDFORM. " BUILD_sort_tab
Calling an alv from another alv report
REPORT zteststs.
*-----------------------------------------------------
* type pools
*----------------------------------------------------
TYPE-POOLS: slis.
*----------------------------------------------------
* tables
*----------------------------------------------------
TABLES:pa0002,
pa0008.
*----------------------------------------------------
* internal tables
*----------------------------------------------------
DATA:BEGIN OF it_pa0002 OCCURS 0,
checkbox,
pernr LIKE pa0002-pernr,
begda LIKE pa0002-begda,
endda LIKE pa0002-endda,
vorna LIKE pa0002-vorna,
nachn LIKE pa0002-nachn,
END OF it_pa0002.
DATA:BEGIN OF it_pa002 OCCURS 0,
pernr LIKE pa0002-pernr,
begda LIKE pa0002-begda,
endda LIKE pa0002-endda,
vorna LIKE pa0002-vorna,
nachn LIKE pa0002-nachn,
END OF it_pa002.
DATA:BEGIN OF it_pa00021 OCCURS 0,
pernr LIKE pa0002-pernr,
begda LIKE pa0002-begda,
endda LIKE pa0002-endda,
vorna LIKE pa0002-vorna,
nachn LIKE pa0002-nachn,
expand TYPE xfeld VALUE 'X',
END OF it_pa00021.
DATA:BEGIN OF it_pa0008 OCCURS 0,
pernr LIKE pa0008-pernr,
begda LIKE pa0008-begda,
endda LIKE pa0008-endda,
ansal LIKE pa0008-ansal,
lga01 LIKE pa0008-lga01,
bet01 LIKE pa0008-bet01,
END OF it_pa0008.
DATA: it_field_cat TYPE slis_t_fieldcat_alv,
it_field_cat1 TYPE slis_t_fieldcat_alv,
it_layout1 TYPE slis_layout_alv,
wa_field_cat TYPE slis_fieldcat_alv,
wa_field_cat1 TYPE slis_fieldcat_alv,
it_layout TYPE slis_layout_alv,
it_events TYPE slis_t_event,
wa_events TYPE slis_alv_event,
it_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
wa_keyinfo TYPE slis_keyinfo_alv.
CONSTANTS:c VALUE 'X'.
*-----------------------------------------------
* selection screen
*-----------------------------------------------
SELECT-OPTIONS: s_pernr FOR pa0002-pernr.
*-----------------------------------------------
* start of selection
*-----------------------------------------------
START-OF-SELECTION.
SET PF-STATUS 'DATA' .
PERFORM get_data.
PERFORM build_field_cat.
PERFORM get_events.
PERFORM display_data.
*&------------------------------------------------*
*& Form get_data
*-------------------------------------------------*
FORM get_data .
SELECT pernr
begda
endda
vorna
nachn
FROM pa0002
INTO CORRESPONDING FIELDS OF TABLE it_pa0002
WHERE pernr IN s_pernr.
ENDFORM. " get_data
*&----------------------------------------------*
*& Form build_field_cat
*----------------------------------------------*
FORM build_field_cat .
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'CHECKBOX'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'Check Box'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'PERNR'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'Personnel no'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'BEGDA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'Start date'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'ENDDA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'End date'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'VORNA'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'First name'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat-tabname = 'PA0002'.
wa_field_cat-fieldname = 'NACHN'.
wa_field_cat-ref_tabname = 'IT_PA0002'.
wa_field_cat-reptext_ddic = 'Last name'.
APPEND wa_field_cat TO it_field_cat.
CLEAR wa_field_cat.
wa_field_cat1-tabname = 'PA0002'.
wa_field_cat1-fieldname = 'PERNR'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
wa_field_cat1-reptext_ddic = 'Personnel no'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0002'.
wa_field_cat1-fieldname = 'BEGDA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
wa_field_cat1-reptext_ddic = 'Start date'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0002'.
wa_field_cat1-fieldname = 'ENDDA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
wa_field_cat1-reptext_ddic = 'End date'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0002'.
wa_field_cat1-fieldname = 'VORNA'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
wa_field_cat1-reptext_ddic = 'First name'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat.
wa_field_cat1-tabname = 'PA0002'.
wa_field_cat1-fieldname = 'NACHN'.
wa_field_cat1-ref_tabname = 'IT_PA00021'.
wa_field_cat1-reptext_ddic = 'Last name'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'PERNR'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'personnelno'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'BEGDA'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'begindate'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'ENDDA'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'enddate'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'ANSAL'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'annualsalary'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'LGA01'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'wagetype'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
wa_field_cat1-tabname = 'PA0008'.
wa_field_cat1-fieldname = 'BET01'.
wa_field_cat-ref_tabname = 'IT_PA0008'.
wa_field_cat1-reptext_ddic = 'Amount'.
APPEND wa_field_cat1 TO it_field_cat1.
CLEAR wa_field_cat1.
ENDFORM. " build_field_cat
*&------------------------------------------------*
*& Form display_data
*-------------------------------------------------*
FORM display_data .
it_layout-box_fieldname = 'CHECKBOX'.
it_layout-edit = 'X'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
it_fieldcat = it_field_cat
is_layout = it_layout
it_events = it_events
TABLES
t_outtab = it_pa0002.
ENDFORM. " display_data
*&------------------------------------------------*
*& Form get_events
*------------------------------------------------*
FORM get_events .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
IMPORTING
et_events = it_events.
READ TABLE it_events INTO wa_events
WITH KEY name = slis_ev_top_of_page.
IF sy-subrc = 0.
wa_events-form = 'TOP_OF_PAGE'.
MODIFY it_events FROM wa_events INDEX sy-tabix.
ENDIF.
ENDFORM. " get_events
*&--------------------------------------------*
*& Form top_of_page
*---------------------------------------------*
FORM top_of_page.
wa_header-typ = 'H'.
wa_header-info = 'EMPLOYEE DATA'.
APPEND wa_header TO it_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = it_header.
ENDFORM. "top_of_page
*&---------------------------------------------*
*& Form GUI_SET
*&---------------------------------------------*
FORM gui_set USING rt_extab TYPE slis_t_extab .
SET PF-STATUS 'DATA' .
ENDFORM. "GUI_SET
*&---------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
r_selfield TYPE slis_selfield.
DATA:v_pernr LIKE pa0002-pernr.
CASE r_ucomm.
WHEN 'DET'.
DATA: v_flag.
CLEAR : v_flag.
LOOP AT it_pa0002.
IF it_pa0002-checkbox = 'X'.
v_pernr = it_pa0002-pernr.
SELECT pernr
begda
endda
vorna
nachn
FROM pa0002
INTO CORRESPONDING FIELDS OF TABLE it_pa00021
WHERE pernr = v_pernr.
MOVE-CORRESPONDING it_pa0002 TO it_pa002.
APPEND it_pa002.
ENDIF.
ENDLOOP.
SELECT pernr
begda
endda
ansal
lga01
bet01
FROM pa0008
INTO TABLE it_pa0008
FOR ALL ENTRIES IN it_pa002
WHERE pernr = it_pa002-pernr.
it_pa00021[] = it_pa002[].
IF NOT it_pa0008[] IS INITIAL.
SORT it_pa0008 BY pernr.
READ TABLE it_pa0008 INDEX 1.
ENDIF.
it_layout1-group_change_edit = c.
it_layout1-colwidth_optimize = c.
it_layout1-zebra = c.
it_layout1-detail_popup = c.
it_layout1-get_selinfos = c.
it_layout-expand_fieldname = 'EXPAND'.
wa_keyinfo-header01 = 'PERNR'.
wa_keyinfo-item01 = 'PERNR'.
CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = it_layout1
it_fieldcat = it_field_cat1
i_tabname_header = 'PA0002'
i_tabname_item = 'PA0008'
is_keyinfo = wa_keyinfo
i_screen_start_column = 12
i_screen_start_line = 6
i_screen_end_column = 90
i_screen_end_line = 35
TABLES
t_outtab_header = it_pa00021
t_outtab_item = it_pa0008.
CLEAR: it_pa00021,it_pa0002,it_pa0008.
WHEN 'BACK'.
EXIT.
ENDCASE.
ENDFORM. "USER_COMMAND
Thursday, October 30, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment