Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jayme_alonso
Participant

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!

19 Comments