Академический Документы
Профессиональный Документы
Культура Документы
What if you could reformat a standard ABAP list as easily as a Microsoft Excel
spreadsheet? Many R/3 users are not aware that the report development using ABAP List
Viewer(ALV), which comes standard with R/3(since version 4.5X), lets you come very
close to doing just that. Unlike a standard ABAP list, ALV provides the end-user the
flexibility to individually customize the data output. Many traditional developers are
under the impression that ALV is a complicated and difficult tool to understand and use
until they started using. It really saves lot of time and system resources. This document is
intended for the users who want to quickly convert ABAP lists to ALV format. A
template was provided as a part of this paper which can be used to considerably reduce
the amount of time to less than 30 minutes to convert each ABAP list to ALV format.
However there are some restrictions that are outlined in this paper. Using this template,
you can also run ALV reports in the background unlike the standard examples provided
by SAP with the only exception that you will not have all ALV features like sorting are
available from spool.
SAP provides a set of ALV function modules that can be used to output 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 standard system
provides functions that allow the user to sort, filter, and sum data in tables. Depending on
the application, the ALV Grid Control includes additional application-specific functions
and hides functions available in the standard system.
The SAP List Viewer (ALV) standardizes the use of lists in the SAP System.
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
So, keep in mind the above constraints and check whether you list type can be built by
ALV.
TIPS:
For a description of some examples about ALV components, look at transaction
LIBS and reuse library transaction SE83.
For practical examples of the ALV Grid Control, see development class SLIS.
The SAP program BALVBT01 provides an example of displaying multiple ALV
LIST reports on one page
Single-line and multiple-line lists can be replaced by ALV.
REPORT ZSROP200
NO STANDARD PAGE HEADING
LINE-SIZE 255
LINE-COUNT 65
MESSAGE-ID zi.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
TABLES:
vbrp.
*--------------------------------
* Global Types
*--------------------------------
TYPE-POOLS: slis.
*--------------------------------
* Global Internal Tables
*--------------------------------
DATA:
i_fieldcat_alv TYPE slis_t_fieldcat_alv,
i_events TYPE slis_t_event,
i_event_exit TYPE slis_t_event_exit,
i_list_comments TYPE slis_t_listheader,
i_excluding TYPE slis_t_extab.
* Display data
* This is the internal table which will be passed on to ALV function module to display
data. Replace this with your internal table.
DATA: BEGIN OF i_data OCCURS 0,
vbeln LIKE vbrp-vbeln, "Billing document
posnr LIKE vbrp-posnr,
matnr LIKE vbrp-matnr,
fkimg LIKE vbrp-fkimg,
meins LIKE vbrp-meins,
matkl LIKE vbrp-matkl,
arktx LIKE vbrp-arktx,
werks LIKE vbrp-werks,
vstel LIKE vbrp-vstel,
lgort LIKE vbrp-lgort,
mvgr2 LIKE vbrp-mvgr2,
vbelv LIKE vbrp-vbelv,
vgbel LIKE vbrp-vgbel,
aubel LIKE vbrp-aubel,
kondm LIKE vbrp-kondm,
ktgrm LIKE vbrp-ktgrm,
vkgrp LIKE vbrp-vkgrp,
vkbur LIKE vbrp-vkbur,
kzwi1 LIKE vbrp-kzwi1,
kvgr2 LIKE vbrp-kvgr2,
kvgr3 LIKE vbrp-kvgr3,
kvgr4 LIKE vbrp-kvgr4,
prsdt LIKE vbrp-prsdt,
fbuda LIKE vbrp-fbuda,
txjcd LIKE vbrp-txjcd,
oid_extbol LIKE vbrp-oid_extbol,
oic_mot LIKE vbrp-oic_mot,
oic_truckn LIKE vbrp-oic_truckn,
oic_ptrip LIKE vbrp-oic_ptrip,
oignrule LIKE vbrp-oignrule,
END OF i_data.
*--------------------------------
* Global Variables
*--------------------------------
DATA:
w_variant LIKE disvariant,
wx_variant LIKE disvariant,
w_variant_save(1) TYPE c,
w_exit(1) TYPE c,
w_repid LIKE sy-repid,
w_user_specific(1) TYPE c,
w_callback_ucomm TYPE slis_formname,
w_print TYPE slis_print_alv,
w_layout TYPE slis_layout_alv,
w_html_top_of_page TYPE slis_formname,
w_fieldcat_alv LIKE LINE OF i_fieldcat_alv,
w_excluding LIKE LINE OF i_excluding,
w_events LIKE LINE OF i_events,
w_event_exit LIKE LINE OF i_event_exit,
w_list_comments LIKE LINE OF i_list_comments.
*--------------------------------
* Global Constants
*--------------------------------
*constants:
*--------------------------------
* Selection Screen – replace selection screen in BLUE per your requirement
*--------------------------------
SELECTION-SCREEN BEGIN OF BLOCK selection WITH FRAME TITLE text-f01.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN SKIP 1.
PARAMETERS:
p_list RADIOBUTTON GROUP rb01.
SELECTION-SCREEN END OF BLOCK blk_params.
*--------------------------------
* Initialization
*--------------------------------
INITIALIZATION.
PERFORM init_variant.
PERFORM variant_default USING p_vari.
*--------------------------------
* At Selection Screen PBO
*--------------------------------
AT SELECTION-SCREEN OUTPUT.
*----------------------------------
* At Selection Screen Value Request
*----------------------------------
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_vari.
PERFORM variant_f4 USING p_vari.
*--------------------------------
* At Selection Screen
*--------------------------------
AT SELECTION-SCREEN.
PERFORM variant_fill.
*--------------------------------
* Start of Selection
*--------------------------------
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM fieldcat_build.
PERFORM event_build.
PERFORM event_exit_build.
PERFORM exclude_build.
PERFORM print_build.
PERFORM layout_build.
PERFORM display_data.
*--------------------------------
* Top of Page
*--------------------------------
TOP-OF-PAGE.
*--------------------------------
* Top of Page During Line Sel
*--------------------------------
TOP-OF-PAGE DURING LINE-SELECTION.
*--------------------------------
* At User Command
*--------------------------------
*AT USER-COMMAND.
*--------------------------------
* At Line Selection
*--------------------------------
*AT LINE-SELECTION.
*--------------------------------
* Macros
*--------------------------------
DEFINE skip_1.
write: /001 sy-vline,
at sy-linsz sy-vline.
END-OF-DEFINITION.
*----------------------------------------------------------------------
* Forms
*----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form variant_f4
*&---------------------------------------------------------------------*
FORM variant_f4 USING p_variant.
IF sy-subrc <> 0.
MESSAGE i000(zz) WITH text-g01.
ENDIF.
IF w_exit IS INITIAL.
w_variant-variant = wx_variant-variant.
p_variant = wx_variant-variant.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form init_variant
*&---------------------------------------------------------------------*
FORM init_variant.
CLEAR: w_variant.
w_repid = sy-repid.
w_variant-report = w_repid.
w_variant-username = sy-uname.
w_variant_save = 'A'. "All types
ENDFORM.
*&---------------------------------------------------------------------*
*& Form variant_default
*&---------------------------------------------------------------------*
FORM variant_default USING p_variant.
wx_variant = w_variant.
CASE sy-subrc.
WHEN 0.
p_variant = wx_variant-variant.
WHEN 2.
CLEAR: p_variant.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form variant_fill
*&---------------------------------------------------------------------*
FORM variant_fill.
CLEAR: w_variant.
IF p_vari IS INITIAL.
w_variant-variant = 'STANDARD'.
w_variant-report = w_repid.
ELSE.
w_variant-variant = p_vari.
w_variant-report = w_repid.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form fieldcat_build
*&---------------------------------------------------------------------*
FORM fieldcat_build.
WHEN 'OIC_TRUCKN'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'OIC_PTRIP'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'OIGNRULE'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'MVGR2'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'VSTEL'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'KVGR2'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'VBELV'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'KVGR3'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'KVGR4'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'KZWI1'.
w_fieldcat_alv-seltext_l = 'Gross Value'.
w_fieldcat_alv-no_out = 'X'.
WHEN 'OID_EXTBOL'.
w_fieldcat_alv-seltext_l = 'Gross Value'.
w_fieldcat_alv-no_out = 'X'.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form display_data
*&---------------------------------------------------------------------*
FORM display_data.
w_callback_ucomm = 'CALLBACK_UCOMM'.
CASE 'X'.
WHEN p_grid.
IF p_html = 'X'.
w_html_top_of_page = 'HTML_TOP_OF_PAGE'.
ENDIF.
WHEN p_list.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_background_id = 'ALV_BACKGROUND'
i_callback_program = w_repid
i_default = 'X'
i_save = 'A'
is_variant = w_variant
is_layout = w_layout
i_callback_user_command = w_callback_ucomm
it_fieldcat = i_fieldcat_alv
it_events = i_events
it_event_exit = i_event_exit
is_print = w_print
TABLES
t_outtab = i_data.
ENDCASE.
ENDFORM.
*---------------------------------------------------------------------*
* FORM user_command *
*---------------------------------------------------------------------*
FORM callback_ucomm USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'.
*Interactive list. Replace with your Tcode and parameter id
SET PARAMETER ID 'VF' FIELD rs_selfield-value.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM get_data.
REFRESH i_data.
CLEAR counter.
SELECT vbeln posnr fkimg meins prsdt fbuda netwr vbelv vgbel aubel
matnr arktx matkl werks lgort kondm mvgr2 vstel ktgrm vkgrp vkbur kvgr2
kvgr3 kvgr4 kzwi1 txjcd oid_extbol oic_truckn oic_ptrip oignrule FROM
vbrp INTO
LOOP AT ivbrp.
MOVE: ivbrp-vbeln TO i_data-vbeln,
ivbrp-posnr TO i_data-posnr,
ivbrp-fkimg TO i_data-fkimg,
ivbrp-meins TO i_data-meins,
ivbrp-prsdt TO i_data-prsdt,
ivbrp-fbuda TO i_data-fbuda,
ivbrp-mvgr2 TO i_data-mvgr2,
ivbrp-vbelv TO i_data-vbelv,
ivbrp-vgbel TO i_data-vgbel,
ivbrp-aubel TO i_data-aubel,
ivbrp-matnr TO i_data-matnr,
ivbrp-arktx TO i_data-arktx,
ivbrp-matkl TO i_data-matkl,
ivbrp-mvgr2 TO i_data-mvgr2,
ivbrp-werks TO i_data-werks,
ivbrp-lgort TO i_data-lgort,
ivbrp-vstel TO i_data-vstel,
ivbrp-kondm TO i_data-kondm,
ivbrp-ktgrm TO i_data-ktgrm,
ivbrp-vkgrp TO i_data-vkgrp,
ivbrp-kzwi1 TO i_data-kzwi1,
ivbrp-kvgr2 TO i_data-kvgr2,
ivbrp-kvgr3 TO i_data-kvgr3,
ivbrp-kvgr4 TO i_data-kvgr4,
ivbrp-txjcd TO i_data-txjcd,
ivbrp-oid_extbol TO i_data-oid_extbol,
ivbrp-oignrule TO i_data-oignrule,
ivbrp-oic_ptrip TO i_data-oic_ptrip,
ivbrp-oic_truckn TO i_data-oic_truckn.
APPEND i_data.
counter = sy-tabix.
ENDLOOP.
ENDFORM.
*---------------------------------------------------------------------*
* FORM ALV_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM alv_top_of_page.
CLEAR: i_list_comments[].
w_list_comments-typ = 'H'. "H=Header, S=Selection, A=Action
w_list_comments-key = ''.
w_list_comments-info = 'Material Valuation'. “Replace desc
APPEND w_list_comments TO i_list_comments.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form event_build
*&---------------------------------------------------------------------*
FORM event_build.
ENDFORM.
*---------------------------------------------------------------------*
* FORM alv_end_of_list *
*---------------------------------------------------------------------*
FORM alv_end_of_list.
CLEAR: i_list_comments[].
ENDFORM.
*---------------------------------------------------------------------*
* FORM alv_end_of_page *
*---------------------------------------------------------------------*
FORM alv_end_of_page.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form print_build
*&---------------------------------------------------------------------*
FORM print_build.
w_print-no_print_listinfos = 'X'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form layout_build
*&---------------------------------------------------------------------*
FORM layout_build.
w_layout-zebra = 'X'.
w_layout-no_vline = 'X'.
w_layout-colwidth_optimize = 'X'.
w_layout-detail_popup = 'X'.
w_layout-detail_initial_lines = 'X'.
w_layout-detail_titlebar = 'Detail Title Bar'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form event_exit_build
*&---------------------------------------------------------------------*
FORM event_exit_build.
CLEAR: i_event_exit[].
* Pick
w_event_exit-ucomm = '&ETA'.
w_event_exit-before = ' '.
w_event_exit-after = 'X'.
APPEND w_event_exit TO i_event_exit.
ENDFORM.
*---------------------------------------------------------------------*
* FORM HTML_TOP_OF_PAGE *
*---------------------------------------------------------------------*
FORM html_top_of_page USING r_top TYPE REF TO cl_dd_document.
DATA:
text TYPE sdydo_text_element,
s_table TYPE REF TO cl_dd_table_element,
col_key TYPE REF TO cl_dd_area,
col_info TYPE REF TO cl_dd_area,
a_logo TYPE REF TO cl_dd_area.
* Split TOP-Document
CALL METHOD r_top->vertical_split
EXPORTING split_area = r_top
split_width = '99%'
IMPORTING right_area = a_logo.
* Fill TOP-Document
CALL METHOD r_top->add_text
EXPORTING text = 'Invoice Analysis: Line Item Details'
sap_style = 'HEADING'.
text = sy-uname. .
CALL METHOD col_info->add_text
EXPORTING text = text
sap_style = 'Key'.
**************************************************************
CALL METHOD s_table->new_row.
year = sy-datlo(4).
month = sy-datlo+4(2).
date = sy-datlo+6(2).
text = erdat.
CALL METHOD col_info->add_text EXPORTING text = text.
***************************************************************
text = 'Time' .
CALL METHOD col_key->add_text
EXPORTING text = text
sap_emphasis = 'Strong'.
hour = sy-timlo(2).
min = sy-timlo+2(2).
sec = sy-timlo+4(2).
text = time .
CALL METHOD col_info->add_text
EXPORTING text = text
sap_style = 'Success'.
*************************************************************
CALL METHOD s_table->new_row.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form exclude_build
*&---------------------------------------------------------------------*
FORM exclude_build.
Conclusion…
With the inclusion of ALV in version 4.5X and later, SAP has added a powerful and
extremely useful tool that is easy to learn and use. It helps you turn data into information
so you can be more effective. It lets you create information faster, on the fly, and without
tying up your organization’s IT resources.