Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ALV GRID display

Dear all,

pls suggest me for the below issue.

requirement is as follows:

ALV grid contains 4 columns for example, a, b, c, d.

the titles of these 4 columns should come from data element field label (i.e. from Heading). but currently it is taking 'short field label' of the data element. but i want 'field label (i.e. heading) of the data element.

for example the 4 field names from the table z_yt2_formul is:

1. SPRAS

2. VORLAGE

3. TITEL

4. TEXT

current code is as follows:

DATA: lt_form TYPE TABLE OF z_yt2_formul,

PERFORM alv_process TABLES lt_form.

FORM alv_process TABLES pt_form STRUCTURE z_yt2_formul.

DATA: ls_form TYPE z_yt2_formul.

DATA: lt_fieldcat TYPE TABLE OF slis_fieldcat_alv,

lt_events TYPE slis_t_event,

ls_layout TYPE slis_layout_alv,

lv_repid(40) TYPE c.

DATA: lv_start_line TYPE i VALUE '8',

lv_end_line TYPE i,

lv_tfill TYPE sytfill.

DATA: lt_excl TYPE slis_t_extab.

lv_repid = sy-repid.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = lv_repid

i_structure_name = 'Z_YT2_FORMUL'

CHANGING

ct_fieldcat = lt_fieldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

gt_form_alv[] = pt_form[].

PERFORM prepare_layout CHANGING ls_layout.

PERFORM prepare_fieldcat TABLES lt_fieldcat.

PERFORM event_tab_get CHANGING lt_events[].

APPEND '&TAKE' TO lt_excl.

DESCRIBE TABLE gt_form_alv LINES lv_tfill.

lv_end_line = lv_start_line + lv_tfill + 1.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = lv_repid

is_layout = ls_layout

it_fieldcat = lt_fieldcat

it_excluding = lt_excl

it_events = lt_events

i_screen_start_column = 8

i_screen_start_line = lv_start_line

i_screen_end_column = 120 i_screen_end_line = lv_end_line

TABLES

t_outtab = gt_form_alv

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDFORM. " ALV_PROCESS

FORM prepare_layout CHANGING ps_layout TYPE slis_layout_alv.

ps_layout-zebra = 'X'.

ps_layout-box_fieldname = 'SELECTED'.

ENDFORM. " PREPARE_LAYOUT

FORM prepare_fieldcat TABLES pt_fieldcat STRUCTURE gs_ref_fieldcat.

DATA: ls_cat TYPE slis_fieldcat_alv.

LOOP AT pt_fieldcat INTO ls_cat.

CASE ls_cat-fieldname.

WHEN 'SPRAS'.

ls_cat-just = 'C'.

ls_cat-outputlen = 4.

ls_cat-col_pos = 1.

MODIFY pt_fieldcat FROM ls_cat.

WHEN 'VORLAGE'.

ls_cat-outputlen = 25.

ls_cat-col_pos = 2.

MODIFY pt_fieldcat FROM ls_cat.

WHEN 'TITEL'.

WHEN 'TEXT'.

WHEN OTHERS.

DELETE pt_fieldcat.

ENDCASE.

ENDLOOP.

ENDFORM. " PREPARE_FIELDCAT

FORM event_tab_get CHANGING pt_events TYPE slis_t_event.

*"Registration of events to happen during list display

DATA: ls_event TYPE LINE OF slis_t_event.

*

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0 "0 = einfache Liste REUSE_ALV_LIST_DISPLAY

IMPORTING

et_events = pt_events.

READ TABLE pt_events INTO ls_event

WITH KEY name = slis_ev_user_command.

ls_event-form = slis_ev_user_command.

MODIFY pt_events FROM ls_event INDEX sy-tabix.

READ TABLE pt_events INTO ls_event

WITH KEY name = slis_ev_pf_status_set.

ls_event-form = slis_ev_pf_status_set.

MODIFY pt_events FROM ls_event INDEX sy-tabix.

ENDFORM. " EVENT_TAB_GET

Regards

Venkat

Former Member
Not what you were looking for? View more on this topic or Ask a question