Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV and Interactive Reports in SAP ABAP?

Former Member
0 Kudos

Hi All,

What type of reports we can generate in SAP ABAP using ALV & Interactive in real time Scenario? Do SAP provides some Standard reports? Plz give some examples?

Thanks in Advance.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Put a "DEMO_SALV*" F4 search in SE38. you will get the list of example programs for ALV.

Regards

Naren

5 REPLIES 5

Former Member
0 Kudos

Hi,

Put a "DEMO_SALV*" F4 search in SE38. you will get the list of example programs for ALV.

Regards

Naren

Former Member
0 Kudos

Hi Kapoor,

Check the below links,

[http://www.sap-img.com/abap/what-is-alv-programming.htm|http://www.sap-img.com/abap/what-is-alv-programming.htm]

[http://www.sap-img.com/abap/an-interactive-alv-report.htm|http://www.sap-img.com/abap/an-interactive-alv-report.htm]

Former Member
0 Kudos

Hi,,

There are 2 type of reports. They are:

1. Interactive report

2. Classic reports

In classic reports,we can see the output in single list where as in interactive reports we can see the output in multiple list.

In ABAP, there are a total of 7 types of reports. They are:

· Classical

· Interactive

· Logical Database

· ABAP query

· ALV Reports (ALV stands for ABAP List Viewer)

· Report Writer/Report Painter

· Views (There are different types of views also)

Classical Reports

These are the most simple reports. Programmers learn this one first. It is just an output of data using the Write statement inside a loop.

· Classical reports are normal reports. These reports are not having any sub reports. IT IS HAVING ONLY ONE SCREEN/LIST FOR OUTPUT.

Events In Classical Reports.

· INTIALIZATION: This event triggers before selection screen display.

· AT-SELECTION-SCREEN: This event triggers after proccesing user input still selection screen is in active mode.

· START OF SELECTION: Start of selection screen triggers after proceesing selection screen.

· END-OF-SELECTION : It is for Logical Database Reporting.

Interactive Reports

As the name suggests, the user can Interact with the report. We can have a drill down into the report data. For example, Column one of the report displays the material numbers, and the user feels that he needs some more specific data about the vendor for that material, he can HIDE that data under those material numbers.

And when the user clicks the material number, another report (actually sub report/secondary list) which displays the vendor details will be displayed.

We can have a basic list (number starts from 0) and 20 secondary lists (1 to 21).

Events associated with Interactive Reports are:

1. AT LINE-SELECTION

2. AT USER-COMMAND

3. AT PF

4. TOP-OF-PAGE DURING LINE-SELECTION.

HIDE statement holds the data to be displayed in the secondary list.

sy-lisel : contains data of the selected line.

sy-lsind : contains the level of report (from 0 to 21)

Interactive Report Events:

· AT LINE-SELECTION : This Event triggers when we double click a line on the list, when the event is triggered a new sublist is going to be generated. Under this event what ever the statements that are been return will be displayed on newly generated sublist.

· AT PFn: For predefined function keys...

· AT USER-COMMAND : It provides user functions keys.

· TOP-OF-PAGE DURING LINE-SELECTION :top of page event for secondary list.

Logical Database Reports

Logical database is another tool for ABAP reports. Using LDB we can provide extra features for ABAP reports.

While using LDB there is no need for us to declare Parameters.

Selection-screen as they will be generated automatically.

We have to use the statement NODES in ABAP report.

If there are many tables the Performance will be slow as all the table data will be read from top node to bottom node .

ABAP Query Reports

ABAP query is another tool for ABAP. It provides efficency for ABAP reports. These reports are very accurate.

Transaction Code : SQ01

Report Writer

Key Concept :

Super users and end users can use Report Painter/Report Writer tools to write their own reports.

Giving them the ability to report on additional fields at their discretion shifts the report maintenance burden to them, saving SAP support groups time and effort normally spent creating and maintaining the reports.

Instead of using ABAP code to write a report in FI and CO, many users build a Report Painter/ Report Writer library using transaction MC27.

However, this workaround has some drawbacks. Little known transaction GRCT solves these problems in most cases, and eliminates the need to use transaction MC27.

ABAP Report Types

ABAP report types are those ones available in some report's attributes screen, i.e. :

· Executable program

· Function group (containing function modules)

· Include

· Interface pool

· Class pool

· Module pool

· Subroutine pool

Also ALV means ABAP List Viewer. Most convenient way to use it is through reuse library (cf. transaction se83) available from release 4.6 of SAP R/3.

ALV is available in two modes: list and grid. List mode is good old list processing with standard functionnalities, and grid mode is using a new OCX object displaying grids

Reward all helpfull answer.

Kind Regards

Yogesh

Former Member
0 Kudos

Plz give some examples of reports generated by an ABAPer in real time scenarion.

Former Member
0 Kudos

Hi Mohnish,

You can refer the following ALV sample code :

TYPE-POOLS: slis.

TABLES : afko,afpo .

+--


Data declarations--
+

DATA : BEGIN OF it_afpo OCCURS 0,

AUFNR LIKE afpo-AUFNR,

PSMNG LIKE afpo-PSMNG,

WEMNG LIKE afpo-WEMNG,

PWERK LIKE afpo-PWERK,

DAUAT LIKE afpo-DAUAT,

END OF it_afpo.

DATA : BEGIN OF it_afko OCCURS 0,

AUFNR LIKE afko-AUFNR,

GSTRP LIKE afko-GSTRP,

GSTRS LIKE afko-GSTRS,

GSTRI LIKE afko-GSTRI,

GSUZI LIKE afko-GSUZI,

PLNBEZ LIKE AFKO-PLNBEZ,

END OF it_afko.

DATA : BEGIN OF it_makt OCCURS 0,

matnr TYPE matnr,

maktx TYPE maktx,

END OF it_makt.

DATA : BEGIN OF it_output OCCURS 0,

AUFNR LIKE afpo-AUFNR,

PSMNG LIKE afpo-PSMNG,

WEMNG LIKE afpo-WEMNG,

DAUAT LIKE afpo-DAUAT,

GSTRP LIKE afko-GSTRP,

GSTRS LIKE afko-GSTRS,

GSTRI LIKE afko-GSTRI,

GSUZI LIKE afko-GSUZI,

PLNBEZ LIKE AFKO-PLNBEZ,

matnr LIKE makt-matnr,

maktx LIKE makt-maktx,

END OF it_output.

DATA: wa_output LIKE it_output,

wa_afpo LIKE it_afpo,

wa_afko LIKE it_afko,

wa_makt like it_makt.

DATA : wk_date1(10) TYPE c,

wk_date2(10) TYPE c,

wk_datehead TYPE string.

+--


Selection screen parameters--
+

INITIALIZATION.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_matnr FOR afpo-matnr.

PARAMETERS : p_pwerk type afpo-pwerk OBLIGATORY.

SELECT-OPTIONS: s_dauat for afpo-dauat OBLIGATORY,

s_gstrp for afko-GSTRP OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

--


internal tables for alv--

DATA : gt_fieldcat TYPE slis_t_fieldcat_alv, "catalog for alv

gt_heading TYPE slis_t_listheader, "list for header1

gt_sort TYPE slis_t_sortinfo_alv, "Sorting of the

gt_event TYPE slis_t_event,

gt_selfield TYPE slis_selfield,

gv_alv_event TYPE slis_alv_event,

gv_repname TYPE sy-repid,

gs_layout TYPE slis_layout_alv,

gv_save TYPE c.

CONSTANTS gc_forname_top_of_page TYPE slis_formname VALUE

'TOP-OF-PAGE'.

START-OF-SELECTION.

PERFORM get_data.

PERFORM output_data.

PERFORM build_comment USING gt_heading[].

PERFORM eventstab.

PERFORM sub_t_sort_build.

PERFORM build_field_catalog.

PERFORM display_data.

--


Data selection--

&----


*& Form get_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data.

select AUFNR

PSMNG

WEMNG

MATNR

PWERK

DAUAT

from afpo CLIENT SPECIFIED

INTO TABLE it_afpo

WHERE mandt = sy-mandt

AND matnr IN s_matnr

and pwerk = p_pwerk

and dauat in s_dauat.

select AUFNR

GSTRP

GSTRS

GSTRI

GSUZI

PLNBEZ

from afko CLIENT SPECIFIED

INTO table it_afko

FOR ALL ENTRIES IN it_afpo

WHERE mandt = sy-mandt

AND aufnr = it_afpo-aufnr

and gstrp in s_gstrp.

SELECT matnr

maktx

FROM makt

INTO table it_makt

FOR ALL ENTRIES IN it_afKo

WHERE matnr = it_afKo-PLNBEZ.

ENDFORM. " get_data

&----


*& Form output_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM output_data.

loop at it_afko into wa_afko.

LOOP AT it_afpo into wa_afpo

WHERE aufnr = wa_afKo-aufnr.

wa_output-AUFNR = wa_afpo-AUFNR.

wa_output-PSMNG = wa_afpo-PSMNG.

wa_output-WEMNG = wa_afpo-WEMNG.

wa_output-DAUAT = wa_afpo-DAUAT.

ENDLOOP.

loop at it_makt into wa_makt

where matnr = wa_afKo-PLNBEZ.

wa_output-matnr = wa_makt-matnr.

wa_output-maktx = wa_makt-maktx.

endloop.

wa_output-GSTRP = wa_afko-GSTRP.

wa_output-GSTRS = wa_afko-GSTRS.

wa_output-GSTRI = wa_afko-GSTRI.

wa_output-GSUZI = wa_afko-GSUZI.

APPEND wa_output TO it_output.

ENDLOOP.

CLEAR wa_afpo.

CLEAR wa_afko.

CLEAR wa_output.

SORT IT_OUTPUT BY GSTRP GSUZI.

ENDFORM. " output_data

--


Header for ALV--

*&----


*

*& Form build_comment

*&----


*

  • text

*----


*

  • -->P_GT_HEADING[] text

*----


*

FORM build_comment USING p_heading TYPE slis_t_listheader.

DATA : ls_header TYPE slis_listheader.

*--poputale the report header info

ls_header-typ = 'H'.

MOVE : text-002 TO ls_header-info.

APPEND ls_header TO p_heading.

CLEAR ls_header.

ls_header-typ = 'S'.

ls_header-key = text-013 .

"'User:'

ls_header-info = sy-uname.

APPEND ls_header TO p_heading.

*

CLEAR: ls_header.

*

ENDFORM. " build_comment

&----


*& Form eventstab

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM eventstab.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = gt_event

EXCEPTIONS

list_type_wrong = 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.

READ TABLE gt_event

WITH KEY name = slis_ev_top_of_page

INTO gv_alv_event.

IF sy-subrc EQ 0.

MOVE gc_forname_top_of_page TO gv_alv_event-form.

APPEND gv_alv_event TO gt_event.

ENDIF.

ENDFORM. " eventstab

&----


*& Form build_field_catalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_field_catalog.

DATA ls_fieldcat TYPE slis_fieldcat_alv.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 1.

ls_fieldcat-fieldname = 'DAUAT'.

ls_fieldcat-outputlen = 12.

ls_fieldcat-tabname = 'it_output'.

ls_fieldcat-seltext_l = 'Order Type'.

ls_fieldcat-KEY = 'X'.

APPEND ls_fieldcat TO gt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 2.

ls_fieldcat-fieldname = 'AUFNR'.

ls_fieldcat-outputlen = 10.

ls_fieldcat-tabname = 'it_output'.

ls_fieldcat-seltext_l = 'Order Number'.

APPEND ls_fieldcat TO gt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-col_pos = 3.

ls_fieldcat-fieldname = 'MATNR'.

ls_fieldcat-outputlen = 12.

ls_fieldcat-tabname = 'it_output'.

ls_fieldcat-seltext_l = 'Material Number'.

APPEND ls_fieldcat TO gt_fieldcat.

----


you can add fields as per your requirement.*----


*

ENDFORM. " build_field_catalog

*----


*-*

*-- Form top of page

*----


-

FORM top-of-page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = gt_heading.

ENDFORM. "TOP-OF-PAGE

&----


*& Form display_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data.

gv_save = 'A'.

gv_repname = sy-repid.

gs_layout-colwidth_optimize = 'X'.

gs_layout-zebra = 'X'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = gv_repname

is_layout = gs_layout

it_sort = gt_sort[]

it_fieldcat = gt_fieldcat[]

i_default = 'X'

i_save = gv_save

it_events = gt_event[]

TABLES

t_outtab = it_output

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_data

&----


*& Form sub_t_sort_build

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_t_sort_build.

DATA ls_sort TYPE slis_sortinfo_alv.

ls_sort-spos = 1.

ls_sort-tabname = 'it_output'.

ls_sort-fieldname = 'DAUAT'.

ls_sort-subtot = 'X'.

ls_sort-up = 'X'.

ls_sort-group = '*'.

APPEND ls_sort TO gt_sort.

ENDFORM. " sub_t_sort_build

Reward points, if helpful

Regards,

Ramneet