You are on page 1of 8

Search

Hom e Tra i ni ngs Qui z Ti ps Tutori a l s Functi ona l Ce rt Q's I nte rvi e w Q's Jobs Te sti m oni a l s Adve rti se Conta ct Us

SAP Virtual/Onsite
Trainings
Document Categories:
ABAPTM
Adobe Forms
ABAP-HR
ALE & IDocs
ALV
BAPI
BASIS
BSP
Business Objects
Business Workflow
CRM NEW
LSMW
SAP Script/Smart Forms
BI/BW
eXchange Infrastructure (XI)
Enterprise Portals (EP)
eCATT
Object Oriented Programming
SAP Query
Userexits/BADIs
WebDynpro for Java/ABAPTM
Others

ALV with user defined buttons on toolbar


By Swarna S, Tata Consultancy Services

What's New?
ABAP Test Cockpit HOT
SAP ABAP Pragmas
Understanding SE32 (ABAP
Text Element Maintenance)
Creating an IDoc File on SAP
Application Server
Understanding Advance with
dialog option of SAP Workflow

open in browser PRO version

*&---------------------------------------------------------------------*
*&Report:ZALV_TOOLBAR
*
*&Author : Swarna.S
*&---------------------------------------------------------------------*
*& AS : ALV report with user defined buttons on its toolbar
*& and when clicking the last yellow button(arrow) can display the
*& toolbar and expand it in three steps
*---------------------------------------------------------------------*
REPORT zalv_toolbar.

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

dialog option of SAP Workflow


SAP Workflow Scenario:
Maintenance Notification
Approval
Enhancements to a standard
class
Working with Floating Field in
Adobe Forms
Inserting data from Internal
Table into the step Send Mail
Display GL Account long text
using enhancement
framework
Differences between
polymorphism in JAVA and
ABAP
Passing multiline parameters
from an ABAP Class event to a
Workflow container
Concept of Re-evaluate agents
for active work items in SAP
Workflow
Dynamic creation of
component usage in ABAP
WebDynpro
Adobe Forms: Display symbols
like copyright and others
Deactivate Hold functionality in
Purchase order (ME21N)
Quiz on OOABAP
Add fields in FBL5N using
BADIs
Tutorial on Wide casting
Defining a Range in Module
Pool Program
Copy fields from one
structure/table into another
structure/table
Side Panel Usage in NWBC

*type pools declaratins for icon and alv


TYPE-POOLS : slis,icon.
*Structure declaration for tcodes
TYPES : BEGIN OF ty_table,
tcode TYPE tcode,
pgmna TYPE progname,
END OF ty_table.
*Structure for tocde text
TYPES : BEGIN OF ty_itext,
tcode TYPE tcode,
ttext TYPE ttext_stct,
sprsl TYPE sprsl,
END OF ty_itext.
*Structure for output display
TYPES : BEGIN OF ty_output,
tcode TYPE tcode,
pgmna TYPE progname,
ttext TYPE ttext_stct,
END OF ty_output.
*internal table and work area declarations
DATA : it_table TYPE STANDARD TABLE OF ty_table INITIAL SIZE 0,
it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
it_ittext TYPE STANDARD TABLE OF ty_itext INITIAL SIZE 0,
wa_table TYPE ty_table,
wa_output TYPE ty_output,
wa_ittext TYPE ty_itext.
*Class definition for ALV toolbar
CLASS:
lcl_alv_toolbar
DEFINITION DEFERRED.
*Declaration for toolbar buttons
DATA : ty_toolbar TYPE stb_button.
* Data declarations for ALV

Contribute?

DATA: c_ccont TYPE REF TO cl_gui_custom_container,


"Custom container object
c_alvgd
TYPE REF TO cl_gui_alv_grid,
"ALV grid object
it_fcat
TYPE lvc_t_fcat,
"Field catalogue
it_layout
TYPE lvc_s_layo,
"Layout
c_alv_toolbar
TYPE REF TO lcl_alv_toolbar,
"Alv toolbar
c_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager. "Toolbar manager

Sample Specs

*Initialization event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.

What's Hot?
Web Dynpro for ABAP Tutorials
Join the Mailing List
Enter name and email address below :
Name:

open in browser PRO version

*Subroutine to get values from tstc table


PERFORM fetch_data.
*subroutine for alv display
PERFORM alv_output.
*---------------------------------------------------------------------*
*
CLASS lcl_alv_toolbar DEFINITION
*---------------------------------------------------------------------*

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Name:

*
ALV event handler
*---------------------------------------------------------------------*
CLASS lcl_alv_toolbar DEFINITION.
PUBLIC SECTION.

Email:

Subscribe

Unsubscribe
GO

*Constructor
METHODS: constructor
IMPORTING
io_alv_grid TYPE REF TO cl_gui_alv_grid,
*Event for toolbar
on_toolbar
FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING
e_object.
ENDCLASS.

"lcl_alv_toolbar DEFINITION

*---------------------------------------------------------------------*
*
CLASS lcl_alv_toolbar IMPLEMENTATION
*---------------------------------------------------------------------*
*
ALV event handler
*---------------------------------------------------------------------*
CLASS lcl_alv_toolbar IMPLEMENTATION.
METHOD constructor.
*

Create ALV toolbar manager instance


CREATE OBJECT c_alv_toolbarmanager
EXPORTING
io_alv_grid
= io_alv_grid.
ENDMETHOD.

"constructor

METHOD on_toolbar.
*
*

Add customized toolbar buttons.


variable for Toolbar Button
ty_toolbar-icon
= icon_generate.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button1'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon
= icon_voice_output.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button2'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon
= icon_phone.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button3'.
APPEND ty_toolbar TO e_object->mt_toolbar.
ty_toolbar-icon
= icon_mail.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button4'.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

APPEND ty_toolbar TO e_object->mt_toolbar.


ty_toolbar-icon
= icon_voice_input.
ty_toolbar-butn_type = 0.
ty_toolbar-text = 'Button5'.
APPEND ty_toolbar TO e_object->mt_toolbar.
**
**

Call reorganize method of toolbar manager to


display the toolbar
CALL METHOD c_alv_toolbarmanager->reorganize
EXPORTING
io_alv_toolbar = e_object.

ENDMETHOD.
ENDCLASS.

"on_toolbar
"lcl_alv_toolbar IMPLEMENTATION

*&---------------------------------------------------------------------*
*&
Form fetch_data
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM fetch_data .
* Select the tcodes upto 200 rows from TSTC
SELECT

tcode
pgmna
FROM tstc
INTO CORRESPONDING FIELDS OF TABLE it_table
UP TO 200 ROWS
WHERE dypno NE '0000'.

*Select the tcode textx


IF it_table[] IS NOT INITIAL.
SELECT ttext
tcode
sprsl
FROM tstct
INTO CORRESPONDING FIELDS OF TABLE it_ittext
FOR ALL ENTRIES IN it_table
WHERE tcode = it_table-tcode
AND sprsl = 'E'.
ENDIF.
* Apppending the data to the internal table of ALV output
LOOP AT it_table INTO wa_table.
wa_output-tcode = wa_table-tcode.
wa_output-pgmna = wa_table-pgmna.
*

open in browser PRO version

For texts
READ TABLE it_ittext INTO wa_ittext WITH KEY tcode = wa_table-tcode.
wa_output-ttext = wa_ittext-ttext.

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

APPEND wa_output TO it_output.


CLEAR wa_output.
ENDLOOP.
ENDFORM.
" fetch_data
*&---------------------------------------------------------------------*
*&
Form alv_output
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM alv_output .
*Calling the ALV
CALL SCREEN 0600.
ENDFORM.

" alv_output

** Calling the ALV screen with custom container


*On this statement double click it takes you to the screen painter SE51.*Enter the attributes
*Create a Custom container and name it CC_CONT and OK code as OK_CODE.
*Save check and Activate the screen painter.
*Now a normal screen with number 600 is created which holds the ALV grid.
* PBO of the actual screen , Here we can give a title and customized menus
*&---------------------------------------------------------------------*
*&
Module STATUS_0600 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE status_0600 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
" STATUS_0600 OUTPUT
* calling the PBO module ALV_GRID.
*&---------------------------------------------------------------------*
*&
Module ALV_GRID OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE alv_grid OUTPUT.
*create object for custom container
CREATE OBJECT c_ccont
EXPORTING
container_name = 'CC_CONT'.
*create object of alv grid
CREATE OBJECT c_alvgd
EXPORTING
i_parent = c_ccont.
* create ALV event handler
CREATE OBJECT c_alv_toolbar
EXPORTING
io_alv_grid = c_alvgd.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

* Register event handler


SET HANDLER c_alv_toolbar->on_toolbar FOR c_alvgd.
* Fieldcatalogue for ALV
PERFORM alv_build_fieldcat.
* ALV attributes FOR LAYOUT
PERFORM alv_report_layout.
CHECK NOT c_alvgd IS INITIAL.
* Call ALV GRID
CALL METHOD c_alvgd->set_table_for_first_display
EXPORTING
is_layout
= it_layout
CHANGING
it_outtab
= it_output
it_fieldcatalog
= it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error
= 2
too_many_lines
= 3
OTHERS
= 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE.

" ALV_GRID

OUTPUT

*&---------------------------------------------------------------------*
*&
Form alv_build_fieldcat
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_IT_FCAT text
*----------------------------------------------------------------------*
FORM alv_build_fieldcat.
DATA lv_fldcat TYPE lvc_s_fcat.
CLEAR lv_fldcat.
lv_fldcat-row_pos
lv_fldcat-col_pos
lv_fldcat-fieldname
lv_fldcat-tabname
lv_fldcat-outputlen
lv_fldcat-scrtext_m

=
=
=
=
=
=

'1'.
'1'.
'TCODE'.
'IT_OUTPUT'.
8.
'TCODE'.

APPEND lv_fldcat TO it_fcat.


CLEAR lv_fldcat.
lv_fldcat-row_pos
lv_fldcat-col_pos
lv_fldcat-fieldname
lv_fldcat-tabname
lv_fldcat-outputlen
lv_fldcat-scrtext_m

open in browser PRO version

=
=
=
=
=
=

'1'.
'2'.
'PGMNA'.
'IT_OUTPUT'.
15.
'PROGNAME'.

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

APPEND lv_fldcat TO it_fcat.


CLEAR lv_fldcat.
lv_fldcat-row_pos
lv_fldcat-col_pos
lv_fldcat-fieldname
lv_fldcat-tabname
lv_fldcat-outputlen
lv_fldcat-scrtext_m

=
=
=
=
=
=

'1'.
'3'.
'TTEXT'.
'IT_OUTPUT'.
60.
'Description'.

APPEND lv_fldcat TO it_fcat.


CLEAR lv_fldcat.
ENDFORM.

" alv_build_fieldcat

*&---------------------------------------------------------------------*
*&
Form alv_report_layout
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_IT_LAYOUT text
*----------------------------------------------------------------------*
FORM alv_report_layout.
it_layout-cwidth_opt = 'X'.
it_layout-zebra = 'X'.
ENDFORM.

" alv_report_layout

* PAI module of the screen created. In case we use an interactive ALV or


*for additional functionalities we can create OK codes
*and based on the user command we can do the coding.
*&---------------------------------------------------------------------*
*&
Module USER_COMMAND_0600 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE user_command_0600 INPUT.
ENDMODULE.

" USER_COMMAND_0600

INPUT

Output:

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM


Home Contribute About Us Privacy Terms Of Use Disclaimer Safe Companies: Advertise on SAPTechnical.COM | Post Job Contact Us
2006-2007 SAPTec hnic al.COM. All rights reserved.
All produc t names are trademarks of their respec tive c ompanies. SAPTec hnical.COM is in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other c ountries.
Every effort is made to ensure c ontent integrity. Use information on this site at your own risk.

Graphic Design by Round the Bend Wizards

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You might also like