2023 Jul 11 11:12 PM
I would like to use optimised column width for an ALV grid, but the columns should have a minimum width of N regardless of content.
The problem I'm trying to solve is to stop headings being too short to be meaningful, e.g. a column should always have a minimum width of 5 even if it only contains single- or double-digit numbers.
It's very surprising that I haven't found his questions asked before, as it seems a reasonable thing to try to do. I've also spent a couple of hours trying to do this with regular ALV and SALV functionality, to no avail. So I thought I'd ask here before digging into the innards of S/ALV or writing code to do the optimisation by inspecting the data. Surely there must be a simpler way?
BTW, this works great on SAP GUI for Java, an optimised ALV column is the width of the short description or the longest content field, whichever is the biggest.
2023 Jul 12 6:20 AM
Same surprise for me in this other ALV question 2 days ago 😉
You should indicate the ABAP version because there may be some important version differences.
Same for technology used (cl_gui_alv_grid, cl_salv_table, IDA, etc.)
Also screenshots.
On my 7.57 system, this is fine.
SELECT * FROM sbook INTO TABLE @data(alv_table).
cl_salv_table=>factory( IMPORTING r_salv_table = data(salv) CHANGING t_table = alv_table ).
salv->get_columns( )->set_optimize( ).
salv->display( ).
NB: without SET_OPTIMIZE:
2023 Jul 12 1:57 PM
Hi Sandra,
Thanks for your input. The issue is on 7.50 and 7.52, not tested on my 7.55 yet, but I have noted this in the past with less inconvenient examples. It came up with an ALV Grid, but I have tried to use SALV instead and didn't fare much better (I did mention ALV and SALV in my question).
Your example looks a bit different on 7.50:
Interestingly using Java GUI it optimizes to the short text length, which is perfect. So maybe it's SAPGUI (SAP GUI 8.00 & 8.00 SP3)? Still, this is something that should run on multiple systems and versions.
Another SALV Example showing something closer to our problem is this:
Code:
TYPES: BEGIN OF t_struc,
bukrs TYPE bukrs,
f1 TYPE i,
f2 TYPE i,
f3 TYPE i,
END OF t_struc.
DATA itab TYPE STANDARD TABLE OF t_struc WITH EMPTY KEY.
itab = VALUE #(
( bukrs = '1000' f1 = 5 f2 = 12 f3 = 32496732 )
( bukrs = '2000' f1 = 5 f2 = 12 f3 = 32496732 )
( bukrs = '3000' f1 = 5 f2 = 12 f3 = 32496732 )
).
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(alv)
CHANGING t_table = itab ).
DATA(cols) = alv->get_columns( ).
cols->set_optimize( ).
cols->get_column( 'F1' )->set_short_text( 'Text1' ).
cols->get_column( 'F2' )->set_short_text( 'Text2' ).
cols->get_column( 'F3' )->set_short_text( 'Text3' ).
* cols->get_column( 'F1' )->set_output_length( 4 ).
CATCH cx_salv_error INTO DATA(error).
MESSAGE error->get_text( ) TYPE 'E'.
ENDTRY.
alv->get_functions( )->set_all( ).
alv->display( ).
2023 Jul 12 2:24 PM
Hi Mike,
I think it must be the GUI version because this is what I get on 7.60 (I have the older version because I only need it for SFP, but it also works fine on my Java GUI).
Regards,
Ryan Crosby
2023 Jul 12 3:49 PM
Maybe the difference is the SAP GUI theme, I use Quartz Dark Theme. I'm using SAP GUI 7.70 PL 3.
Your code in my system:
2023 Jul 12 4:43 PM
Thanks Sandra and Ryan, really useful feedback.
So it appears that 7.60, 7.70 and Java GUI 8.00 work fine, 8.00 doesn't. Can anyone else test this with SAPGUI 8.00?
Can't find any note on OSS.