‎2007 Sep 07 8:03 AM
HI..
Iam new in using ALV...
this is the following report i created...
When iam executing the following report its getting short dumped..
can anyone help me out in this...
I didnt know how to use the FM reuse_alv_fieldcatalog_merge and iam facing problems in it....
My requirement is to display matnr from mara in alv....
If possible suggest me the step by step process in alv or send me a sample program too for displaying one or two fields of a table using alv.....
REPORT ZIND_ALV_TEST.
type-pools: slis.
data: begin of iline occurs 0,
matnr like mara-matnr,
end of iline.
data: gt_fieldcat type slis_t_fieldcat_alv.
select matnr from mara into table iline.
perform setup-fieldcatalog using gt_fieldcat[].
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ' '
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME = mara
IS_LAYOUT =
IT_FIELDCAT = gt_fieldcat[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = iline
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
form setup-fieldcatalog using fieldcat type slist_fieldcat_alv.
data: ls_fieldcat type slis_fieldcat_alv.
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_internal_tabname = 'ILINE'
i_structure_name = 'mara'
changing
ct_fieldcat = gt_fieldcat.
endform. " FIELDCATALOG
‎2007 Sep 07 8:12 AM
Check this sample program
TYPE-POOLS: slis.
TYPE-POOLS: slis.
DATA : BEGIN OF xmara,
matnr LIKE makt-matnr,
spras LIKE makt-spras,
maktx LIKE makt-maktx,
END OF xmara.
DATA: imara LIKE STANDARD TABLE OF xmara WITH HEADER LINE.
DATA: fieldcat TYPE slis_t_fieldcat_alv.
DATA: repid TYPE syrepid.
repid = sy-repid.
SELECT matnr spras maktx
FROM makt
INTO TABLE imara
UP TO 100 ROWS
WHERE spras = sy-langu.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = repid
i_internal_tabname = 'XMARA'
i_inclname = repid
i_bypassing_buffer = 'X'
CHANGING
ct_fieldcat = fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fieldcat
TABLES
t_outtab = imara.Regards
Gopi
‎2007 Sep 07 8:09 AM
REPORT ZIND_ALV_TEST.
type-pools: slis.
data: begin of iline occurs 0,
matnr like mara-matnr,
end of iline.
<b>TYPE-POOLS: slis.
data: i_fieldcatalog TYPE slis_t_fieldcat_alv,
wa_fieldcatalog LIKE LINE OF i_fieldcatalog,
l_repid type sy-repid</b>
select matnr from mara into table iline.
<b> CLEAR: wa_fieldcatalog.
wa_fieldcatalog-fieldname = 'MATNR'.
wa_fieldcatalog-tabname = 'ILINE'.
wa_fieldcatalog-seltext_l = 'Material No.'.
wa_fieldcatalog-outputlen = 20.
wa_fieldcatalog-col_pos = 1.
APPEND wa_fieldcatalog TO i_fieldcatalog.
l_repid = sy-repid.
</b>
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE = ' '
<b> I_CALLBACK_PROGRAM = l_repid</b>
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME = mara
IS_LAYOUT =
IT_FIELDCAT = i_fieldcatalog
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IR_SALV_LIST_ADAPTER =
IT_EXCEPT_QINFO =
I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = iline
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.
‎2007 Sep 07 8:15 AM
Thanks for ur response but i would like to know how to use FM reuse_alv_fieldcatalog_merge...
I heard that generally we use this FM for displaying particular fields frm a table, is this true??? can u help me on it....
‎2007 Sep 07 8:12 AM
Check this sample program
TYPE-POOLS: slis.
TYPE-POOLS: slis.
DATA : BEGIN OF xmara,
matnr LIKE makt-matnr,
spras LIKE makt-spras,
maktx LIKE makt-maktx,
END OF xmara.
DATA: imara LIKE STANDARD TABLE OF xmara WITH HEADER LINE.
DATA: fieldcat TYPE slis_t_fieldcat_alv.
DATA: repid TYPE syrepid.
repid = sy-repid.
SELECT matnr spras maktx
FROM makt
INTO TABLE imara
UP TO 100 ROWS
WHERE spras = sy-langu.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = repid
i_internal_tabname = 'XMARA'
i_inclname = repid
i_bypassing_buffer = 'X'
CHANGING
ct_fieldcat = fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = fieldcat
TABLES
t_outtab = imara.Regards
Gopi
‎2007 Sep 07 8:19 AM
‎2007 Sep 07 8:18 AM
Hi Naveen,
There are two way to create fieldcatalog using this FM.
1. pass standard se11 structure in parameter I_STRUCTURE_NAME
or
2. Pass internal table in parameter I_INTERNAL_TABNAME declared using following declaration i.e. using Occurs 0.
Refer this code :
*&----Error table for Infotype 0007
DATA : BEGIN OF T_ERR_0007 OCCURS 0,
PERNR TYPE CHAR8, "EMPLOYEE NUMBER
SCHKZ TYPE CHAR8, "SHIFT
DAT02 TYPE CHAR10, "CONVERSION_DATE
MSG_0007 TYPE CHAR251, "ERROR_MESSAGE
END OF T_ERR_0007.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = SY-REPID
I_INTERNAL_TABNAME = 'T_ERR_0007'
I_STRUCTURE_NAME = 'INFO_0006'
I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = 'ZUHCM002_LOAD_PA_TOP'
I_BYPASSING_BUFFER =
I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = P_T_FCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Reward points if helpful.
Regards,
Hemant
‎2007 Sep 07 8:26 AM
Hi Naveen Plz care fully see this program and u can find any kind of answer in ALV Reporting from this program , Try to debugging this program and analysis ur self and am also write comment each and every line .
TYPE-POOLS: slis.
To pass name of the report in function module for ALV
DATA: v_repid LIKE sy-repid .
To pass the overall structure of the ALV report
DATA: struct_layout TYPE slis_layout_alv.
DATA: struct_layout1 TYPE slis_layout_alv.
Internal table to capture various events in ALV
DATA : i_events TYPE slis_t_event.
Table for catalog of the fields to be displayed
DATA: i_fieldcat TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat TYPE slis_fieldcat_alv.
DATA: i_fieldcat1 TYPE slis_t_fieldcat_alv.
DATA : x_fieldcat1 TYPE slis_fieldcat_alv.
Internal table to mention the sort sequence
DATA : it_sort TYPE slis_t_sortinfo_alv.
DATA : x_sort TYPE slis_sortinfo_alv.
Internal table to display top of page
DATA : i_list_top_of_page TYPE slis_t_listheader.
Structure to display variants
DATA : i_variant LIKE disvariant,
i_variant1 LIKE disvariant.
Internal table to pass data
DATA: BEGIN OF i_tab OCCURS 0,
mblnr LIKE mseg-mblnr ,
matnr LIKE mseg-matnr,
maktg LIKE makt-maktg ,
charg LIKE mseg-charg ,
werks LIKE mseg-werks,
lgort LIKE mseg-lgort,
menge LIKE mseg-menge ,
meins LIKE mseg-meins ,
dmbtr LIKE mseg-dmbtr,
ebeln LIKE mseg-ebeln,
icn(4) TYPE c ,
sym(4) TYPE c ,
excpt(2) TYPE c ,
box(1),
END OF i_tab.
*EJECT
DATA : BEGIN OF i_doc OCCURS 0 .
INCLUDE STRUCTURE mseg.
DATA : END OF i_doc.
-------End of Data Declaration-------------*
PARAMETERS : p_var LIKE disvariant-variant.
INITIALIZATION.
v_repid = sy-repid.
Display default variant
PERFORM sub_variant_init.
AT SELECTION-SCREEN ON p_var.
Once the user has entered variant, check about its existence
PERFORM sub_check_pvar.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
Display a list of various variants of the report when the
user presses F4 key in the variant field
PERFORM sub_variant_f4.
START-OF-SELECTION.
Prepare field catalog for the main report. State the name of
the field , name of internal table , various formatting options etc
PERFORM sub_prepare_fieldcatalog.
Fetches records from database into table i_tab to be passed as export
parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
PERFORM sub_select_record.
Populate stat and icon columns of internal table i_tab with specific
columns and symbols based on some logic for quantity and value fields.
PERFORM sub_modify_records.
Defines the overall layout of the report
PERFORM sub_determine_alv_layout.
Defines the sort sequence of the report
PERFORM sub_determine_sort_sequence.
Defines the event table
PERFORM sub_eventtab_build USING i_events.
Things to be written at the top of the page
PERFORM sub_comment_build USING i_list_top_of_page.
Display the ALV list
PERFORM sub_show_alv_list.
struct_layout-hotspot_fieldname = 'X'.
AT LINE-SELECTION.
PERFORM sub_hotspot.
&----
*& Form SUB_VARIANT_INIT
&----
Display default variant
----
FORM sub_variant_init.
i_variant1-report = sy-repid.
Search default variant for the report
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant1
EXCEPTIONS
not_found = 2.
If default variant is found , use it as default.
Else , use the variant LAYOUT1.
IF sy-subrc = 0.
p_var = i_variant1-variant.
ELSE.
p_var = 'LAYOUT1'.
ENDIF.
ENDFORM. " SUB_VARIANT_INIT
&----
*& Form SUB_CHECK_PVAR
&----
Once the user has entered variant, check about its existence
----
FORM sub_check_pvar.
If the name of the variable is not blank, check about its existence
IF NOT p_var IS INITIAL.
CLEAR i_variant.
i_variant-report = sy-repid.
i_variant-variant = p_var.
CALL FUNCTION 'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
i_save = 'A'
CHANGING
cs_variant = i_variant.
If no such variant found , flash error message
IF sy-subrc NE 0 .
MESSAGE e398(00) WITH 'No such variant exists'.
ELSE.
If variant exists , use the variant name to populate structure
I_VARIANT1 which will be used for export parameter : IS_VARIANT
in the function module : REUSE_ALV_GRID_DISPLAY
CLEAR i_variant1.
MOVE p_var TO i_variant1-variant.
MOVE sy-repid TO i_variant1-report.
ENDIF.
ELSE.
CLEAR i_variant.
ENDIF.
ENDFORM. " SUB_CHECK_PVAR
&----
*& Form SUB_PREPARE_FIELDCATALOG
&----
Prepare field catalog for the main report. State the name of
the field , name of internal table , various formatting options etc
----
FORM sub_prepare_fieldcatalog.
First field to appear in ALV list
x_fieldcat-col_pos = 1.
Name of the internal table field
x_fieldcat-fieldname = 'SYM'.
Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
Heading for the field
x_fieldcat-seltext_m = 'Stat'.
The field is going to contain a symbol
x_fieldcat-symbol = 'X'.
Append the specifications to the internal table for field catalog.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
Second field to appear in ALV list
x_fieldcat-col_pos = 2.
Name of the field in the internal table
x_fieldcat-fieldname = 'MATNR'.
Name of the internal table
x_fieldcat-tabname = 'I_TAB'.
Heading for the column
x_fieldcat-seltext_m = 'MatItem'.
It is going to be the key field.The color for this field is going to
be different
x_fieldcat-key = 'X'.
x_fieldcat-key_sel = 'X'.
Single click on the field will trigger double click event.Also, a hand
will appear when the cursor navigates to the field
x_fieldcat-hotspot = 'X'.
The column and those left to it will not scroll
x_fieldcat-fix_column = 'X'.
F1 help will come as it is referenced to DDIC table
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 3.
x_fieldcat-fieldname = 'MAKTG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Description'.
X_FIELDCAT-OUTPUTLEN = 50.
x_fieldcat-hotspot = space.
The field is centre(C for centre, R and L for left and
right) justified
x_fieldcat-just = 'C'.
x_fieldcat-key = 'X'.
x_fieldcat-fix_column = 'X'.
X_fieldcat-no_out = 'X'.
x_fieldcat-fix_column = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 4.
x_fieldcat-fieldname = 'CHARG'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Batch'.
X_FIELDCAT-OUTPUTLEN = 10.
x_fieldcat-hotspot = space.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 5.
x_fieldcat-fieldname = 'EBELN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Purchase Order'.
X_FIELDCAT-OUTPUTLEN = 14.
The field will be colored differently(Cxyz)
x_fieldcat-emphasize = 'C511'.
Initially the field will be hidden
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 6.
x_fieldcat-fieldname = 'MBLNR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Document no'.
X_FIELDCAT-OUTPUTLEN = 14.
x_fieldcat-emphasize = 'C711'.
x_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 7.
x_fieldcat-fieldname = 'WERKS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Plant'.
X_FIELDCAT-OUTPUTLEN = 5.
x_fieldcat-emphasize = 'C310'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 8.
x_fieldcat-fieldname = 'LGORT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'St.Loc'.
X_FIELDCAT-OUTPUTLEN = 7.
X_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 9.
x_fieldcat-fieldname = 'MENGE'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Quantity'.
x_fieldcat-outputlen = 12.
Summation is allowed for this field
x_fieldcat-do_sum = 'X'.
x_fieldcat-ref_tabname = 'MSEG'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 10.
x_fieldcat-fieldname = 'ICN'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = ''.
x_fieldcat-outputlen = 2.
x_fieldcat-icon = 'X'.
X_fieldcat-no_out = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 11.
x_fieldcat-fieldname = 'MEINS'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Unit'.
x_fieldcat-outputlen = 5.
x_fieldcat-qfieldname = 'MEINS'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 12.
x_fieldcat-fieldname = 'DMBTR'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = 'Local curr'.
x_fieldcat-outputlen = 12.
x_fieldcat-inttype = 'P'.
x_fieldcat-just = 'R'.
x_fieldcat-do_sum = 'X'.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
x_fieldcat-col_pos = 13.
x_fieldcat-fieldname = 'EXCPT'.
x_fieldcat-tabname = 'I_TAB'.
x_fieldcat-seltext_m = ''.
x_fieldcat-outputlen = 3.
APPEND x_fieldcat TO i_fieldcat.
CLEAR x_fieldcat.
ENDFORM. " SUB_PREPARE_FIELDCATALOG
&----
*& Form SUB_SELECT_RECORD
&----
Fetches records from database into table i_tab to be passed as export
parameter t_outtab in function module : REUSE_ALV_GRID_DISPLAY
----
FORM sub_select_record.
SELECT mblnr amatnr amaktg charg
werks lgort menge meins dmbtr ebeln
FROM makt AS a JOIN mseg AS b
ON ( amatnr = bmatnr )
INTO TABLE i_tab
WHERE b~bwart = '101' .
ENDFORM. " SUB_SELECT_RECORD
&----
*& Form SUB_MODIFY_RECORDS
&----
Populate stat and icon columns of internal table i_tab with specific
columns and symbols based on some logic for quantity and value fields.
----
FORM sub_modify_records.
LOOP AT i_tab.
IF i_tab-dmbtr GT 10000.
Field icn of internal table is going to contain icon . For this column
*icon_allowed is set in the field catalog table. For various icons,see
type pool <ICON>
i_tab-icn = '@1V@'.
MODIFY i_tab TRANSPORTING icn.
ENDIF.
IF i_tab-menge GT 50.
Field icn of internal table is going to contain symbol . For this
column symbol_allowed is set in the field catalog table. For various
icons,see type pool <SYMBOL>
i_tab-sym = 'N'.
MODIFY i_tab TRANSPORTING sym.
ENDIF.
IF i_tab-werks NE 'SDC1'.
This field will contain lights , traffic signals : red.yellow,green
That this field will be used as a light will be specified in the
column of structure STRUCT_LAYOUT.
i_tab-excpt = '1'.
MODIFY i_tab TRANSPORTING excpt.
ENDIF.
ENDLOOP.
ENDFORM. " SUB_MODIFY_RECORDS
&----
*& Form SUB_DETERMINE_ALV_LAYOUT *
&----
*& Defines the overall structure of the report layout *
----
FORM sub_determine_alv_layout.
Field EXCPT will show the light signal
struct_layout-lights_fieldname = 'EXCPT'.
Field BOS of the internal table will act as pushbutton and will appear
at the left of the grid display. User will press that to select a
record
struct_layout-box_fieldname = 'BOX'.
struct_layout-totals_text = 'Totqty '.
struct_layout-zebra = 'X'.
struct_layout-confirmation_prompt = 'X'.
struct_layout-detail_titlebar = 'Details of Storing'.
struct_layout-no_sumchoice = 'X'.
struct_layout-totals_only = 'X'.
ENDFORM. " SUB_DETERMINE_ALV_LAYOUT
&----
*& Form SUB_DETERMINE_SORT_SEQUENCE
&----
Defines the sort sequence of the report
----
FORM sub_determine_sort_sequence.
x_sort-spos = 1. " Sort order
x_sort-fieldname = 'MATNR'.
x_sort-tabname = 'I_TAB'.
x_sort-up = 'X'.
x_sort-subtot = 'X'. " Sub total allowed
APPEND x_sort TO it_sort.
CLEAR x_sort.
ENDFORM. " SUB_DETERMINE_SORT_SEQUENCE
&----
*& Form SUB_SHOW_ALV_LIST
&----
Shows ALV list in grid form
----
FORM sub_show_alv_list.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
Name of the program
i_callback_program = v_repid
title
i_grid_title = 'Details of Storing'
calls subroutine : PF_STATUS_SET
i_callback_pf_status_set = 'PF_STATUS_SET'
Calls subroutine : user_command
i_callback_user_command = 'USER_COMMAND'
Overall structure of the report
is_layout = struct_layout
Passes the field catg internal table
it_fieldcat = i_fieldcat
Passws the sort sequence internal table
it_sort = it_sort
i_default = 'X'
i_save = 'A'
Passes the internal table for variants
is_variant = i_variant1
fetches different events into internal table i_events
it_events = i_events[]
TABLES
Passes data table for ALV display
t_outtab = i_tab
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. " SUB_SHOW_ALV_LIST
&----
*& Form set_status
&----
Form used to set the Custom pf-status of the List Display
----
rt_extab :
----
FORM pf_status_set USING i_rt_extab TYPE slis_t_extab.
DATA : x_extab TYPE slis_extab.
x_extab-fcode = '&LFO'.
APPEND x_extab TO i_rt_extab.
Pf-status STANDARD of program SAPLSALV is copied to ZSTANDARD of the
current program and the pushbutton for Information (okcode=&LFO) is
excluded
SET PF-STATUS 'ZSTANDARD' EXCLUDING i_rt_extab .
ENDFORM. "pf_status_set
&----
*& Form user_command
&----
Form used to handle USER_COMMAND events
----
rf_ucomm: Function Code
rs : Internal Table containing the selection information.
----
FORM user_command USING rf_ucomm LIKE sy-ucomm
rs TYPE slis_selfield.
DATA : v_mblnr LIKE mseg-mblnr.
CASE rf_ucomm.
A custom pushbutton for record deletion is set in the GUI status.
When a record is selected , the field BOC for that record becomes 'X'.
The records are traced and deleted and the fields are refreshed( rs
of type slis_selfield is refreshed)
WHEN '&DEL'. "Print button clicked.
DELETE i_tab WHERE box = 'X'.
rs-refresh = 'X'.
When the user selects a row and presses the Select pushbutton ( user
defined ) from the application toolbar, the details of the document
will be shown in another ALV list
WHEN '&SEL'.
PERFORM sub_select_document.
set parameter id 'MBN' field i_tab-mblnr.
call transaction 'MB03'.
Ok code for double click is &IC1 for ALV report
WHEN '&IC1'.
PERFORM sub_hotspot.
ENDCASE.
ENDFORM. "user_command
&----
*& Form SUB_HOTSPOT
&----
text
----
--> p1 text
<-- p2 text
----
FORM sub_hotspot.
MESSAGE i398(00) WITH 'Hello'.
ENDFORM. " SUB_HOTSPOT
&----
*& Form SUB_VARIANT_F4
&----
Display a list of various variants of the report when the
user presses F4 key in the variant field
----
FORM sub_variant_f4.
i_variant-report = sy-repid.
Utilising the name of the report , this function module will
search for a list of variants and will fetch the selected one into
the parameter field for variants
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = i_variant
i_save = 'A'
i_display_via_grid = 'X'
IMPORTING
es_variant = i_variant1
EXCEPTIONS
not_found = 1
program_error = 2
OTHERS = 3.
IF sy-subrc = 0.
p_var = i_variant1-variant.
ENDIF.
ENDFORM. " SUB_VARIANT_F4
&----
*& Form SUB_SELECT_DOCUMENT
&----
text
----
--> p1 text
<-- p2 text
----
FORM sub_select_document.
DATA : v_lines TYPE i .
READ TABLE i_tab WITH KEY box = 'X'.
SELECT *
FROM mseg INTO TABLE i_doc
WHERE mblnr = i_tab-mblnr.
IF sy-subrc EQ 0 .
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_program_name = v_repid
i_internal_tabname = 'I_DOC'
i_structure_name = 'MSEG'
CHANGING
ct_fieldcat = i_fieldcat1
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR struct_layout1.
struct_layout1-colwidth_optimize = 'X'.
REFRESH it_sort.
CLEAR it_sort.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = v_repid
i_grid_title = 'Details of Document'
is_layout = struct_layout1
it_fieldcat = i_fieldcat1
i_structure_name = 'MSEG'
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = i_doc
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.
ENDIF.
ENDFORM. " SUB_SELECT_DOCUMENT
&----
*& Form SUB_COMMENT_BUILD
&----
text
----
-->P_I_LIST_TOP_OF_PAGE text
----
FORM sub_comment_build USING i_top_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.
***Header
CLEAR ls_line.
ls_line-typ = 'H'.
LS_LINE-KEY: not used for this type
ls_line-info = 'Heading list'.
APPEND ls_line TO i_top_of_page.
***Selection
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Key 1'.
ls_line-info = 'Material '.
APPEND ls_line TO i_top_of_page.
ls_line-key = 'Key 2'.
ls_line-info = 'Document no'.
APPEND ls_line TO i_top_of_page.
***Action
CLEAR ls_line.
ENDFORM. " SUB_COMMENT_BUILD
&----
*& Form SUB_EVENTTAB_BUILD
&----
Defines the event table
----
FORM sub_eventtab_build USING l_events TYPE slis_t_event.
DATA: ls_event TYPE slis_alv_event.
Get the different events of the ALV
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = l_events.
Search the top of page events
READ TABLE l_events WITH KEY name = slis_ev_top_of_page INTO ls_event.
IF sy-subrc = 0.
MOVE 'TOP_OF_PAGE' TO ls_event-form.
APPEND ls_event TO l_events.
ENDIF.
ENDFORM. " SUB_EVENTTAB_BUILD
----
FORM TOP_OF_PAGE *
----
When TOP-OF-PAGE will be fired , this event will be called and it
will use the contents of i_list_top_of_page for output in the header
----
FORM top_of_page.
*
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = i_list_top_of_page.
ENDFORM. "top_of_page
Regards,
Nihar Swain........
‎2007 Sep 07 9:49 AM
‎2007 Sep 07 10:00 AM