Google Search - Blog...........

ABAP - Handling Radio Buttons In ALV Report

*---------------------------------------------------------*
* This program will give you an idea, how to use the
* Radio buttons and check boxes with OOP's ALV.
*---------------------------------------------------------*

REPORT zfi_payment_voucher MESSAGE-ID zmmg.

CLASS cl_alv DEFINITION DEFERRED.

TYPE-POOLS: abap, icon.

DATA: event_receiver TYPE REF TO cl_alv.

DATA: v_okcode TYPE sy-ucomm,
alvgrid TYPE REF TO cl_gui_alv_grid,
ccont TYPE REF TO cl_gui_custom_container,
it_fcat TYPE lvc_t_fcat ,
wa_fcat LIKE LINE OF it_fcat,
wa_lout TYPE lvc_s_layo ,
cont TYPE scrfname VALUE 'ZCUST',
V_AMT TYPE CHAR15.


TYPES: BEGIN OF ty_bsik,
bukrs TYPE bsik-bukrs,
lifnr TYPE bsik-lifnr,
gjahr TYPE bsik-gjahr,
belnr TYPE bsik-belnr,
buzei TYPE bsik-buzei,
budat TYPE bsik-budat,
bldat TYPE bsik-bldat,
xblnr TYPE bsik-xblnr,
wrbtr TYPE bsik-wrbtr,
sgtxt TYPE bsik-sgtxt,
END OF ty_bsik.


TYPES: BEGIN OF ty_bkpf,
bukrs LIKE bkpf-bukrs,
belnr LIKE bkpf-belnr,
gjahr LIKE bkpf-gjahr,
blart LIKE bkpf-blart,
bldat LIKE bkpf-bldat,
budat LIKE bkpf-budat,
xblnr LIKE bkpf-xblnr,
END OF ty_bkpf.

TYPES: BEGIN OF ty_bseg,
bukrs TYPE bseg-bukrs,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
umskz TYPE bseg-umskz,
SHKZG TYPE bseg-SHKZG,
wrbtr TYPE bseg-wrbtr,
pswsl TYPE bseg-pswsl,
sgtxt TYPE bseg-sgtxt,
END OF ty_bseg.

TYPES: BEGIN OF ty_final,
check TYPE c,
bukrs LIKE bseg-bukrs,
belnr LIKE bseg-belnr,
gjahr LIKE bseg-gjahr,
blart LIKE bkpf-blart,
bldat LIKE bkpf-bldat,
budat LIKE bkpf-budat,
xblnr LIKE bkpf-xblnr,
buzei TYPE char3,
radio1(4), "Radio button
radio2(4),
wrbtr TYPE char15,
wrbtr1 TYPE char15,
curr TYPE char4,
sgtxt TYPE char50,
handle_style TYPE lvc_t_styl,
END OF ty_final.


DATA: it_bsik TYPE TABLE OF ty_bsik,
it_bkpf TYPE TABLE OF ty_bkpf,
it_bseg TYPE TABLE OF ty_bseg,
it_final TYPE TABLE OF ty_final,
wa_bsik LIKE LINE OF it_bsik,
wa_bkpf LIKE LINE OF it_bkpf,
wa_bseg LIKE LINE OF it_bseg,
wa_final LIKE LINE OF it_final.


DATA: v_col TYPE sy-index,
v_test TYPE char15,
v_test2 TYPE char15,
v_test1 type char2,
v_len type i.

DATA: v_lines TYPE i,
lt_selected_rows TYPE lvc_t_row.

TABLES: bkpf,
bseg,
bsik.

INCLUDE .

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_lifnr TYPE bseg-lifnr,
p_bukrs TYPE bkpf-bukrs.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.

PARAMETERS : p_check1 AS CHECKBOX,
p_check2 AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b3.

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE text-004.
PARAMETERS: p_prepby TYPE char30 OBLIGATORY,
p_chekby TYPE char30 OBLIGATORY,
p_apvdby TYPE char30 OBLIGATORY,
p_ptext TYPE char120 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b4.

START-OF-SELECTION.

CALL SCREEN 101.

*----------------------------------------------------------------------*
* CLASS cl_alv DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_alv DEFINITION.

PUBLIC SECTION.

METHODS:

handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column,

handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id
e_column_id
es_row_no
sender.

ENDCLASS. "cl_alv DEFINITION

*----------------------------------------------------------------------*
* CLASS cl_alv IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_alv IMPLEMENTATION.

METHOD: handle_double_click.


CALL METHOD alvgrid->get_selected_rows
IMPORTING
et_index_rows = lt_selected_rows.

ENDMETHOD. "handle_double_click


METHOD: handle_hotspot_click.

* define local data
FIELD-SYMBOLS:
TYPE ty_final,
TYPE ANY.

READ TABLE it_final ASSIGNING INDEX es_row_no-row_id.
CHECK ( IS ASSIGNED ).
* Set all radio buttons "unselected"
-radio1 = icon_wd_radio_button_empty.
-radio2 = icon_wd_radio_button_empty.
ASSIGN COMPONENT e_column_id-fieldname OF STRUCTURE
TO .
IF ( IS ASSIGNED ).
* Set selected radio button "selected".
= icon_radiobutton.
ENDIF.
* Force PAI followed by refresh of table display in PBO
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH'.
* IMPORTING
* RC =
CALL METHOD alvgrid->refresh_table_display.


ENDMETHOD. "handle_hotspot_click

ENDCLASS. "cl_alv IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module DISPLAY_ALV OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE display_alv OUTPUT.

IF ccont IS INITIAL.

SELECT bukrs
lifnr
gjahr
belnr
buzei
budat
bldat
xblnr
wrbtr
sgtxt
FROM bsik
INTO TABLE it_bsik
WHERE bukrs = p_bukrs
AND lifnr = p_lifnr.

IF sy-subrc = 0.

SELECT bukrs
belnr
gjahr
blart
bldat
budat
xblnr
FROM bkpf
INTO TABLE it_bkpf
FOR ALL ENTRIES IN it_bsik
WHERE bukrs = it_bsik-bukrs
AND belnr = it_bsik-belnr
AND gjahr = it_bsik-gjahr
* and blart = it_bsik-blart
AND bldat = it_bsik-bldat
AND budat = it_bsik-budat
AND xblnr = it_bsik-xblnr.

IF sy-subrc = 0.

SELECT bukrs
belnr
gjahr
buzei
umskz
SHKZG
wrbtr
pswsl
sgtxt
FROM bseg
INTO TABLE it_bseg
FOR ALL ENTRIES IN it_bsik
WHERE bukrs = it_bsik-bukrs
AND belnr = it_bsik-belnr
AND gjahr = it_bsik-gjahr
AND buzei = it_bsik-buzei.
ENDIF.

ENDIF.

LOOP AT it_bsik INTO wa_bsik.

wa_final-buzei = wa_bsik-buzei.
wa_final-sgtxt = wa_bsik-sgtxt.

READ TABLE it_bseg INTO wa_bseg WITH KEY bukrs = wa_bsik-bukrs
belnr = wa_bsik-belnr
gjahr = wa_bsik-gjahr
buzei = wa_bsik-buzei.
IF sy-subrc = 0.

if not wa_bseg-wrbtr is initial.

wa_final-wrbtr = wa_bseg-wrbtr.

if wa_bseg-SHKZG = 'S'.
concatenate '-' wa_final-wrbtr into wa_final-wrbtr.
endif.


CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
CHANGING
value = wa_final-wrbtr .

endif.

wa_final-curr = wa_bseg-pswsl.

ENDIF.
READ TABLE it_bkpf INTO wa_bkpf WITH KEY bukrs = wa_bsik-bukrs
belnr = wa_bsik-belnr
gjahr = wa_bsik-gjahr.
IF sy-subrc = 0.
wa_final-bukrs = wa_bkpf-bukrs.
wa_final-belnr = wa_bkpf-belnr.
wa_final-blart = wa_bkpf-blart.
wa_final-bldat = wa_bkpf-bldat.
wa_final-budat = wa_bkpf-budat.
wa_final-xblnr = wa_bkpf-xblnr.
ENDIF.

wa_final-radio1 = icon_radiobutton. "Empty Radio Buttons
wa_final-radio2 = icon_wd_radio_button_empty..

IF p_check1 = 'X'.

READ TABLE it_bseg INTO wa_bseg WITH KEY belnr = wa_final-belnr.
IF sy-subrc = 0 AND wa_bseg-umskz IS INITIAL.
APPEND wa_final TO it_final.
CLEAR wa_final.
ENDIF.

ELSEIF p_check2 = 'X'.

READ TABLE it_bseg INTO wa_bseg WITH KEY belnr = wa_final-belnr.
IF sy-subrc = 0 AND wa_bseg-umskz IS NOT INITIAL.
APPEND wa_final TO it_final.
CLEAR wa_final.
ENDIF.

ELSEIF p_check1 = 'X' AND p_check2 = 'X'.

READ TABLE it_bseg INTO wa_bseg WITH KEY belnr = wa_final-belnr.
IF sy-subrc = 0.
APPEND wa_final TO it_final.
CLEAR : wa_final, wa_bseg, wa_bsik.
ENDIF.

ENDIF.
ENDLOOP.

SORT it_final BY belnr buzei.


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

CREATE OBJECT ccont
EXPORTING
container_name = cont
repid = sy-repid
dynnr = sy-dynnr
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.

CREATE OBJECT alvgrid
EXPORTING
i_parent = ccont
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
OTHERS = 5.

PERFORM fieldcat USING 'CHECK' 'Check' '' .
PERFORM fieldcat USING 'BUKRS' 'Comp Code' '' .
PERFORM fieldcat USING 'BELNR' 'Accnt Doc No' '' .
PERFORM fieldcat USING 'BLART' 'Doc Type' '' .
PERFORM fieldcat USING 'BLDAT' 'Document Date' '' .
PERFORM fieldcat USING 'BUDAT' 'Posting Date' '' .
PERFORM fieldcat USING 'XBLNR' 'Ref. Doc NO' '' .
PERFORM fieldcat USING 'BUZEI' 'Item' '' .
PERFORM fieldcat USING 'SGTXT' 'Item Text' '' .
PERFORM fieldcat USING 'CURR' 'Currency' '' .
PERFORM fieldcat USING 'RADIO1' 'Full Amount' '' .
PERFORM fieldcat USING 'RADIO2' 'Partial Amount' '' .
PERFORM fieldcat USING 'WRBTR' 'Full Amount' '' .
PERFORM fieldcat USING 'WRBTR1' 'Partial Amount' '' .

wa_lout-sel_mode = 'A'.
wa_lout-cwidth_opt = 'X'.
wa_lout-zebra = 'X'.
wa_lout-stylefname = 'HANDLE_STYLE'.

CALL METHOD alvgrid->set_table_for_first_display
EXPORTING
is_layout = wa_lout
CHANGING
it_outtab = it_final
it_fieldcatalog = it_fcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.

CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR alvgrid.
SET HANDLER event_receiver->handle_hotspot_click FOR alvgrid.

ELSE.

CALL METHOD alvgrid->check_changed_data.

CALL METHOD alvgrid->refresh_table_display.
ENDIF.

CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = alvgrid.


ENDMODULE. " DISPLAY_ALV OUTPUT

*&---------------------------------------------------------------------*
*& Form FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0627 text
* -->P_0628 text
* -->P_0629 text
*----------------------------------------------------------------------*
FORM fieldcat USING value(p_0627)
value(p_0628)
value(p_0629).

v_col = v_col + 1.

wa_fcat-fieldname = p_0627.
wa_fcat-reptext = p_0628.
wa_fcat-no_out = p_0629.
wa_fcat-col_pos = v_col.
wa_fcat-tabname = 'IT_FINAL'.

IF wa_fcat-fieldname = 'CHECK'.
wa_fcat-checkbox = 'X'.
wa_fcat-edit = 'X'.
ELSEIF wa_fcat-fieldname = 'RADIO1'.

wa_fcat-tabname = 'IT_FINAL'.
wa_fcat-seltext = 'Full Payment'.
wa_fcat-outputlen = 6.
wa_fcat-icon = 'X'. "Icons
wa_fcat-hotspot = 'X'. "Interactive Handling
ELSEIF wa_fcat-fieldname = 'RADIO2'.

wa_fcat-fieldname = 'RADIO2'.
wa_fcat-seltext = 'Partial Payment'.
wa_fcat-outputlen = 6.
wa_fcat-icon = 'X'. "Icons
wa_fcat-hotspot = 'X'. "Interactive Handling
ELSEIF wa_fcat-fieldname = 'WRBTR1'.
* wa_fcat-hotspot = 'X'. "Interactive Handling
ENDIF.

APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.


ENDFORM. " FIELDCAT
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0101 OUTPUT.
SET PF-STATUS 'BBB'.
SET TITLEBAR 'BBB'.

ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0101 INPUT.

CASE: sy-ucomm.
WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
LEAVE TO SCREEN 0.
WHEN '&IC1'.

CALL METHOD alvgrid->check_changed_data.
WHEN 'REFRESH'.

DATA: ls_edit TYPE lvc_s_styl,
lt_edit TYPE lvc_t_styl,
ls_field TYPE lvc_fname,
l_index TYPE i.

DATA: it_cells TYPE lvc_t_cell,
it_column TYPE lvc_t_col,
it_selected_col TYPE lvc_t_ceno,
wa_cells LIKE LINE OF it_cells,
v_index TYPE sy-index.



CALL METHOD alvgrid->get_selected_cells
IMPORTING
et_cell = it_cells.

CALL METHOD alvgrid->get_selected_columns
IMPORTING
et_index_columns = it_column.

CALL METHOD alvgrid->get_selected_cells_id
IMPORTING
et_cells = it_selected_col.

READ TABLE it_cells INTO wa_cells INDEX 1.
IF sy-subrc = 0.
v_index = wa_cells-row_id.
ENDIF.

CALL METHOD alvgrid->check_changed_data.

LOOP AT it_final INTO wa_final.

l_index = sy-tabix.
ls_edit-fieldname = 'WRBTR1'.

IF wa_final-radio1 = '@R6@'.
ls_edit-style = cl_gui_alv_grid=>mc_style_disabled.

CLEAR : wa_final-wrbtr1.

ELSEIF wa_final-radio1 = '@SR@'.
ls_edit-style = cl_gui_alv_grid=>mc_style_enabled.
ENDIF.

ls_edit-style2 = space.
ls_edit-style3 = space.
ls_edit-style4 = space.
ls_edit-maxlen = 20.
INSERT ls_edit INTO TABLE lt_edit.

REFRESH: wa_final-handle_style.
APPEND LINES OF lt_edit TO wa_final-handle_style.

MODIFY it_final INDEX l_index FROM wa_final.
* transporting handle_style.
REFRESH: lt_edit,wa_final-handle_style.
CLEAR :wa_final,ls_edit.

ENDLOOP.


* define local data
DATA:
ls_stable TYPE lvc_s_stbl.
ls_stable-row = abap_true.
ls_stable-col = abap_true.
CALL METHOD alvgrid->refresh_table_display
* EXPORTING
* is_stable = ls_stable
EXCEPTIONS
finished = 1
OTHERS = 2.

WHEN 'PRINT'.

DATA: it_data TYPE TABLE OF zpay_voucher WITH HEADER LINE,
v_curr TYPE char5.

CALL METHOD alvgrid->check_changed_data.

REFRESH : it_data.



clear : v_curr.

LOOP AT it_final INTO wa_final WHERE check = 'X'.

if v_curr is initial.
MOVE wa_final-curr TO v_curr.
ELSE.
IF wa_final-curr NE v_curr.
MESSAGE e013 WITH 'Please select entries with the same currencies'.
ENDIF.

ENDIF.

it_data-bldat = wa_final-bldat.
it_data-belnr = wa_final-belnr.
it_data-xblnr = wa_final-xblnr.
it_data-buzei = wa_final-buzei.
it_data-sgtxt = wa_final-sgtxt.
it_data-curr = wa_final-curr.

CONDENSE : it_data-curr.

IF wa_final-wrbtr1 IS NOT INITIAL.
move wa_final-wrbtr1 to v_test1.
REPLACE ALL OCCURRENCES OF ',' IN wa_final-wrbtr1 WITH space.
condense wa_final-wrbtr1.
it_data-wrbtr = wa_final-wrbtr1.
ELSE.
REPLACE ALL OCCURRENCES OF ',' IN wa_final-wrbtr WITH space.
condense wa_final-wrbtr.
it_data-wrbtr = wa_final-wrbtr.
ENDIF.

APPEND it_data.
CLEAR it_data.
ENDLOOP.
*-----IF u want you can display this data in another alv layout or process
* this data to call some smartform, or display this using the write statement

ENDIF.
ENDCASE.

ENDMODULE. " USER_COMMAND_0101 INPUT



ALSO READ:

- Handling Radio Buttons in SALV Tree Display.

- Display The PO Status In ALV Report - MM.

- SALV List With Check Box.

- SALV List With Symbol.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


No comments:

Post a Comment