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

Former Member
0 Likes
623

can we write a write statement in alv's? if yes, how?

1 ACCEPTED SOLUTION
5 REPLIES 5
Read only

Former Member
0 Likes
577

Hi Kaladhar,

ABAP List Viewer

The common features of report are column alignment, sorting, filtering, subtotals, totals etc. To implement these, a lot of coding and logic is to be put. To avoid that we can use a concept called ABAP List Viewer (ALV).

This helps us to implement all the features mentioned very effectively.

Using ALV, We can have three types of reports:

1. Simple Report

2. Block Report

3. Hierarchical Sequential Report

There are some function modules which will enable to produce the above reports without much effort.

All the definitions of internal tables, structures and constants are declared in a type-pool called SLIS.

1. SIMPLE REPORT.

The important function modules are

a. Reuse_alv_list_display

b. Reuse_alv_fieldcatalog_merge

c. Reuse_alv_events_get

d. Reuse_alv_commentary_write

e. Reuse_alv_grid_display

A. REUSE_ALV_LIST_DISPLAY : This is the function module which prints the data.

The important parameters are :

I. Export :

i. I_callback_program : report id

ii. I_callback_pf_status_set : routine where a user can set his own pf status or change the functionality of the existing pf status

iii. I_callback_user_command : routine where the function codes are handled

iv. I_structure name : name of the dictionary table

v. Is_layout : structure to set the layout of the report

vi. It_fieldcat : internal table with the list of all fields and their attributes which are to be printed (this table can be populated automatically by the function module REUSE_ALV_FIELDCATALOG_MERGE

vii. It_events : internal table with a list of all possible events of ALV and their corresponding form names.

II. Tables :

i. t_outtab : internal table with the data to be output

B. REUSE_ALV_FIELDCATALOG_MERGE : This function module is used to populate a fieldcatalog which is essential to display the data in ALV. If the output data is from a single dictionary table and all the columns are selected, then we need not exclusively create the field catalog. Its enough to mention the table name as a parameter(I_structure name) in the REUSE_ALV_LIST_DISPLAY. But in other cases we need to create it.

The Important Parameters are :

I. Export :

i. I_program_name : report id

ii. I_internal_tabname : the internal output table

iii. I_inclname : include or the report name where all the dynamic forms are handled.

II Changing

ct_fieldcat : an internal table with the type SLIS_T_FIELDCAT_ALV which is

declared in the type pool SLIS.

C. REUSE_ALV_EVENTS_GET : Returns table of possible events for a list type

Parameters :

I. Import :

Et_Events : The event table is returned with all possible CALLBACK events

for the specified list type (column 'NAME'). For events to be processed by Callback, their 'FORM' field must be filled. If the field is initialized, the event is ignored. The entry can be read from the event table, the field 'FORM' filled and the entry modified using constants from the type pool SALV.

II. Export :

I_List_type :

0 = simple list REUSE_ALV_LIST_DISPLAY

1 = hierarchcal-sequential list REUSE_ALV_HIERSEQ_LIST_DISPLAY

2 = simple block list REUSE_ALV_BLOCK_LIST_APPEND

3 = hierarchical-sequential block list

REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_COMMENTARY_WRITE : This is used in the Top-of-page event to print the headings and other comments for the list.

Parameters :

I. it_list_commentary : internal table with the headings of the type slis_t_listheader.

This internal table has three fields :

Typ : ‘H’ – header, ‘S’ – selection , ‘A’ - action

Key : only when typ is ‘S’.

Info : the text to be printed

E. REUSE_ALV_GRID_DISPLAY : A new function in 4.6 version, to display the results in grid rather than as a preview.

Parameters : same as reuse_alv_list_display

This is an example for simple list.

2. BLOCK REPORT

This is used to have multiple lists continuously.

The important functions used in this report are:

A. REUSE_ALV_BLOCK_LIST_INIT

B. REUSE_ALV_BLOCK_LIST_APPEND

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

D. REUSE_ALV_BLOCK_LIST_DISPLAY

A. REUSE_ALV_BLOCK_LIST_INIT

Parameters:

I. I_CALLBACK_PROGRAM

II. I_CALLBACK_PF_STATUS_SET

III. I_CALLBACK_USER_COMMAND

This function module is used to set the default gui status etc.

B. REUSE_ALV_BLOCK_LIST_APPEND

Parameters :

Export :

I. is_layout : layout settings for block

II. it_fieldcat : field catalog

III. i_tabname : internal table name with output data

IV. it_events : internal table with all possible events

Tables :

i. t_outtab : internal table with output data.

This function module adds the data to the block.

Repeat this function for all the different blocks to be displayed one after the other.

C. REUSE_ALV_BLOCK_LIST_HS_APPEND

This function module is used for hierarchical sequential blocks.

D. REUSE_ALV_BLOCK_LIST_DISPLAY

Parameters : All the parameters are optional.

This function module display the list with data appended by the above function.

Here the functions REUSE_ALV_FIELDCATALOG_MERGE, REUSE_ALV_EVENTS_GET, REUSE_ALV_COMMENTARY_WRITE can be used.

3. Hierarchical reports :

Hierarchical sequential list output.

The function module is

A. REUSE_ALV_HIERSEQ_LIST_DISPLAY

Parameters:

I. Export:

i. I_CALLBACK_PROGRAM

ii. I_CALLBACK_PF_STATUS_SET

iii. I_CALLBACK_USER_COMMAND

iv. IS_LAYOUT

v. IT_FIELDCAT

vi. IT_EVENTS

vii. i_tabname_header : Name of the internal table in the program containing the

output data of the highest hierarchy level.

viii. i_tabname_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

ix. is_keyinfo : This structure contains the header and item table field

names which link the two tables (shared key).

II. Tables

i. t_outtab_header : Header table with data to be output

ii. t_outtab_item : Name of the internal table in the program containing the

output data of the lowest hierarchy level.

slis_t_fieldcat_alv : This internal table contains the field attributes. This internal table can be populated automatically by using ‘REUSE_ALV_FIELDCATALOG_MERGE’.

Important Attributes :

A. col_pos : position of the column

B. fieldname : internal fieldname

C. tabname : internal table name

D. ref_fieldname : fieldname (dictionary)

E. ref_tabname : table (dictionary)

F. key(1) : column with key-color

G. icon(1) : icon

H. symbol(1) : symbol

I. checkbox(1) : checkbox

J. just(1) : (R)ight (L)eft (C)ent.

K. do_sum(1) : sum up

L. no_out(1) : (O)blig.(X)no out

M. outputlen : output length

N. seltext_l : long key word

O. seltext_m : middle key word

P. seltext_s : short key word

Q. reptext_ddic : heading (ddic)

R. ddictxt(1) : (S)hort (M)iddle (L)ong

S. datatype : datatype

T. hotspot(1) : hotspot

cheers,

hema.

Read only

Former Member
0 Likes
577

We can write the write statement, but this data displays in only LPS not in Grid display.

Read only

Former Member
0 Likes
577

Hi Kaladar,

It is possible to use WRITE statemnt in alv's.But we can use write statements for HEADING and printing FOOTER information.

Reward points if helpful.

Kiran Kumar.G.A

Have a Nice Day..

Read only

Former Member
0 Likes
577

pls go thru this brief docu, hope this will helpfull for u

FU REUSE_ALV_COMMENTARY_WRITE

____________________________________________________

Short Text

List body comment block output

Functionality

List header information is output according to its type. The output

information is put in an internal table. Output attributes are assigned

to each line via the TYP field.

This module outputs formatted simple header information at TOP-OF-PAGE.

See this sample code

&----


*& Report ZALVLOGO

*&

&----


*&

*&

&----


REPORT ZALVLOGO.

TYPE-POOLS : slis.

*ALV Formatting tables /structures

DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: gt_events TYPE slis_t_event.

DATA: gs_layout TYPE slis_layout_alv.

DATA: gt_page TYPE slis_t_listheader.

DATA: gs_page TYPE slis_listheader.

DATA: v_repid LIKE sy-repid.

*ALV Formatting work area

DATA: w_fieldcat TYPE slis_fieldcat_alv.

DATA: w_events TYPE slis_alv_event.

DATA: gt_bsid TYPE TABLE OF bsid WITH HEADER LINE.

INITIALIZATION.

PERFORM build_events.

PERFORM build_page_header.

START-OF-SELECTION.

*perform build_comment. "top_of_page - in initialization at present

SELECT * FROM bsid INTO TABLE gt_bsid UP TO 10 ROWS.

*perform populate_for_fm using '1' '3' 'BUKRS' '8' 'GT_BSID' 'Whee'.

*USING = Row, Column, Field name, display length, table name, heading

*OR

PERFORM build_fieldcat.

gs_layout-zebra = 'X'.

*top of page event does not work without I_callback_program

v_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

i_structure_name = 'BSID'

i_background_id = 'ALV_BACKGROUND'

i_grid_title = 'This is the grid title'

I_GRID_SETTINGS =

is_layout = gs_layout

it_fieldcat = gt_fieldcat[]

it_events = gt_events[]

TABLES

t_outtab = gt_bsid.

************************************************************************

Form..............: populate_for_fm

Description.......: Populates fields for function module used in ALV

************************************************************************

FORM populate_for_fm USING p_row

p_col

p_fieldname

p_len

p_table

p_desc.

w_fieldcat-row_pos = p_row. "Row Position

w_fieldcat-col_pos = p_col. "Column Position

w_fieldcat-fieldname = p_fieldname. "Field name

w_fieldcat-outputlen = p_len. "Column Lenth

w_fieldcat-tabname = p_table. "Table name

w_fieldcat-reptext_ddic = p_desc. "Field Description

w_fieldcat-input = '1'.

APPEND w_fieldcat TO gt_fieldcat.

CLEAR w_fieldcat.

ENDFORM. " populate_for_fm

&----


*& Form build_events

&----


FORM build_events.

DATA: ls_event TYPE slis_alv_event.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = gt_events.

READ TABLE gt_events

WITH KEY name = slis_ev_user_command

INTO ls_event.

IF sy-subrc = 0.

MOVE slis_ev_user_command TO ls_event-form.

APPEND ls_event TO gt_events.

ENDIF.

READ TABLE gt_events

WITH KEY name = slis_ev_top_of_page

INTO ls_event.

IF sy-subrc = 0.

MOVE slis_ev_top_of_page TO ls_event-form.

APPEND ls_event TO gt_events.

ENDIF.

ENDFORM. " build_events

&----


*& Form USER_COMMAND

&----


When user command is called it uses 2 parameters. The itab

passed to the ALV is in whatever order it currently is on screen.

Therefore, you can read table itab index rs_selfield-tabindex to get

all data from the table. You can also check r_ucomm and code

accordingly.

&----


FORM user_command USING r_ucomm LIKE sy-ucomm

rs_selfield TYPE slis_selfield.

READ TABLE gt_bsid INDEX rs_selfield-tabindex.

error checking etc.

SET PARAMETER ID 'KUN' FIELD gt_bsid-kunnr.

CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

ENDFORM. "user_command

&----


*& Form top_of_page

&----


Your own company logo can go here if it has been saved (OAOR)

If the logo is larger than the size of the headings in gt_page,

the window will not show full logo and will have a scroll bar. Thus,

it is a good idea to have a standard ALV header if you are going to

use logos in your top of page.

&----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = gt_page

i_logo = 'ENJOYSAP_LOGO'.

ENDFORM. "top_of_page

&----


*& Form build_fieldcat

&----


*Many and varied fields are available here. Have a look at documentation

*for FM REUSE_ALV_LIST_DISPLAY and REUSE_ALV_FIELDCATALOG_MERGE

-


FORM build_fieldcat.

w_fieldcat-fieldname = 'BUDAT'.

w_fieldcat-seltext_m = 'Dte pst'.

w_fieldcat-ddictxt(1) = 'M'.

w_fieldcat-edit = 'x'.

Can change the position of fields if you do not want them in order

of the DDIC or itab

w_fieldcat-row_pos = '1'.

w_fieldcat-col_pos = '10'.

APPEND w_fieldcat TO gt_fieldcat.

CLEAR w_fieldcat.

ENDFORM. " build_fieldcat

&----


*& Form build_page_header

&----


gt_page is used in top of page (ALV subroutine - NOT event)

*H = Header, S = Selection, A = Action

-


FORM build_page_header.

For Headers, Key is not printed and is irrelevant. Will not cause

a syntax error, but is not used.

gs_page-typ = 'H'.

gs_page-info = 'Header 1'.

APPEND gs_page TO gt_page.

gs_page-typ = 'H'.

gs_page-info = 'Header 2'.

APPEND gs_page TO gt_page.

For Selections, the Key is printed (bold). It can be anything up to 20

bytes. It gets printed in order of code here, not by key value.

gs_page-typ = 'S'.

gs_page-key = 'And the winner is:'.

gs_page-info = 'Selection 1'.

APPEND gs_page TO gt_page.

gs_page-typ = 'S'.

gs_page-key = 'Runner up:'.

gs_page-info = 'Selection 2'.

APPEND gs_page TO gt_page.

For Action, Key is also irrelevant.

gs_page-typ = 'A'.

gs_page-info = 'Action goes here'.

APPEND gs_page TO gt_page.

ENDFORM. " build_page_header

Reward points if useful.