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

first alv

Former Member
0 Likes
1,018

Hi,

This is my first alv.

Let say i have itab with 5 fields f1.......f5.

Kindly tell me how to display in a alv format.

Thanks and regads

alv

Hi,

This is my first alv.

Let say i have itab with 5 fields f1.......f5.

Kindly tell me how to display in a alv format.

Thanks and regads

alv

8 REPLIES 8
Read only

anversha_s
Active Contributor
0 Likes
983

hi,

welcome.

simple chk this link.

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

regards

Anver

Read only

0 Likes
983

Thanks anver...........:-)

Read only

amit_khare
Active Contributor
0 Likes
983

Hi,

Check this example -

1) Report for ALV

report ---

message-id ---.

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

*Table Declaration

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

tables : -


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

*Pool

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

type-pools : slis.

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

*Data Declaration

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

***Internal table for MARA***

data :----


***Field description for ALV***

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_sort type slis_t_sortinfo_alv.

data: repname like sy-repid.

data: fieldtab type slis_t_fieldcat_alv,

fieldtab1 type slis_t_fieldcat_alv,

i_grid_title type lvc_title,

heading type slis_t_listheader,

f_events type slis_t_event,

f1_event type slis_alv_event,

gs_layout type slis_layout_alv.

***Constants***

constants : formname_top_of_page type slis_formname value 'TOP_OF_PAGE'.

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

*Selection Screen

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

selection-screen : -


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

*At Selection Screen

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

at selection-screen.

***Validation for material type***

-


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

*Start of Selection

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

start-of-selection.

-


***ALV Display starts***

perform display.

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

&----


*& Form display

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form display .

perform build_comment using heading[].

perform build_fieldcatalog.

*perform sort_build using gt_sort[].

perform eventtab_build using f_events[].

perform call_alv1.

endform. " display

**TOP_OF_PAGE***

form top_of_page.

.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = heading.

endform. "TOP_OF_PAGE

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

&----


*& Form build_comment

&----


  • text

----


  • -->P_HEADING[] text

----


form build_comment using p_heading type slis_t_listheader.

data: htext type slis_listheader,

text(200) type c,

l_sep(150) type c,

c_date(10),

c_date1(10),

v_wcntr(10),

v_wcntr1(10),

date1 type string.

htext-typ = 'H'.

format color 1 intensified off.

move text-t04 to text.

htext-info = text.

append htext to p_heading.

clear text.

concatenate sy-datum6(2) '/' sy-datum4(2) '/' sy-datum+0(4)

into date1.

htext-typ = 'S'.

format color 4 inverse.

move : 'Date :' to text+10,

date1 to text+30.

htext-info = text.

append htext to p_heading.

clear text.

endform. " build_comment

&----


*& Form build_fieldcatalog

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_fieldcatalog .

data: l_fieldcat type slis_fieldcat_alv.

clear l_fieldcat.

l_fieldcat-fieldname = 'MATNR'.

l_fieldcat-outputlen = 20.

l_fieldcat-tabname = 'i_tab'.

l_fieldcat-no_out = ' '.

l_fieldcat-seltext_l = text-010.

append l_fieldcat to fieldtab1.

MTART

MATKL

WERKS

endform. " build_fieldcatalog

&----


*& Form eventtab_build

&----


  • text

----


  • -->P_F_EVENTS[] text

----


form eventtab_build using p_f_events.

call function 'REUSE_ALV_EVENTS_GET'

exporting

i_list_type = 2

importing

et_events = f_events

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.

***Append top-of-page***

read table f_events with key name = slis_ev_top_of_page

into f1_event.

if sy-subrc = 0.

move formname_top_of_page to f1_event-form.

append f1_event to f_events.

clear f1_event.

endif.

endform. " eventtab_build

&----


*& Form call_alv1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form call_alv1 .

repname = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = repname

it_fieldcat = fieldtab1

i_default = 'X'

i_save = ' '

it_events = f_events[]

tables

t_outtab = i_tab

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. " call_alv1

Regards,

Amit

Read only

Former Member
0 Likes
983

chk this link , many ALV examples

http://www.geocities.com/mpioud/Abap_programs.html

Read only

Former Member
0 Likes
983

****declaration for fieldcatalog

DATA: g_fieldcat TYPE slis_t_fieldcat_alv,

g_layout TYPE slis_layout_alv.

INITIALIZATION.

g_layout-zebra = 'X'.

g_layout-colwidth_optimize = 'X' .

v_repid = sy-repid.

PERFORM SUB_BUILD_FIELDCAT.

Start-of-selection.

PERFORM SUB_DISPLAY_ALV.

FORM SUB_BUILD_FIELDCAT .

REFRESH: G_FIELDCAT.

CLEAR: G_FIELDCAT.

PERFORM SUB_INIT_FIELDCAT USING G_FIELDCAT[] 'FIELD1'

'ITAB'

'S.NO'.

PERFORM SUB_INIT_FIELDCAT USING G_FIELDCAT[] 'FIELD2'

'ITAB'

'Appl.No'.

ENDFORM.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = V_REPID

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

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE =

  • I_GRID_SETTINGS =

IS_LAYOUT = G_LAYOUT

IT_FIELDCAT = G_FIELDCAT[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

I_SAVE = 'A'

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

Read only

Former Member
0 Likes
983

Hi,

ALV is similar to your normal report,

i will tell you the basic alv report..

you start like a normal report.. its just that instead of write statement for displaying you use two function modules ...

1. reuse_alv_fieldcatalog_merge -

field catalog is a kind of structure for your output display which you have to merge with your internal table data.

2. reuse_alv_grid_display.

this displays your internal table data which you have merged with the field catalog structure in the output list in grid format.

before starting the program you have to create a structure fieldcat like slis_t_fieldcat_alv.

taken from type pools slis.

regards,

pankaj singh

Read only

Former Member
0 Likes
983

Hi Jyoti ,

I will just list down the steps you need to get the desired reult.

1. Select the data you want to display into an internal table.

2. Create a field catalog ( field catalog is basically an internal table which contains the fields you want to display in the ALV) . The field catalog will be an internal table of type 'LVC_S_FCAT'.

3. Once you are done with step 1 and 2 , call the FM

'REUSE_ALV_GRID_DISPLAY' , passing field catalog internal table to 'IT_FIELDCAT' and the internal table with data to 'T_OUTTAB'.

Hope this helps.

Regards

Arun

Read only

Former Member
0 Likes
983

Hi,

check the following code.


REPORT  ZTEST_ALV                                                .
type-pools:slis.
data :   it_fieldcat type slis_t_fieldcat_alv,
          it_fieldcat1 type slis_t_fieldcat_alv.
data: x_fieldcat type
slis_fieldcat_alv.
data : itab2 type table of mara.
 
x_fieldcat-fieldname = 'MATNR'.
x_fieldcat-tabname = 'MARA'.
x_fieldcat-col_pos  = 1.
append x_fieldcat to it_fieldcat.
clear x_fieldcat.
 
select * from mara into table itab2.
 
call function 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat              = it_fieldcat
TABLES
t_outtab                 = itab2
EXCEPTIONS
program_error            = 1
others                   = 2.

regards,

kinshuk