SM30, change standard width of Tablecontrol
One thing that always bothered me with the Table Maintenance Generator is that when we create a Dialog for a table with many fields the Table Control always show a width of 80 columns, even when the screen has space to show more content.
Wouldn’t be great if we could harness this lost space?
Well, you can say, there is a simple fix for this. We can manually change the width of the Table Control, but the problem with this approach is that when the Generator is executed again (because a field was added to the table for example), the Table Control returns to the 80 columns layout.
With the solution proposed below, every time that the table is called in SM30, if the width is less than the desired the code kicks in and resizes the Table Control.
Solution:
Call the function to change it in the initialization event of the program using “Events” and pass to it the desired width of the Table Control. If the Table control and the enclosing canvas is less than the value passed the function change the width and re-generate the Dialog screen.
FUNCTION zsd_resize_table_ctrl.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(IV_TABLE) TYPE STRING
*" REFERENCE(IV_MAINT_FG) TYPE STRING
*" REFERENCE(IV_DYNPRO_NO) TYPE CHAR4
*" REFERENCE(IV_WIDTH) TYPE I
*"----------------------------------------------------------------------
CHECK iv_width <= 255.
DATA:
BEGIN OF gs_dynpro_descr,
prog TYPE progname,
dynpro TYPE char4,
END OF gs_dynpro_descr.
DATA:
lv_fnam TYPE d021s-fnam,
h TYPE d020s,
ls_f TYPE d021s,
f TYPE d021s OCCURS 0 WITH HEADER LINE,
e TYPE d022s OCCURS 0 WITH HEADER LINE,
m TYPE d023s OCCURS 0 WITH HEADER LINE.
DATA:
m1 TYPE string,
l1 TYPE string,
w1 TYPE string.
CONCATENATE 'SAPL' iv_maint_fg INTO gs_dynpro_descr-prog.
gs_dynpro_descr-dynpro = iv_dynpro_no.
CONCATENATE 'TCTRL_' iv_table INTO lv_fnam.
IMPORT DYNPRO h f e m ID gs_dynpro_descr.
READ TABLE f INTO ls_f WITH KEY fnam = lv_fnam.
CHECK sy-subrc = 0.
CHECK h-noco < iv_width.
h-noco = iv_width.
* convert to hexa
DATA: lv_crmt_ei_kb_id TYPE crmt_ei_kb_id.
lv_crmt_ei_kb_id = iv_width - 2.
CALL FUNCTION 'CRM_EI_KB_CONV_DEC_TO_HEX'
EXPORTING
iv_decimal = lv_crmt_ei_kb_id
IMPORTING
ev_hex = lv_crmt_ei_kb_id.
CHECK NOT lv_crmt_ei_kb_id+30(2) IS INITIAL.
ls_f-leng = lv_crmt_ei_kb_id+30(2). " '9B'. " 155 em hexa
MODIFY f FROM ls_f INDEX sy-tabix TRANSPORTING leng.
CHECK sy-subrc = 0.
EXPORT DYNPRO h f e m ID gs_dynpro_descr.
GENERATE DYNPRO h f e m ID gs_dynpro_descr MESSAGE m1 LINE l1 WORD w1.
ENDFUNCTION.
In the Table Maintenance Generator select the menu below:
Add the event 19, “after initializing global variables, field symbols, etc.” for events reference see http://help.sap.com/saphelp_nw70/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/content.htm
Call the function passing, the maintenance table, maintenance function group, dynpro number and desired width.
FORM check_and_resize_tablecontrol.
CALL FUNCTION 'ZSD_RESIZE_TABLE_CTRL'
EXPORTING
iv_table = 'ZTABLE'
iv_maint_fg = 'ZMAINT_FG'
iv_dynpro_no = '1100'
iv_width = 160.
ENDFORM.
And that’s about it, see ya!
Hi,
good blog.thanks for your effort it is very useful.
Regards,
Gurunath
Hi Jayme,
Another option would be to change the value of the constant MAXCOLNS in the standard include MSVIMTOP:
CONSTANTS:
START_COL TYPE I VALUE '4', "first col in list dynp + checkbx
SUBST_COL TYPE I VALUE '2', "first column for subset fields
OLD_SUBST_COL TYPE I VALUE '10', "first column for subset fields
MAX_BLK TYPE I VALUE '1', "max. blocksize for STEP-LOOP
MAXCOLNS TYPE I VALUE '83', "max. column count rl. 4.6
Kind regards
You see, the great thing about posting in SDN is that when you think you've searched and there is no apparent solution, there are some people that thought about this before you.
Great tip! Thank you Arseni!
Hello Arseni,
Good option 🙂 But how do you change the value of the constant - code modification/enhancement?
BR,
Suhas
Well.. you can always register an object and change it. It is way easier than convincing your BASIS colleague the reason why you need this. 😆
Wow, thx, the width of SM30 is really annoing thing 😎
Good one. Thanks to Arseni for his sharing. But how can we change the value of a constant. As sap says "If you try to change the value of a constant, a syntax error or runtime error occurs".
http://help.sap.com/saphelp_erp60_sp/helpdata/en/fc/eb3041358411d1829f0000e829fbfe/content.htm
Guys, you can't change the value of a constant. The include that Arseni suggested to be changed can only be if you open the standard program (what I personally dont recommend).
I've seen his solution and haven't payed attention to the fact that the include mentioned was standard. My mistake ...
Hi,
Good one .Thanks for sharing
Very helpful, Jayme. I'm used to modifying table maintenance dialogs the old way you described, by modifying the table control. I'll make sure and use this when applicable.
My rule of thumb is that if you're modifying a table with 1-4 fields, don't modify the screen. If there are 5-8 fields, resize the table control, and if there are 8+ columns, use a two-step maintenance dialog.
Nice addin eric....
Hi Alonso,
A heartfelt thanks in the first place for such an informative and vivid blog. I am sure many developers around the globe found this article extremely useful like me.
In my project I have come across exactly a similar requirement. Jumped I started searching a suitable solution and landed up to this blog. I implemented this and it worked as expected.
While implementing I found some points of corrigendum to the code above. My findings are listed below -
Apart from these details everything worked seamlessly. Kudos to your contribution!
Thanks Again!!!
Excelled Job Jayme....!
Hi Jayme,
Maybe I am too late or this is an eternal problem. Instead of having to code every timetime an event, is there not a standard setting somewhere which can be changed (i.e. where does it get the 80 char from?)
Regards
Hello Jayme
Thank you for the solution, which worked well.
The Part with the FuMo-Call can also be handled dynamically:
can be replaced by ...
X_HEADER is a global variable with header data of the called maintenance view. This variable holds all relevant data for this case. I did check this solution for single step maintenance, but double step should work equally.
Thanks much need one like it...
Hi, Friends.
I'm trying to use your method for resize my table, but there's an error. Something like"Illegal Form ..."
Thanks a lot! Just in case you have namespaces for your function groups, you must adjust iv_maint_fg. For example like this:
Nice blog informative thanks for sharing...