01-17-2007 9:44 AM
01-17-2007 9:46 AM
hi
check this
http://help.sap.com/saphelp_nw04/helpdata/en/99/49b844d61911d2b469006094192fe3/frameset.htm
development class SLIS for demo programs.
Regards
Sourabh
01-17-2007 9:47 AM
Create internal table, get the data into internal table, set the field catalog, call the function module.
report ztest_0001.
Global ALV Data Declarations
type-pools: slis.
Internal Tables
data: begin of itab occurs 0,
matnr type mara-matnr,
maktx type makt-maktx,
end of itab.
start-of-selection.
perform get_data.
perform call_alv.
*********************************************************************
Form GET_DATA
*********************************************************************
form get_data.
select maramatnr maktmaktx
into corresponding fields of table itab
from mara
inner join makt
on maramatnr = maktmatnr
up to 20 rows.
endform.
************************************************************************
CALL_ALV
************************************************************************
form call_alv.
data: ifc type slis_t_fieldcat_alv.
data: xfc type slis_fieldcat_alv.
data: repid type sy-repid.
repid = sy-repid.
clear xfc. refresh ifc.
clear xfc.
xfc-reptext_ddic = 'Material Number'.
xfc-fieldname = 'MATNR'.
xfc-tabname = 'ITAB'.
xfc-outputlen = '18'.
append xfc to ifc.
clear xfc.
xfc-reptext_ddic = 'Material Description'.
xfc-fieldname = 'MAKTX'.
xfc-tabname = 'ITAB'.
xfc-outputlen = '40'.
append xfc to ifc.
Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = ifc
tables
t_outtab = itab.
endform.
01-17-2007 9:47 AM
REPORT Z_ALV__ITEM .
TYPE-POOLS : slis.
*-------------- Data
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE t001.
DATA : flag tyPE c,
END OF itab.
*
*DATA: itab like t001 occurs 0 with header line.
DATA : alvfc TYPE slis_t_fieldcat_alv.
DATA : alvly TYPE slis_layout_alv.
data v_repid like sy-repid.
*--------- Select Data
v_repid = sy-repid.
SELECT * FROM t001 INTO TABLE itab.
*------- Field Catalogue
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = v_repid
i_internal_tabname = 'ITAB'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = v_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
changing
ct_fieldcat = alvfc[] .
*---------------Display
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = alvfc[]
i_callback_program = v_repid
is_layout = alvly
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
01-17-2007 9:50 AM
Hi,
In very detail it's not easy, i believe it's better for you to test the function modules to work with ALV :
REUSE_ALV_FIELDCATALOG_MERGE to create the fieldcatalogue
REUSE_ALV_GRID_DISPLAY - to display the ALV in grid format
REUSE_ALV_LIST_DISPLAY - to display the ALV in list format
Anyone, here's one exemple of creating ALV reports :
REPORT ZALV_SLAS_GDF .
Declaração de Dados
TABLES: ZSLA_NIV_SAT.
selection-screen begin of block b1 with frame title text-001.
select-options DATA for ZSLA_NIV_SAT-DATA. " Data
select-options LIFNR for ZSLA_NIV_SAT-LIFNR. " Nº de conta fornecedor
select-options WERKS for ZSLA_NIV_SAT-WERKS. " Centro
select-options EBELN for ZSLA_NIV_SAT-EBELN. " Nº contrato
selection-screen end of block b1.
DATA: BEGIN OF itab1 OCCURS 100.
include structure ZSLA_NIV_SAT.
data: END OF itab1.
*----
*
Outros dados necessários:
Campo para guardar o nome do report
DATA: i_repid LIKE sy-repid.
Campo para verificar o tamanho da tabela
DATA: i_lines LIKE sy-tabix.
*----
*
Dados para mostrar o ALV
TYPE-POOLS: SLIS.
*DATA: int_fcat type SLIS_T_FIELDCAT_ALV with header line.
DATA: int_fcat type SLIS_T_FIELDCAT_ALV.
DATA: l_key TYPE slis_keyinfo_alv.
START-OF-SELECTION.
Ler dados para dentro da tabela imat
SELECT * FROM ZSLA_NIV_SAT
INTO CORRESPONDING FIELDS OF TABLE itab1
WHERE data in data
and lifnr in lifnr
and ebeln in ebeln
and werks in werks.
CLEAR: i_lines.
DESCRIBE TABLE itab1 LINES i_lines.
IF i_lines lt 1.
WRITE: / 'Não foram seleccionadas entradas.'.
EXIT.
ENDIF.
END-OF-SELECTION.
*----
*
Agora, começa-se o ALV
*
*----
*
Para usar o ALV, nós precisamos de uma estrutura do dicionário de
*dados DDIC ou de uma coisa chamada Fieldcatalogue.
Existe 2 maneiras de preencher a coisa referida acima:
*Automaticamente e Manualmente
Como preencher Automaticamente?
O fieldcatalouge pode ser gerado pela Função
*'REUSE_ALV_FIELDCATALOG_MERGE' a partir de uma tabela de qualquer fonte
Para que se possa utilizar esta função tabela tem que ter campos do
*dicionário de dados, como é o caso da tabela ITAB1
*----
*
Guardar o nome do programa
i_repid = sy-repid.
Create Fieldcatalogue from internal table
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME =
i_repid
I_INTERNAL_TABNAME =
'ITAB1' "LETRAS GRANDES
I_INCLNAME =
i_repid
CHANGING
CT_FIELDCAT =
int_fcat[]
EXCEPTIONS
INCONSISTENT_INTERFACE =
1
PROGRAM_ERROR =
2
OTHERS =
3.
IF SY-SUBRC <> 0.
WRITE: / 'Returncode', sy-subrc,
'from FUNCTION REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
*Isto era o Fieldcatalogue
*----
*
E agora estamos preparados para executar o ALV
Chama o ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = i_repid
IT_FIELDCAT = int_fcat[]
I_DEFAULT = ' '
I_SAVE = ' ' "'A'
TABLES
T_OUTTAB = itab1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
WRITE: /
'Returncode', sy-subrc, 'from FUNCTION REUSE_ALV_GRID_DISPLAY'.
ENDIF.
Best regards,
Paulo Sousa
01-17-2007 10:24 AM
hi rajsekar,
<u><b>alv grid types</b></u>
<b>1) list/ grid </b>
these are having rows and columns
function modules for this type are
<b>REUSE_ALV_LIST_DISPLAY
REUSE_ALV_GRID_DISPLAY</b>2)
<b>2) HIERARCHY</b>
this will have header and line items
function module for this type
<b>REUSE_ALV_HIERSEQ_LIST_DISPLAY</b>
<b>3) tree</b>
this will nodes and child type structure
function module for this type
<b>REUSE_ALV_TREE_DISPLAY</b>
<b>4) APPEND</b>
this can append all the different types of lists where each list has different number of columns
<u><b>events associated with alvs</b></u>
1) top of page
2) end of page
3) top of list
4) end of list
5) on double click
6) on link click
7) on user command
01-17-2007 10:28 AM
example program for alv
using <b>'REUSE_ALV_GRID_DISPLAY'</b>
************************************************************************
S T A R T O F P R O G R A M
************************************************************************
************************************************************************
P R O G R A M D E S C R I P T I O N *
************************************************************************
************************************************************************
*
This program helps us to create an ALV Report that displays the ,
details of all Materials in a selected plant. Here the data is
selected from table MARC, MARA and MAKT and displays the output is
displayed in alv grid format
*
************************************************************************
&----
t y p e - p o o l s
&----
<b>TYPE-POOLS: slis .</b>
----
types : TY_MATERIAL
*
----
Structure to pass the material details to the alv function module .
TYPES : BEGIN OF ty_plant ,
si_no TYPE i "Serial Number for records,
werks TYPE marc-werks "Plant ,
matnr TYPE mara-matnr "Material Number,
maktx TYPE makt-maktx "Material Description,
mtart TYPE mara-mtart "Material Type,
volum TYPE mara-volum "Volume,
ntgew TYPE mara-ntgew "Net weight,
ersda TYPE mara-ersda "Creation date,
laeda TYPE mara-laeda "Date of Last Change,
END OF ty_plant .
----
Internal table and work area declaration
*
----
DATA : it_plant TYPE TABLE OF ty_plant "internal table for ty_plant,
wa_plant TYPE ty_plant , "workarea for ty_plant,
<b>it_field TYPE slis_t_fieldcat_alv , "internal table for " "slis_t_fieldcat_alv
wa_field TYPE slis_fieldcat_alv . "workarea for "slis_fieldcat_alv</b>
----
Parameters declaration
----
************************************************************************
S E L E C T I O N S C R E E N
************************************************************************
*************************************
*B E G I N O F B L O C K *
*************************************
SELECTION-SCREEN BEGIN OF BLOCK plant WITH FRAME TITLE text-019.
********************************************
text-001 ----> MATERIAL MASTER ALV REPORT*
********************************************
************************************************************************
P A R A M E T E R D E C L A R A T I O N
************************************************************************
PARAMETERS : plant_no TYPE marc-werks OBLIGATORY .
*************************************
E N D O F B L O C K *
*************************************
SELECTION-SCREEN END OF BLOCK plant .
Checks if any value is entered in the selection screen .
&----
*& AT SELECTION-SCREEN
&----
AT SELECTION-SCREEN .
SELECT SINGLE
werks
FROM marc
INTO plant_no
WHERE werks EQ plant_no AND matnr EQ marc~matnr .
IF sy-subrc IS NOT INITIAL .
MESSAGE e002(zgm01) .
ENDIF .
************************************************************************
S T A R T - O F - S E L E C T I O N
************************************************************************
START-OF-SELECTION .
PERFORM f001_select_and_write ."to read data from Mara, Marc and Makt
<b>PERFORM f002_alv_grid_display USING text-001 text-002."serial number
PERFORM f002_alv_grid_display USING text-003 text-004."Plant Number
PERFORM f002_alv_grid_display USING text-005 text-006."Material Number
PERFORM f002_alv_grid_display USING text-007 text-008."Material
"Description
PERFORM f002_alv_grid_display USING text-009 text-010."Material Type
PERFORM f002_alv_grid_display USING text-011 text-012."Volume
PERFORM f002_alv_grid_display USING text-013 text-014."Net Weight
PERFORM f002_alv_grid_display USING text-015 text-016."Creation Date
PERFORM f002_alv_grid_display USING text-017 text-018."Last Changed
"Date
PERFORM f003_alv_grid_display ." to display the grid</b>
END-OF-SELECTION .
************************************************************************
E N D - O F - S E L E C T I O N
************************************************************************
&----
*& Form f001_select_and_write
&----
text
----
FORM f001_select_and_write .
Selects the material details from MARA, MARC and MAKT .
SELECT marc~werks
mara~matnr
makt~maktx
mara~mtart
mara~volum
mara~ntgew
mara~ersda
mara~laeda
INTO CORRESPONDING FIELDS OF TABLE it_plant
FROM ( ( marc INNER JOIN mara ON marcmatnr = maramatnr )
INNER JOIN makt ON maktmatnr = marcmatnr )
WHERE marc~werks = plant_no AND spras = 'EN' .
IF sy-subrc EQ 0 .
LOOP AT it_plant INTO wa_plant .
MOVE sy-tabix TO wa_plant-si_no.
MODIFY it_plant FROM wa_plant TRANSPORTING si_no.
ENDLOOP .
ELSE .
MESSAGE e002(zgm01) .
ENDIF .
ENDFORM . "f001_select_and_write
&----
*& Form f002_alv_grid_display
&----
text
----
-->FNAME text
-->SELTEXT text
----
<b>FORM f002_alv_grid_display USING fname TYPE string seltext TYPE string .
wa_field-fieldname = fname .
wa_field-seltext_l = seltext .
wa_field-intlen = 30.
wa_field-outputlen = 20.
APPEND wa_field TO it_field.
CLEAR wa_field.
ENDFORM .
"f002_alv_grid_display</b>&----
*& Form f003_alv_grid_display
&----
text
----
FORM f003_alv_grid_display .
<b>CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'</b>
EXPORTING
i_callback_program = sy-repid
i_grid_title = text-022
<b>it_fieldcat = it_field[]</b> <b>
TABLES
t_outtab = it_plant</b>
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 . "f003_alv_grid_display
************************************************************************
E N D O F P R O G R A M
01-17-2007 10:39 AM
Hi,
Programming Steps:
Declare data areas for list viewer
Declare internal table to store selected data
Select data into internal table
Build field catalog
Build sort catalog
Build event catalog
Start list viewer
STEP 1:
Specifying a field Catalogue
Specify a heading for a report.
Type lvc_title
Create a field catalogue for the report
Table of type slis_t_fieldcat_alv
line_fieldcat-fieldname : Field name
line_fieldcat-tabname : Itab name
line_fieldcat-key : Specifies key
line_fieldcat-seltext_m : Coloumn header
line_fieldcat-hotspot : Indicate hotspot
line_fieldcat-checkbox : Display checkbox
line_fieldcat-edit : Allow editing
STEP 2:
Choosing and saving Layouts
Save options
' ' = No display variants can be saved
'X' = Standard display variants can be saved
'U = User-specific display variants can be saved
'A' = Standard & user-specific can be saved
Layout options
Structure type slis_layout_alv
i_layout-colwidth_optimize = 'X' : Opt col width
i_layout-zebra = X : Alt color pattern
i_layout-no_vline = X : No vertical line
STEP 3:
A Simple ALV Program
Using REUSE_ALV_GRID_DISPLAY
Passing minimum parameter
Data to be displayed
Format of Column ( Field Catalogue )
Let ALV set standard PF_status
STEP 4:
Initialize Events
Initialize events
Type slis_t_event
Use event 'TOP_OF_PAGE' to write a header
Type slis_t_listheader
REUSE_ALV_COMMENTARY_WRITE
ALV supports 16 events
Regards,
Gunasree
01-17-2007 12:24 PM
Hi,
this will explain everything about alv:
ALV programs.
http://www.geocities.com/mpioud/Abap_programs.html
. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
How can I use ALV for reports that are going to be run in background?
http://www.sapfans.com/forums/viewtopic.php?t=83243
http://www.sapfans.com/forums/viewtopic.php?t=19224
ALV
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - http://www.sapgenie.com/abap/reports.htm
http://www.allsaplinks.com/material.html
http://www.sapdevelopment.co.uk/reporting/reportinghome.htm
Top-of-page in ALV
ALV Group Heading
http://www.sap-img.com/fu037.htm
ALV
http://www.geocities.com/mpioud/Abap_programs.html
http://www.geocities.com/mpioud/Abap_programs.html
http://www.sapdevelopment.co.uk/reporting/reportinghome.htm
Simple ALV report
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
ALV
1. Please give me general info on ALV.
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
2. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
3. How do I add subtotals (I have problem to add them)...