Optimizing Data Visualization in SAP ALV: List Display vs Grid Display
List Display vs Grid Display in ALV :-
In SAP, ALV (ABAP List Viewer) provides various ways to display tabular data. Two common layout options are list display and grid display:
- List Display:
- In list display, the data is presented in a simple list format, typically with rows and columns.
- It is straightforward and easy to read, with each row representing a record and each column representing a field.
- List display is suitable for displaying basic tabular data without much formatting or customization.
- Grid Display:
- Grid display offers more flexibility and customization options compared to list display.
- It allows users to configure column widths, change column order, apply sorting, filtering, and grouping functionalities.
- Grid display is more interactive and user-friendly, as users can manipulate the data presentation according to their preferences.
- It provides a more visually appealing presentation of data, with options to customize colors, fonts, and alignments.
Choosing between list display and grid display depends on the specific requirements of the application and the preferences of the end-users. If users need more flexibility and interactivity, grid display is usually preferred. However, if simplicity and readability are more important, list display may be sufficient.
We have seen the practical implementation of List display in our last part, now let’s see the practical implementation of grid display :-
Implementation of grid display :-
-
Step 1 :- Replace the REUSE_ALV_LIST_DISPLAY function module with REUSE_ALV_GRID_DISPLAY.
Code :-
*************************************************
*Start of Program
*Type Strcuture fo Both header and Item table
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF ty_vbap.
********************************************
*Type structure for final table.
TYPES : BEGIN OF ty_final,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF ty_final.
*************************************************
*Declaring the internal table and work area
DATA : lt_vbak type table of ty_vbak,
ls_vbak type ty_vbak,
lt_vbap type table of ty_vbap,
ls_vbap type ty_vbap,
lt_final type table of ty_final,
ls_final type ty_final,
lv_vbeln type vbeln_va.
DATA : lt_fieldcat type table of slis_fieldcat_alv.
***************
*Declaring a select option.
SELECT-OPTIONS : s_vbeln for lv_vbeln.
START-OF-SELECTION.
SELECT vbeln erdat erzet ernam vbtyp
from vbak into table lt_vbak
where vbeln in s_vbeln.
if lt_vbak is not INITIAL.
select vbeln posnr matnr
from vbap
into table lt_vbap
FOR ALL ENTRIES IN lt_vbak
where vbeln = lt_vbak-vbeln.
loop at lt_vbap into ls_vbap.
ls_final-posnr = ls_vbap-posnr.
ls_final-matnr = ls_vbap-matnr.
Read table lt_vbak into ls_vbak with KEY vbeln = ls_vbap-vbeln.
if sy-subrc eq 0.
ls_final-vbeln = ls_vbak-vbeln.
ls_final-erdat = ls_vbak-erdat.
ls_final-erzet = ls_vbak-erzet.
ls_final-ernam = ls_vbak-ernam.
ls_final-vbtyp = ls_vbak-vbtyp.
endif.
append ls_final to lt_final.
clear : ls_final, ls_vbak, ls_vbap.
ENDLOOP.
***************************************
*Call REUSE ALV fieldcatalog merge
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'ZAR_ORDER_DETAILS'
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3
.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* IS_LAYOUT =
IT_FIELDCAT = lt_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
TABLES
t_outtab = lt_final
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
endif.
*****************
*End of Program
*****************************************************
Execute the program :-
Manually Creating a Field Catalog :-
-
We have used the Reuse field catalog merge to create field catalog, now let’s see how we can manually create field catalog.
-
Step 1 :- define internal table and work area for the field catalog.
-
Step 2 :- Follow the below code :-
Code :-
*************************************************
*Start of Program
*Type Strcuture fo Both header and Item table
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF ty_vbap.
********************************************
*Type structure for final table.
TYPES : BEGIN OF ty_final,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF ty_final.
*************************************************
*Declaring the internal table and work area
DATA : lt_vbak type table of ty_vbak,
ls_vbak type ty_vbak,
lt_vbap type table of ty_vbap,
ls_vbap type ty_vbap,
lt_final type table of ty_final,
ls_final type ty_final,
lv_vbeln type vbeln_va.
****************************************
*Internal table and work area for fielcatalog.
DATA : lt_fieldcat type table of slis_fieldcat_alv,
ls_fieldcat type slis_fieldcat_alv.
***************
*Declaring a select option.
SELECT-OPTIONS : s_vbeln for lv_vbeln.
START-OF-SELECTION.
SELECT vbeln erdat erzet ernam vbtyp
from vbak into table lt_vbak
where vbeln in s_vbeln.
if lt_vbak is not INITIAL.
select vbeln posnr matnr
from vbap
into table lt_vbap
FOR ALL ENTRIES IN lt_vbak
where vbeln = lt_vbak-vbeln.
loop at lt_vbap into ls_vbap.
ls_final-posnr = ls_vbap-posnr.
ls_final-matnr = ls_vbap-matnr.
Read table lt_vbak into ls_vbak with KEY vbeln = ls_vbap-vbeln.
if sy-subrc eq 0.
ls_final-vbeln = ls_vbak-vbeln.
ls_final-erdat = ls_vbak-erdat.
ls_final-erzet = ls_vbak-erzet.
ls_final-ernam = ls_vbak-ernam.
ls_final-vbtyp = ls_vbak-vbtyp.
endif.
append ls_final to lt_final.
clear : ls_final, ls_vbak, ls_vbap.
ENDLOOP.
***************************************
*Manually writing the fieldcatalog
ls_fieldcat-seltext_l = 'Sales Document Number'.
ls_fieldcat-fieldname = 'VBELN'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Creation Date'.
ls_fieldcat-fieldname = 'ERDAT'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Created On'.
ls_fieldcat-fieldname = 'ERZET'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Created By'.
ls_fieldcat-fieldname = 'ERNAM'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Document Category'.
ls_fieldcat-fieldname = 'VBTYP'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Item Number'.
ls_fieldcat-fieldname = 'POSNR'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
ls_fieldcat-seltext_l = 'Material Number'.
ls_fieldcat-fieldname = 'MATNR'.
append ls_fieldcat to lt_fieldcat.
clear ls_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* IS_LAYOUT =
IT_FIELDCAT = lt_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
TABLES
t_outtab = lt_final
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
endif.
*****************
*End of Program
*****************************************************
Comments
Post a Comment