Search on this Website

Tuesday, September 30, 2008

Abap code to add a check box for each record when a list is displayed


REPORT ZSACHIN2.

TYPE-POOLS: slis.

*---internal tables

DATA: BEGIN OF it_flight OCCURS 0,
SEL, " add a single character field in the final output table
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF it_flight,

*--internal tables for alv

it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fcat LIKE LINE OF it_fieldcat,
layout TYPE slis_layout_alv,
it_sort type slis_t_sortinfo_alv,
wa_sort like line of it_sort.

DATA: BEGIN OF it_flight_sel OCCURS 0,
SEL,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
seatsocc LIKE sflight-seatsocc,
END OF it_flight_sel.

data: wa_flight like it_flight.

* In the layout set give the name of the field
* whose checkbox will be created ( SEL as it has 1 char only )

layout-box_fieldname = 'SEL'.



*---start-of-selection .

START-OF-SELECTION.

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING
i_program_name = sy-repid
i_internal_tabname = 'IT_FLIGHT'
i_inclname = sy-repid
CHANGING
ct_fieldcat = it_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2.


*----get data

SELECT carrid
connid
fldate
seatsmax
seatsocc
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE it_flight
UP TO 20 ROWS.



wa_fcat-do_sum = 'X'.
MODIFY it_fieldcat FROM wa_fcat TRANSPORTING do_sum
WHERE fieldname = 'SEATSOCC' .



wa_sort-fieldname = 'CARRID'.
wa_sort-group = 'UL'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
clear wa_sort.



wa_sort-fieldname = 'CONNID'.
wa_sort-subtot = 'X'.
wa_sort-up = 'X'.
APPEND wa_sort TO it_sort.
clear wa_sort.



CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
is_layout = layout
it_fieldcat = it_fieldcat
it_sort = it_sort
TABLES
t_outtab = it_flight
EXCEPTIONS
program_error = 1.


FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.

* Check function code
CASE r_ucomm.

* WHEN '&IC1'.
** Check field clicked on within ALVgrid report
* IF rs_selfield-fieldname = 'EBELN'.
** Read data table, using index of row user clicked on
* READ TABLE it_ekko INTO wa_ekko INDEX rs_selfield-tabindex.
** Set parameter ID for transaction screen field
* SET PARAMETER ID 'BES' FIELD wa_ekko-ebeln.
** Sxecute transaction ME23N, and skip initial data entry screen
* CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* ENDIF.

WHEN '&IC1'. "'&DATA_SAVE'. "user presses SAVE
loop at it_flight into wa_flight.

if wa_flight-Sel EQ 'X'.

* collecting records in table it_flight_sel to process further
append wa_flight to it_flight_sel.
clear wa_flight.

endif.
endloop.
ENDCASE.

ENDFORM.

No comments: