2

ALV Report Sample

SAP provides a set of ALV (ABAP List Viewer) function modules which can be used to enhance the output of a Report. An ALV is a tool which enables the display of data in a grid, combining a better readability along with greater functionality, like sorting, filter, searching, exporting to Excel, etc. The included sample code is for a simple ALV which will display materials based on a selection screen “From…To”.

Steps to get this ALV running

1. Enter transaction code SE38

2. Create a new Report (in the example called ZHR_MYALV)

3. Copy and paste the code below:

REPORT ZHR_MYALV.
*******************************************************************
*Simple example to use ALV and to define the ALV data in an internal
*table
********************************************************************
*data definition

tables:
marav. "Table MARA and table MAKT

*---------------------------------------------------------------------*
* Data to be displayed in ALV
* Using the following syntax, REUSE_ALV_FIELDCATALOG_MERGE can auto-
* matically determine the fieldstructure from this source program
Data:
begin of imat occurs 100,
matnr like marav-matnr, "Material number
maktx like marav-maktx, "Material short text
matkl like marav-matkl, "Material group (so you can test to make
                        " intermediate sums)
ntgew like marav-ntgew, "Net weight, numeric field (so you can test to
                        "make sums)
gewei like marav-gewei, "weight unit (just to be complete)
end of imat.

*---------------------------------------------------------------------*
* Other data needed
* field to store report name
data i_repid like sy-repid.
* field to check table length
data i_lines like sy-tabix.

*---------------------------------------------------------------------*
* Data for ALV display
TYPE-POOLS: SLIS.
data int_fcat type SLIS_T_FIELDCAT_ALV.

*---------------------------------------------------------------------*
select-options:
s_matnr for marav-matnr matchcode object MAT1.

*---------------------------------------------------------------------*
start-of-selection.

* read data into table imat
  select * from marav
  into corresponding fields of table imat
  where
  matnr in s_matnr.

* Check if material was found
  clear i_lines.
  describe table imat lines i_lines.
  if i_lines lt 1.
*   Using hardcoded write here for easy upload
    write: /
    'No materials found.'.
    exit.
  endif.

end-of-selection.

* To use ALV, we need either a reference to a structure defined in
* the SAP Data Dictionary (DDIC) or an in-program structure called
* the Field Catalog.
* The Field Catalog can be declared explicitly or generated by FUNCTION
* 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any
* report source, including this report.
*---------------------------------------------------------------------*

* Store report name
  i_repid = sy-repid.

* Create Fieldcatalogue from internal table
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      I_PROGRAM_NAME         = i_repid
      I_INTERNAL_TABNAME     = 'IMAT'  "capital letters!
      I_INCLNAME             = i_repid
    CHANGING
      CT_FIELDCAT            = int_fcat
    EXCEPTIONS
      INCONSISTENT_INTERFACE = 1
      PROGRAM_ERROR          = 2
      OTHERS                 = 3.
*explanations:
*    I_PROGRAM_NAME is the program which calls this function
*
*    I_INTERNAL_TABNAME is the name of the internal table which you want
*                       to display in ALV
*
*    I_INCLNAME is the ABAP-source where the internal table is defined
*               (DATA....)
*      CT_FIELDCAT contains the Fieldcatalouge that we need later for
*      ALV display

  IF SY-SUBRC <> 0.
    write: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
  ENDIF.

*This was the field catalog
*---------------------------------------------------------------------*
*

* Call for ALV list display
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM = i_repid
      IT_FIELDCAT        = int_fcat
    TABLES
      T_OUTTAB           = imat
    EXCEPTIONS
      PROGRAM_ERROR      = 1
      OTHERS             = 2.

*explanations:
*    I_CALLBACK_PROGRAM is the program which calls this function
*
*    IT_FIELDCAT (just made by REUSE_ALV_FIELDCATALOG_MERGE) contains
*                 now the data definition needed for display
*
*    I_SAVE allows the user to save his own layouts
*
*      T_OUTTAB contains the data to be displayed in ALV

  IF SY-SUBRC <> 0.
    write: /
    'Returncode',
    sy-subrc,
    'from FUNCTION REUSE_ALV_LIST_DISPLAY'.
  ENDIF.

4. Activate the report and click on “Direct Processing (F8)”

5. The selection screen will appear:

ALV Sample Report

6. Fill in some data parameters and click on “Execute (F8)” to display the result.

ALV Sample Report

This is an example that you can use and adapt to build your own ALV reports.

Author : webmaster

Author's Website | Articles from

Working as an Information Systems Consultant for over 10 years now, I've found that working with SAP brought me added value on how to deal and manage IT and Information Systems Projects. More than a hobby, this blog is aimed to propagate SAP knowledge exchange and help other SAP technology or functional Consultants finding any piece of useful information. Please participate with your comments and opinions, it will help enrich the SAP community. Thanks!


Related Posts


User Comments




Community Feeds

  • SAP BPC Training | SAPBPC Placement | SAP Business Planning Consolidation Process Training | SAP BPC

    NewyorkSys is one of the leading top IT Training and Consulting Company in US, with a good placement Track Record. We have certified trainers. We will provide Online Training, Fast Track online training, with job assistance Courses: SAP Technologies, Dataware housing Tools, Oracle Technologies, SAS, JAVA, .NET, BA… Etc.
    ATTEND FREE DEMO CLASS
    NewyorkSys Inc
    USA: +1- 718- 313-0499
    USA: +1-718-305-1757
    E-mail ID: training@NewyorkSys.com
    Visit: http://www.NewyorkSys.com

  • Expertise technique SAP, ABAP

    Expert Technique SAP, ABAP

  • SAP Training and Certification Courses

    Be a part of SAP training and online sap certification to boost up your skills and career. SAP training helps to improve your business methodologies which are beneficial to generate business around the world. JKT SAP Academy is an authorize education partner of sap and provide sap training for sap abap, sap erp, sap basis, sap fi,sap co, sap mm, sap sd, sap pp and other functional modules.

  • SAP All Modules Training & Placement By Newyorksys.com

    NewyorkSys is one of the leading top IT Training and Consulting Company in US, with a good placement track record. We have certified trainers. We will provide Online Training, Fast Track online training, with job assistance Courses : SAP Technologies,Dataware housing Tools , Oralce Technologies,SAS,JAVA,.NET,BA .. etc. ATTEND FREE DEMO CLASS NewyorkSys Inc USA:+1- 718 – 313-0499
    USA:+1-718-305-1757
    E-mail ID: training@NewyorkSys.com
    Visit: http://www.NewyorkSys.com

  • SAP HR/HCM Training | SAP HR/HCM Placement | SAP Human Resource / Human Capital Management Training,

    SAP HR/HCM Online Course. NewyorkSys is one of the leading top IT Training and Placement Company in US, with a Good placement track record. We have Certified Trainers. We will provide Online Training, Fast Track Online Training, with Job Assistance. SAP Technologies, Data Warehousing Tools, Oralce Technologies, SAS, JAVA, .NET, BA . ATTEND FREE DEMO CLASS. NewyorkSys Inc. – USA: +1- 718-313-0499;+1-718-305-1757 E: training@newyorksys.com

  • NEWYORKSYS: SAP FICO Training | SAP FICO Placement | sap finance controlling training | SAP FICO Onl

    SAP FICO Online Course. NewyorkSys is one of the leading top IT Training and Placement Company in US, with a Good placement track record. We have Certified Trainers. We will provide Online Training, Fast Track Online Training, with Job Assistance. SAP Technologies, Data Warehousing Tools, Oralce Technologies, SAS, JAVA, .NET, BA . ATTEND FREE DEMO CLASS. NewyorkSys Inc. – USA: +1- 718-313-0499;+1-718-305-1757 E: training@newyorksys.com

  • NEWYORKSYS: SAP FICO Training | SAP FICO Placement | sap finance controlling training | SAP FICO Onl

    SAP FICO Online Course. NewyorkSys is one of the leading top IT Training and Placement Company in US, with a Good placement track record. We have Certified Trainers. We will provide Online Training, Fast Track Online Training, with Job Assistance. SAP Technologies, Data Warehousing Tools, Oralce Technologies, SAS, JAVA, .NET, BA . ATTEND FREE DEMO CLASS. NewyorkSys Inc. – USA: +1- 718-313-0499;+1-718-305-1757 E: training@newyorksys.com

  • Sap Training

    Sappractices offers customized SAP training based on changing demands of SAP industry.Our SAP Certified experts are real time working professionals having multiple domain implementation experience.They have worked on almost all the verticals and add on technologies.They have an experience in handling the critical issues.Our Training model not only focus on key technologies,it also brings the knowledge feeding on other related technologies,based on the job market.

    sappractices@gmail.com
    http://www.sappractices.com

  • SAP Training Manuals

    Teach yourself SAP with our SAP Training Course Manuals. This is the best low cost solution to learning SAP. Our training course is easy to follow, up-to-date, well formatted, uses plain language and is illustrated in colour. We supply all our documents in Microsoft Word format so you can easily customise the manuals for your project.

  • SAP SD Certification Material

    It is a website that you can use to build you SAP SD skills and prepare for SAP Certification. SAP sample questions, books, tips&tricks are provided. Good luck with certification!

Submit More
;;