IT WORK/SAP FI and ABAP

[ABAP] ALV Toolbar에 Cutomized button 추가 How to add a customized button in ALV Toolbar

Bathildis 2016. 4. 20. 10:09
반응형

 

 <Customized Button 추가 전>

<Before adding a customized button>

 

 

<Customized Button 추가 후>

<After adding a customized button>

 

 위와 같이 표준 ALV Toolbar에 버튼을 추가하고 싶은 경우.

When you want to add a customized button in ALV Toolbar

 

1.  먼저 Handle_toolbar의 Event Receiver를 선언한다.

1. Declare Event Receiver of Handle_toolbar

CLASS  LCL_EVENT_RECEIVER  DEFINITION .

  PUBLIC SECTION.
    METHODS :

      HANDLE_TOOLBAR       FOR EVENT TOOLBAR
                    OF CL_GUI_ALV_GRID
        IMPORTING SENDER E_OBJECT E_INTERACTIVE,

ENDCLASS.

2.  Handle_toolbar를 Container에 지정해준다.

2. Set Handle_toolbar to the container

FORM SET_EVENT_HANDLER .
	CREATE OBJECT EVENT_RECEIVER.

	" FOR 뒤에는 본인이 선언한 ALV 이름 You should change "GL_100GRID" to your own
	SET HANDLER : EVENT_RECEIVER->HANDLE_TOOLBAR FOR GL_100GRID, 

	" Toolbar에서 사용할 User Command 
	EVENT_RECEIVER->HANDLE_USER_COMMAND FOR GL_100GRID. 
ENDFORM.

 

3.  Toolbar에 넣을 버튼을 정의해준다.

3. Define the button you want to add

FORM HANDLE_TOOLBAR USING P_SENDER
                          P_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET
                          P_INTERACTIVE TYPE CHAR01. 

  DATA : LS_TOOLBAR TYPE STB_BUTTON. 

  CLEAR LS_TOOLBAR. 
  LS_TOOLBAR-BUTN_TYPE = 3.
  APPEND LS_TOOLBAR TO P_OBJECT->MT_TOOLBAR .

  CLEAR LS_TOOLBAR. 
  LS_TOOLBAR-FUNCTION  = 'MASS_CHANGE'.
  LS_TOOLBAR-ICON      = ICON_MASS_CHANGE.
  LS_TOOLBAR-QUICKINFO = '입력값을 일괄적용합니다.' .
  LS_TOOLBAR-TEXT      = '일괄적용'.
  LS_TOOLBAR-DISABLED  = ' '.
  APPEND LS_TOOLBAR TO P_OBJECT->MT_TOOLBAR .

ENDFORM.

4. Toolbar의 User Command를 정의해준다.

4. Define User Command 

FORM HANDLE_USER_COMMAND USING P_SENDER
                               P_E_UCOMM.

  CALL METHOD CL_GUI_CFW=>SET_NEW_OK_CODE
    EXPORTING
      NEW_CODE = P_E_UCOMM.

  CASE P_E_UCOMM.
    WHEN 'MASS_CHANGE'.
      MESSAGE S000 WITH 'Succeeded'.
  ENDCASE.

ENDFORM.

 

Function에서 주어진 이름으로 User_command에서 호출이 가능하다.

아이콘은 ICON 테이블에서 원하는 것을 찾아서 넣어주면 된다.

Icon, Quickinfo, Text 세가지 모두 생략 가능

 

You can call the name you give to LS_TOOLBAR-FUNCTION

You can find icon in table "ICON"

"ICON", "Quickinfo", "Text" are not mandatory.

 

 

반응형

 

반응형