Friday, 13 March 2015

                                                             Reports

 Report:These reports are used to fetch business-specific data from SAP standard databases under specified selection criteria, fetched data is processed

In abap there are total 7 types of reports, they are
1. Classical reports.
2. Interactive reports.

1. Classical reports: Single screen detail information is called as classical report. These are most simple reports. Classical reports are normal reports. These reports are not having any sub reports.

SCREEN EVENTS:
Initialization: Executing process will start from here before selection screen.
At-selection-screen: This event triggers after processing user input still selection screen is in active mode or selection screen validation.
At selection-screen output: is to change selection screen dynamically.
At selection-screen on value-request for:

LIST EVENTS:
Start-of –selection: To read / select the data from data source.
End-of-selection: To process the internal table.
Top-of-page: To print default heading for every page.
End-of-page: To print default text at end of page.

Default event for every program: Start-of-selection.
Default printer name LP01.

Report zclass LINE-COUNT 25 to print number of lines in page.
Report zclass LINE-COUNT 25(3) to print end of page footer.

2. Interactive report: Drill down report.
Anywhere in output screen whenever user perform action on any field in basic list output / header data it will trigger another screen. I.e. second list output data the detail description of which we clicked basic list output field.
In a given report program we can generate maximum 21 list output.
1 basic list output.
20 secondary list output.
Hide: It will capture the one field data at a time. It shows the detailed data output of that field in second list output.
Hotspot: It will change the pointer symbol in output screen by placing in that particular field.

INTERACTIVE REPORT EVENTS:
At line-selection: user interacting with output of program generating further drilldown output is called as interactive report.
At user-command: It provides user function keys.
Top-of-page during line-selectionTo print default heading in second list output screen.
End-of –page during line-selection: To print default text at end of second list output screen.
Syntax:
Get cursor field value .
E.g. At line-selection.
       Data: g_field(20) type c,
                  G_value(10) type n.
Get cursor field g_field value g_value.
If g_field eq ‘it_ekko-ebeln’.

Menu painter: It is equal to menubar + title bar + Application tool bar + standard tool bar.
T code SE41.
We can create button up to 1-35.
We can create standard bar up to 7.
We can create sub menu up to 3.
In a report program use both AT USER-COMMAND & AT LINE-SELECTION the system will perform AT USER-COMMAND.

Set pf-status ‘ZRJ’: To call menu program buttons in program.
Set title bar ‘ZRJ’: Tocall menu bar title text.
e.g. AT USER-COMMAND
Data: g_field(20) type c,
         G_value(10) type n.
Get cursor field g_field value g_value.
If g_field eq ‘it_vbrk-vbeln’.
If sy-ucomm eq ‘VBRP’.
Select vbeln
          Matnr into table it_vbrp
                      From vbrp
          Where vbeln eq g_value.
Loop atit_vbrp.
Write: / it_vbap-ebeln.
Endloop.

Difference between ranges & select options:
Select option will generate selection screen. We give input values dynamically whereas ranges we give input statically. But functionality wise both are same.
At user-command
Data: g_vbeln(10) type n.
Range r_vbeln for vbrk-vbeln.
Refresh: r_vbeln, it_vbrp[].
Do.
Read line sy-index field value chk1.
It_vbrk-vbeln into g_vbeln.

If chk1 eq ‘X’.
R_vbeln-sign = ‘I’.
R_vbeln-option = ‘EQ’.
R_vbeln-low = G_vbeln.
Append r_vbeln.
Clear r_vbeln.
Elseifsy-subrc ne 0.
Exit.
Endif.
Enddo.
If not  r_vbeln[] is initial.
Select vbeln
           Posnr      into table it_vbrp
                           From vbrp
                          Where vbeln eq g_value.
Loop at it_vbrp.
Write: / it_vbrp-vbeln.
Endloop.

3. Logical database reports:
Using ldb we can provide extra features for abapreports.
Selection screen as they will generated automatically.

4. Abap query reports:
It provides efficiency for abap reports.
These reports are very accurate.
Transaction code: SQO3, SQO2, SQ03.

5. Report writer:
SAP user & end user can use report painter / report writer tools to write their own reports.
T code MC27.

6. ABAP report types:
a. Executable program
b. Function group
c. Include program
d. Interface pool
e. Class pool
f. Module pool
g. Subroutine pool.

7. ALV [application list viewer]:
Without using write statement we have SAP standard function module called ALV.

a. reuse_alv_list _display:
We can’t display top-of-page.
We can’t resize in output screen.
We can’t hide records in output.
Old.
Data: it_fields type slis_t_fieldcat_alv,
         Wa_fields type slis_fieldcat_alv,
        Wa_layout type slis_layout_alv,
        It_sort type slis_t_sortinfo_alv,
      Wa_sort type sils_sortinfo_alv.

b. reuse_alv_grid_display:
wa_field_fieldname
wa_field_seltext_l
wa_field_do_sum
wa_field_field_key
wa_field_hotspot
Append wa_field to it_field.
Clear wa_field.
Data: it_header type slis_t_listheader,
wa_header type slis_listheader,
wa_header –type = ‘H’.
wa_header_info = ‘purchase details’.
Append wa_headerto to it_header.

How to upload log’s in ALV grid:
Go to OAOR  or OAER T-code.

ALV hierarchy:
In a single list output we can display data from two internal tables by using hierarchy method like header table & item table.
Type-pools slis.
Data: wa_key type slis_keyinfo_alv.   It will create structure for common field between two internal tables.
Data: it_field type slis_t_fieldcat_alv.
         Wa_layout type slis_layout_alv.
NOTE: Maximum we can pass five key fields to ALV hierarchy.

Useful system variables in interactive reports.
Sy-lisel – selected line contents
Sy-lsind – list index.
Sy-lilli – selected line no.
Sy-ucomm – Function code of selected function key.

ALV stands for ABAP List Viewer. ALV gives us a standard List format and user interface to all our ABAP reports. ALV is created by a set of standard function modules provided by SAP.
ALV provides a lot of inbuilt functions to our reports and some of the functions  are listed below.
Sorting of records
Filtering of records
Totals and Sub-totals
Download the report output to Excel/HTML
Changing the order of the columns in the report
Hide the unwanted columns  from the report
Because of the above functions, ALV substantially decreases the report development time. ALV takes care of rendering the list and we can concentrate only on the data retrieval part.
Some of the function modules used to create ALV reports are listed below.


Q. How to skip lines on the selection screen?
Selection-screen.
At line selection:
Triggering: Trigger for line selection from the output list.
Purpose: used to print the secondary list based on the selected line contents.
At user command:
Triggers for the user interaction through function keys. To validate user command & display the secondary list.
USER CAN INTERACT
A.    Line selection(DoubleClick)
B.     User command(click on function key)
Importance of at selection screen output is modify the selection screen
Q. How many times the event initialization triggers while the displaying the list of 20 pages, and also top-of-page?
Initialization triggers only one time top-of-page will triggers 20 times.
Q. how to print different page headers on each page using the TOP-OF-PAGE?
Top-of-page.
Case sy-pagno.
When 1.
Write ‘page1’.
When 2.
Write ‘page2’.
When others.
Write ‘others’.

Endcase.

FUNCTION MODULE
DESCRIPTION
REUSE_ALV_LIST_DISPLAY
Display an ALV list
REUSE_ALV_GRID_DISPLAY
Display an ALV grid
REUSE_ALV_COMMENTARY_WRITE
Output List header information
REUSE_ALV_VARIANT_F4
Display variant selection dialog box
REUSE_ALV_VARIANT_EXISTENCE
Checks whether a variant exists
REUSE_ALV_FIELDCATALOG_MERGE
Create field catalog from dictionary structure or internal table
Simple ALV report.
DATA: it_spfli TYPE TABLE OF spfli.

SELECT * FROM spfli INTO TABLE it_spfli.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    i_structure_name = 'SPFLI'
  TABLES
    t_outtab         = it_spfli.
Simple ALV Output List:

An ALV report is created using the standard function modules provided by SAP.
An ALV report can be created using the following steps.
Include SLIS type pool – SLIS type pool contains all the data types required by ALV function modules.
Data retrieval – Code the logic to fetch the data from database table into an Internal Table.
Build Field Catalog – Add the columns into an internal that you want to display in the ALV output list.
Pass the data table and field catalog table to ALV function module
TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
Output:


The field catalog is a table which contains information on the fields to be displayed on the ALV output.

First we need to build a field catalog before displaying any output in the ALV. We have the following three ways to build a field catalog.
Automatically through a Data Dictionary structure. (Example in What is SAP ALV?)
Manually in ABAP program. (Example in Create a simple ALV)
Semi-automatically by combining the above two procedures.
The third option is used in the following cases.
We want to display all the fields from the DDIC structure but want to modify certain attributes like descriptions etc.
We want to display most of the fields i.e. we want to hide certain fields.
Add new fields.
To generate a field catalog semi-automatically:
Declare an internal table of type SLIS_T_FIELDCAT_ALV.
Call function module REUSE_ALV_FIELDCATALOG_MERGE and pass the DDIC structure of the output table and the internal table for the field catalog. The function module generates the field catalog and fills the internal table accordingly.
Read the rows you want to change, and adapt the fields accordingly. If your output table contains more fields than are stored in the Data Dictionary, you must append one row for each new field to the field catalog.
Example Program
TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*

DATA: BEGIN OF wa_sbook,
      status(4).
      INCLUDE STRUCTURE sbook.
DATA: END OF wa_sbook.
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * UP TO 10 ROWS FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'STATUS'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Status'.    " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

*Merge Field Catalog
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
   EXPORTING
     i_structure_name             = 'SBOOK'
   CHANGING
      ct_fieldcat                 = it_fieldcat
   EXCEPTIONS
     inconsistent_interface       = 1
     program_error                = 2
     OTHERS                       = 3.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
Output:


Status column is added to the field catalog along all the fields of structure SBOOK.

To display header in ALV grid use the following steps.
Build the ALV header table.
Pass the TOP-OF-EVENT subroutine name and callback program name to I_CALLBACK_TOP_OF_PAGE and I_CALLBACK_PROGRAM parameters of REUSE_ALV_GRID_DISPLAY function module.
Display the ALV header by passing the ALV header table built in   step one to function module ‘REUSE_ALV_COMMENTARY_WRITE’ inside TOP-OF-EVENT subroutine.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*     Data Decalaration
*----------------------------------------------------------------------*
DATA: it_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPE sy-repid.
DATA: it_listheader TYPE slis_t_listheader,
      wa_listheader TYPE slis_listheader.
*----------------------------------------------------------------------*
*     START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.

  SELECT * FROM spfli INTO TABLE it_spfli.

  PERFORM build_alv_header.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = g_repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      i_structure_name       = 'SPFLI'
    TABLES
      t_outtab               = it_spfli.

*&---------------------------------------------------------------------*
*&      Form  BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
FORM build_alv_header .

*  Type H is used to display headers i.e. big font
  wa_listheader-typ  = 'H'.
  wa_listheader-info ='Flight Details'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.

*  Type S is used to display key and value pairs
  wa_listheader-typ = 'S'.
  wa_listheader-key = 'Date :' .
  CONCATENATE  sy-datum+6(2)
               sy-datum+4(2)
               sy-datum(4)
               INTO wa_listheader-info
               SEPARATED BY '/'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.

*  Type A is used to display italic font
  wa_listheader-typ = 'A'.
  wa_listheader-info ='SAP ALV Report'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.
ENDFORM.                    " BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_listheader.

ENDFORM.                    "top_of_page
Output:


Use the below steps to display the logo in ABAP ALV header.

First upload the logo that you want to display in ABAP ALV header.
Build the ALV header table.
Pass the TOP-OF-EVENT subroutine name and callback program name to I_CALLBACK_TOP_OF_PAGE and I_CALLBACK_PROGRAM parameters of REUSE_ALV_GRID_DISPLAY function module.
Display the ALV header and logo by passing the ALV header table built in   step two and logo that you uploaded  in step one to function module ‘REUSE_ALV_COMMENTARY_WRITE’ inside TOP-OF-EVENT subroutine.
TYPE-POOLS: slis.
*----------------------------------------------------------------------*
*     Data Decalaration
*----------------------------------------------------------------------*
DATA: it_spfli TYPE TABLE OF spfli.
DATA: g_repid TYPE sy-repid.
DATA: it_listheader TYPE slis_t_listheader,
      wa_listheader TYPE slis_listheader.
*----------------------------------------------------------------------*
*     START-OF-SELECTION
*----------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.

  SELECT * FROM spfli INTO TABLE it_spfli.

  PERFORM build_alv_header.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = g_repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      i_structure_name       = 'SPFLI'
    TABLES
      t_outtab               = it_spfli.

*&---------------------------------------------------------------------*
*&      Form  BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
FORM build_alv_header .

*  Type H is used to display headers i.e. big font
  wa_listheader-typ  = 'H'.
  wa_listheader-info ='Flight Details'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.

*  Type S is used to display key and value pairs
  wa_listheader-typ = 'S'.
  wa_listheader-key = 'Date :' .
  CONCATENATE  sy-datum+6(2)
               sy-datum+4(2)
               sy-datum(4)
               INTO wa_listheader-info
               SEPARATED BY '/'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.

*  Type A is used to display italic font
  wa_listheader-typ = 'A'.
  wa_listheader-key = 'Date    :' .
  wa_listheader-info ='SAP ALV Report'.
  APPEND wa_listheader TO it_listheader.
  CLEAR wa_listheader.
ENDFORM.                    " BUILD_ALV_HEADER
*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = it_listheader
      i_logo         = 'MYLOGO'.

ENDFORM.                    "top_of_page
Output:


Use below steps to calculate totals in ABAP ALV.

Build field catalog and set the field DO_SUM of field catalog to ‘X’ for the field for which you want calculate the totals.
Pass field catalog to function module ‘REUSE_ALV_GRID_DISPLAY’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'LOCCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
*Calculate Total for Price 
  wa_fieldcat-do_sum     = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'LOCCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
Output:

Subtotal in ABAP ALV
To calculate subtotal in ALV, build sort catalog and set the field SUBTOT of sort catalog to ‘X’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types

*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv,
      it_sort      TYPE slis_t_sortinfo_alv,
      wa_sort      TYPE slis_sortinfo_alv..
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'LOCCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
  wa_fieldcat-do_sum     = 'X'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'LOCCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.
*Build sort catalog
  wa_sort-spos      = 1.
  wa_sort-fieldname = 'CARRID'.
  wa_sort-up        = 'X'.
  wa_sort-subtot    = 'X'.
  APPEND wa_sort TO it_sort.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat   = it_fieldcat
      it_sort       = it_sort
    TABLES
      t_outtab      = it_sbook
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
Output:

If you want to calculate subtotals for more fields, just add a record in sort field catalog for each field.
*Build sort catalog
  wa_sort-spos      = 1.
  wa_sort-fieldname = 'CARRID'.
  wa_sort-up        = 'X'.
  wa_sort-subtot    = 'X'.
  APPEND wa_sort TO it_sort.

  wa_sort-spos      = 2.
  wa_sort-fieldname = 'CONNID'.
  wa_sort-up        = 'X'.
  wa_sort-subtot    = 'X'.
  APPEND wa_sort TO it_sort.
Output:

Use below steps to disable icons in ABAP ALV toolbar.
Fetch data from database table.
Build field catalog and fill the excluding table with function codes of icons that you want to disable. &ILT& is the function code for Filter Icon.
Pass field catalog and excluding table to function module ‘REUSE_ALV_GRID_DISPLAY’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: it_excluding TYPE      slis_t_extab,
      wa_excluding TYPE          slis_extab.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.

  wa_fieldcat-fieldname  = 'PASSNAME'.
  wa_fieldcat-seltext_m  = 'Passenger Name'.
  APPEND wa_fieldcat TO it_fieldcat.

*Build excluding table. Append the function codes of the icons to
*excluding table that you want to disable
  wa_excluding-fcode = '&ILT'.  " Function code for filter icon
  APPEND wa_excluding TO it_excluding.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat        = it_fieldcat
      it_excluding       = it_excluding
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

output:

Use below steps to disable icons in ABAP ALV toolbar.
Fetch data from database table.
Build field catalog.
To get the currency wise totals of price, fill the CFIELDNAME field of field catalog with the currency column name and set do_sum to ‘X’.
To get the quantity wise totals of luggage, fill the QFIELDNAME field of field catalog with the weight unit column name and set do_sum to ‘X’.
Pass field catalog to function module ‘REUSE_ALV_GRID_DISPLAY’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
  wa_fieldcat-do_sum     = 'X'.
  wa_fieldcat-cfieldname = 'FORCURKEY'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'LUGGWEIGHT'.
  wa_fieldcat-seltext_m  = 'Weight'.
  wa_fieldcat-do_sum     = 'X'.
  wa_fieldcat-qfieldname = 'WUNIT'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'WUNIT'.
  wa_fieldcat-seltext_m  = 'Unit'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      it_fieldcat        = it_fieldcat
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
Output:

Use below steps to disable icons in ABAP ALV toolbar.
Add a column to the internal table to hold the traffic lights value(i.e. 1 for RED, 2 for YELLOW and 3 for GREEN).
Fetch data from database table and build field catalog.
Assign different traffic lights to each row based on condition.
To display traffic lights in the ALV, fill the lights field name in the LIGHTS_FIELDNAME of ALV layout.
Pass field catalog to function module ‘REUSE_ALV_GRID_DISPLAY’.
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_sbook.
        INCLUDE STRUCTURE sbook.
TYPES: icon TYPE c,  " Add field to hold traffic light value
       END OF ty_sbook.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF ty_sbook.
DATA: wa_sbook     TYPE ty_sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: is_layout    TYPE slis_layout_alv.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.

*Assign different traffic lights to each row based on condition
  LOOP AT it_sbook INTO wa_sbook.
    IF wa_sbook-luggweight LE 0.
      wa_sbook-icon = 1.  " Red Traffic Light
    ELSEIF wa_sbook-luggweight LE 10.
      wa_sbook-icon = 2.  " Yellow Traffic Light
    ELSE.
      wa_sbook-icon = 3.  " Green Traffic Light
    ENDIF.
    MODIFY it_sbook FROM wa_sbook TRANSPORTING icon.
    CLEAR: wa_sbook.
  ENDLOOP.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'LUGGWEIGHT'.
  wa_fieldcat-seltext_m  = 'Weight'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'WUNIT'.
  wa_fieldcat-seltext_m  = 'Unit'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

*Fill layout info.
*Fill traffic lights field name in the ALV layout
  is_layout-lights_fieldname = 'ICON'.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      is_layout          = is_layout
      it_fieldcat        = it_fieldcat
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
Output:







No comments:

Post a Comment