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 report required

Former Member
0 Kudos

hi

can anyone send me a simple and easily understandable ALV report.

points will be rewarded....

8 REPLIES 8

Former Member
0 Kudos

Hi Sunil,

Below codes hepls you a lot to understand ALV with ease.

REPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .

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

*Simple example to use ALV and to define the ALV data in an internaltable

*ALV will generate the column headings on its own, so one does not need

*to work on headlines and transalation.

*ALV allows the user to select the columns he wants to see, so the user

*does not need to contact a developer for every change he likes to have.

*ALV allows the user to create his own sums, so u2026

*ALV has a simple way to work with internal tables.

*If you really want to save time, use ALV instead of write!

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

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

----


* It is that simple. Go ahead and try yourself!

----


Reward points if useful.

Thankyou,

Regards.

Former Member
0 Kudos

REPORT Z_ALV_SIMPLE_EXAMPLE_WITH_ITAB .

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

*Simple example to use ALV and to define the ALV data in an internal

*table

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

  • Martin Schlegel, BearingPoint, December 2004

*

  • Thanks to Madhusudhan Sonee and Rama Krishna Kommineni for testing

  • and feedback

*

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

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

*For a very long time, people gave me the feeling that ALV is a

*complicated tool that is difficult to understand and to use.

*Lately I had to use it and I discovered that ALV is easy to use and

*saves a lot of work:

*ALV will generate the column headings on its own, so one does not need

*to work on headlines and transalation.

*ALV allows the user to select the columns he wants to see, so the user

*does not need to contact a developer for every change he likes to have.

*ALV allows the user to create his own sums, so u2026

*ALV has a simple way to work with internal tables.

*If you really want to save time, use ALV instead of write!

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

*

*Please take 30 minutes to explore the following example and see how

*easy it is to use ALV!

*

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

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

*

----


*

  • yes, it is that simple. Go ahead and try yourself!

*

----


Regards.

Ankesh

Former Member
0 Kudos

Hi Venkat,

Please check this link

http://yashtechiesabap.blogspot.com/2008/06/firsr-step-in-alv-simple-program.html

Please check this code

BASIC ALV REPORT

TYPE-POOLS:slis.

DATA:w_repid LIKE sy-repid.

DATA:fs_layout TYPE slis_layout_alv.

DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
fs_fieldcat TYPE slis_fieldcat_alv.
*********************************************
DATA:BEGIN OF fs_string,
carrid LIKE spfli-carrid,
connid LIKE spfli-connid,
countryfr LIKE spfli-countryfr,
countryto LIKE spfli-countryto,
END OF fs_string.
DATA:t_spfli LIKE TABLE OF fs_string.


PERFORM get_data.
PERFORM prepare_fieldcatalog.
PERFORM display_output.


*&---------------------------------------------------------------------*
*& Form prepare_fieldcatalog
*&---------------------------------------------------------------------*
* Fills data to the fieldcatalaog
*----------------------------------------------------------------------*
FORM prepare_fieldcatalog .


fs_fieldcat-col_pos = 1.
fs_fieldcat-fieldname = 'CARRID'.
fs_fieldcat-seltext_m = 'Airlinecarrier'.
fs_fieldcat-key = 'X'.
fs_fieldcat-hotspot = 'X'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.


fs_fieldcat-col_pos = 2.
fs_fieldcat-fieldname = 'CONNID'.
fs_fieldcat-seltext_m = 'Connectionid'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.


fs_fieldcat-col_pos = 3.
fs_fieldcat-fieldname = 'COUNTRYFR'.
fs_fieldcat-seltext_m = 'Countryfrom'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.


fs_fieldcat-col_pos = 4.
fs_fieldcat-fieldname = 'COUNTRYTO'.
fs_fieldcat-seltext_m = 'Countryto'.
APPEND fs_fieldcat TO t_fieldcat.
CLEAR fs_fieldcat.


ENDFORM. " prepare_fieldcatalog


*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
* Fetch data from database table to internal table
*----------------------------------------------------------------------*
FORM get_data .


SELECT carrid
connid
countryfr
countryto
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE t_spfli.
w_repid = sy-repid.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form DISPLAY_OUTPUT
*----------------------------------------------------------------------*
* Function module to display ALV
*----------------------------------------------------------------------*
FORM display_output .


CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = w_repid
it_fieldcat = t_fieldcat[]
TABLES
t_outtab = t_spfli
* EXCEPTIONS
* PROGRAM_ERROR = 1
.
Endform. 

Best regards,

raam

Former Member
0 Kudos

Hi

just check this out-

1.

report zfieldcat_ms.

tables : ztest213.

type-pools slis. " FOR FIELD CATALOGS IN ALV LIST DISPLAY

data : itab1 like ztest213 occurs 0 with header line. " INTERNAL TABLES

data : itab2 like ztest213 occurs 0 with header line.

data : bd_fcat type slis_t_fieldcat_alv. "DEFINING BODY FOR FIELD CATALOGUES

data : hd_fcat like line of bd_fcat. " DEFINING HEADERLINE FOR FIELD CTALOGUES

data : check type c length 1, "CHECKBOX

w type c length 20. "ACCOUNT NUMBER

select * from ztest213 into table itab1.

write : 'ACCOUNT NUMBER '.

loop at itab1.

write : / check as checkbox , itab1-accno.

endloop.

hide : itab1.

start-of-selection.

set pf-status 'FCAT_GUI'.

at line-selection.

at user-command.

case sy-ucomm.

when 'EXECUTE'.

do.

read line sy-index field value check itab1-accno into w. "ASSIGNS CONTENTS OF ROW TO SY-LISEL

if sy-subrc <> 0.

exit.

elseif check = 'X'.

read table itab1 with key accno = w.

if sy-subrc eq 0.

move-corresponding itab1 to itab2.

append itab2.

endif.

endif.

enddo.

perform fieldcatalog. "SUBROUTINE CALL TO DISPLAY THE INTERNAL TABLE CONTENTS IN ALV LIST WITH FIELD CATALOG

call function 'REUSE_ALV_LIST_DISPLAY' "CALLING FUNCTION MODULE

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

  • I_CALLBACK_PROGRAM = ' '

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_STRUCTURE_NAME =

  • IS_LAYOUT =

it_fieldcat = bd_fcat[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER =

  • IT_EXCEPT_QINFO =

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = itab2

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.

endcase.

clear : itab2[].

&----


*& Form FIELDCATALOG

&----


  • text

----


form fieldcatalog.

hd_fcat-seltext_l = 'ACCOUNT NUMBER'.

hd_fcat-fieldname = 'ACCNO'.

hd_fcat-tabname = 'itab2'.

append hd_fcat to bd_fcat.

hd_fcat-seltext_l = 'TRANSACTION'.

hd_fcat-fieldname = 'TRTYPE'.

hd_fcat-tabname = 'itab2'.

append hd_fcat to bd_fcat.

hd_fcat-seltext_l = 'Transaction Date'.

hd_fcat-fieldname = 'TRDE'.

hd_fcat-tabname = 'itab2'.

append hd_fcat to bd_fcat.

hd_fcat-seltext_l = 'amount'.

hd_fcat-fieldname = 'AMOUNT'.

hd_fcat-tabname = 'itab2'.

append hd_fcat to bd_fcat.

  • hd_fcat-seltext_l = 'Paymode'.

  • hd_fcat-fieldname = 'PAYMODE'.

  • hd_fcat-tabname = 'itab2'.

*

  • APPEND hd_fcat TO bd_fcat.

  • hd_fcat-seltext_l = 'CUSTOMER'.

  • hd_fcat-fieldname = 'CUSTID'.

  • hd_fcat-tabname = 'itab2'.

*

  • APPEND hd_fcat TO bd_fcat.

*

endform. "fieldcatalog

2.

report zalv_ms.

*

data : itab like ztest213 occurs 0 with header line.

tables : ztest213 .

select * from ztest213 into table itab.

loop at itab.

call function 'REUSE_ALV_LIST_DISPLAY' (for list display)

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE = ' '

  • I_CALLBACK_PROGRAM = ' '

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

i_structure_name = 'ztest213'

  • IS_LAYOUT =

  • IT_FIELDCAT =

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IR_SALV_LIST_ADAPTER =

  • IT_EXCEPT_QINFO =

  • I_SUPPRESS_EMPTY_DATA = ABAP_FALSE

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = itab

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.

endloop.

loop at itab.

call function 'REUSE_ALV_GRID_DISPLAY' (for grid display)

exporting

i_interface_check = ' '

i_bypassing_buffer = ' '

i_buffer_active = ' '

i_callback_program = ' '

i_callback_pf_status_set = ' '

i_callback_user_command = ' '

i_callback_top_of_page = ' '

i_callback_html_top_of_page = ' '

i_callback_html_end_of_list = ' '

i_structure_name = 'ztest213'

i_background_id = ' '

i_grid_title =

i_grid_settings =

is_layout =

it_fieldcat =

it_excluding =

it_special_groups =

it_sort =

it_filter =

is_sel_hide =

i_default = 'X'

i_save = ' '

is_variant =

it_events =

it_event_exit =

is_print =

is_reprep_id =

i_screen_start_column = 0

i_screen_start_line = 0

i_screen_end_column = 0

i_screen_end_line = 0

i_html_height_top = 0

i_html_height_end = 0

it_alv_graphics =

it_hyperlink =

it_add_fieldcat =

it_except_qinfo =

ir_salv_fullscreen_adapter =

importing

e_exit_caused_by_caller =

es_exit_caused_by_user =

tables

t_outtab = itab

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.

endloop.

hope it helps.

reward if useful.

Regards

Megha Sharma

Former Member
0 Kudos

Hi,

I think this will help u a lot...Plz reward if helpful to u...

REPORT ZSDR_SOSA NO STANDARD PAGE HEADING

LINE-COUNT 65 LINE-SIZE 100.

--


Tables--

tables: vbap, vbak, vbpa, vbkd, makt,konv.

--


Data Fetching--

TYPE-POOLS: slis.

data:begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

arktx like vbap-arktx,

kdmat like vbap-kdmat,

taxm1 like vbap-taxm1,

end of i_vbap.

data:begin of i_vbak occurs 0,

vbeln like vbak-vbeln,

audat like vbak-audat,

vbtyp like vbak-vbtyp,

vkorg like vbak-vkorg,

knumv like vbak-knumv,

kunnr like vbak-kunnr,

end of i_vbak.

data:begin of i_vbpa occurs 0,

vbeln like vbpa-vbeln,

posnr like vbpa-posnr,

parvw like vbpa-parvw,

kunnr like vbpa-kunnr, "SH

kunnr1 like vbpa-kunnr, "SP

end of i_vbpa.

data:begin of i_konv occurs 0,

knumv like konv-knumv,

kschl like konv-kschl,

kbetr like konv-kbetr,

mwsk1 like konv-mwsk1,

end of i_konv.

data:begin of i_vbkd occurs 0,

vbeln like vbkd-vbeln,

posnr like vbkd-posnr,

bstkd like vbkd-bstkd,

bstdk like vbkd-bstdk,

end of i_vbkd.

data:begin of i_makt occurs 0,

matnr like makt-matnr,

spras like makt-spras,

maktx like makt-maktx, "MAt. Desc

maktx1 like makt-maktx, "Cust mat. no.

end of i_makt.

data:wa_makt like makt.

DATA:BEGIN OF itab OCCURS 0,

vbeln like vbap-vbeln, "SD no.

audat like vbak-audat, "Order date

kunnr like vbpa-kunnr, "sold to party

kunnr1 like vbpa-kunnr, "ship to party

matnr like vbap-matnr, "Mat. No.

maktx like makt-maktx, "Material Desc.

kdmat like vbap-kdmat, "Cust. Mat.no.

maktx1 like makt-maktx, "Customer Mat. desc.

bstkd like vbkd-bstkd, "PO number

bstdk like vbkd-bstdk, "PO date

kbetr like konv-kbetr, "Basic Price

knumv like vbak-knumv,

vkorg like vbak-vkorg,

vbtyp like vbak-vbtyp,

parvw like vbpa-parvw,

kschl like konv-kschl,

mwsk1 like konv-mwsk1,

posnr like vbap-posnr,

arktx like vbap-arktx,

taxm1 like vbap-taxm1,

END OF itab.

--


ALV DECLARATION--

*

DATA :v_pgm LIKE sy-repid.

DATA :col_pos TYPE i.

DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,

gd_tab_group TYPE slis_t_sp_group_alv,

gd_layout TYPE slis_layout_alv,

gd_repid LIKE sy-repid,

gt_events TYPE slis_t_event,

gd_prntparams TYPE slis_print_alv.

DATA:fcat TYPE slis_t_fieldcat_alv,

fcat1 TYPE slis_t_fieldcat_alv,

fcat2 TYPE slis_t_fieldcat_alv,

eve TYPE slis_t_event,

eve1 TYPE slis_t_event,

subtot TYPE slis_t_sortinfo_alv,

g_subtot LIKE LINE OF subtot.

----


--


SELECTION SCREEN--

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

SELECT-OPTIONS:s_audat FOR vbak-audat,

s_vkorg for vbak-vkorg,

s_kunnr for vbak-kunnr.

SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.

PARAMETERS:p_sorder RADIOBUTTON GROUP rad1,

p_agree RADIOBUTTON GROUP rad1,

p_order radiobutton group rad1.

SELECTION-SCREEN END OF BLOCK b2.

--


Initialization--

INITIALIZATION.

v_pgm = sy-repid.

--


Start-of-selection--

Start-of-selection.

if p_sorder = 'X'.

perform get_sorder_data.

perform process_data.

perform display_data1.

elseif p_agree = 'X'.

perform get_agree_data.

perform process_data.

perform display_data1.

elseif p_order = 'X'.

perform get_order_data.

perform process_data.

perform display_data1.

endif.

&----


*& Form get_sorder_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_sorder_data .

*Get from VBAK table.

select vbeln audat vbtyp vkorg knumv kunnr

from vbak into table i_vbak

where audat in s_audat

and vkorg in s_vkorg

and kunnr in s_kunnr

and vbtyp in ('C','E').

*Get from VBAP table.

if not i_vbak[] is initial.

clear:i_vbap. refresh:i_vbap.

select vbeln posnr matnr arktx kdmat taxm1

from vbap into table i_vbap

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

*Get from VBPA table.

if not i_vbap[] is initial.

clear:i_vbpa. refresh:i_vbpa.

select vbeln posnr parvw kunnr

from vbpa into table i_vbpa

for all entries in i_vbap

where vbeln = i_vbap-vbeln

and parvw in ('AG','KB','RE','RG','VE','WE','ZM').

endif.

*Get from KONV table.

if not i_vbak[] is initial.

clear:i_konv. refresh:i_konv.

select knumv kschl kbetr mwsk1

from konv into table i_konv

for all entries in i_vbak

where knumv = i_vbak-knumv

and kschl = 'PR00'.

endif.

*Get from VBKD table.

if not i_vbak[] is initial.

clear:i_vbkd. refresh:i_vbkd.

select vbeln posnr bstkd bstdk

from vbkd into table i_vbkd

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

**Get from MAKT table.

  • if not i_vbap[] is initial.

  • clear:i_makt. refresh:i_makt.

*

  • select single maktx

  • from makt into i_makt

  • for all entries in i_vbap

  • where matnr = i_vbap-matnr

  • and spras = sy-langu.

  • endif.

ENDFORM. " get_sorder_data

&----


*& Form process_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM process_data .

Loop at i_vbap.

itab-vbeln = i_vbap-vbeln.

itab-posnr = i_vbap-posnr.

itab-matnr = i_vbap-matnr.

itab-arktx = i_vbap-arktx.

itab-kdmat = i_vbap-kdmat.

itab-taxm1 = i_vbap-taxm1.

*Get from MAKT table.

select single maktx from makt

into wa_makt-maktx

where matnr = itab-matnr

and spras = sy-langu.

if sy-subrc = 0.

itab-maktx = wa_makt-maktx.

itab-maktx1 = wa_makt-maktx.

endif.

read table i_vbak with key vbeln = itab-vbeln.

if sy-subrc = 0.

itab-audat = i_vbak-audat.

itab-knumv = i_vbak-knumv.

itab-vkorg = i_vbak-vkorg.

itab-vbtyp = i_vbak-vbtyp.

endif.

read table i_vbpa with key vbeln = itab-vbeln.

if sy-subrc = 0.

itab-parvw = i_vbpa-parvw.

itab-kunnr = i_vbpa-kunnr.

itab-kunnr1 = i_vbpa-kunnr.

endif.

read table i_konv with key knumv = itab-knumv.

if sy-subrc = 0.

itab-kschl = i_konv-kschl.

itab-kbetr = i_konv-kbetr.

itab-mwsk1 = i_konv-mwsk1.

endif.

read table i_vbkd with key vbeln = itab-vbeln.

if sy-subrc = 0.

itab-bstkd = i_vbkd-bstkd.

itab-bstdk = i_vbkd-bstdk.

endif.

read table i_makt with key matnr = itab-matnr.

if sy-subrc = 0.

itab-maktx = i_makt-maktx.

itab-maktx1 = i_makt-maktx1.

endif.

append itab.

clear itab.

endloop.

delete itab where not audat in s_audat.

delete itab where not vkorg in s_vkorg.

delete itab where not kunnr in s_kunnr.

ENDFORM. " process_data

&----


*& Form display_data1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_data1 .

PERFORM get_buildfieldcat1.

PERFORM display_alv.

ENDFORM. " display_data1

&----


*& Form display_alv

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_alv .

IF itab[] IS INITIAL.

MESSAGE 'No Data Exist' TYPE 'E'.

ENDIF.

DATA: title TYPE lvc_title

, datelow(10) TYPE c

, datehigh(10) TYPE c

.

DATA: gd_repid LIKE sy-repid

, gd_layout TYPE slis_layout_alv

.

***************Layout Formatting***************

gd_layout-no_input = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-zebra = 'X'.

gd_layout-totals_text = 'Totals'(201).

gd_layout-totals_only = 'X'.

gd_layout-f2code = 'DISP'. "Sets fcode for when double

"click(press f2)

***************Layout Formatting***************

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_pgm

i_callback_top_of_page = 'ALV_TOP_OF_PAGE' "see FORM

i_callback_user_command = 'USER_COMMAND' "'ALV_USER_COMMAND'

  • i_grid_title = title

is_layout = gd_layout

it_fieldcat = fieldcatalog[]

  • it_special_groups = gd_tabgroup

  • it_events = gt_events

  • is_print = gd_prntparams

i_save = 'X'

it_sort = subtot

  • is_variant = z_template

TABLES

t_outtab = itab

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_alv

*

&----


&----


*& Form ALV_TOP_OF_PAGE

&----


  • ALV Report Header *

----


  • --> p1 text

  • <-- p2 text

----


FORM alv_top_of_page .

*ALV Header declarations

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader,

t_line LIKE wa_header-info,

ld_lines TYPE i,

ld_linesc(10) TYPE c.

  • FORM alv_top_of_page1 .

DATA: i_header TYPE slis_t_listheader,

wa1_header TYPE slis_listheader,

i_line LIKE wa1_header-info,

lld_lines TYPE i,

lld_linesc(10) TYPE c.

  • Title

wa1_header-typ = 'H'.

wa1_header-info = 'Schedule Line-Basic Price Details'.

APPEND wa1_header TO t_header.

CLEAR wa1_header.

  • Date

wa_header-typ = 'S'.

wa_header-key = 'Date: '.

CONCATENATE sy-datum+6(2) '.'

sy-datum+4(2) '.'

sy-datum(4) INTO wa_header-info. "todays date

APPEND wa_header TO t_header.

CLEAR: wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Time: '.

CONCATENATE

sy-uzeit(2) ':'

sy-uzeit+2(2) ':'

sy-uzeit+4(2) INTO wa_header-info. "time

APPEND wa_header TO t_header.

CLEAR: wa_header.

wa_header-typ = 'A'.

wa_header-info = t_line.

APPEND wa_header TO t_header.

CLEAR: wa_header, t_line.

  • Total No. of Rows Displayed

DESCRIBE TABLE itab LINES ld_lines.

ld_linesc = ld_lines.

CONCATENATE 'Total No. of Rows: ' ld_linesc

INTO t_line SEPARATED BY space.

wa_header-typ = 'A'.

wa_header-info = t_line.

APPEND wa_header TO t_header.

CLEAR: wa_header, t_line.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header

  • i_logo = 'Z_LOGO'

.

ENDFORM. "alv_top_of_page

&----


*& Form get_buildfieldcat1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_buildfieldcat1 .

DATA position TYPE i.

position = -1.

position = position + 1.

fieldcatalog-fieldname = 'VBELN'.

fieldcatalog-seltext_m = 'Sales Order No.'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'AUDAT'.

fieldcatalog-seltext_m = 'Order Date'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 15.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'KUNNR'.

fieldcatalog-seltext_m = 'Sold to Party'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'KUNAG'.

fieldcatalog-seltext_m = 'Ship to Party'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'MATNR'.

fieldcatalog-seltext_m = 'Material No.'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'MAKTX'.

fieldcatalog-seltext_m = 'Material Desc.'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'KDMAT'.

fieldcatalog-seltext_m = 'Customer Material No.'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'MAKTX1'.

fieldcatalog-seltext_m = 'Customer Material Desc'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'BSTKD'.

fieldcatalog-seltext_m = 'Purchase Order No.'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'BSTDK'.

fieldcatalog-seltext_m = 'Purchase Order Date'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

position = position + 1.

fieldcatalog-fieldname = 'KBETR'.

fieldcatalog-seltext_m = 'Basic Price'.

fieldcatalog-col_pos = position.

fieldcatalog-outputlen = 10.

APPEND fieldcatalog TO fieldcatalog.

CLEAR fieldcatalog.

ENDFORM. " get_buildfieldcat1

&----


*& Form get_agree_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_agree_data .

*Get from VBAK table.

select vbeln audat vbtyp vkorg knumv kunnr

from vbak into table i_vbak

where audat in s_audat

and vkorg in s_vkorg

and kunnr in s_kunnr

and vbtyp in ('C','E').

*Get from VBAP table.

if not i_vbak[] is initial.

clear:i_vbap. refresh:i_vbap.

select vbeln posnr matnr arktx kdmat taxm1

from vbap into table i_vbap

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

*Get from VBPA table.

if not i_vbap[] is initial.

clear:i_vbpa. refresh:i_vbpa.

select vbeln posnr parvw kunnr

from vbpa into table i_vbpa

for all entries in i_vbap

where vbeln = i_vbap-vbeln

and parvw in ('AG','KB','RE','RG','VE','WE','ZM').

endif.

*Get from KONV table.

if not i_vbak[] is initial.

clear:i_konv. refresh:i_konv.

select knumv kschl kbetr mwsk1

from konv into table i_konv

for all entries in i_vbak

where knumv = i_vbak-knumv

and kschl = 'PR00'.

endif.

*Get from VBKD table.

if not i_vbak[] is initial.

clear:i_vbkd. refresh:i_vbkd.

select vbeln posnr bstkd bstdk

from vbkd into table i_vbkd

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

ENDFORM. " get_agree_data

&----


*& Form get_order_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_order_data .

*Get from VBAK table.

select vbeln audat vbtyp vkorg knumv kunnr

from vbak into table i_vbak

where audat in s_audat

and vkorg in s_vkorg

and kunnr in s_kunnr

and vbtyp in ('C','E').

*Get from VBAP table.

if not i_vbak[] is initial.

clear:i_vbap. refresh:i_vbap.

select vbeln posnr matnr arktx kdmat taxm1

from vbap into table i_vbap

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

*Get from VBPA table.

if not i_vbap[] is initial.

clear:i_vbpa. refresh:i_vbpa.

select vbeln posnr parvw kunnr

from vbpa into table i_vbpa

for all entries in i_vbap

where vbeln = i_vbap-vbeln

and parvw in ('AG','KB','RE','RG','VE','WE','ZM').

endif.

*Get from KONV table.

if not i_vbak[] is initial.

clear:i_konv. refresh:i_konv.

select knumv kschl kbetr mwsk1

from konv into table i_konv

for all entries in i_vbak

where knumv = i_vbak-knumv

and kschl = 'PR00'.

endif.

*Get from VBKD table.

if not i_vbak[] is initial.

clear:i_vbkd. refresh:i_vbkd.

select vbeln posnr bstkd bstdk

from vbkd into table i_vbkd

for all entries in i_vbak

where vbeln = i_vbak-vbeln.

endif.

ENDFORM. " get_order_data

With Regards,

Seevangi

Former Member
0 Kudos

Hi,

ALV (Abap List Viewer)

We can easily implement basic features of reports like Sort, Allign, Filtering, Totals-Subtotals etc... by using ALV. Three types of reports we can do by ALV as 1. Simple Report, 2. Block Reprot and 3. Hierarchical Sequential Report.

alv grid types

1) list/ grid

these are having rows and columns

function modules for this type are

REUSE_ALV_LIST_DISPLAY

REUSE_ALV_GRID_DISPLAY2)

2) HIERARCHY

this will have header and line items

function module for this type

REUSE_ALV_HIERSEQ_LIST_DISPLAY

3) tree

this will nodes and child type structure

function module for this type

REUSE_ALV_TREE_DISPLAY

4) APPEND

this can append all the different types of lists where each list has different number of columns

events associated with alvs

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

some useful links:

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

http://help.sap.com/saphelp_nw04/helpdata/en/99/49b844d61911d2b469006094192fe3/frameset.htm

Example:

REPORT Z_ALV__ITEM .


TYPE-POOLS : slis.

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.

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.


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.

Please reward points if it helps

Thanks

VIkranth

Former Member
0 Kudos

Please Check this code

-


REPORT ZALV_GRID_SAMPLE .

TABLES VBAK.

DATA it_vbak LIKE VBAK OCCURS 0 WITH HEADER LINE.

SELECT * FROM VBAK

INTO CORRESPONDING FIELDS OF TABLE it_vbak

UP TO 10 ROWS.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'VBAK'

I_GRID_TITLE = 'SALES ORDER INFO'

TABLES

T_OUTTAB = it_vbak

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.

-


Former Member
0 Kudos

Hi Venkat,

1. Define the selection screen (if required)

2. Build the final internal table which is to be display in the ALV, based on your requirement.

3. build the field catalog internal table.

4. build the event internal table and define the event subroutine, if events are need.

5. Call the below function module

a. REUSE_ALV_LIST_DISPLAY - ALV List or

b. REUSE_ALV_GRID_DISPLAY - ALV Grid

c. call the method SET_TABLE_FOR_FIRST_DISPLAY of the CL_GUI_ALV_GRID - OO ALV.

Refer the following links.

[http://www.sap-img.com/abap/abap-example-program-alv-grid-control.htm|http://www.sap-img.com/abap/abap-example-program-alv-grid-control.htm]

[http://www.sapdev.co.uk/reporting/reportinghome.htm|http://www.sapdev.co.uk/reporting/reportinghome.htm]

[http://www.sapmaterial.com/alv1.html|http://www.sapmaterial.com/alv1.html]

Sample Programs are available in SE38.

1. Give the program name BCALV*, press F4.

Reward if found helpful

Regards,

Boobalan Suburaj