Application Development and Automation 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: 
Read only

How to display data horizontally

Former Member
0 Likes
1,058

Hi,

I have to display data the following format.

sales order item description 01/09/2010 02/09/2010 03/09/2010

100 1 test 3 4 6

in currently i am displaying the following format.

sales order date1 date2 date3

item

description

1.how to fill field catelog.

2. i have written code like below,

wa_lvc_cat-fieldname = 'COLUMNTEXT'.

wa_lvc_cat-ref_table = 'LVC_S_DETA'.

APPEND wa_lvc_cat TO lt_lvc_cat.

wa_fieldcat-fieldname = 'COLUMNTEXT'.

wa_fieldcat-ref_tabname = 'LVC_S_DETA'.

wa_fieldcat-key = 'X'.

APPEND wa_fieldcat TO lt_fieldcat.

DESCRIBE TABLE i_final.

DO sy-tfill TIMES.

  • For each line, a column 'VALUEx' is created in the fieldcatalog

  • Build Fieldcatalog

WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.

CONCATENATE 'VALUE' wa_lvc_cat-fieldname

INTO wa_lvc_cat-fieldname.

wa_lvc_cat-ref_field = 'VALUE'.

wa_lvc_cat-ref_table = 'LVC_S_DETA'.

APPEND wa_lvc_cat TO lt_lvc_cat.

  • Build Fieldcatalog

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = wa_lvc_cat-fieldname.

wa_fieldcat-ref_fieldname = 'VALUE'.

wa_fieldcat-ref_tabname = 'LVC_S_DETA'.

APPEND wa_fieldcat TO lt_fieldcat.

ENDDO.

  • create dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_lvc_cat

IMPORTING

ep_table = l_dyntable.

ASSIGN l_dyntable->* TO <dynamictable>.

  • create structure as structure of the internal table

CREATE DATA l_structure LIKE LINE OF <dynamictable>.

ASSIGN l_structure->* TO <header>.

  • create structure = structure of the internal table

CREATE DATA l_structure LIKE i_final.

ASSIGN l_structure->* TO <ls_table>.

  • create field catalog from our table structure

  • wa_fieldcat-fieldname = 'DATE'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

*

  • wa_fieldcat-fieldname = 'CNT'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

  • wa_fieldcat-fieldname = 'FUNCT'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

*

wa_fieldcat-fieldname = 'ITEM'.

wa_fieldcat-tabname = 'I_FINAL'.

APPEND wa_fieldcat TO lt_fieldcatalogue.

*

wa_fieldcat-fieldname = 'TRANS'.

wa_fieldcat-tabname = 'I_FINAL'.

APPEND wa_fieldcat TO lt_fieldcatalogue.

*call function 'REUSE_ALV_FIELDCATALOG_MERGE'

  • exporting

  • i_structure_name = <LS_TABLE>

  • changing

  • ct_fieldcat = lt_fieldcatalogue

  • exceptions

  • inconsistent_interface = 1

  • program_error = 2

  • others = 3.

*IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

*ENDIF.

DESCRIBE TABLE lt_fieldcatalogue.

  • fill the internal to display <dynamictable>

DO sy-tfill TIMES.

IF sy-index = 1.

READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.

ENDIF.

  • For each field of it_table

ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.

IF sy-subrc NE 0. EXIT .ENDIF.

READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.

  • Fill 1st column

<dynheader> = wa_fieldcat-seltext_m.

IF <dynheader> IS INITIAL.

<dynheader> = wa_fieldcat-fieldname.

ENDIF.

*filling the other columns

LOOP AT i_final INTO <ls_table>.

l_col = sy-tabix + 1.

ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.

IF sy-subrc NE 0. EXIT .ENDIF.

ASSIGN COMPONENT l_col OF STRUCTURE <header> TO

<dynheader>.

IF sy-subrc NE 0. EXIT .ENDIF.

WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.

ENDLOOP.

APPEND <header> TO <dynamictable>.

ENDDO.

*layout for alv output

lt_layout-zebra = 'X'.

lt_layout-no_colhead = 'X'..

lt_layout-colwidth_optimize ='X'.

lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.

*alv grid output for display

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = lt_layout

it_fieldcat = lt_fieldcat

TABLES

t_outtab = <dynamictable>.

Plz correct me code.

Hi,

I have to display data the following format.

sales order item description 01/09/2010 02/09/2010 03/09/2010

100 1 test 3 4 6

in currently i am displaying the following format.

sales order date1 date2 date3

item

description

1.how to fill field catelog.

2. i have written code like below,

wa_lvc_cat-fieldname = 'COLUMNTEXT'.

wa_lvc_cat-ref_table = 'LVC_S_DETA'.

APPEND wa_lvc_cat TO lt_lvc_cat.

wa_fieldcat-fieldname = 'COLUMNTEXT'.

wa_fieldcat-ref_tabname = 'LVC_S_DETA'.

wa_fieldcat-key = 'X'.

APPEND wa_fieldcat TO lt_fieldcat.

DESCRIBE TABLE i_final.

DO sy-tfill TIMES.

  • For each line, a column 'VALUEx' is created in the fieldcatalog

  • Build Fieldcatalog

WRITE sy-index TO wa_lvc_cat-fieldname LEFT-JUSTIFIED.

CONCATENATE 'VALUE' wa_lvc_cat-fieldname

INTO wa_lvc_cat-fieldname.

wa_lvc_cat-ref_field = 'VALUE'.

wa_lvc_cat-ref_table = 'LVC_S_DETA'.

APPEND wa_lvc_cat TO lt_lvc_cat.

  • Build Fieldcatalog

CLEAR wa_fieldcat.

wa_fieldcat-fieldname = wa_lvc_cat-fieldname.

wa_fieldcat-ref_fieldname = 'VALUE'.

wa_fieldcat-ref_tabname = 'LVC_S_DETA'.

APPEND wa_fieldcat TO lt_fieldcat.

ENDDO.

  • create dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = lt_lvc_cat

IMPORTING

ep_table = l_dyntable.

ASSIGN l_dyntable->* TO <dynamictable>.

  • create structure as structure of the internal table

CREATE DATA l_structure LIKE LINE OF <dynamictable>.

ASSIGN l_structure->* TO <header>.

  • create structure = structure of the internal table

CREATE DATA l_structure LIKE i_final.

ASSIGN l_structure->* TO <ls_table>.

  • create field catalog from our table structure

  • wa_fieldcat-fieldname = 'DATE'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

*

  • wa_fieldcat-fieldname = 'CNT'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

  • wa_fieldcat-fieldname = 'FUNCT'.

  • wa_fieldcat-tabname = 'I_FINAL'.

  • APPEND wa_fieldcat TO lt_fieldcatalogue.

*

wa_fieldcat-fieldname = 'ITEM'.

wa_fieldcat-tabname = 'I_FINAL'.

APPEND wa_fieldcat TO lt_fieldcatalogue.

*

wa_fieldcat-fieldname = 'TRANS'.

wa_fieldcat-tabname = 'I_FINAL'.

APPEND wa_fieldcat TO lt_fieldcatalogue.

*call function 'REUSE_ALV_FIELDCATALOG_MERGE'

  • exporting

  • i_structure_name = <LS_TABLE>

  • changing

  • ct_fieldcat = lt_fieldcatalogue

  • exceptions

  • inconsistent_interface = 1

  • program_error = 2

  • others = 3.

*IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

*ENDIF.

DESCRIBE TABLE lt_fieldcatalogue.

  • fill the internal to display <dynamictable>

DO sy-tfill TIMES.

IF sy-index = 1.

READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX 1.

ENDIF.

  • For each field of it_table

ASSIGN COMPONENT 1 OF STRUCTURE <header> TO <dynheader>.

IF sy-subrc NE 0. EXIT .ENDIF.

READ TABLE lt_fieldcatalogue INTO wa_fieldcat INDEX sy-index.

  • Fill 1st column

<dynheader> = wa_fieldcat-seltext_m.

IF <dynheader> IS INITIAL.

<dynheader> = wa_fieldcat-fieldname.

ENDIF.

*filling the other columns

LOOP AT i_final INTO <ls_table>.

l_col = sy-tabix + 1.

ASSIGN COMPONENT sy-index OF STRUCTURE <ls_table> TO <dyndata>.

IF sy-subrc NE 0. EXIT .ENDIF.

ASSIGN COMPONENT l_col OF STRUCTURE <header> TO

<dynheader>.

IF sy-subrc NE 0. EXIT .ENDIF.

WRITE <dyndata> TO <dynheader> LEFT-JUSTIFIED.

ENDLOOP.

APPEND <header> TO <dynamictable>.

ENDDO.

*layout for alv output

lt_layout-zebra = 'X'.

lt_layout-no_colhead = 'X'..

lt_layout-colwidth_optimize ='X'.

lt_layout-window_titlebar = 'ALV GRID TRANSPOSED'.

*alv grid output for display

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

is_layout = lt_layout

it_fieldcat = lt_fieldcat

TABLES

t_outtab = <dynamictable>.

Plz correct me code.

2 REPLIES 2
Read only

andreas_mann3
Active Contributor
0 Likes
856

here's a sample to prepare a alv-fieldcatalog with many similar value-fields:

 
*get metadata of itab
DESCRIBE FIELD itab INTO td.

  LOOP AT td-types INTO watypes.
    READ TABLE td-names INTO wanames INDEX  watypes-idx_name.
    CHECK sy-subrc = 0.
    MOVE wanames-name TO fld-name.

    READ TABLE td-names INTO wanames INDEX  watypes-idx_help_id .
    MOVE wanames-name TO fld-def.
    WHILE wanames-continue = '*'.
      hindex = watypes-idx_help_id + 1.
      READ TABLE td-names INTO wanames INDEX  hindex.
      CONCATENATE fld-def  wanames-name INTO fld-def.
    ENDWHILE.
    APPEND fld.
  ENDLOOP.

*build fieldcatalog
  LOOP AT fld.
    CLEAR katalog.
    katalog-fieldname = fld-name.
    IF fld-name = 'RCOMP'
     OR fld-name ='GSBER'
     OR fld-name ='ITEM'
     OR fld-name ='FUNKTION'.
      katalog-key = 'X'.
    ENDIF.

    SPLIT fld-def AT '-' INTO t f.

    SELECT SINGLE scrtext_m leng
           FROM  dd03m INTO: (katalog-reptext_ddic, katalog-outputlen)
           WHERE  tabname     = t
           AND    fieldname   = f
           AND    ddlanguage  = sy-langu.
    IF sy-subrc <> 0.
      katalog-reptext_ddic = fld-name.
    ENDIF.

    IF fld-name = 'TXT'.
      katalog-outputlen = 30.
    ELSEIF fld-name = 'GSBER'.
      katalog-outputlen = 4.
    ELSE.
      katalog-tabname = t.
    ENDIF.


*here: different value-fields
    IF fld-name BETWEEN 'KSL00' AND 'KSL99'.
      IF fld-name <> 'KSL99'.
        CONCATENATE 'Periode' fld-name+3(2) '/' jahr INTO
                     katalog-reptext_ddic SEPARATED BY space.

*hide fields
        IF NOT fld-name+3(2)  IN buper.
          katalog-no_out = 'X'.
        ENDIF.
      ELSE.
        katalog-outputlen = 19.
        IF ohnevj = 'X'.
          katalog-reptext_ddic = 'Summe'.
        ELSE.
*previous year
          CONCATENATE 'Periode' buper-low '/' vorjahr INTO
                       katalog-reptext_ddic SEPARATED BY space.
        ENDIF.
      ENDIF.
      katalog-currency = 'EUR'.
      katalog-do_sum = 'X'.
      katalog-inttype  = 'P'.
      katalog-datatype = 'CURR'.
    ENDIF.

*hide more fields
    CASE fld-name.
      WHEN 'GSBER'.
        MOVE x_gebe TO katalog-no_out.
        katalog-reptext_ddic = 'Gsbr'.
      WHEN 'ITEM'.
        MOVE x_item TO katalog-no_out.
      WHEN 'FUNKTION'.
        MOVE x_func TO katalog-no_out.
      WHEN 'TXT'.
        MOVE x_text TO katalog-no_out.
    ENDCASE.


    APPEND katalog TO cat.

  ENDLOOP.

...

grx

A.

Read only

0 Likes
856

I didn't get your point.mine is different of kind of requirement.