Application Development and Automation 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: 
Read only

alv sample reports

Former Member
0 Likes
1,872

hi all,

i'm new to ALV please send some real time sample of alv reports.

Regards

Rishi

7 REPLIES 7
Read only

Former Member
0 Likes
1,113

Hi

This is a simple ALV Report.

*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.

----


*

  • Now, we start with ALV

*

----


*

*

  • To use ALV, we need a DDIC-structure or a thing called Fieldcatalogue.

  • The fieldcatalouge can be generated by FUNCTION

  • 'REUSE_ALV_FIELDCATALOG_MERGE' from an internal table from any

  • report source, including this report.

  • The only problem one might have is that the report and table names

  • need to be in capital letters. (I had it )

*

*

----


  • 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 fieldcatlogue

----


*

  • And now, we are ready to display our list

  • Call for ALV list display

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

  • I_CALLBACK_PROGRAM = 'Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB'

I_CALLBACK_PROGRAM = i_repid

IT_FIELDCAT = int_fcat

I_SAVE = 'A'

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.

Read only

Former Member
0 Likes
1,113

Hi,

************************ALV GRID DECLARATION**************************

DATA: o_alvgrid TYPE REF TO cl_gui_alv_grid,

o_container TYPE scrfname VALUE 'CUST_CTRL_0300',

o_custom_container TYPE REF TO cl_gui_custom_container,

i_fieldcat TYPE lvc_t_fcat,

wa_layout TYPE lvc_s_layo,

wa_fieldcat TYPE lvc_s_fcat,

i_excl_func TYPE ui_functions,

ok_code LIKE sy-ucomm,

i_sort TYPE lvc_t_sort,

wa_sort TYPE lvc_s_sort.

IF NOT i_final[] IS INITIAL.

CALL SCREEN 0300.

ELSE.

with is the screen(double click on the screen).

MODULE status_0300 OUTPUT.

SET PF-STATUS 'STATUS01'.

SET TITLEBAR 'TITLE01'.

IF o_alvgrid IS INITIAL.

  • To Create instances

PERFORM f6000_create_object.

*To create field catalog

PERFORM f6100_field_catalog TABLES i_fieldcat .

*To create for layout for display

PERFORM f6200_create_layout.

  • Set Sort field

PERFORM f6300_set_sortfield TABLES i_sort .

  • Generate ALV Grid

PERFORM display_list TABLES i_final

i_fieldcat

i_sort

USING wa_layout.

ENDIF.

ENDMODULE. " STATUS_0300 OUTPUT

FORM f6000_create_object .

IF o_custom_container IS INITIAL.

CREATE OBJECT o_custom_container

EXPORTING container_name = o_container.

ENDIF.

ENDIF.

ENDFORM. " f6000_create_object

FORM f6100_field_catalog TABLES p_fieldcat STRUCTURE lvc_s_fcat.

DATA wa_fieldcat TYPE lvc_s_fcat.

REFRESH p_fieldcat.

REFRESH p_fieldcat.

wa_fieldcat-col_pos = 1.

wa_fieldcat-fieldname = text-006. "ZZVCITYGATE

wa_fieldcat-outputlen = 15.

wa_fieldcat-tabname = text-007. "I_FINAL

wa_fieldcat-coltext = text-008. "Virtual City Gate

wa_fieldcat-fix_column = c_x.

wa_fieldcat-just = c_x.

APPEND wa_fieldcat TO p_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 2.

wa_fieldcat-fieldname = text-009. "ZZKUNNR

wa_fieldcat-outputlen = 10.

wa_fieldcat-tabname = text-007. "I_FINAL

wa_fieldcat-coltext = text-010. "Business Partner

wa_fieldcat-fix_column = c_x.

wa_fieldcat-just = c_x.

APPEND wa_fieldcat TO p_fieldcat.

CLEAR wa_fieldcat.

wa_fieldcat-col_pos = 3.

wa_fieldcat-fieldname = text-011. "ZOFFRCONT

wa_fieldcat-outputlen = 10.

wa_fieldcat-tabname = text-007. "I_FINAL

wa_fieldcat-coltext = text-012. "OCM Contract

wa_fieldcat-fix_column = c_x.

wa_fieldcat-just = c_x.

APPEND wa_fieldcat TO p_fieldcat.

FORM f6200_create_layout .

wa_layout-zebra = c_x.

wa_layout-info_fname = text-029. "ROW_COLOR

wa_layout-cwidth_opt = c_x.

wa_layout-sel_mode = c_a.

ENDFORM. " f6200_create_layout

FORM display_list TABLES p_i_final STRUCTURE wa_final

p_i_fieldcat STRUCTURE lvc_s_fcat

p_i_sort STRUCTURE lvc_s_sort

USING p_wa_layout.

*-- Display Report

CALL METHOD o_alvgrid->set_table_for_first_display

EXPORTING

i_save = c_a

is_layout = p_wa_layout

CHANGING

it_outtab = p_i_final[]

it_fieldcatalog = p_i_fieldcat[]

it_sort = p_i_sort[]

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4.

IF sy-subrc <> 0.

ENDIF.

i think this will help u,

Regads,

kk.

Read only

Former Member
0 Likes
1,113

Hi Rishi,

Type BCALV* in se38 and press F4 you will get all examples of ALV.

Hope this would help you.

Amit.

Read only

Former Member
0 Likes
1,113
Read only

Former Member
0 Likes
1,113

Hi

You Can find Simple real time Interactive ALV report at the following link

[http://www.the18news.com/index.php/sap-abap/interactive-alv-real-time-report/|http://www.the18news.com/index.php/sap-abap/interactive-alv-real-time-report/]

I Hope you will Satisfy with this.

Read only

Former Member
0 Likes
1,113

a search of this forum would have led you to SAP's executable demonstration programs, named like:

BCALV* for older style of ALV reporting, BALV* for previous (and still viable) OO-class-based ALV and SALV* for current simplified class-based technology.

Read only

Former Member
0 Likes
1,113

Hi ,

Please check package SLIS in se80. The package contains all the examples of ALV ( Grid, Custom Container) .

Thanks

Renu