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 -Problem

Former Member
0 Likes
283

Hi All,

My requirement is in ALV report i want Pushbutton and checkboxes.

how can we write code and which one we use plz help me urgent,

Regards,

venkat

1 REPLY 1
Read only

Former Member
0 Likes
241

PUSH BUTTON

set your pf status in alv then in application toolbar assign the name and fcode for that activate pf status.
for accessing the push button fcode you have to write code in user command
check example program

BCALV_GRID_05

Here is a sample report showing how to use buttons in ALV grid lists. Please note that I "abused" field BUKRS for the push button. Normally you would define a separate column for that.

*&----


*

*& Report ZUS_SDN_ALV_EVT_BUTTON_CLICK

*&

*&----


*

*&

  • Flow logic of screen '0100' (contains no dynpro elements):

  • PROCESS BEFORE OUTPUT.

  • MODULE STATUS_0100.

**

  • PROCESS AFTER INPUT.

  • MODULE USER_COMMAND_0100.

*&----


*

REPORT ZUS_SDN_ALV_EVT_BUTTON_CLICK.

DATA:

gd_okcode TYPE ui_func,

*

gt_fcat TYPE lvc_t_fcat,

go_docking TYPE REF TO cl_gui_docking_container,

go_grid1 TYPE REF TO cl_gui_alv_grid.

DATA:

gt_knb1 TYPE STANDARD TABLE OF knb1.

PARAMETERS:

p_bukrs TYPE bukrs DEFAULT '2000' OBLIGATORY.

*----


*

  • CLASS lcl_eventhandler DEFINITION

*----


*

*

*----


*

CLASS lcl_eventhandler DEFINITION.

PUBLIC SECTION.

CLASS-METHODS:

handle_button_click FOR EVENT button_click OF cl_gui_alv_grid

IMPORTING

es_col_id

es_row_no

sender.

ENDCLASS. "lcl_eventhandler DEFINITION

*----


*

  • CLASS lcl_eventhandler IMPLEMENTATION

*----


*

*

*----


*

CLASS lcl_eventhandler IMPLEMENTATION.

METHOD handle_button_click.

  • define local data

DATA:

ls_knb1 TYPE knb1,

ls_col_id TYPE lvc_s_col.

READ TABLE gt_knb1 INTO ls_knb1 INDEX es_row_no-row_id.

CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.

SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.

CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.

    • OR: show your popup

  • call screen '0200' starting at 5 5

  • ending at 10 20.

ENDMETHOD. "handle_button_click

ENDCLASS. "lcl_eventhandler IMPLEMENTATION

START-OF-SELECTION.

SELECT * FROM knb1 INTO TABLE gt_knb1

WHERE bukrs = p_bukrs.

  • Create docking container

CREATE OBJECT go_docking

EXPORTING

parent = cl_gui_container=>screen0

ratio = 90

EXCEPTIONS

OTHERS = 6.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Create ALV grid

CREATE OBJECT go_grid1

EXPORTING

i_parent = go_docking

EXCEPTIONS

OTHERS = 5.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • Set event handler

SET HANDLER:

lcl_eventhandler=>handle_button_click FOR go_grid1.

  • Build fieldcatalog and set button for field KUNNR

PERFORM build_fieldcatalog_knb1.

  • Display data

CALL METHOD go_grid1->set_table_for_first_display

CHANGING

it_outtab = gt_knb1

it_fieldcatalog = gt_fcat

EXCEPTIONS

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.

  • Link the docking container to the target dynpro

CALL METHOD go_docking->link

EXPORTING

repid = syst-repid

dynnr = '0100'

  • CONTAINER =

EXCEPTIONS

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.

  • ok-code field = GD_OKCODE

CALL SCREEN '0100'.

END-OF-SELECTION.

*&----


*

*& Module STATUS_0100 OUTPUT

*&----


*

  • text

*----


*

MODULE status_0100 OUTPUT.

SET PF-STATUS 'STATUS_0100'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

*&----


*

*& Module USER_COMMAND_0100 INPUT

*&----


*

  • text

*----


*

MODULE user_command_0100 INPUT.

CASE gd_okcode.

WHEN 'BACK' OR

'END' OR

'CANC'.

SET SCREEN 0. LEAVE SCREEN.

WHEN OTHERS.

ENDCASE.

CLEAR: gd_okcode.

ENDMODULE. " USER_COMMAND_0100 INPUT

*&----


*

*& Form BUILD_FIELDCATALOG_KNB1

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM build_fieldcatalog_knb1 .

  • define local data

DATA:

ls_fcat TYPE lvc_s_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

i_structure_name = 'KNB1'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

  • I_INTERNAL_TABNAME =

CHANGING

ct_fieldcat = gt_fcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT gt_fcat INTO ls_fcat

WHERE ( fieldname = 'BUKRS' ).

ls_fcat-style = cl_gui_alv_grid=>mc_style_button.

MODIFY gt_fcat FROM ls_fcat.

ENDLOOP.

ENDFORM. " BUILD_FIELDCATALOG_KNB1

CHECKBOX


chk this std pgm BCALV_EDIT_05

BCALV_EDIT_05

This example shows how to use checkboxes within an ALV Grid Control. You learn:

(1) how to define a column for editable checkboxes for an attribute of your list

(2) how to evaluate the checked checkboxes

(3) how to switch between editable and non-editable checkboxes

Define the final output table with the first columns as TYPE C.

Eg. DATA: BEGIN OF I_itab occurs 0,

cb(1) TYPE c,

....................

END OF I_itab.

Then while building the fieldcatalog.

CASE ...

WHEN 'CB'.

w_fieldcat-checkbox = 'X'.

..

At declaring field catalog using structure LVC_S_FCAT

mark CHECKBOX = 'X' and also EDIT = 'X'.

For reference check below subroutine in program BCALV_EDIT_05.

form build_fieldcat changing pt_fieldcat type lvc_t_fcat.

data ls_fcat type lvc_s_fcat.

call function 'LVC_FIELDCATALOG_MERGE'

exporting

i_structure_name = 'SFLIGHT'

changing

ct_fieldcat = pt_fieldcat.

*§A2.Add an entry for the checkbox in the fieldcatalog

clear ls_fcat.

ls_fcat-fieldname = 'CHECKBOX'.

  • Essential: declare field as checkbox and

  • mark it as editable field:

ls_fcat-checkbox = 'X'.

ls_fcat-edit = 'X'.

  • do not forget to provide texts for this extra field

ls_fcat-coltext = text-f01.

ls_fcat-tooltip = text-f02.

ls_fcat-seltext = text-f03.

  • optional: set column width

ls_fcat-outputlen = 10.

*

append ls_fcat to pt_fieldcat.

endform.

Message was edited by:

Ramesh Babu Chirumamilla