Application Development 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: 

REUSE_ALV_GRID_DISPLAY (column heading)

Former Member
0 Kudos

Hi,

I am using REUSE_ALV_GRID_DISPLAY FM to display the data from internal table. For internal table I used a linetype(work area) and rowtype(body). I got the required data into the internal table and then I used

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_STRUCTURE_NAME = 'zline'

TABLES

T_OUTTAB = itab.

to display the output. Where 'zline' is the linetype for my internal table. I got the proper column headings in the output.

My question is, how can I change the heading of a column. Let us say column heading 'Material' to 'Material used'.

I appreciate if anyone can tell me the complete proceedure to change the column heading. It would be easy for me to follow as I am new to the ALV stuff. Thanks.

1 ACCEPTED SOLUTION

Manohar2u
Active Contributor
0 Kudos

For this you need to fill the field catalog

Refer to this guide for filling field catalog.

<a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf">http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf</a>

Regds

Manohar

10 REPLIES 10

Manohar2u
Active Contributor
0 Kudos

For this you need to fill the field catalog

Refer to this guide for filling field catalog.

<a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf">http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf</a>

Regds

Manohar

Manohar2u
Active Contributor
0 Kudos

Refer to this example program

<a href="http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm">http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm</a>

Regds

Manohar

Former Member
0 Kudos

Hi Manahor,

My internal table has fields from different tables. I see that in the example internal table has fields from only EKPO.

Should there be anything else added inthe fieldcatalog FORM in the example. Like fieldcatalog-tabname? Please look at the example once and clarify my doubt.

Former Member
0 Kudos

Hi

Try this sample:

DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,

GT_REPID TYPE SY-REPID.

GT_REPID = SY-REPID.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

I_PROGRAM_NAME = GT_REPID

I_INTERNAL_TABNAME = 'ZLINE'

I_INCLNAME = GT_REPID

CHANGING

CT_FIELDCAT = GT_FIELDCAT[].

LOOP AT GT_FIELDCAT INTO LS_FIELDCAT.

CASE LS_FIELDCAT-FIELDNAME.

  • Here change the fields attributes

WHEN 'MATNR'.

LS_FIELDCAT-SELTEXT_L = 'Material Used'.

LS_FIELDCAT-SELTEXT_M = 'Material Used'.

LS_FIELDCAT-SELTEXT_S = 'Mat. Used'.

.....................

ENDCASE.

MODIFY GT_FIELDCAT FROM LS_FIELDCAT.

ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

................

it_fieldcat = gt_fieldcat

  • I_STRUCTURE_NAME = 'zline'

..................

Max

Former Member
0 Kudos

Hi Max,

I am trying what you told me.

But something unusual is happening. I tried what exactly you told me. What I observed is, I have a column 'MATNR', for this column there was no change in the heading. I tried for another column 'Mittelwert1' of type 'QMITTEWRTC'. For this column the original heading is 'Mean value /s' and when I try with my heading 'Test ' it is changing to 'Mean Value'.

I tried to print the values in the fieldcatalog after making the modifications. I see that the fieldcatalog is getting modified properly but when I try to go for grid display, its not working.

Do you have any clue whats happening here. Thanks

Former Member
0 Kudos

Hi Max,

I tried as above

loop at field_body into field_wa.

case field_wa-fieldname.

when 'MITTELWERT1'.

field_wa-seltext_l = 'Test p'.

field_wa-seltext_m = 'Test '.

field_wa-seltext_s = 'Te '.

endcase.

modify field_body from field_wa.

endloop.

Thanks

Former Member
0 Kudos

Hi

The label is automatically choose by the system in according to the size of the field: try this

loop at field_body into field_wa.

case field_wa-fieldname.

when 'MITTELWERT1'.

field_wa-seltext_l = 'Test p'.

field_wa-seltext_m = 'Test '.

field_wa-seltext_s = 'Te '.

field_wa-reptextdic = 'Test'.

endcase.

modify field_body from field_wa.

endloop.

Max

Former Member
0 Kudos

Hi Max,

Thank you very much. Its working. I gave you full points. You really deserve them.

I got one more quick question.

My requirement is something like this. The number of records I display in the list using REUSE_ALV_GRID_DISPLAY must be limited to 500. However, I should be able to export all the records(even if they are more than 500) to Excel sheet.

Waiting for your reply!

Former Member
0 Kudos

Hi

There are several ways to export the data to Excel, anyway perhaps this is easier one:

PARAMETERS: FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\test.xls',

OPEN AS CHECKBOX.

  • File name

DATA: FILENAME TYPE STRING.

  • Table with data for file

DATA: BEGIN OF ITAB OCCURS 0,

FIELD1(6) TYPE C,

FIELD2(6) TYPE C,

FIELD3(6) TYPE C,

END OF ITAB.

  • Create the labels of colunms

ITAB-FIELD1 = 'FIELD1'.

ITAB-FIELD2 = 'FIELD2'.

ITAB-FIELD3 = 'FIELD3'.

APPEND ITAB.

  • Inser the data to be displayed in the file

DO 9 TIMES.

MOVE SY-INDEX TO ITAB-FIELD1.

ITAB-FIELD2 = ITAB-FIELD3 = ITAB-FIELD1.

APPEND ITAB.

ENDDO.

  • Create the file

MOVE FILE TO FILENAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FILENAME

FILETYPE = 'ASC'

WRITE_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = ITAB

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

IF OPEN = 'X'.

  • Open file if it's requested

CALL FUNCTION 'WS_EXECUTE'

EXPORTING

DOCUMENT = 'X'

COMMANDLINE = FILE

PROGRAM = 'EXCEL'

EXCEPTIONS

OTHERS = 99.

ENDIF.

ENDIF.

Max

Clemenss
Active Contributor
0 Kudos

Hi Raju,

from ALV, depending on what is defined in PF status, you have two ways of export to excel.

One is, when you push Excel button and have to go thru 3 popups informing you that sorting and filters are ignored and giving you the freedom to use EXCEL. This one starts Excel and transfers all data.

Say, you add a field 'counter' to your internal table. Set a filter to display records with counter < 500 but not display the counter itself, save as default variant.

Starting Excel, all records will be transfered.

If your excel button starts excel inplace dirctly inside the grid display area, then you need another PF status. I'm not on the system now, I think OK-codes are &XXL and $XLS - must try.

Regards,

Clemens