Skip to Content
author's profile photo Former Member
Former Member

ALV Column Width Issue

Hi,

ALV Column Width Issue

I want to fix my width of columns in my ALV attached is snapshot of my report please guide me

Regards

Untitled.png (149.5 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Jul 28, 2012 at 05:07 AM

    Hiiii,

    Just do this ,

    In your fieldcatalog set property

    <FIELD_CAT_NAME>-outputlen = <specify length>. or provide your code .😊

    Add a comment
    10|10000 characters needed characters exceeded

    • Hiii,

      Check below modified code .... if you need more help tell me 😊


      *&---------------------------------------------------------------------*

      *& Report /BWN0/Z_PROJECT_SUMMERY

      * created by sarosh durrani

      *&

      *&---------------------------------------------------------------------*

      *&

      *&

      *&---------------------------------------------------------------------*






      TABLES: proj, prps, afvc, afvv, afvu, cosp, coss.



      type-pools: slis. "ALV Declarations

      *Data Declaration

      *----------------

      TYPES: BEGIN OF p_proj,

      SNO TYPE int4,

      * v_sno(6) type c,

      pspid TYPE proj-pspid,

      pspnr TYPE proj-pspnr,

      ernam TYPE proj-ernam,

      stspr TYPE proj-stspr,

      pwhie TYPE proj-pwhie,

      besta TYPE proj-besta,

      scope TYPE proj-scope,

      xstat TYPE proj-xstat,

      postu TYPE proj-postu,

      smprf TYPE proj-smprf,

      erdat TYPE proj-erdat,

      post1 TYPE proj-post1,

      sakto TYPE afvc-sakto,

      a type i,
      b type i,
      c type i,

      END OF p_proj.





      TYPES: BEGIN OF pl_afvc,

      * SNO TYPE int4,

      sakto TYPE afvc-sakto,

      projn TYPE afvc-projn,

      psphi TYPE prps-psphi,

      END OF pl_afvc.



      *DATA: IT_PRPS TYPE TABLE OF PRPS.



      DATA: it_proj TYPE STANDARD TABLE OF p_proj WITH HEADER LINE,

      it_afvc TYPE STANDARD TABLE OF pl_afvc WITH HEADER LINE,

      wa_proj TYPE p_proj,

      VSNO TYPE INT4.





      *ALV data declarations

      data: fieldcatalog type slis_t_fieldcat_alv with header line,

      gd_tab_group type slis_t_sp_group_alv,

      gd_layout type slis_layout_alv,

      gd_repid like sy-repid.



      *PARAMETER: CURRDATE TYPE EKPO-AEDAT.

      *SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.

      ************************************************************************



      *Start-of-selection.

      START-OF-SELECTION.



      perform data_retrieval.

      perform build_fieldcatalog.

      perform build_layout.

      perform display_alv_report.



      *&---------------------------------------------------------------------*

      *& Form BUILD_FIELDCATALOG

      *&---------------------------------------------------------------------*

      * Build Fieldcatalog for ALV Report

      *----------------------------------------------------------------------*

      VSNO = VSNO + 1.



      * it_proj-SNO = VSNO.





      form build_fieldcatalog.

      fieldcatalog-fieldname = 'SNO'.

      fieldcatalog-seltext_m = 'Serial number'.

      fieldcatalog-col_pos = 1.

      * fieldcatalog-outputlen = 5.

      * fieldcatalog-emphasize = 'C170'.

      fieldcatalog-key = 'X'.

      * fieldcatalog-do_sum = 'X'.

      fieldcatalog-no_zero = 'X'.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'POSTU'.

      fieldcatalog-seltext_m = 'Description'.

      fieldcatalog-col_pos = 2.

      fieldcatalog-outputlen = 50.

      fieldcatalog-emphasize = 'C170'.

      fieldcatalog-key = 'X'.

      fieldcatalog-do_sum = 'X'.

      fieldcatalog-no_zero = 'X'.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'ERNAM'.

      fieldcatalog-seltext_m = 'Quantity'.

      fieldcatalog-col_pos = 3.

      fieldcatalog-outputlen = 20.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'STSPR'.

      fieldcatalog-seltext_m = 'Ex-Factory'.

      fieldcatalog-col_pos = 4.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'PWHIE'.

      fieldcatalog-seltext_m = 'Delivery'.

      fieldcatalog-col_pos = 5.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'BESTA'.

      fieldcatalog-seltext_m = 'Erection'.

      fieldcatalog-col_pos = 6.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'SCOPE'.

      fieldcatalog-seltext_m = 'Crane'.

      fieldcatalog-col_pos = 7.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'XSTAT'.

      fieldcatalog-seltext_m = 'Total'.

      fieldcatalog-col_pos = 8.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'PSPID'.

      fieldcatalog-seltext_m = 'Ex-Factory'.

      fieldcatalog-col_pos = 9.

      * fieldcatalog-outputlen = 15.

      * fieldcatalog-datatype = 'CURR'.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'SMPRF'.

      fieldcatalog-seltext_m = 'Delivery'.

      fieldcatalog-col_pos = 10.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'ERDAT'.

      fieldcatalog-seltext_m = 'Erection'.

      fieldcatalog-col_pos = 11.



      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'POST1'.

      fieldcatalog-seltext_m = 'Erection1'.

      fieldcatalog-col_pos = 12.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.



      fieldcatalog-fieldname = 'SAKTO'.

      fieldcatalog-seltext_m = 'Cost Element'.

      fieldcatalog-col_pos = 13.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.


      fieldcatalog-fieldname = 'A'.

      fieldcatalog-seltext_m = 'A'.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.


      fieldcatalog-fieldname = 'B'.

      fieldcatalog-seltext_m = 'B'.

      * fieldcatalog-col_pos = 4.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.


      fieldcatalog-fieldname = 'C'.

      fieldcatalog-seltext_m = ' C = Sum a + b'.

      * fieldcatalog-col_pos = 5.

      append fieldcatalog to fieldcatalog.

      clear fieldcatalog.


      endform. " BUILD_FIELDCATALOG



      *&---------------------------------------------------------------------*

      *& Form BUILD_LAYOUT

      *&---------------------------------------------------------------------*

      * Build layout for ALV grid report

      *----------------------------------------------------------------------*

      form build_layout.

      gd_layout-no_input = 'X'.

      gd_layout-colwidth_optimize = '30'.

      gd_layout-totals_text = 'Totals'(201).

      gd_layout-totals_only = 'X'.

      gd_layout-f2code = 'DISP'. "Sets fcode for when double

      * "click(press f2)

      gd_layout-zebra = 'X'.

      gd_layout-group_change_edit = 'X'.

      gd_layout-header_text = 'helllllo'.



      * gd_layout-expand_fieldname = 'EXPAND'.
      *
      * gd_layout-window_titlebar = 'Hierarchical ALV list display'.
      *
      * gd_layout-lights_tabname = 'it_proj'.
      *
      * gd_layout-colwidth_optimize = '30'.





      endform. " BUILD_LAYOUT



      *&---------------------------------------------------------------------*

      *& Form DISPLAY_ALV_REPORT

      *&---------------------------------------------------------------------*

      * Display report using ALV grid

      *----------------------------------------------------------------------*

      form display_alv_report.

      gd_repid = sy-repid.

      call function 'REUSE_ALV_LIST_DISPLAY'

      exporting

      i_callback_program = gd_repid

      * i_callback_top_of_page = 'TOP_OF_PAGE' "see FORM

      * i_callback_user_command = 'USER_COMMAND'

      * i_grid_title = outtext

      is_layout = gd_layout

      it_fieldcat = fieldcatalog[]

      it_special_groups = gd_tab_group

      * IT_EVENTS = GT_XEVENTS

      i_save = 'X'

      * is_variant = z_template



      tables

      t_outtab = it_proj



      * t_outtabnew = it_prps

      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_REPORT





      *&---------------------------------------------------------------------*

      *& Form DATA_RETRIEVAL

      *&---------------------------------------------------------------------*

      * Retrieve data form EKPO table and populate itab it_ekko

      *----------------------------------------------------------------------*

      form data_retrieval.





      *select PSPID ERNAM STSPR PWHIE BESTA SCOPE XSTAT POSTU SMPRF ERDAT from proj into corresponding fields of table it_proj.





      select * from proj into corresponding fields of table it_proj.



      select afvc~sakto afvc~projn prps~psphi FROM afvc INNER JOIN prps

      ON AFVC~PROJN = PRPS~PSPNR into corresponding fields of table it_afvc FOR ALL ENTRIES IN it_proj WHERE PRPS~PSPHI = it_PROJ-PSPNR .





      LOOP AT it_proj INTO wa_proj .

      wa_proj-sno = sy-tabix.

      READ TABLE it_afvc with key psphi = wa_proj-pspnr .

      IF sy-SUBRC eq 0.

      wa_proj-sakto = it_afvc-sakto.

      ENDIF.

      wa_proj-a = sy-tabix.
      wa_proj-b = sy-tabix * 2.
      wa_proj-c = wa_proj-a + wa_proj-b.


      MODIFY it_proj FROM wa_proj TRANSPORTING SNO sakto a b c.

      CLEAR wa_proj.


      ENDLOOP.






      endform. " DATA_RETRIEVAL



      *up to 10 rows

      *PARAMETER: CURRDATE TYPE EKPO-AEDAT.

      *SELECT-OPTIONS: DOCNUM FOR EKKO-EBELN.



      *-------------------------------------------------------------------*

      * Form TOP-OF-PAGE *

      *-------------------------------------------------------------------*

      * ALV Report Header *

      *-------------------------------------------------------------------*

      Form top_of_page.

      *ALV Header declarations

      data: t_header type slis_t_listheader,

      wa_header type slis_listheader,

      t_line like wa_header-info,

      ld_lines type i,

      ld_linesc(10) type c.



      * Title

      wa_header-typ = 'H'.

      wa_header-info = 'EKKO Table Report'.

      append wa_header to t_header.

      clear wa_header.



      * Date

      wa_header-typ = 'S'.

      wa_header-key = 'Date: '.

      CONCATENATE sy-datum+6(2) '.'

      sy-datum+4(2) '.'

      sy-datum(4) INTO wa_header-info. "todays date

      append wa_header to t_header.

      clear: wa_header.



      * Total No. of Records Selected

      describe table it_proj lines ld_lines.

      ld_linesc = ld_lines.

      concatenate 'Total No. of Records Selected: ' ld_linesc

      into t_line separated by space.

      wa_header-typ = 'A'.

      wa_header-info = t_line.

      append wa_header to t_header.

      clear: wa_header, t_line.



      call function 'REUSE_ALV_COMMENTARY_WRITE'

      EXPORTING

      it_list_commentary = t_header.

      * i_logo = 'Z_LOGO'.

      endform. "top_of_page

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2012 at 05:06 AM

    In the layout options , you will ahve a field colwidth_optimize , set the value of that to 'X'

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 28, 2012 at 11:36 AM

    Data: gt_layout TYPE slis_layout_alv OCCURS 0 WITH HEADER LINE.

    gt_layout-colwidth_optimize ='X'.

    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

    EXPORTING

    i_callback_program = sy-repid

    I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'

    I_CALLBACK_USER_COMMAND = ' '

    i_callback_top_of_page = 'TOP_OF_PAGE'

    i_grid_title = '

    * I_GRID_SETTINGS =

    is_layout = gt_layout

    * it_events = gt_event

    i_save = 'A'

    it_fieldcat = gt_fieldcat

    TABLES

    t_outtab = gt_final

    EXCEPTIONS

    program_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    TRY like this it will help u.😊

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.