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: 

ALV grid ouput

Former Member
0 Kudos
63

Hi,

i have to make an alv report in which i have to display the columns horizontally like:

name from date to date

contract

contaract a/c

meter no

code....

can you please help me how to do it?

Thanks,

Anand.

5 REPLIES 5

Former Member
0 Kudos
46

Hi,

Just open this link :

U will get a report what u desire.

http://www.saptechnical.com/Tutorials/ALV/ALVMainPage.htm

Regards,

Shiva (Reward if help ful).

Former Member
0 Kudos
46

Hi Anand,

Goto TCode SE38 and type BCALV_* and press F4.

This will give you a list of ALV sample programs.

Reward if helpful,

Regards,

Esha Raj

Former Member
0 Kudos
46

TYPE-POOLS: slis.

DATA: BEGIN OF itab OCCURS 0,

vbeln TYPE vbeln,

expand,

END OF itab.

DATA: BEGIN OF itab1 OCCURS 0,

vbeln TYPE vbeln,

posnr TYPE posnr,

matnr TYPE matnr,

netpr TYPE netpr,

END OF itab1.

DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB'.

s_fieldcatalog-rollname = 'VBELN'.

s_fieldcatalog-outputlen = '12'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '1'.

s_fieldcatalog-fieldname = 'VBELN'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'VBELN'.

s_fieldcatalog-outputlen = '12'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '2'.

s_fieldcatalog-fieldname = 'POSNR'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'POSNR'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'MATNR'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'MATNR'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'NETPR'.

s_fieldcatalog-tabname = 'ITAB1'.

s_fieldcatalog-rollname = 'NETPR'.

s_fieldcatalog-do_sum = 'X'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

DATA: s_layout TYPE slis_layout_alv.

s_layout-subtotals_text = 'SUBTOTAL TEXT'.

s_layout-key_hotspot = 'X'.

s_layout-expand_fieldname = 'EXPAND'.

SELECT vbeln UP TO 100 ROWS

FROM

vbak

INTO TABLE itab.

IF NOT itab[] IS INITIAL.

SELECT vbeln posnr matnr netpr

FROM vbap

INTO TABLE itab1

FOR ALL ENTRIES IN itab

WHERE vbeln = itab-vbeln.

ENDIF.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

DATA: s_keyinfo TYPE slis_keyinfo_alv.

s_keyinfo-header01 = 'VBELN'.

s_keyinfo-item01 = 'VBELN'.

CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

EXPORTING

i_callback_program = v_repid

is_layout = s_layout

it_fieldcat = t_fieldcatalog

i_tabname_header = 'ITAB'

i_tabname_item = 'ITAB1'

is_keyinfo = s_keyinfo

TABLES

t_outtab_header = itab

t_outtab_item = itab1

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.

Reward points..

prasanth_kasturi
Active Contributor
0 Kudos
46

hi,

in field catllogue there is row_pos. populate it.

example

populating the field cat for the fields add the following

for contract row_pos = '1'.

contaract a/c row_pos = '2'.

etc.....

regards

prasanth

venkat_o
Active Contributor
0 Kudos
46

Hi Anand, Check the below sample program. It works fine. I have given comments wherever those are needed. very understandable.


REPORT  zvenkat_alv_2_grid_description.

TYPES:
      BEGIN OF t_mard,
       werks TYPE mard-werks,
       lgort TYPE mard-lgort,
       matnr TYPE mard-matnr,
       insme TYPE mard-insme,
       einme TYPE mard-einme,
       speme TYPE mard-speme,
      END OF t_mard.
DATA:
      w_mard TYPE t_mard.
DATA:
      i_mard TYPE STANDARD TABLE OF t_mard.
*&---------------------------------------------------------------------*
" ALV Declarations
"&---------------------------------------------------------------------*
"     ALV internal tables and Structures
"     ----------------------------------
"     To refer ALV tables(slis tables) and structures.SLIS must be
"     declared under TYPE-POOLS(see below).SLIS is a Type group which is
"     defined in Dictionary.Internal tables and structures and constants
"     are defined under type group.(Double click on SLIS).
*&---------------------------------------------------------------------*
* Types Pools
TYPE-POOLS:
   slis.
* Types
TYPES:
   t_fieldcat         TYPE slis_fieldcat_alv,
   t_events           TYPE slis_alv_event,
   t_layout           TYPE slis_layout_alv.
* Workareas
DATA:
   w_fieldcat         TYPE t_fieldcat,
   w_events           TYPE t_events,
   w_layout           TYPE t_layout.
* Internal Tables
DATA:
   i_fieldcat         TYPE STANDARD TABLE OF t_fieldcat,
   i_fieldcat1        TYPE STANDARD TABLE OF t_fieldcat,
   i_events           TYPE STANDARD TABLE OF t_events.
*&---------------------------------------------------------------------*
*&      START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM get_data_from_database .

*&---------------------------------------------------------------------*
  "      END-OF-SELECTION
  "     Steps to create simple ALV program
  "     ----------------------------------
  "      1. Pass an internal table with the set of output information
  "      2. Pass a field catalog as an internal table
  "      3. Pass a structure with general list layout details
*&---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM build_fieldcatalog.
  PERFORM build_events.
  PERFORM build_layout.
  PERFORM display_data.
*&---------------------------------------------------------------------*
  "      Form  build_fieldcatalog
  "     Fieldcatalog Internal table
  "     --------------------------
  "    1. It contains descriptions of the list output fields
  "       (usually a subset of the internal output table fields).
  "    2. A field catalog is required for every ALV list output.
*&---------------------------------------------------------------------*
FORM build_fieldcatalog .
  CLEAR :
    w_fieldcat,
   i_fieldcat[].

  PERFORM build_fcat USING:
        "Field   Int.Table Column headings
        'WERKS' 'I_MARD' 'WERKS',
        'LGORT' 'I_MARD' 'LGORT',
        'MATNR' 'I_MARD' 'MATNR',
        'INSME' 'I_MARD' 'INSME',
        'EINME' 'I_MARD' 'EINME',
        'SPEME' 'I_MARD' 'SPEME'.
ENDFORM.                    " build_fieldcatalog

*&---------------------------------------------------------------------*
*&      Form  display_data
*&---------------------------------------------------------------------*
FORM display_data .
  DATA :program LIKE sy-repid VALUE sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = program
      is_layout          = w_layout
      it_fieldcat        = i_fieldcat
      it_events          = i_events
    TABLES
      t_outtab           = i_mard.
  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_data

*&---------------------------------------------------------------------*
*&      Form  get_data_from_database
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data_from_database .
  CLEAR :i_mard,
         i_mard[].

  SELECT werks lgort matnr insme einme speme
  FROM mard
  INTO CORRESPONDING FIELDS OF TABLE i_mard
    UP TO 100 ROWS.


ENDFORM.                    " get_data_from_database

*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM top_of_page.

  DATA :
  i_header TYPE slis_t_listheader,
  w_header LIKE LINE OF i_header.

  DATA:l_date1 TYPE datum,
       l_date2 TYPE datum.

  w_header-typ = 'S'.
  w_header-info = sy-title.
  APPEND w_header TO i_header.
  CLEAR w_header.

  w_header-typ = 'H'.
  w_header-info = sy-repid.
  APPEND w_header TO i_header.
  CLEAR w_header.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
    EXPORTING
      it_list_commentary = i_header
      i_logo             = 'ENJOYSAP_LOGO'.

ENDFORM.                    "top_of_page
*&---------------------------------------------------------------------*
*&      Form  BUILD_FCAT
*&---------------------------------------------------------------------*

FORM build_fcat  USING  l_field l_tab l_text.

  w_fieldcat-fieldname = l_field.
  w_fieldcat-tabname   = l_tab.
  w_fieldcat-seltext_m = l_text.
  APPEND w_fieldcat TO i_fieldcat.
  CLEAR w_fieldcat.

ENDFORM.                    " BUILD_FCAT
*&---------------------------------------------------------------------*
"      Form  build_events
"     Events
"     ------
"    1. When we use ALV,certain events TOP-OF-PAGE ,END-OF-PAGE,
"       AT LINE-SELECTION,AT USER-COMMANDs are not triggered.
"    2. To perform those Functions ,we have to build Events table and
"       pass this table through REUSE_ALV_LIST_DISPALY Function.
*&---------------------------------------------------------------------*
FORM build_events .
  CLEAR :
         w_events,i_events[].

  w_events-name = 'TOP_OF_PAGE'.
  w_events-form = 'TOP_OF_PAGE'.
  APPEND w_events TO i_events.
  CLEAR w_events.
ENDFORM.                    " build_events
*&---------------------------------------------------------------------*
"&      Form  build_layout
"     Layouts
"     -------
"  Use :We change the display of our list using layouts.
"  ===
"  Features
"  ========
"    The layouts that you can use vary according to the type of list:
"   1-->In all lists, you can do the following:
"       (a).Choose one of the std layouts supplied with the std system.
"       (b).Change the current layout of the list .
"   2-->In lists that use only the standard layouts in the std system
"       you cannot save your changes to the current layout.When you
"       choose the layouts, only the standard layouts will be proposed.
"   3-->In some lists, you can also save the layouts that you have
"       defined as our own layouts.
"      User-defined layouts are generally saved for all users. They can
"       then be used by all users. All users will be able to choose from
"       the user-defined layouts as well as the standard layouts.
"   4-->In some lists, you can also save user-specific layouts that you
"       have defined . When you choose the current layout,only these
"       layouts are available to you.
"   5-->You can delete or transport layouts, or define them as initial
"       layouts
"   6-->STRUCTURE :SLIS_LAYOUT_ALV.
*&---------------------------------------------------------------------*
FORM build_layout .
  CLEAR:
        w_layout.
  w_layout-colwidth_optimize = 'X'.
ENDFORM.                    " build_layout
I hope that it helps u . Regards, Venkat.O