Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set field length in Dynamic IT tab

Former Member
0 Kudos

Hi All,

I am creating 1 dynamic internal table with refrence of field catalog, but in the dynamic IT tab and work area i am gettinf field length is 10 char.

But i want to change this into 15 or 20 char like this.... how can i change this

Please help me .

DATA: ep_tab TYPE REF TO data,

new_line TYPE REF TO data.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

I_STYLE_TABLE = c_char

it_fieldcatalog = it_fieldcatalog

I_LENGTH_IN_BYTE = ' '

IMPORTING

ep_table = ep_tab.

ASSIGN ep_tab->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

This is my code.

Regards,

Arjun.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

well this is just part of your code.

actually the wrong part, or at least not the part the error is hiding.

if you get created a table and your field length are not ok, then you need to rework your field catalog.

if the field is declared as a char10 field in field catalof, it will get a char10 field in table as well.

5 REPLIES 5

Former Member
0 Kudos

well this is just part of your code.

actually the wrong part, or at least not the part the error is hiding.

if you get created a table and your field length are not ok, then you need to rework your field catalog.

if the field is declared as a char10 field in field catalof, it will get a char10 field in table as well.

0 Kudos

Hi Thanks for your reply.

I hope its taking from field catalog.

my filed catalog as difined like this.

TYPES : ty_fldcat TYPE lvc_s_fcat.

it_fieldcatalog TYPE TABLE OF ty_fldcat,

this field catalog i am assinging in that class.

So where can set the field length of fieldcatalog.

Regards,

Arjun.

0 Kudos

Hi,

You can populate the work area for the field catalog in the following way.

ty_fldcat -fieldname = <fieldname>.

ty_fldcat -datatype = 'CHAR'.

ty_fldcat -inttype = 'C'.

ty_fldcat -intlen = 20.

APPEND ty_fldcat TO it_fieldcatalog .

Former Member
0 Kudos

Hi,

try this


*&---------------------------------------------------------------------*
** ALV DECALRATION
*&---------------------------------------------------------------------*

DATA : wa_lvc_cat TYPE lvc_s_fcat,
       gt_lvc_cat TYPE lvc_t_fcat.

DATA : wa_fieldcat TYPE slis_fieldcat_alv,
       gt_fieldcat TYPE slis_t_fieldcat_alv.


DATA : wa_slis_layout TYPE slis_layout_alv.

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


 PERFORM create_dynamic_itab.         " Fill fieldcatlog and create dynamic itab 


*&---------------------------------------------------------------------*
*&      Form  CREATE_DYNAMIC_ITAB
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_dynamic_itab .

  CLEAR g_pos .
  PERFORM fill_gt_lvc_cat_fld USING 'MATNR' 18 .  "fieldname outputlen.

  PERFORM fill_gt_fieldcat_field USING c_x 'MATNR'  'CHAR' 18   text-006.

  PERFORM fill_gt_lvc_cat_fld USING 'CODE' 40 .

  PERFORM fill_gt_fieldcat_field USING ' ' 'CODE'  'CHAR' 40  text-024.


 CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_lvc_cat
    IMPORTING
      ep_table        = new_table.


ENDFORM.                    " CREATE_DYNAMIC_ITAB

*&---------------------------------------------------------------------*
*&      Form  FILL_gt_lvc_cat_FLD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_0006   text
*      -->P_18     text
*----------------------------------------------------------------------*
FORM fill_gt_lvc_cat_fld  USING   p_fieldname TYPE any
                                  p_outputlen TYPE any.


  wa_lvc_cat-fieldname =  p_fieldname .  " 'MATNR'
  wa_lvc_cat-outputlen =  p_outputlen.   " 18
  APPEND wa_lvc_cat TO gt_lvc_cat.
  CLEAR wa_lvc_cat.


ENDFORM.                    " FILL_gt_lvc_cat_FLD
*&---------------------------------------------------------------------*
*&      Form  FILL_GT_FIELDCAT_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_C_X  text
*      -->P_0012   text
*      -->P_0013   text
*      -->P_18     text
*      -->P_TEXT_006  text
*----------------------------------------------------------------------*
FORM fill_gt_fieldcat_field  USING    p_key        TYPE any
                                      p_fieldname  TYPE any
                                      p_datatype   TYPE any
                                      p_outputlen  TYPE any
                                      p_seletext_m TYPE any.

  g_pos = g_pos + 1.

  wa_fieldcat-col_pos    = g_pos.        " 1.
  wa_fieldcat-key        = p_key .       " c_x.
  wa_fieldcat-fieldname  = p_fieldname.  " 'MATNR'.
  wa_fieldcat-datatype   = p_datatype.   " 'CHAR'.
  wa_fieldcat-outputlen  = p_outputlen.                     " 18.
  wa_fieldcat-seltext_m  = p_seletext_m. " text-006.   "'Material'.
  APPEND wa_fieldcat TO gt_fieldcat.
  CLEAR wa_fieldcat.

ENDFORM.                    " FILL_GT_FIELDCAT_FIELD

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

PERFORM fill_output_layout.          " Fill the output data into field symbol


*&---------------------------------------------------------------------*
*&      Form  FILL_OUTPUT_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_output_layout .

  ASSIGN new_table->* TO <fs_table>.
  CREATE DATA new_line LIKE LINE OF <fs_table>.
  ASSIGN new_line->* TO <fs_line>.

  LOOP AT  gt_mseg INTO wa_mseg.

      ASSIGN COMPONENT 'MATNR' OF STRUCTURE <fs_line> TO <fs_field>.
      <fs_field> = wa_mseg-matnr.

    READ TABLE  gt_grdtrans INTO wa_grdtrans WITH KEY mawerk = wa_mseg-WERKS
                                                         matnr  = wa_mseg-matnr
                                                         mat_doc = wa_mseg-mblnr binary search.


        IF sy-subrc = 0.
        LOOP AT gt_qmfe INTO wa_qmfe WHERE qmnum = wa_grdtrans-qmnum.
         
         READ TABLE gt_qpct2 INTO wa_qpct2 WITH KEY  codegruppe   = wa_qmfe-fegrp
                                                     code        = wa_qmfe-fecod
                                                     BINARY SEARCH .

          IF sy-subrc = 0.
          ASSIGN COMPONENT 'CODE' OF STRUCTURE <fs_line> TO <fs_field>.
          <fs_field> = wa_qpct2-kurztext.
         ENDIF.
         endloop.
         clear wa_qmfe.
        ENDIF.

 ENDLOOP.
    CLEAR wa_mseg.

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

PERFORM fill_layout.                 " Filling the layout of REUSE_ALV_GRID_DISPALY


*&---------------------------------------------------------------------*
*&      Form  FILL_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM fill_layout .

  wa_slis_layout-zebra             = c_x.
  wa_slis_layout-colwidth_optimize = c_x.

ENDFORM.                    " FILL_LAYOUT

Edited by: ShaliniSinha on Mar 30, 2009 1:49 PM

Edited by: ShaliniSinha on Mar 30, 2009 1:55 PM

Former Member
0 Kudos

Simply loop at the fieldcatalog, before you call CALL METHOD cl_alv_table_create=>create_dynamic_table, and change the field outputlen of the field that you want the length to be 20 and modify the internal table.

This should resolve your problem.

regards,

Advait