Skip to Content

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!

To report this post you need to login first.

13 Comments

You must be Logged on to comment or reply to a post.

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

    (0) 
    1. Jayme Alonso 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!

      (0) 
  2. Jayme Alonso 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 …

    (0) 
  3. Eric Peterson

    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.

    (1) 
  4. 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 groupmay 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!!!

    (1) 

Leave a Reply