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: 

Displaying data on an ALV report

Former Member
0 Kudos
117

Hi Abaper's

I have data that is stored in an internal table and I want to display it in an ALV report, How can I achieve this?

Thanx in advance

Thandie

1 ACCEPTED SOLUTION

faisal_altaf2
Active Contributor
0 Kudos
82

Hi,

Try to run the following code you will find the Ans.

*&---------------------------------------------------------------------*
TABLES : ekpo.
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.
*&---------------------------------------------------------------------*

TYPES : BEGIN OF t_ekpo,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        menge TYPE ekpo-menge,

        END OF t_ekpo.
*&---------------------------------------------------------------------*
*VARIABLES
DATA : check(1),
       rep_id TYPE sy-repid.
*&---------------------------------------------------------------------*
*INTERNAL TABLE TYPE OF ZEKPO
DATA : it_ekpo TYPE STANDARD TABLE OF t_ekpo WITH HEADER LINE.
*&---------------------------------------------------------------------*
*FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv,
       wa_field TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*SORTING
DATA : it_sort TYPE slis_t_sortinfo_alv,
       wa_sort TYPE slis_sortinfo_alv.
*&---------------------------------------------------------------------*
INITIALIZATION.
  check = 'X'.
  rep_id = sy-repid.
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  SELECT ebeln
         ebelp
         matnr
         werks
         menge
         FROM ekpo
         INTO CORRESPONDING FIELDS OF TABLE it_ekpo.


*&---------------------------------------------------------------------*
*          FIELD CATALOG
*&---------------------------------------------------------------------*
  wa_field-fieldname = 'EBELN'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'PO #'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'EBELP'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Line Item'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MATNR'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 15.
  wa_field-seltext_l = 'Material'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'WERKS'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 6.
  wa_field-seltext_l = 'Plant'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MENGE'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Qty.'.
*  wa_field-outputlen = 17.
*  wa_field-edit = 'X'.
  wa_field-do_sum = check.
  APPEND wa_field TO it_field.
  CLEAR wa_field.


*&---------------------------------------------------------------------*
*          SORT W.R.T. PURCHASE ORDER NUMBER
*&---------------------------------------------------------------------*
  wa_sort-spos = 1.
  wa_sort-fieldname = 'EBELN'.
  wa_sort-tabname = 'IT_EKPO'.
  wa_sort-up = check.
  wa_sort-subtot = check.
  APPEND wa_sort TO it_sort.
  CLEAR wa_sort.

*&---------------------------------------------------------------------*
*          DISPLAY RECORDS IN ALV GRID
*&---------------------------------------------------------------------*
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = rep_id
      it_fieldcat        = it_field
      it_sort            = it_sort
    TABLES
      t_outtab           = it_ekpo
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc = 0.
  ENDIF.

Kind Regards,

Faisal

5 REPLIES 5

Former Member
0 Kudos
82

Hi,

You can use class cl_salv_table to display the ALV. Refer to SALV Demo programs. eg. SALV_DEMO_TABLE_*

Regards,

Kritesh Shah

I355602
Product and Topic Expert
Product and Topic Expert
0 Kudos
82

Hi,

Use this link, simple steps to learn to display data in ALV Grid.

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/learn%252bto%252bdisplay%252bdata%252bin...

Hope this solves your problem.

Thanks & Regards,

Tarun Gambhir

Former Member
0 Kudos
82

Hi,

Declare itab for Field catalog and then for this all itab out put fields should be populated in itab of Filed catalog.

then call FM REUSE_ALV_LIST_DISPLAY

Regards,

Sunil

faisal_altaf2
Active Contributor
0 Kudos
83

Hi,

Try to run the following code you will find the Ans.

*&---------------------------------------------------------------------*
TABLES : ekpo.
*&---------------------------------------------------------------------*
TYPE-POOLS : slis.
*&---------------------------------------------------------------------*

TYPES : BEGIN OF t_ekpo,
        ebeln TYPE ekpo-ebeln,
        ebelp TYPE ekpo-ebelp,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        menge TYPE ekpo-menge,

        END OF t_ekpo.
*&---------------------------------------------------------------------*
*VARIABLES
DATA : check(1),
       rep_id TYPE sy-repid.
*&---------------------------------------------------------------------*
*INTERNAL TABLE TYPE OF ZEKPO
DATA : it_ekpo TYPE STANDARD TABLE OF t_ekpo WITH HEADER LINE.
*&---------------------------------------------------------------------*
*FIELD CATALOG
DATA : it_field TYPE slis_t_fieldcat_alv,
       wa_field TYPE slis_fieldcat_alv.
*&---------------------------------------------------------------------*
*SORTING
DATA : it_sort TYPE slis_t_sortinfo_alv,
       wa_sort TYPE slis_sortinfo_alv.
*&---------------------------------------------------------------------*
INITIALIZATION.
  check = 'X'.
  rep_id = sy-repid.
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  SELECT ebeln
         ebelp
         matnr
         werks
         menge
         FROM ekpo
         INTO CORRESPONDING FIELDS OF TABLE it_ekpo.


*&---------------------------------------------------------------------*
*          FIELD CATALOG
*&---------------------------------------------------------------------*
  wa_field-fieldname = 'EBELN'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'PO #'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'EBELP'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Line Item'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MATNR'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 15.
  wa_field-seltext_l = 'Material'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'WERKS'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 6.
  wa_field-seltext_l = 'Plant'.
  APPEND wa_field TO it_field.
  CLEAR wa_field.

  wa_field-fieldname = 'MENGE'.
  wa_field-tabname = 'IT_TAB'.
  wa_field-outputlen = 10.
  wa_field-seltext_l = 'Qty.'.
*  wa_field-outputlen = 17.
*  wa_field-edit = 'X'.
  wa_field-do_sum = check.
  APPEND wa_field TO it_field.
  CLEAR wa_field.


*&---------------------------------------------------------------------*
*          SORT W.R.T. PURCHASE ORDER NUMBER
*&---------------------------------------------------------------------*
  wa_sort-spos = 1.
  wa_sort-fieldname = 'EBELN'.
  wa_sort-tabname = 'IT_EKPO'.
  wa_sort-up = check.
  wa_sort-subtot = check.
  APPEND wa_sort TO it_sort.
  CLEAR wa_sort.

*&---------------------------------------------------------------------*
*          DISPLAY RECORDS IN ALV GRID
*&---------------------------------------------------------------------*
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = rep_id
      it_fieldcat        = it_field
      it_sort            = it_sort
    TABLES
      t_outtab           = it_ekpo
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

  IF sy-subrc = 0.
  ENDIF.

Kind Regards,

Faisal

Former Member
0 Kudos
82

Hi,

Refer this link, which gives various way can be done with ALV along with demo programs.

You can display your data whichever way you required.

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

Edited by: ABAPer on Jan 27, 2009 3:13 PM

Edited by: ABAPer on Jan 27, 2009 3:14 PM

Edited by: ABAPer on Jan 27, 2009 3:14 PM