Monday, May 18, 2009

ALV interface check

By Joyjit Ghosh

In ALV we have an option to check the interface parameters, which we are passing from our program. This check will identify any problem(s) that may occur during calling the ALV FM or ALV class method. It is advisable to perform this check before formal submission of the code to avoid any inconsistency that can lead to problem(s), even program termination in worst case. To enable this check interface parameter I_INTERFACE_CHECK of ALV FM(s) must contain ‘X’.

Example: 
*&-------------------------------------------------------------*
*& Report Z_ALV_INTERFACE_CHECK *
*& *
*&--------------------------------------------------------------
REPORT  z_alv_interface_check                   .
***************************************************************
* Type pool declaration for ALV
***************************************************************
TYPE-POOLS: slis.
***************************************************************
* Table
***************************************************************
TABLES: sbook.
***************************************************************
* Type declaration for SBOOK table
***************************************************************
TYPES: BEGIN OF ty_sbook,
carrid TYPE s_carr_id, " Airline Code
connid TYPE s_conn_id, " Flight Connection Number
fldate TYPE s_date, " Flight date
bookid TYPE s_book_id, " Booking number
customid TYPE s_customer," Customer Number
END OF ty_sbook.
*****************************************************************
* Table declaration for SBOOK table
*****************************************************************
DATA: i_sbook TYPE STANDARD TABLE OF ty_sbook INITIAL SIZE 0,

****************************************************************
* Table declaration for field catalog
****************************************************************
i_fcata TYPE slis_t_fieldcat_alv.
****************************************************************
* Workarea declaration for field catalog table
****************************************************************
DATA: w_fcata TYPE slis_fieldcat_alv.
****************************************************************
* Selection screen
**************************************************************
SELECT-OPTIONS: s_carrid FOR sbook-carrid.
***************************************************************
* Start-of-selection event
****************************************************************
* Fetch data from sbook table
PERFORM fetch_data.
* Populate field catalog
PERFORM populate_catalog.
* Display data in ALV
PERFORM display_alv.
*&--------------------------------------------------------------
*& Form fetch_data
*&-------------------------------------------------------------
FORM fetch_data .
  SELECT  carrid       " Airline Code
connid " Flight Connection Number
fldate " Flight date
bookid " Booking number
customid " Customer Number
FROM sbook
INTO TABLE i_sbook
WHERE carrid IN s_carrid.
  IF sy-subrc = 0.
    SORT i_sbook BY carrid.
  ENDIF.
ENDFORM.                    " fetch_data
*&-------------------------------------------------------------*
*& Form populate_catalog
*&--------------------------------------------------------------
FORM populate_catalog .
  w_fcata-fieldname = 'CARRID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Airline Code'(001).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
  w_fcata-fieldname = 'CONNID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Flight Connection Number'(002).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
* Wrong field name FIDATE
  w_fcata-fieldname = 'FIDATE'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Flight date'(003).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
* Wrong field name BOOKLD
  w_fcata-fieldname = 'BOOKLD'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Booking number'(004).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
  w_fcata-fieldname = 'CUSTOMID'.
w_fcata-tabname = 'I_SBOOK'.
w_fcata-seltext_m = 'Customer Number'(005).
w_fcata-ddictxt = 'M'.
APPEND w_fcata to i_fcata.
ENDFORM.                    " populate_catalog
*&----------------------------------------------------------
*& Form display_alv
*&-----------------------------------------------------------
form display_alv .
data: l_repid type sy-repid.
l_repid = sy-repid.
* Interface check parameter, we have to pass ‘X’ as value in this parameter
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = 'X'
I_CALLBACK_PROGRAM = l_repid
IT_FIELDCAT = i_fcata
TABLES
t_outtab = i_sbook
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

Selection screen:

Output:

Additional screen (before showing the final output) to show the error or warning or success message(s)

Also various buttons are present on the application tool bar to check contents of Fieldcatalog, Layout, Sort, Filter, Events, Variant, and Special Fieldgroup.

Fieldcatalog:

Layout:

Sort:

Filter:

Event:

Variant:

Field group:

From the initial screen if we press back button then it will display the final output.

Final output:

Note:

  1. Always remember to switch off this check before formal code delivery otherwise these extra screen(s) can confuse the end user.
  2. In ECC 5.0, I have seen that this check does not work with FM REUSE_ALV_GRID_DISPLAY, in that case we need to convert grid to list temporarily to implement this check.

No comments: