Skip to Content
Author's profile photo Jayme Alonso

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:

/wp-content/uploads/2013/08/events_270215.jpg

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

/wp-content/uploads/2013/08/form_270216.jpg

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!

Assigned Tags

      19 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi,

      good blog.thanks for your effort it is very useful.

      Regards,

      Gurunath

      Author's profile photo Arseni Gallardo
      Arseni Gallardo

      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

      Author's profile photo Jayme Alonso
      Jayme Alonso
      Blog Post Author

      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!

      Author's profile photo Former Member
      Former Member

      Hello Arseni,

      Good option 🙂 But how do you change the value of the constant - code modification/enhancement?

      BR,

      Suhas

      Author's profile photo Fabio Pagoti
      Fabio Pagoti

      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. 😆

      Author's profile photo Denis Skuridin
      Denis Skuridin

      Wow, thx, the width of SM30 is really annoing thing 😎

      Author's profile photo abilash n
      abilash n

      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

      Author's profile photo Jayme Alonso
      Jayme Alonso
      Blog Post Author

      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 ...

      Author's profile photo Former Member
      Former Member

      Hi,

      Good one .Thanks for sharing

      Author's profile photo Former Member
      Former Member

      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.

      Author's profile photo abilash n
      abilash n

      Nice addin eric....

      Author's profile photo Saswata Chandra
      Saswata Chandra

      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 -

      1. Program Name - This line "CONCATENATE 'SAPL' iv_maint_fg INTO gs_dynpro_descr-prog" is trying to programmatically create the program name of the TMG which always have SAPL as prefix. But concatenating that to iv_maint_fg(assuming fg in variable name means function group) may not give the program name. Thus the subsequent READ fails. So, point to remember is -  iv_maint_fg need to have such data which when concatenated with 'SAPL' produces the program name. e.g. my program name SAPLZOWG_OCP_INSTAN. My iv_maint_fg should have 'ZOWG_OCP_INSTAN'.
      2. iv_dynpro_no - This field should have the overview screen no(not the details screen). Usually for a two step maintenance we want this functionality to be enabled for the overview screen only. e.g. If your overview screen no is 9000 and details screen no 9001 then iv_dynpro_no should contain 9000.

      Apart from these details everything worked seamlessly. Kudos to your contribution!

      Thanks Again!!!

      Author's profile photo Former Member
      Former Member

       

      Excelled Job Jayme....!

      Author's profile photo Former Member
      Former Member

      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

      Author's profile photo Damian Rauchenstein
      Damian Rauchenstein

      Hello Jayme

       

      Thank you for the solution, which worked well.

      The Part with the FuMo-Call can also be handled dynamically:

      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.

      can be replaced by ...

      FORM check_and_resize_tablecontrol.
      
      
        CALL FUNCTION 'ZSD_RESIZE_TABLE_CTRL'
          EXPORTING
            iv_table     = conv string( X_HEADER-VIEWNAME )
            iv_maint_fg  = conv string( X_HEADER-area )
            iv_dynpro_no = conv SYST_DYNNR( X_HEADER-liste )
            iv_width     = 160.
      
      ENDFORM.
      

      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.

      Author's profile photo S Abinath
      S Abinath

      Thanks much need one like it...

      Author's profile photo Sigy Freud
      Sigy Freud

      Hi, Friends.
      I'm trying to use your method for resize my table, but there's an error. Something like"Illegal Form ..."

      Author's profile photo Philipp Stekl
      Philipp Stekl

      Thanks a lot!  Just in case you have namespaces for your function groups, you must adjust iv_maint_fg. For example like this:

        "if imported function group name contains namespace, then add SAPL behind namespace prefix
        DATA(lv_adj_fgname) = iv_maint_fg.
        IF lv_adj_fgname CA '/'.
          REPLACE ALL  OCCURRENCES
                  OF REGEX '/(.*)/(.*)'
                  IN lv_adj_fgname WITH '/$1/SAPL$2'.
        ELSE.
          lv_adj_fgname = 'SAPL' && lv_adj_fgname.
        ENDIF.
      Author's profile photo S Abinath
      S Abinath

      Nice blog informative thanks for sharing...