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

ALV program with Field Catalog

Former Member
0 Likes
2,753

Hi ,

Can any body please provide me sample ALV programs with Field Catalog and GRID DISPLAY. and also please give me the steps for writing the program.

Thanks in advance.

KP

5 REPLIES 5
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,593

There are a lot of examples, here in the ABAP forum. You can search for more. Here is a very simple one.



report zrich_0003 .



* Global ALV Data Declarations
type-pools: slis.

* Internal Tables
data: begin of ialv occurs 0,
      test1(10) type c,
      test2(10) type c,
      end of ialv.

data: fieldcat  type slis_t_fieldcat_alv.

start-of-selection.

  perform get_data.
  perform call_alv.

*********************************************************************
*      Form  GET_DATA
*********************************************************************
form get_data.

  ialv-test1 = 'ABC'.
  ialv-test2 = 'DEF'.
  append ialv.

  ialv-test1 = 'GHI'.
  ialv-test2 = 'JKL'.
  append ialv.


  ialv-test1 = '123'.
  ialv-test2 = '456'.
  append ialv.


endform.                    "GET_DATA

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

*  CALL_ALV
************************************************************************

form call_alv.

  perform build_field_catalog.


* Call ABAP List Viewer (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat  = fieldcat
    tables
      t_outtab     = ialv.

endform.                    "CALL_ALV

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

* BUILD_FIELD_CATALOG
************************************************************************

form build_field_catalog.


  clear: fieldcat. refresh: fieldcat.

  data: tmp_fc type slis_fieldcat_alv.

  tmp_fc-reptext_ddic = 'Test1'.
  tmp_fc-fieldname    = 'TEST1'.
  tmp_fc-tabname      = 'IALV'.
  tmp_fc-outputlen    = '10'.
  append tmp_fc to fieldcat.

  tmp_fc-reptext_ddic = 'Test2'.
  tmp_fc-fieldname    = 'TEST2'.
  tmp_fc-tabname      = 'IALV'.
  tmp_fc-outputlen    = '10'.
  append tmp_fc to fieldcat.


endform.                    "BUILD_FIELD_CATALOG

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,593

Hi,

Check the program BCALV_GRID_DEMO for Grid using OO..

Check this example for using the FM REUSE_ALV_GRID_DISPLAY..

TYPE-POOLS: slis.

  • Data declaration.

DATA: BEGIN OF itab OCCURS 0,

vbeln TYPE vbeln,

erdat TYPE erdat,

auart TYPE auart,

netwr TYPE vbak-netwr,

END OF itab.

DATA: wa_kna1 TYPE kna1.

DATA: t_fieldcatalog TYPE slis_t_fieldcat_alv.

DATA: s_fieldcatalog TYPE slis_fieldcat_alv.

  • Selection-screen.

PARAMETERS: p_kunnr TYPE kunnr OBLIGATORY.

AT SELECTION-SCREEN.

SELECT SINGLE * FROM kna1 INTO wa_kna1

WHERE kunnr = p_kunnr.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH 'Invalid customer'.

LEAVE LIST-PROCESSING.

ENDIF.

START-OF-SELECTION.

  • Building the field catalog.

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 = '2'.

s_fieldcatalog-fieldname = 'ERDAT'.

s_fieldcatalog-tabname = 'ITAB'.

s_fieldcatalog-rollname = 'ERDAT'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '3'.

s_fieldcatalog-fieldname = 'AUART'.

s_fieldcatalog-tabname = 'ITAB'.

s_fieldcatalog-rollname = 'AUART'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

s_fieldcatalog-col_pos = '4'.

s_fieldcatalog-fieldname = 'NETWR'.

s_fieldcatalog-tabname = 'ITAB'.

s_fieldcatalog-rollname = 'NETWR_AK'.

s_fieldcatalog-do_sum = 'X'.

APPEND s_fieldcatalog TO t_fieldcatalog.

CLEAR: s_fieldcatalog.

  • Get the sales orders.

SELECT vbeln erdat auart netwr

FROM

vbak

INTO TABLE itab

WHERE kunnr = p_kunnr.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH 'No records found'.

LEAVE LIST-PROCESSING.

ENDIF.

DATA: v_repid TYPE syrepid.

v_repid = sy-repid.

  • Display the alv

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = v_repid

it_fieldcat = t_fieldcatalog

TABLES

t_outtab = itab.

Thanks,

Naren

Read only

0 Likes
1,593

Thanks for the information

Read only

0 Likes
1,593

Refer this link

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

Also see the same in

<b>SE38 > Environment > control Examples.</b>

Please reward points and close the thread if ur problem got solved.

Read only

Former Member
0 Likes
1,593

Hi,

For ALV GRID DISPLAY (using <b>OOPS</b>),

1)Create an object of the <b>container</b>(an instance of a class like cl_gui_custom_container).

2)Create an object of the <b>ALV using class cl_gui_alv_grid</b> and give the CONTAINER name that you define in your screen layout as the parent of the ALV.

3)Call the method <b>SET_TABLE_FOR_FIRST_DISPLAY</b> of the class cl_gui_alv_grid.

4)<b>Field catalog</b> is used when you want a variation of the standard structure to be displayed on your ALV.A variable of table type <b>LVC_T_FCAT</b> is defined and variations can be made as per the requirements.The variable is then passed in the method SET_TABLE_FOR_FIRST_DISPLAY.

<b>A SAMPLE PROGRAM:</b>

REPORT SAMPLE:

*-- GLOBAL DATA DECLARATIONS FOR ALV

<b>DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.</b>

DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.

<b>DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.</b>

DATA gt_fieldcat TYPE lvc_t_fcat.

Data:i_spfli type table of spfli.

*The value CC_ALV is given to the custom container in the screen layout

START-OF-SELECTION.

select * from spfli into table i_spfli.

Call screen 100.

----


  • MODULE STATUS_0100 OUTPUT

----


MODULE STATUS_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

*Create container

<b>CREATE OBJECT gr_ccontainer

EXPORTING container_name = gc_custom_control_name.</b>

*Create ALV

<b>CREATE OBJECT gr_alvgrid

EXPORTING i_parent = gr_ccontainer.</b>

*field catalog

<b>PERFORM prepare_field_catalog CHANGING gt_fieldcat.</b>

*to display the ALV

<b>CALL METHOD gr_alvgrid->set_table_for_first_display</b>

EXPORTING

I_STRUCTURE_NAME = 'SPFLI'

CHANGING

it_outtab = i_spfli[]

it_fieldcatalog = gt_fieldcat.

ENDMODULE. "display_alv OUTPUT

----


  • MODULE USER_COMMAND_0100 INPUT

----


MODULE user_command_0100 INPUT.

IF sy-ucomm = 'BACK' OR

sy-ucomm = 'EXIT' OR

sy-ucomm = 'CANCEL'.

LEAVE PROGRAM.

ENDIF.

ENDMODULE.

&----


*& Form prepare_field_catalog

&----


FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.

DATA ls_fcat TYPE lvc_s_fcat.

ls_fcat-ref_table = 'SPFLI'.

ls_fcat-fieldname = 'CARRID'.

APPEND ls_fcat TO pt_fieldcat.

CLEAR ls_fcat.

ls_fcat-fieldname = 'CONNID'.

ls_fcat-ref_table = 'SPFLI'.

APPEND ls_fcat TO pt_fieldcat.

CLEAR ls_fcat.

ls_fcat-fieldname = 'DEPTIME'.

ls_fcat-ref_table = 'SPFLI'.

APPEND ls_fcat TO pt_fieldcat.

CLEAR ls_fcat.

ls_fcat-fieldname = 'ARRTIME'.

ls_fcat-ref_table = 'SPFLI'.

APPEND ls_fcat TO pt_fieldcat.

CLEAR ls_fcat.

endform.

<b>For more sample programs refer:</b>http://www.geocities.com/victorav15/sapr3/abap_ood.html#d_grid

http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_color.htm

http://www.sapdevelopment.co.uk/reporting/alvhome.htm

<b>-->download the PDF from following link.</b>

www.abap4.it/download/ALV.pdf

http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf

<b>Some more:</b>

http://www.sap-hefte.de/download/dateien/1025/087_leseprobe.pdf

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d97...

http://www.alvgmbh.de/dwnload/gonio_t.pdfhttp://

<b>You can get all demo programs for ALV:</b>Go to se38 and type BCALV* and press F4 for all demo porgrams.

Regards,

Beejal

**Reward if this helps