2007 May 01 8:42 AM
what is ALV (detailed)? how v use it. related Questions asked in interview.
regards.
what is ALV (detailed)? how v use it. related Questions asked in interview.
regards.
2007 May 01 8:45 AM
2007 May 01 8:45 AM
Please use the search functionality of this forum. Because this question is certainly asked before.
Hans
2007 May 01 8:49 AM
ALV is Application List viewer. Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length. In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output. The report output can contain up to 90 columns in the display with the wide array of display options.
advantages.
Collapse multiple reports into one, drastically cutting down your report development time
Save many hours using built-in ALV sorting, subtotaling and filtering capabilities
Add conditional structures into your ALV report: No programming required!
Combine ALV with display variants to meet a wide range of reporting requirements more easily
Dynamically reorder column layouts and add/subtract fields
Enable users and analysts to save their own personalized variants
2007 May 01 9:06 AM
Hi
The advantages are many -
The keyword is flexibility. In the past I have sometimes programmed more programs that was basically the same report with minor variations - in one case i programmed 10 very similar reports for pp evaluation.
With ALV the users can define their own display variants without changing the program.
The display variant covers sorting, summarizing, filtering, hiding fields. The users can also make variants that show only total lines or subtotal lines or both - and by one click in the report they can expand one total line to display the underlying item lines.
The users can also choose to let the report show directly in excel. This is a very powerful option. You can upload excel templates with predefined formulas and macros. This can make you very popular - especially with Finance people that already have a lot of excel files, they populate with SAP data to make al kind of voodoo calculations that will help them see into the future.
With ALV you can give them an ABAP report that automatic popup with their own favorite excel book - without having to do a lot of troublesome and time consuming work to download the data and fit it into the excel sheet.
If you are new to ALV you can very quick make a simple ALV report. Basically it has 3 steps.
1) build an internal table with the data you want do display
2) build a field catalog table (each record in this table describes one column in the list)
3) call the ALV function
Later you can make use of more complicated functions like call back routines.
You have both functions modules and ABAP OO classes to help you with step 2 and 3. I have used the function modules for many years so its hard for me to change, but if I should start all over today I would forget about the function modules and go for the OO approach.
http://help.sap.com/saphelp_46c/helpdata/en/99/49b844d61911d2b469006094192fe3/frameset.htm
and Look at this link.....
http://www.sapdevelopment.co.uk/reporting/alvhome.htm
Go thru the foll link...just copy and paste the example pgms and know the diff.
http://www.sapdevelopment.co.uk/reporting/alvhome.htm
1. First we prepare a outputlist which we want to display .
2.WE made a fieldcatalog table which will say the display of the columns.
Ex: position of columns, heading, length etc.
3. Then we prepare a layout structure which contain the layout informations.
4. we call a FM ( ex: RUSE_ALV_GRID_DISPLY or REUSE_ALV_LIST_DISPLAY)
ex:
*&---------------------------------------------------------------------*
*& Report ZDEMO_ALVGRID *
*& *
*&---------------------------------------------------------------------*
*& *
*& Example of a simple ALV Grid Report *
*& ................................... *
*& *
*& The basic requirement for this demo is to display a number of *
*& fields from the EKKO table. *
*&---------------------------------------------------------------------*
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,
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.
* There are a number of ways to create a fieldcat.
* For the purpose of this example i will build the fieldcatalog manualy
* by populating the internal table fields individually and then
* appending the rows. This method can be the most time consuming but can
* also allow you more control of the final product.
* Beware though, you need to ensure that all fields required are
* populated. When using some of functionality available via ALV, such as
* total. You may need to provide more information than if you were
* simply displaying the result
* I.e. Field type may be required in-order for
* the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
* fieldcatalog-do_sum = 'X'.
* fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X' "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form BUILD_LAYOUT
*&---------------------------------------------------------------------*
* Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for when double
* "click(press f2)
* gd_layout-zebra = 'X'.
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
* Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
* i_callback_user_command = 'USER_COMMAND'
* i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
* it_special_groups = gd_tabgroup
* IT_EVENTS = GT_XEVENTS
i_save = 'X'
* is_variant = z_template
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*& Form DATA_RETRIEVAL
*&---------------------------------------------------------------------*
* Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform.
You can also prepare alv display by using class.
ex:
STEPS:
1. Call a screen.
2. Go to the screen layout and add a custom control .
3. Go to attribute and give a name to the custom control (Ex: 'CUSTOM_CONTROL').
4. Give a name to the ok_code ( Ex: ok_code) in the attribute of the screen.
5. Data Declaration section:
I. Data declaration for ALV
a. Declare a object type cl_gui_alv_grid for ALV Grid instance referance
b. Declare a object type cl_gui_custom_container for Custom container instance referance
c. Declare Name of the custom control added to the screen
d. Declare field catalog table of type lvc_t_fcat.
e. Declare layout of type lvc_s_layo.
II. Data declaration for fetching data as input
III. Declare variables for ok_code.
6. Set pf-status and titlebar for the screen.
7. Write PBO. IN PBO do the following:
i. Check whether gr_alvgrid is initial.
a. If yes do the following.
Create instance for custom container (gr_container) by passing the container name.
Create instance for ALV grid by passing the custom control instance reference.
select the material data from database
Build field ctalog
Build layout
Call method set_table_for_first_display for the object gr_alvgrid(alv grid instance reference) with passing layout, input table and field catalog.
b. If NO do the following.
Call method refresh_table_display for the object gr_alvgrid(alv grid instance reference).
ii.
8. Write PAI. IN PAI do the following:
Check the ok_code, if Exit then leave from program.
All the user commands where user do any actions in the screen will be code here . For this purpose check the value of ok_code and according that ok_code, code the functionality for the particular user actions.
REPORT zdemoab.
************************************
*DATA DECLARATION
*************************************
*---Global data deckaration for alv
*--ALV Grid instance referance
DATA: gr_alvgrid TYPE REF TO cl_gui_alv_grid,
*--Name of the custom control added to the screen
gc_custom_control_name TYPE scrfname VALUE 'CUSTOM_CONTROL',
*--Custom container instance referance
gr_container TYPE REF TO cl_gui_custom_container,
*--Field catalog table
gt_fieldcat TYPE lvc_t_fcat,
*--Layout structure
gs_layout TYPE lvc_s_layo.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm.
*---Input table
TYPES: BEGIN OF t_mara,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
meins TYPE mara-meins,
END OF t_mara.
TYPES: t_mara_table TYPE STANDARD TABLE OF t_mara.
DATA: gt_mara TYPE STANDARD TABLE OF t_mara.
************************************
*MAIN
*************************************
CALL SCREEN 101.
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
SET PF-STATUS 'STATUS-0101'.
SET TITLEBAR 'TITLE'.
ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module display_alv OUTPUT
*&---------------------------------------------------------------------*
MODULE display_alv OUTPUT.
IF gr_alvgrid IS INITIAL.
*----Create custom container instance
CREATE OBJECT gr_container
EXPORTING
container_name = gc_custom_control_name
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6 .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----Create ALV grid instance
CREATE OBJECT gr_alvgrid
EXPORTING
i_parent = gr_container
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5 .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* select the material data from database
PERFORM get_input CHANGING gt_mara..
* prepare field catalog
PERFORM prepare_fieldcatalog CHANGING gt_fieldcat.
* prepare layout
PERFORM prepare_layout CHANGING gs_layout.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = gt_mara[]
it_fieldcatalog = gt_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display
EXCEPTIONS
finished = 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.
ENDMODULE. " display_alv OUTPUT
*&---------------------------------------------------------------------*
*& Form get_input
*&---------------------------------------------------------------------*
FORM get_input CHANGING gt_mara_table TYPE t_mara_table.
SELECT matnr mtart matkl meins INTO TABLE gt_mara_table
FROM mara UP TO 10 ROWS.
ENDFORM. " get_input
*&---------------------------------------------------------------------*
*& Form prepare_fieldcatalog
*&---------------------------------------------------------------------*
FORM prepare_fieldcatalog CHANGING gt_fieldcat_table TYPE lvc_t_fcat.
DATA: ls_fcat TYPE lvc_s_fcat,
l_col_no TYPE i.
CLEAR: ls_fcat,
l_col_no .
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 18.
ls_fcat-coltext = 'Material No'.
ls_fcat-seltext = 'Material No'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MTART'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 4.
ls_fcat-coltext = 'Material type'.
ls_fcat-seltext = 'Material type'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MATKL'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 9.
ls_fcat-coltext = 'Material group'.
ls_fcat-seltext = 'Material group'.
APPEND ls_fcat TO gt_fieldcat_table.
l_col_no = l_col_no + 1.
ls_fcat-fieldname = 'MEINS'.
ls_fcat-ref_table = 'MARA'.
ls_fcat-col_pos = l_col_no.
ls_fcat-outputlen = 3.
ls_fcat-coltext = 'Unit'.
ls_fcat-seltext = 'Unit'.
APPEND ls_fcat TO gt_fieldcat_table.
CLEAR: ls_fcat,
l_col_no .
ENDFORM. " prepare_fieldcatalog
*&---------------------------------------------------------------------*
*& Form prepare_layout
*&---------------------------------------------------------------------*
FORM prepare_layout CHANGING p_gs_layout TYPE lvc_s_layo.
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Material'.
p_gs_layout-smalltitle = 'X'.
ENDFORM. " prepare_layout
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0101 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
ENDMODULE. " USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
*& Form exit_program
*&---------------------------------------------------------------------*
FORM exit_program .
LEAVE PROGRAM.
ENDFORM. " exit_program
Regards Rk
Message was edited by:
Rk Pasupuleti
2007 May 01 10:04 AM
Hi,
Sap provides a set of ALV (ABAP LIST VIEWER) function modules, which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length. In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output. The report output can contain up to 90 columns in the display with the wide array of display options.
The commonly used ALV functions used for this purpose are;
1. REUSE_ALV_VARIANT_DEFAULT_GET
2. REUSE_ALV_VARIANT_F4
3. REUSE_ALV_VARIANT_EXISTENCE
4. REUSE_ALV_EVENTS_GET
5. REUSE_ALV_COMMENTARY_WRITE
6. REUSE_ALV_FIELDCATALOG_MERGE
7. REUSE_ALV_LIST_DISPLAY
8. REUSE_ALV_GRID_DISPLAY
9. REUSE_ALV_POPUP_TO_SELECT
The different steps used for getting the above function modules into use are described below.
Sap standard type pools: SLIS, KKBLO.
Sap standard tables types taken from the type pools are:
SLIS_LAYOUT_ALV,
SLIS_T_FIELDCAT_ALV
SLIS_T_LISTHEADER,
SLIS_T_EVENT,
SLIS_SELFIELD.
reward points if helpful.
regards,
kiran kumar k
2007 May 01 6:54 PM
2007 May 11 4:43 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |