Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

ALV adding a new column

Former Member
0 Likes
2,066

Hi!

In ALV, how do you create columns and add them so that they are displayed?

We have a list viewer and we want to add a new column to it.

regards

Baran

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,867

Hi Baran,

Populate the fieldcatalog seperately like this...

data: WA_FLDCAT_SUMMARY TYPE LVC_S_FCAT,

IT_FLDCAT_SUMMARY TYPE LVC_T_FCAT.

*--populating the fieldcatalog used for displaying summary details

WA_FLDCAT_SUMMARY-FIELDNAME = 'MBDAT'.

WA_FLDCAT_SUMMARY-TABNAME = 'IT_SUMMARY'.

WA_FLDCAT_SUMMARY-REPTEXT = TEXT-002.

WA_FLDCAT_SUMMARY-COL_POS = '1'.

WA_FLDCAT_SUMMARY-OUTPUTLEN = 20.

WA_FLDCAT_SUMMARY-KEY = 'X'.

APPEND WA_FLDCAT_SUMMARY TO IT_FLDCAT_SUMMARY.

CLEAR WA_FLDCAT_SUMMARY.

Now asusal pass this in the method.

*--displaying the summary details

SORT IT_SUMMARY BY MBDAT.

CALL METHOD OBJ_GRID_SUMMARY->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = X_SUMMARY

CHANGING

IT_FIELDCATALOG = IT_FLDCAT_SUMMARY

IT_OUTTAB = IT_SUMMARY[].

Regards,

Vidya

7 REPLIES 7
Read only

Former Member
0 Likes
1,867

Hi Baran,

Add that new field in the fieldcatalog and populate the value in the value in the internal table.

loop at it_fieldcatalog into wa_fieldcatalog.

 wa_fieldcatalog-fieldname = 'NEW_FIELD'.
 wa_fieldcatalog-outputlen = '15'.
 append wa_fieldcatalog to it_fieldcatalog.
 clear wa_fieldcatalog,
endloop.

Read only

0 Likes
1,867

thanks for the reply,

do you know which method contains the fieldcatalog?

Read only

0 Likes
1,867

this is not a method , may be u can show ur code

Read only

0 Likes
1,867

Hi baran ,

There are alternative ways if you're creating it for use in list viewer you don't have to use methods.

  • use this for merging fields that you use in your

  • internal table

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'WT_LIST'

i_client_never_display = 'X'

i_inclname = gc_include_name

CHANGING

ct_fieldcat = wt_fcat2

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

----


*

if you want to append directly or after the fieldcatalog merge

such as :

CLEAR ws_fcat.

ws_fcat-fieldname = 'BANKN'.

ws_fcat-tabname = 'WT_VENDOR'.

ws_fcat-ref_fieldname = 'BANKN'.

ws_fcat-ref_tabname = 'LFBK'.

ws_fcat-input = wv_edit.

APPEND ws_fcat TO wt_fcat.

*----


hope this helps

Read only

Former Member
0 Likes
1,868

Hi Baran,

Populate the fieldcatalog seperately like this...

data: WA_FLDCAT_SUMMARY TYPE LVC_S_FCAT,

IT_FLDCAT_SUMMARY TYPE LVC_T_FCAT.

*--populating the fieldcatalog used for displaying summary details

WA_FLDCAT_SUMMARY-FIELDNAME = 'MBDAT'.

WA_FLDCAT_SUMMARY-TABNAME = 'IT_SUMMARY'.

WA_FLDCAT_SUMMARY-REPTEXT = TEXT-002.

WA_FLDCAT_SUMMARY-COL_POS = '1'.

WA_FLDCAT_SUMMARY-OUTPUTLEN = 20.

WA_FLDCAT_SUMMARY-KEY = 'X'.

APPEND WA_FLDCAT_SUMMARY TO IT_FLDCAT_SUMMARY.

CLEAR WA_FLDCAT_SUMMARY.

Now asusal pass this in the method.

*--displaying the summary details

SORT IT_SUMMARY BY MBDAT.

CALL METHOD OBJ_GRID_SUMMARY->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

IS_LAYOUT = X_SUMMARY

CHANGING

IT_FIELDCATALOG = IT_FLDCAT_SUMMARY

IT_OUTTAB = IT_SUMMARY[].

Regards,

Vidya

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,867

Hello Baran

If you ALV list is based on a DDIC structure you can use function module LVC_FIELDCATALOG_MERGE to create the fieldcatalog.

The documentation of the function module says that you can also use a structure defined within your application. However, this poses some restrictions on the structure definition. Therefore I disregard this option and almost always define a DDIC stucture for my ALV lists.

Regards

Uwe

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,867

Hello Baran

The function module REUSE_ALV_FIELDCATALOG_MERGE returns the fieldcatalog in table type SLIS_T_FIELDCAT_ALV which is not compatible with the requirements of CL_GUI_ALV_GRID. You have to convert SLIS_T_FIELDCAT_ALV to LVC_T_FCAT in order to use (function module availabe for this conversion).

All these REUSE_... function modules belong to the old-fashioned way to create ALV lists. If you do not have specific requirements (e.g. hierarchical ALV lists) then I recommend to exclusively use ABAP-OO means (classes, e.g. CL_GUI_ALV_GRID) for ALV lists.

At the beginning the effort for learing is higher yet the reward in the long term is a much higher flexibility in coding.

Regards

Uwe