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

Multi-line ALV using ROW_POS in field catalog



 
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: 1640

PostPosted: Sun Mar 02, 2008 1:54 pm    Post subject: Multi-line ALV using ROW_POS in field catalog Reply with quote

Does you business requirement needs single line item in ALV to be displayed in multiple rows/lines for better readability? You then surely need a multi-line ALV, which can be implemented by just a simple tweaking in your ALV field catalog.

You can achieve this objective using property ROW_POS of Field catalog. Just assign a value between 1 to 3 to each of the records (denoting output internal table’s columns/fields) in field catalog. That’s it. Value is restricted between 1 and 3 since ALV can handle maximum of 3 rows for 1 ALV line item.
The example followed will completely clear the usage.

Here is the code to build the field catalog of an ALV.

Code:
FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: ls_fieldcat TYPE slis_fieldcat_alv.
ls_fieldcat-fieldname = ‘CARRID’.
ls_fieldcat-key       = ‘X’.
ls_fieldcat-ref_fieldname = ‘CARRID’.
ls_fieldcat-ref_tabname = ‘SFLIGHT’.
ls_fieldcat-row_pos = 1.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘CONNID’.
ls_fieldcat-key       = ‘X’.
ls_fieldcat-ref_fieldname = ‘CONNID’.
ls_fieldcat-ref_tabname = ‘SFLIGHT’.
ls_fieldcat-row_pos = 1.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘FLDATE’.
ls_fieldcat-key       = ‘X’.
ls_fieldcat-ref_fieldname = ‘FLDATE’.
ls_fieldcat-ref_tabname = ‘SFLIGHT’.
ls_fieldcat-row_pos = 1.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘PRICE’.
ls_fieldcat-ref_fieldname = ‘PRICE’.
ls_fieldcat-ref_tabname = ‘SFLIGHT’.
ls_fieldcat-row_pos = 2.
APPEND ls_fieldcat TO e01_lt_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = ‘CURRENCY’.
ls_fieldcat-ref_fieldname = ‘CURRENCY’.
ls_fieldcat-ref_tabname = ‘SFLIGHT’.
ls_fieldcat-row_pos = 2.
APPEND ls_fieldcat TO e01_lt_fieldcat.
ENDFORM.

FORM e01_fieldcat_init USING e01_lt_fieldcat TYPE slis_t_fieldcat_alv.

DATA: ls_fieldcat TYPE slis_fieldcat_alv.

ls_fieldcat-fieldname = ‘CARRID’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-ref_fieldname = ‘CARRID’.

ls_fieldcat-ref_tabname = ‘SFLIGHT’.

ls_fieldcat-row_pos = 1.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CONNID’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-ref_fieldname = ‘CONNID’.

ls_fieldcat-ref_tabname = ‘SFLIGHT’.

ls_fieldcat-row_pos = 1.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘FLDATE’.

ls_fieldcat-key       = ‘X’.

ls_fieldcat-ref_fieldname = ‘FLDATE’.

ls_fieldcat-ref_tabname = ‘SFLIGHT’.

ls_fieldcat-row_pos = 1.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘PRICE’.

ls_fieldcat-ref_fieldname = ‘PRICE’.

ls_fieldcat-ref_tabname = ‘SFLIGHT’.

ls_fieldcat-row_pos = 2.

APPEND ls_fieldcat TO e01_lt_fieldcat.

CLEAR ls_fieldcat.

ls_fieldcat-fieldname = ‘CURRENCY’.

ls_fieldcat-ref_fieldname = ‘CURRENCY’.

ls_fieldcat-ref_tabname = ‘SFLIGHT’.

ls_fieldcat-row_pos = 2.

APPEND ls_fieldcat TO e01_lt_fieldcat.

ENDFORM.


The ALV with the above field catalog gives the following multi-lined ALV output.

All the columns with row_pos as 1 in the field catalog are appearing in 1st row where as the ones with row_pos as 2 are appearing in the 2nd row, even though they are one single line item in the ALV output internal table.



ALV-with-ROW_POS-specified-in-Field-catalog.png
 Description:
 Filesize:  6.93 KB
 Viewed:  15796 Time(s)

ALV-with-ROW_POS-specified-in-Field-catalog.png


Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Mar 13, 2010 7:35 pm    Post subject: Reply with quote

Code:
REPORT  zvenkat_alv_color_row.
DATA: BEGIN OF it_data OCCURS 0,
        color TYPE char3,
        arbgb TYPE t100-arbgb,
        msgnr TYPE t100-msgnr,
        text TYPE t100-text,
      END OF it_data.
*ALV Declarations
TYPE-POOLS:slis.
TYPES:
   ty_fieldcat          TYPE slis_fieldcat_alv,
   ty_events            TYPE slis_alv_event,
   ty_layout            TYPE slis_layout_alv.
DATA:
   wa_fieldcat          TYPE ty_fieldcat,
   wa_events            TYPE ty_events,
   wa_layout            TYPE ty_layout.
DATA:
   it_events            TYPE STANDARD TABLE OF ty_events,
   it_fieldcat          TYPE STANDARD TABLE OF ty_fieldcat.
DATA:
   g_program            TYPE sy-repid.
START-OF-SELECTION.
  SELECT * FROM t100 INTO CORRESPONDING FIELDS OF TABLE it_data
  UP TO 20 ROWS WHERE sprsl = sy-langu.
  LOOP AT it_data.
    IF sy-tabix > 10.
      it_data-color = 'C31'.
      MODIFY it_data INDEX sy-tabix.
    ENDIF.
  ENDLOOP.
*Fieldcatalog.
  PERFORM fieldcatalog
  USING:
  1 1 'COLOR' 'IT_DATA' 'COLOR',
  1 2 'ARBGB' 'IT_DATA' 'ARBGB',
  2 3 'MSGNR' 'IT_DATA' 'MSGNR',
  2 4 'TEXT'  'IT_DATA' 'TEXT'.
  wa_layout-info_fieldname = 'COLOR'.
  g_program = sy-repid.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = g_program
      is_layout          = wa_layout
      it_fieldcat        = it_fieldcat
      it_events          = it_events
    TABLES
      t_outtab           = it_data
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
*&---------------------------------------------------------------------*
*&      Form  FIELDCATALOG
*&---------------------------------------------------------------------*
FORM fieldcatalog USING row_pos col_pos field table f_txt.
  wa_fieldcat-row_pos   = row_pos.
  wa_fieldcat-col_pos   = col_pos.
  wa_fieldcat-fieldname = field.
  wa_fieldcat-tabname   = table.
  wa_fieldcat-seltext_l = f_txt.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR  wa_fieldcat.
ENDFORM.                    " FIELDCATALOG
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.