SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create unique handle for ALV layout (variant)



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Sep 13, 2008 7:21 pm    Post subject: Create unique handle for ALV layout (variant) Reply with quote

Author: Clemens Li

Description

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.
Code:
*&---------------------------------------------------------------------*
*&      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.
  DATA:
    lv_string TYPE string,
    lv_len TYPE sytleng,
    lr_c TYPE REF TO data.
  FIELD-SYMBOLS:
    <any> TYPE c,
    <fcat> TYPE LINE OF slis_t_fieldcat_alv.

  LOOP AT pt_fcat ASSIGNING <fcat>.
    CONCATENATE lv_string <fcat>-fieldname INTO lv_string.
  ENDLOOP.
* determine string length
  lv_len = STRLEN( lv_string ).
* create character data object because kernel function does not take string
  CREATE DATA lr_c TYPE c LENGTH lv_len.
* assign data object to field symbol
  ASSIGN lr_c->* TO <any>.
* pass string content to character object
  <any> = lv_string.
* call kernel function to get hash value
  CALL 'C_ENQ_WILDCARD' ID 'TEXT'     FIELD <any>
                        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.

The only thing I have a small doubt is that in theory a four character hash value is not necessarily unique for different base values - until now it always worked. In such a case, we should take other (what?) precautions.

Enjoy!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.