Powered By

Free XML Skins for Blogger

Powered by Blogger

Showing posts with label SAP ALV. Show all posts
Showing posts with label SAP ALV. Show all posts

Thursday, February 12, 2009

sap abap program for Upload Logo for REUSE_ALV_COMMENTARY_WRITE

For those who wish to upload and use a picture in your ALV abap reports.

Steps for uploading Logo :-:
1. Goto the transaction OAER
2. Enter the class name as 'PICTURES'
3. Enter the class type as 'OT'
4. Enter the object key as the name of the logo you wish to give
5. Execute
6. Then in the new screen select Standard doc. types in bottom window
Click on the Screen icon
Now, it will ask for the file path where you have to upload the logo
7. Now you can use this logo in REUSE_ALV_COMMENTARY_WRITE

or

Import Logo and Background Picture for Reporting

In this step, you can import a customer-specific logo and a background picture into the R/3 System. These will be displayed in the header area of reports in HR Funds and Position Management.

From the SPRO:
HR Funds and Position Management --> Dialog Control --> Customize Reporting Interface --> Import Logo and Background Picture for Reporting.

Activities
1. Enter the Name of your logo/background picture as an object key in the initial screen.
2. Make sure that the class name is PICTURES, and the class type is OT.
3. Choose Execute.
4. Double-click the document type Picture on the Create tab page. A dialog box will appear in which you can enter the path in which the logo/background picture can be found.
5. Enter the path and choose Open. The logo will be uploaded into the current R/3 System. If the logo/background picture is to be transported into other systems as well, choose Transport.
6. Return to the initial screen and repeat the procedure after having entered the Name of your background picture as an object key.

Please note that the logo/background picture can only be displayed in ALV-based reports with an HTML header. Manually programmed reports such as business distribution plans are not based on the ALV.

If you have selected several initial objects, ALV-based reports in HR Funds and Position Management will automatically use a hiearchical-sequential display. A logo is not displayed here either. Note also that the logo cannot be printed (see print preview in program).

Make sure that the logo does not exceed a height of 100 pixels because it would mean that the header of the report will be scrollable.

What is SLIS in sap abap ALV

SLIS is the type library for ALV grid.

If you'll use the ALV you have to add TYPE-POOLS : SLIS. command at the beginning of your code.

Consider these :
slis_t_fieldcat_alv is containing "_t_"
It means that it is an internal table and slis_fieldcat_alv is header line of that.

Here is a practical example for alv grid :
Just think that you have an internal table named 'ITAB' to show.

Step1 : First add these lines to your code :
TYPE-POOLS : SLIS.

DATA ALV_PROG_NAME LIKE SY-REPID.
ALV_PROG_NAME = SY-REPID.

DATA : ALV_ITAB_NAME(30),
L_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
ALV_ITAB_NAME = 'ITAB'. "!!Write here the name of your internal table

Step 2 : Add these two function :
The first function is filling the fieldcat L_FIELDCAT that you described, second is showing it on the screen.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = ALV_PROG_NAME
I_INTERNAL_TABNAME = ALV_ITAB_NAME
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
I_INCLNAME = ALV_PROG_NAME
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
CHANGING
CT_FIELDCAT = L_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = ALV_PROG_NAME
* 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 =
IT_FIELDCAT = L_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
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IT_EXCEPT_QINFO =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = ITAB[] "Write here the name of your internal table + []
* 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. *-- Bulent

How to Refresh ALV List/Grid once it is displayed?

This mean to say that if you have a 'refresh' push button in your gui status, every time you press the button, the list should get refreshed.

In ALV, to refresh the table you have to call the method "refresh_table_display".

It has the syntax very similar to creating the table.

It has two parameters. In the first one, you can mention if you want to refresh only the data (the icons are not refreshed)

or

if you want to refresh only the icons around the grid (the data is not refreshed - this option is mostly not used in day to day applications).

the synatx is :-

call method grid (name of grid )->refresh_table_display

exporting

IS_STABLE = (THIS IS FOR DATA REFRESHING)

I_SOFT_REFRESH = (THIS IS FOR ICON REFRESHING).

sap abap ALV 'Classic' Creating User/Global Layout Variants

You are working with the ALV "Classic" function module REUSE_ALV_LIST_DISPLAY.

Reading the documentation for the function module, it seems there is a way to save an ALV layout variant as "user-specific" and/or "global". But unfortunately, you either can only save "globals" (with the '/' as first character of the layout name) or "user-specific".

You have tried the I_SAVE parameter as 'U' and can only save "user-specific". You tried I_SAVE as 'X' and can only save "global". You tried I_SAVE as 'A', but only can only save as "user-specific". The odd thing is, on the Save Layout pop-up dialog the User-Specific checkbox is always "greyed-out", but has a check (for 'U' and 'A') or is checkless (for 'X').

Can "user" and "global" layout variants be saved together from same program with I_SAVE as 'A'?

Why is the User-Specific checkbox on the Save Layout pop-up always "greyed-out"?

You have the following EXPORTING parameters in my function module:
I_DEFAULT = 'X'
I_SAVE = 'A' "<=== this is to be global & user IS_VARIANT = VARIANT

VARIANT has the program's name in the REPORT field.


The "user-specific saving" needs a special authorization:
Authority-check object 'S_ALV_LAYO' id 'ACTVT' field '23', you can
avoid this authorization with IS_LAYOUT-NO_AUTHOR = 'X

How to use ALV for Hierarchical Lists

Can anyone tell me how to use ALV for hierarchical lists using the function code REUSE_ALV_HIERSEQ_LIST_DISPLAY?

Swarna

Hello, there are some nice examples in SAP which use this function module, so you might want to check them out ( where used etc. )

In essence, this is a call in one of my ABAPs

  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
EXPORTING
i_interface_check = 'I'
i_callback_program = gv_repid
* i_callback_pf_status_set = 'STATUS_DATA'
i_callback_user_command = 'COMMAND_DATA'
* is_layout = gs_layout
it_fieldcat = gt_fieldcat
i_default = ' '
i_save = 'A'
i_tabname_header = v_headers_itable
i_tabname_item = v_items_itable
i_structure_name_header = v_headers_table
i_structure_name_item = v_items_table
is_keyinfo = gs_keyinfo
i_bypassing_buffer = 'X'
TABLES
t_outtab_header = i_headers
* t_outtab_item = i_result
t_outtab_item = i_report
EXCEPTIONS
program_error = 1
OTHERS = 2.

The field cat creation worked like this :
FORM fieldcat.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_items_itable
i_structure_name = v_items_table
CHANGING
ct_fieldcat = gt_fieldcat.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_internal_tabname = v_headers_itable
i_structure_name = v_headers_table
CHANGING
ct_fieldcat = gt_fieldcat.

ENDFORM.


and of course you need to tell the thing what is key and item

gs_keyinfo-header01 = 'PA'.
gs_keyinfo-item01 = 'PA'.
gs_keyinfo-item02 = 'SAPDOC'.
PERFORM fieldcat.
I hope this helps you and not confuse you,
Cheers.

sap abap program for Sample ALV: Heading in ALV

report zus_alv_demo_grid .

tables: ekko.
type-pools: slis.

types: begin of t_ekko,
ebeln type ekpo-ebeln,
ebelp type ekpo-ebelp,
statu type ekpo-statu,
aedat type ekpo-aedat,
matnr type ekpo-matnr,
menge type ekpo-menge,
meins type ekpo-meins,
netpr type ekpo-netpr,
peinh type ekpo-peinh,
line_color(4) type c, "Used to store row color
end of t_ekko.

data: it_ekko type standard table of t_ekko initial size 0,
wa_ekko type t_ekko.

*ALV data declarations
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.

* Data declaration for EVENT and PRINT PARAMETER.
data: gt_events type slis_t_event,
gd_prntparams type slis_print_alv.

* data declaration for sorting.
data : it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat.
data : i_list_comments type slis_t_listheader.

start-of-selection.
perform data_retrieval.
* perform user_command.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform build_sortcat.
perform display_alv_report.

end-of-selection.

*TOP-OF-PAGE.
* PERFORM top-of-page.

end-of-page.
*&----------------------------------------------------------
*& Form build_fieldcatalog
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form build_fieldcatalog.

fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
fieldcatalog-do_sum = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.


fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.

endform. " build_fieldcatalog
*&----------------------------------------------------------
*& Form build_layout
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).

* Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
* gd_layout-totals_only = 'X'.
* gd_layout-f2code = 'DISP'. "Sets fcode for
*when double
* "click(press f2)*
* gd_layout-group_change_edit = 'X'.
* gd_layout-header_text = 'helllllo'.
endform. " build_layout
*&----------------------------------------------------------
*& Form data_retrieval
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form data_retrieval.
data: ld_color(1) type c.

select ebeln ebelp statu aedat matnr menge meins netpr
peinh from ekpo into table it_ekko.
*Populate field with color attributes
loop at it_ekko into wa_ekko.
* Populate color variable with colour properties
* Char 1 = C (This is a color property)
* Char 2 = 3 (Color codes: 1 - 7)
* Char 3 = Intensified on/off ( 1 or 0 )
* Char 4 = Inverse display on/off ( 1 or 0 )
* i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
* Only 7 colours so need to reset color value
if ld_color = 8.
ld_color = 1.
endif.
concatenate 'C' ld_color '10' into wa_ekko-line_color.
* wa_ekko-line_color = 'C410'.
modify it_ekko from wa_ekko.
endloop.

endform. " data_retrieval
*&----------------------------------------------------------
*& Form display_alv_report
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
is_layout = gd_layout
i_callback_top_of_page = 'TOP-OF-PAGE'
i_callback_user_command = 'USER_COMMAND'
i_callback_pf_status_set = 'SET_PF_STATUS'
it_event = gt_events
is_print = gd_prntparams
it_fieldcat = fieldcatalog[]
it_sort = it_sortcat
i_save = 'X'
tables
t_outtab = it_ekko
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_REPORT
*&----------------------------------------------------------
*& Form user_command
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
*&----------------------------------------------------------
*& Form top-of-page
*&----------------------------------------------------------
* text
*-----------------------------------------------------------
* --> p1 text
* <-- p2 text
*-----------------------------------------------------------
form 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.

* Title
wa_header-typ = 'H'.
wa_header-info = 'EKKO Table Report'.
append wa_header to t_header.
clear wa_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.

* Total No. of Records Selected
describe table it_ekko lines ld_lines.
ld_linesc = ld_lines.

concatenate 'Total No. of Records Selected: ' 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 = 'GANESH_LOGO'.



endform. " top-of-page

*---------------------------------------------------------------------*
* FORM user_command *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*---------------------------------------------------------------------*
form user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
case r_ucomm.

when '&IC1'.
if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.
when 'ULHAS'.
if rs_selfield-fieldname = 'EBELN'.
read table it_ekko into wa_ekko index rs_selfield-tabindex.
set parameter id 'BES' field wa_ekko-ebeln.
call transaction 'ME23N' and skip first screen.
endif.

endcase.

endform.

*---------------------------------------------------------------------*
* FORM set_pf_status *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> RT_EXTAB *
*---------------------------------------------------------------------*
form set_pf_status using rt_extab type slis_t_extab.
set pf-status 'ZNEWSTATUS'.
endform.
*&---------------------------------------------------------------------*
*& Form build_events
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
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[]
* 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.
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.

read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " build_events
*&---------------------------------------------------------------------*
*& Form build_print_params
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_print_params.
gd_prntparams-reserve_lines = '3'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " build_print_params

*---------------------------------------------------------------------*
* FORM END_OF_PAGE *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_page.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip. write:/40 'Page:', sy-pagno .
endform.

*---------------------------------------------------------------------*
* FORM END_OF_LIST *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form end_of_list.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip. write:/40 'Page:', sy-pagno .
endform.
*&---------------------------------------------------------------------*
*& Form build_sortcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_sortcat.
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
append wa_sort to it_sortcat.

wa_sort-spos = 2.
wa_sort-fieldname = 'EBELP'.
append wa_sort to it_sortcat.

endform. " build_sortcat

sap abap program for Test ALV Display With Header & Footer

*Program to Test ALV Display With Header & Footer.
*&---------------------------------------------------------------------*
*& Report ZRJR02 *
*&---------------------------------------------------------------------*
REPORT ZRJR02 .

*Table declaration.
TABLES:ZEMP_MST,ZDEPT_MST,ZDESG_MST,ZSL_TXN.

*Varriable declaration.
TYPE-POOLS SLIS.
DATA : POS TYPE I.
DATA REPID LIKE SY-REPID.

DATA : F1 TYPE SLIS_T_FIELDCAT_ALV,
F2 TYPE SLIS_FIELDCAT_ALV,
L_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA L_POS TYPE I VALUE 1. "position of the column
DATA GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
*DATA GT_SORT TYPE SLIS_T_SORTINFO_ALV.

data: GT_EVENTS TYPE SLIS_T_EVENT,
FS_EVENTCAT LIKE LINE OF GT_EVENTs.

*Internal table declaration.
*DATA BEGIN OF IT_SORT OCCURS 5.
* INCLUDE TYPE SLIS_SORTINFO_ALV.
*DATA END OF IT_SORT.

DATA:BEGIN OF ITAB OCCURS 0,
ZEMPNO LIKE ZEMP_MST-ZEMPNO,
ZEMPNAME LIKE ZEMP_MST-ZEMPNAME,
ZDEPTCD LIKE ZEMP_MST-ZDEPTCD,
ZDEPTNAME LIKE ZDEPT_MST-ZDEPTNAME,
ZDESGCD LIKE ZEMP_MST-ZDESGCD,
ZDESGNAME LIKE ZDESG_MST-ZDESGNAME,
END OF ITAB.
REFRESH ITAB.CLEAR ITAB.

START-OF-SELECTION.

SELECT A~ZEMPNO A~ZEMPNAME A~ZDEPTCD B~ZDEPTNAME A~ZDESGCD C~ZDESGNAME
FROM ZEMP_MST AS A
INNER JOIN ZDEPT_MST AS B
ON A~ZDEPTCD EQ B~ZDEPTCD
INNER JOIN ZDESG_MST AS C
ON A~ZDESGCD EQ C~ZDESGCD
INTO CORRESPONDING FIELDS OF TABLE ITAB.
IF SY-SUBRC <> 0.
MESSAGE E899(M3) WITH 'No records'.
ENDIF.

perform f_build_eventcat.
PERFORM LAYOUT.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
FORM LAYOUT .
PERFORM FCAT USING 'ZEMPNO' 'ITAB' '' 'Emp.No.' 'ZEMPNO' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZEMPNAME' 'ITAB' '' 'Emp. Name' 'ZEMPNAME' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTCD' 'ITAB' '' 'Dept.Code' 'ZDEPTCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDEPTNAME' 'ITAB' '' 'Dept.Name' 'ZDEPTNAME' 'ZDEPT_MST' ''.
PERFORM FCAT USING 'ZDESGCD' 'ITAB' '' 'Desg.Code' 'ZDESGCD' 'ZEMP_MST' ''.
PERFORM FCAT USING 'ZDESGNAME' 'ITAB' '' 'Desg.Name' 'ZDESGNAME' 'ZDESG_MST' ''.

* PERFORM LSORT USING 'ZEMPNO' 'IDATA' ''.
* PERFORM LSORT USING 'ZEMPNAME' 'IDATA' ''.

* MOVE IT_SORT[] TO GT_SORT[].

REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPID
IT_FIELDCAT = F1
* IT_SORT = GT_SORT
I_SAVE = 'X'
IT_EVENTS = GT_EVENTS[]

TABLES
T_OUTTAB = ITAB.
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. " LAYOUT


*&---------------------------------------------------------------------*
*& Form FCAT
*&---------------------------------------------------------------------*
FORM FCAT USING P_FIELD P_TABLE P_SUM P_TEXT P_RFIELD P_RTABLE P_DISP.
ADD 1 TO POS.
F2-COL_POS = POS.
F2-FIELDNAME = P_FIELD.
F2-TABNAME = P_TABLE.
F2-SELTEXT_L = P_TEXT.
F2-REF_FIELDNAME = P_RFIELD.
F2-REF_TABNAME = P_RTABLE.
F2-DO_SUM = P_SUM.
F2-NO_OUT = P_DISP.
APPEND F2 TO F1.
CLEAR F2.
ENDFORM. " FCAT

*&---------------------------------------------------------------------*
*& Form LSORT
*&---------------------------------------------------------------------*
*FORM LSORT USING P_FIELD P_TABLE P_UP.
* ADD 1 TO L_POS.
* IT_SORT-SPOS = L_POS.
* IT_SORT-FIELDNAME = P_FIELD.
* IT_SORT-TABNAME = P_TABLE.
* IT_SORT-UP = P_UP.
* APPEND IT_SORT.
*ENDFORM. " LSORT
*-------------
FORM F_BUILD_EVENTCAT .
CLEAR: GT_EVENTS. REFRESH: GT_EVENTS.

CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'TOP_OF_PAGE'.
FS_EVENTCAT-FORM = 'F_REPORT_HEADER_ALV'.
APPEND FS_EVENTCAT TO GT_EVENTS.


CLEAR: FS_EVENTCAT.
FS_EVENTCAT-NAME = 'END_OF_LIST'.
FS_EVENTCAT-FORM = 'F_WRITE_SUMMARY'.
APPEND FS_EVENTCAT TO GT_EVENTS.

ENDFORM. " F_BUILD_EVENTCAT

FORM F_REPORT_HEADER_ALV.
CALL FUNCTION 'Z_YHEAD_PRINT'
EXPORTING
TITLE1 = 'XYZ Limited'
TITLE2 = 'Employee Master'
TITLE3 = 'Created on '
COLOR = 'X'
.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form F_WRITE_SUMMARY
*&---------------------------------------------------------------------*
* Write summary before exit
*----------------------------------------------------------------------*
FORM F_WRITE_SUMMARY .

write:/ 'Welcome to XYZ Limited'.
write:/ 'This is a test program to display Report in ALV Format'.

Tuesday, February 10, 2009

ALV ABAP List Viewer

ABAP List Viewer (ALV)
In this chapter you will learn:

Why the ABAP List Viewer (ALV) is useful
Some of the time-saving features of ALV, as well as its ability to enhance information display
The differences between reports written with and without the ALV
Technical information (sample code) to help you build reports with ALV “functionality”
Contents



Overview
If it becomes necessary to write ABAP code to create your reports, then consider using the ABAP List Viewer (ALV) to simplify your development. Available in the R/3 System since Release 3.1, the ABAP List Viewer supports many of the standard R/3 reports. The ALV provides additional program code you can quickly add to any custom report for any SAP module.

Many reports developed for Release 4.0 (and later) utilize the ABAP List Viewer. Additionally, many older standard R/3 reports (and reporting tools) have been modified to include the ABAP List Viewer.

The ABAP List Viewer can be used with any application component or module in the R/3 System. We recommend that developers should adopt ABAP List Viewer as a design principle in all report development activities that occur in your organization.

Note: At the time of press, limited technical support is available for the ABAP List Viewer. However, we believe that support limitations should not prevent you from taking advantage of the functionality offered by ALV.

What Is The ABAP List Viewer?
The ALV is a set of function modules that are added to program code. Programs created before Release 3.1 can be enhanced with the ALV by adding links to the function modules. Developers can use the functionality of the ALV when creating new reports, thus saving time which might otherwise have been spent on report enhancement. Using the ALV also provides a uniform user-interface and list format for ABAP reports. This standardization helps eliminate redundant functions.

The ABAP List Viewer enables both simple and sequential (hierarchical) report lists. Simple lists contain a number of non-hierarchical, user-defined columns. Sequential lists contain columns that consist of column headings and their subordinate rows.

Goals of ALV The primary goals of the ABAP List Viewer are to provide:
Users with a consistent, user-friendly, and functional method of manipulating the data which appears on report lists.
ABAP developers with an efficient and consistent method of programming functions that are commonly needed or requested in reports.


ABAP List Viewer: Cost Versus Benefit Analysis
Before taking advantage of the features of ALV, developers may want to consider the benefits gained versus the “extra time” taken to include ALV in report development. The following table shows estimates of time expenditures in report development. Note that an estimated 50% of report developers’ time is consumed by building “fancy” features and enhancing the look-and-feel of custom reports.

ABAP Report Development Activity Without ALV Percentage of Time Taken to Complete
Finding the right tables and table relationships that need to be included in order for the program to be written 50%
Providing “fancy” features, such as sorting, subtotals, and interactivity 30%
Enhancing the look of the report with column headings, vertical lines, and color 20%
Total 100%

SAP developed the ABAP List Viewer to help reduce the time and effort spent on some of the report development activities. By using the ALV in the programming of custom reports, you could reduce the development time by an estimated 40% (see table below).

ABAP Report Development Activity With ALV Percentage of Time Taken to Complete
Finding the right tables and table relationships that need to be included in order for the program to be written 50%
Preparing field catalog and sort sequence for ALV 1%
Providing “fancy” features, such as sorting, subtotals, and interactivity 9%
Enhancing the look of the report with column headings, vertical lines, and color 0%
Total 60%

Although, the use of ALV adds one more development activity (that is, preparation of the field catalog), the development time spent on other activities is either eliminated or vastly reduced.

Report Lists Without ABAP List Viewer
When a report is written, the report list (output) depends almost entirely on how the developer programmed the report.

Shown below is a sample report list where the programmer did not to use the ABAP List Viewer. For illustration purposes, consider a report that was simply written (using the WRITE command) to the screen. The output of a report created with just the WRITE statement is shown below:

No column headings

List data is “dead.” It is simply a so-called “data dump”

Function bar is blank

A key point to note is that the function bar is blank. In addition, the data in the list is “dead” which means that data listed cannot be used for any further data retrieval. It is essentially a “data-dump.” Among other things, there are no headings for the columns. Any additional functionality would have to be programmed. In short, the interface between the data you see on the screen and the user’s eyes (the GUI) is limited and bland.

Report users routinely ask for additional features in their reports. Often they are looking for the ability to:

Hint: These functions are all available in ALV Sort Resize rows Double-click on one information element to jump to another information element Perform basic calculations Download “stylized” spreadsheets Display several colors Visually separate various pieces of information on the screen

However, for the most part, these features need to be programmed into the list as added functionality to the output of the report. While some of these added functions are relatively easy to program, the manner in which this added functionality works may vary greatly. For example, one programmer may decide to enable a single-click as sufficient user input to jump to a next level of information, while another programmer requires a double-click. Similarly, one programmer may set the output of a field at 10 characters long, but another programmer may program it as 20 characters.

Report Lists With ABAP List Viewer
When you insert the ALV code in your ABAP report program, the report list comes “alive.”

Compare the ALV-enabled list shown on page A-6 with the list shown on the previous page. Although the data is the same, the program has been changed to incorporate the ALV function modules.

With the ALV, the user is presented with a standard interface which, from the outset, includes:

Headers for the columns that appear on the list.
Colors that correspond to indented key information
Buttons that appear on the function bar (some of whose functions will be introduced in the pages that follow)
List data is “alive”

Column headings make data easier to understand

A feature-rich function bar gives the user commonly requested functionality

Function bar is blank

As you review the additional functionality shown above, remember that without the ALV each function would have to be programmed into the report.

Note: This appendix introduces you to some of the functions that the ALV makes possible. However, this appendix does not cover the full breadth of ALV functionality. For more information, refer to the ALV documentation in the R/3 online documentation:
R/3 Library → CA-Cross-Application Components → General Application Functions → ABAP List Viewer

Guided Tour

This guided tour shows possible ways a user could interact with an ALV-enabled report list.

2
1In an ALV-enabled report list, a user can select a particular column and execute a subsequent function, if desired.

Select the column for Sales doc. With ALV’s added functionality the color of the selected column can be changed, making it easy for the report user to know which column has been selected.
Choose Filter. With the filter option, a user can call up a desired subset of information on the output list.


4
3Set the filter for the sales documents to be viewed. In this instance, the user only wants to views sales documents that are between the numbers 1000 and 2000.

Choose Copy to invoke the ALV to filter the list.


6
5The resulting filtered list is shown to the right. To return to the previous list, a user can simply click the arrow buttons without having to exit and re-execute the report.

If not all columns of the report are of interest to the user, the unwanted columns can be hidden. This can be accomplished by setting the current variant to include only the desired columns. To hide (or to view previously hidden columns), choose Display variant.

8
7In the popup window, the columns that currently appear in the list are shown in the left section. Hidden fields (if any) appear on the right section. In this example, all fields appear.

To make one column disappear, select the row which lists the column you want to hide. In this example, we select Material Group.
Then, click the single right-arrow button to move the selected column (Material group) to the hidden fields section.

9The Material Group is now one of the hidden fields.
For this change to take effect, choose Copy.

The “new” output list appears. The original list may be revisited by simply choosing the current variant.




Technical Notes
In order for the reports to provide the consistency, flexibility, and user-friendliness of the ALV, it is necessary to include certain statements in the report’s program code. This section is intended for those who actually write the code for reports.

To include the ALV in a report, the following basic steps must completed:

Declare data areas for List Viewer.
Declare the internal table to store selected data.
Select data into internal table.
Build the field catalogs.
Build event catalogs.
Start ABAP List Viewer using SAP’s standard delivered function modules (see TechTalk below).
Process call back events.
In the standard R/3 System, SAP delivers several function modules related to the ALV.
Use the following function modules with Release 4.0: REUSE_ALV_LIST_DISPLAY (this is the primary function module) or other function modules that begin with the name REUSE_ALV*.

K_KKB_LIST_DISPLAY is still available but should no longer be used!

Review the sample program on page A–10 which shows the coding related to each of steps listed above.

Note: The source code that appears on page A–10 was used to create the sample ALV-enabled report list presented in this appendix. You will find the source code (ZFIGALV.txt) on the companion CD supplied with this guidebook series.

Sample Code Using ALV (Release 4.0B)
**************************************************************

REPORT ZFIGALV .

********Declare Data Areas for List Viewer (Begin)************

TYPE-POOLS: SLIS.

DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

FIELDCAT_LN LIKE LINE OF FIELDCAT,

SORTCAT TYPE SLIS_T_SORTINFO_ALV,

SORTCAT_LN LIKE LINE OF SORTCAT,

EVENTCAT TYPE SLIS_T_EVENT,

EVENTCAT_LN LIKE LINE OF EVENTCAT.

DATA: COL_POS TYPE I.

*******Declare Data Areas for List Viewer (End)***************

*******Declare Internal Table to Store Selected Data (Begin)**

DATA: BEGIN OF IVBAP OCCURS 0,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

MATNR LIKE VBAP-MATNR,

MATKL LIKE VBAP-MATKL,

CHARG LIKE VBAP-CHARG,

KWMENG LIKE VBAP-KWMENG,

VRKME LIKE VBAP-VRKME,

ARKTX LIKE VBAP-ARKTX,

END OF IVBAP.

*******Declare Internal Table to Store Selected Data (End)****

*******Select Data into Internal Table (Begin) ***************

SELECT VBELN POSNR MATNR MATKL KWMENG VRKME

INTO CORRESPONDING FIELDS OF TABLE IVBAP

FROM VBAP WHERE VBELN NE 0.

******* Select Data into Internal Table (End) ****************

******* Build Field Catalogs (Begin)**************************

PERFORM BUILD_FIELDCAT.

PERFORM BUILD_FIELDCAT2.

PERFORM BUILD_FIELDCAT3.

PERFORM BUILD_SORTCAT.

PERFORM BUILD_SORTCAT2.

*******Build Field Catalogs (End)******************************

*******Build Event Catalog (Begin)*****************************

PERFORM BUILD_EVENTCAT.

*******Build Event Catalog (End)*******************************

*******Start List Viewer (Begin)*******************************

PERFORM START_LIST_VIEWER.

*******Start List Viewer (End)*********************************

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

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

*********FORM ROUTINES (Begin)*********************************

FORM BUILD_FIELDCAT.

ADD 1 TO COL_POS.

FIELDCAT_LN-REF_TABNAME = 'VBAP'.

FIELDCAT_LN-FIELDNAME = 'VBELN'.

FIELDCAT_LN-KEY = 'X'.

FIELDCAT_LN-DO_SUM = SPACE.

FIELDCAT_LN-COL_POS = COL_POS.

FIELDCAT_LN-NO_OUT = SPACE.

FIELDCAT_LN-QFIELDNAME = SPACE.

FIELDCAT_LN-HOTSPOT = 'X'.

APPEND FIELDCAT_LN TO FIELDCAT.

ENDFORM.

FORM BUILD_FIELDCAT2.

ADD 1 TO COL_POS.

FIELDCAT_LN-REF_TABNAME = 'VBAP'.

FIELDCAT_LN-FIELDNAME = 'MATNR'.

FIELDCAT_LN-KEY = SPACE.

FIELDCAT_LN-DO_SUM = SPACE.

FIELDCAT_LN-COL_POS = COL_POS.

FIELDCAT_LN-NO_OUT = SPACE.

FIELDCAT_LN-QFIELDNAME = SPACE.

FIELDCAT_LN-HOTSPOT = SPACE.

APPEND FIELDCAT_LN TO FIELDCAT.

ENDFORM.

FORM BUILD_FIELDCAT3.

ADD 1 TO COL_POS.

FIELDCAT_LN-REF_TABNAME = 'VBAP'.

FIELDCAT_LN-FIELDNAME = 'MATKL'.

FIELDCAT_LN-KEY = SPACE.

FIELDCAT_LN-DO_SUM = 'X'.

FIELDCAT_LN-COL_POS = COL_POS.

FIELDCAT_LN-NO_OUT = SPACE.

FIELDCAT_LN-QFIELDNAME = SPACE.

FIELDCAT_LN-HOTSPOT = SPACE.

APPEND FIELDCAT_LN TO FIELDCAT.

ENDFORM.

FORM BUILD_SORTCAT.

SORTCAT_LN-SPOS = '1'.

SORTCAT_LN-FIELDNAME = 'MATNR'.

SORTCAT_LN-UP = 'X'.

SORTCAT_LN-DOWN = SPACE.

SORTCAT_LN-SUBTOT = 'X'.

APPEND SORTCAT_LN TO SORTCAT.

ENDFORM.

FORM BUILD_SORTCAT2.

SORTCAT_LN-SPOS = '2'.

SORTCAT_LN-FIELDNAME = 'VRKME'.

SORTCAT_LN-UP = SPACE.

SORTCAT_LN-DOWN = 'X'.

SORTCAT_LN-SUBTOT = SPACE.

APPEND SORTCAT_LN TO SORTCAT.

ENDFORM.

FORM BUILD_EVENTCAT.

EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.

EVENTCAT_LN-FORM = 'PAGE_HEADER'.

APPEND EVENTCAT_LN TO EVENTCAT.

ENDFORM.

FORM START_LIST_VIEWER.

DATA: PGM LIKE SY-REPID.

PGM = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

* I_INTERFACE_CHECK = ' '

I_CALLBACK_PROGRAM = PGM

* i_callback_pf_status_set = ' '

I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

* I_STRUCTURE_NAME =

* IS_LAYOUT =

IT_FIELDCAT = FIELDCAT

* IT_EXCLUDING =

* IT_SPECIAL_GROUPS =

IT_SORT = SORTCAT

* IT_FILTER =

* IS_SEL_HIDE =

* I_DEFAULT = 'X'

I_SAVE = 'A'

* IS_VARIANT = ' '

* IT_EVENTS =

* IT_EVENT_EXIT =

* IS_PRINT =

* I_SCREEN_START_COLUMN = 0

* I_SCREEN_START_LINE = 0

* I_SCREEN_END_COLUMN = 0

* I_SCREEN_END_LINE = 0

* IMPORTING

* E_EXIT_CAUSED_BY_CALLER =

* es_exit_caused_by_user =

TABLES

T_OUTTAB = IVBAP

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

ENDFORM.

********Process Call Back Events (Begin)***************************

FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM

SELFIELD TYPE SLIS_SELFIELD.

READ TABLE IVBAP INDEX SELFIELD-TABINDEX.

CHECK SY-SUBRC = 0.

CASE UCOMM.

WHEN '&IC1'.

CASE SELFIELD-SEL_TAB_FIELD.

WHEN 'IVBAP-VBELN'.

SET PARAMETER ID 'AUN' FIELD IVBAP-VBELN.

CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.

WHEN 'IVBAP-MATNR'.

SET PARAMETER ID 'MAT' FIELD IVBAP-MATNR.

CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.

ENDCASE.

ENDCASE.

ENDFORM.

********Process Call Back Events (End)******************************

***********FORM ROUTINES (END)**************************************




Review
The ABAP List Viewer (ALV) functionality provided within ABAP can enhance reports in the R/3 System, and was first made available with Release 3.1. The ALV is a set of function modules added to program code. Programs created before this release can be enhanced with the ALV by adding links to the function modules.
Using the ALV provides a uniform user-interface and list format for ABAP reports. This standardization helps eliminate redundant functions.
Using the ALV enhances the functionality provided with reports while decreasing the development time by roughly 40%.
The ALV provides the following features:
Sorting
Resizing of rows
Double-clicking on one information element to jump to another information element
Performing basic calculations
Downloading of stylized spreadsheets
Displaying several colors
Visually separating various pieces of information on the screen
To include the ALV in a report, the following basic steps must completed:
Declare data areas for List Viewer.
Declare the internal table to store selected data.
Select data into internal table.
Build field catalogs.
Build event catalogs.
Start the ABAP List Viewer using SAP’s standard delivered function modules.
Process call back events.
Where to Learn More
For more information, refer to the R/3 Library (online documentation).

In the HTML help documentation, go to:

R/3 System Library → CA-Cross-Application Components → General Application Functions → ABAP List Viewer

What is ALV Programming in sap abap?

What is ALV programming in ABAP? When is this grid used in ABAP?

ALV is Application List viewer.

Sap provides a set of ALV (ABAP LIST VIEWER) function modules which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length.

In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output.

The report output can contain up to 90 columns in the display with the wide array of display options.

The commonly used ALV functions used for this purpose are;

1. REUSE_ALV_VARIANT_DEFAULT_GET
2. REUSE_ALV_VARIANT_F4
3. REUSE_ALV_VARIANT_EXISTENCE
4. REUSE_ALV_EVENTS_GET
5. REUSE_ALV_COMMENTARY_WRITE
6. REUSE_ALV_FIELDCATALOG_MERGE
7. REUSE_ALV_LIST_DISPLAY
8. REUSE_ALV_GRID_DISPLAY
9. REUSE_ALV_POPUP_TO_SELECT

Purpose of the above Functions are differ not all the functions are required in all the ALV Report.

But either no.7 or No.8 is there in the Program.

How you call this function in your report?

After completion of all the data fetching from the database and append this data into an Internal Table. say I_ITAB.

Then use follwing function module.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = 'Prog.name'
I_STRUCTURE_NAME = 'I_ITAB'
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = I_ITAB.
IF SY-SUBRC <> 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC .
ENDIF.
ENDFORM. " GET_FINAL_DATA

SAP ALV Function Modules

(1) REUSE_ALV_LIST_DISPLAY

Display an ALV list as per parameters defined in the function call


(2) REUSE_ALV_GRID_DISPLAY

Display an ALV grid as per parameters defined in the function call

(3) REUSE_ALV_COMMENTARY_WRITE

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.

(4) REUSE_ALV_HIERSEQ_LIST_DISPLAY

This module outputs two internal tables as a formated hierarchical-sequential list.

(5) REUSE_ALV_VARIANT_F4

Display variant selection dialog box.

(6) REUSE_ALV_VARIANT_EXISTENCE

Checks whether a display variant exists.

Archives