Whenever we create more than one ALV grid or list in the same program, we may run into trouble saving a display layout (formerly called variant) for each display.
The procedure is to pass a structure of type DISVARIANT to the object or function. In the DISVARIANT-REPORT we store the report name (SY-REPID) and in the field DISVARIANT-HANDLE a 4-character handle to distinguish our tables displayed. This enables us to store individual layouts for each grid.
But if we use a generic function or method for the display, we may not know which table is actually displayed. In this case, we can not set a unique handle in DISVARIANT-HANDLE.
My idea is to create a unique handle based on the field catalog because we will always have a field catalog for the table display.
To get a unique handle, I concatenate all fields in the field catalog into a string and the create a hash key of length 4 to store as a handle.
This is a sample code - it may be modified as the OO grid uses a slightly different structure for the field catalog (TYPE LVC_T_FCAT as opposed to SLIS_T_FIELDCATALOG_LV)
I'd like to express my thanks to a®s for the hint pointing to the hash kernel function which makes this extremely fast and releiable.
I'd like to express my thanks to a®s for the hint pointing to the hash kernel function which makes this extremely fast and releiable.
*&---------------------------------------------------------------------*
*& Form HASH
*&---------------------------------------------------------------------*
* Used to create unique handle for a fieldcatalog
*----------------------------------------------------------------------*
*& Form HASH
*&---------------------------------------------------------------------*
* Used to create unique handle for a fieldcatalog
*----------------------------------------------------------------------*
FORM hash
using pt_fcat TYPE slis_t_fieldcat_alv
changing ps_divariant TYPE disvariant.
using pt_fcat TYPE slis_t_fieldcat_alv
changing ps_divariant TYPE disvariant.
DATA:
lv_string TYPE string,
lv_len TYPE sytleng,
lr_c TYPE REF TO data.
FIELD-SYMBOLS:
TYPE c,
TYPE LINE OF slis_t_fieldcat_alv.
LOOP AT pt_fcat ASSIGNING.
CONCATENATE lv_string-fieldname INTO lv_string.
ENDLOOP.
lv_string TYPE string,
lv_len TYPE sytleng,
lr_c TYPE REF TO data.
FIELD-SYMBOLS:
LOOP AT pt_fcat ASSIGNING
CONCATENATE lv_string
ENDLOOP.
lv_len = STRLEN( lv_string ).
CREATE DATA lr_c TYPE c LENGTH lv_len.
ID 'TEXTHASH' FIELD ps_divariant-handle.
ENDFORM. " HASH
OK, this is not such a big one - but I like the idea of generic programming. For the experienced developer it may be minor effort to put this in a method.
ALSO READ:
- Customizing Toolbar In ALV Tree Using ABAP OO.
- Dropdown in ALV Grid Display.
- Dynamic ALV Grid/List Display.
- Handling Radio Buttons in SALV Tree Display.
..... Back To Index On ALV List/ Grid Display.
..... Back To MAIN INDEX.
No comments:
Post a Comment