SAPHub

Avoid Truncation of ALV Column in Background Spool

Some times ALV columns get truncated in the background spool. See an example below

TYPE-POOLS: slis.
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_delivery,
       vbeln TYPE vbeln_vl,
       posnr TYPE posnr_vl,
       lfimg TYPE lfimg,
       vgbel TYPE vgbel,
       vgpos TYPE vgpos,
       END OF ty_delivery.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: gwa_out     TYPE ty_delivery,
      gt_out      TYPE TABLE OF ty_delivery.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
*&---------------------------------------------------------------------*
*& Start-of-Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fill some data
  gwa_out-vbeln = '0012345678'.
  gwa_out-posnr = 10.
  gwa_out-lfimg = 2.
  gwa_out-vgbel = '0000123456'.
  gwa_out-vgpos = 10.

  APPEND gwa_out TO gt_out.
  CLEAR gwa_out.

  gwa_out-vbeln = '0012345679'.
  gwa_out-posnr = 10.
  gwa_out-lfimg = 2.
  gwa_out-vgbel = '0000123457'.
  gwa_out-vgpos = 10.

  APPEND gwa_out TO gt_out.
  CLEAR gwa_out.

*Display ALV
  PERFORM display_alv.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
FORM display_alv.
  DATA: lwa_layout TYPE slis_layout_alv.

*Build field catalog
  PERFORM build_field_cat USING: 'VBELN' 'Delivery'  10,
                                 'POSNR' 'Del.Item'   9,
                                 'LFIMG' 'Qty'       22,
                                 'VGBEL' 'SO'        10,
                                 'VGPOS' 'SO Item'    9.

*Optimize column width in the layout
  lwa_layout-colwidth_optimize = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      is_layout     = lwa_layout
      it_fieldcat   = gt_fieldcat
    TABLES
      t_outtab      = gt_out
    EXCEPTIONS
      program_error = 1
      OTHERS        = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CAT
*&---------------------------------------------------------------------*
FORM build_field_cat USING p_field       TYPE any
                           p_description TYPE any
                           p_length      TYPE outputlen.

  DATA: lwa_fieldcat TYPE slis_fieldcat_alv.

  lwa_fieldcat-fieldname  = p_field.
  lwa_fieldcat-outputlen  = p_length.
  lwa_fieldcat-seltext_m  = p_description.

  APPEND lwa_fieldcat TO gt_fieldcat.

ENDFORM.                    " BUILD_FIELD_CAT

One way to control is to disable the conversion at field catalog level.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CAT
*&---------------------------------------------------------------------*
FORM build_field_cat USING p_field       TYPE any
                           p_description TYPE any
                           p_length      TYPE outputlen.

  DATA: lwa_fieldcat TYPE slis_fieldcat_alv.

  lwa_fieldcat-fieldname  = p_field.
  lwa_fieldcat-outputlen  = p_length.
  lwa_fieldcat-seltext_m  = p_description.
  IF p_field = 'VBELN'.
    lwa_fieldcat-no_convext = 'X'.
  ENDIF.
  APPEND lwa_fieldcat TO gt_fieldcat.

ENDFORM.                    " BUILD_FIELD_CAT

In the above example we have disabled the conversion for Delivery field. But the preceding zeros will be displayed in the report. Then how to handle this? Just use the grid setting parameters of REUSE_ALV_GRID_DISPLAY. Set the do not optimize column width for printing flag of grid settings.

TYPE-POOLS: slis.
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_delivery,
       vbeln TYPE vbeln_vl,
       posnr TYPE posnr_vl,
       lfimg TYPE lfimg,
       vgbel TYPE vgbel,
       vgpos TYPE vgpos,
       END OF ty_delivery.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: gwa_out     TYPE ty_delivery,
      gt_out      TYPE TABLE OF ty_delivery.
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
*&---------------------------------------------------------------------*
*& Start-of-Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.

*Fill some data
  gwa_out-vbeln = '0012345678'.
  gwa_out-posnr = 10.
  gwa_out-lfimg = 2.
  gwa_out-vgbel = '0000123456'.
  gwa_out-vgpos = 10.

  APPEND gwa_out TO gt_out.
  CLEAR gwa_out.

  gwa_out-vbeln = '0012345679'.
  gwa_out-posnr = 10.
  gwa_out-lfimg = 2.
  gwa_out-vgbel = '0000123457'.
  gwa_out-vgpos = 10.

  APPEND gwa_out TO gt_out.
  CLEAR gwa_out.

*Display ALV
  PERFORM display_alv.
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV
*&---------------------------------------------------------------------*
FORM display_alv.
  DATA: lwa_layout TYPE slis_layout_alv.
  DATA: lwa_grid   TYPE lvc_s_glay.
*Build field catalog
  PERFORM build_field_cat USING: 'VBELN' 'Delivery'  10,
                                 'POSNR' 'Del.Item'   9,
                                 'LFIMG' 'Qty'       22,
                                 'VGBEL' 'SO'        10,
                                 'VGPOS' 'SO Item'    9.

*Optimize column width in the layout
  lwa_layout-colwidth_optimize = 'X'.

*Do not optimize column width for printing
  lwa_grid-no_colwopt = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_grid_settings = lwa_grid
      is_layout       = lwa_layout
      it_fieldcat     = gt_fieldcat
    TABLES
      t_outtab        = gt_out
    EXCEPTIONS
      program_error   = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

ENDFORM.                    " DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELD_CAT
*&---------------------------------------------------------------------*
FORM build_field_cat USING p_field       TYPE any
                           p_description TYPE any
                           p_length      TYPE outputlen.

  DATA: lwa_fieldcat TYPE slis_fieldcat_alv.

  lwa_fieldcat-fieldname  = p_field.
  lwa_fieldcat-outputlen  = p_length.
  lwa_fieldcat-seltext_m  = p_description.

  APPEND lwa_fieldcat TO gt_fieldcat.

ENDFORM.                    " BUILD_FIELD_CAT