‎2008 Jul 10 6:13 AM
Hi All,
Can anybody send me a sample code for adding checkbox in classical report? i also want to read back which all checkboxes are checked ..
Regards,
Nishant Gupta
‎2008 Jul 10 6:25 AM
Hi,
Go as follows..
DATA:
w_checkbox type c.
w_currline type i.
write:
/2 w_checkbox as checkbox, " Displays the check box.
read line w_currline field value
w_checkbox into w_checkbox.
Check the below code if not clear...
*"Table declarations...................................................
tables:
spfli, " Flight schedule
sflight. " Flight details
*"Selection screen elements............................................
selection-screen begin of block blck1 with frame title text-001.
select-options
s_carrid for spfli-carrid. " Airline carrier id
selection-screen end of block blck1.
*" Field string declarations...........................................
*"--------------------------------------------------------------------*
* Field string declaration to hold flight schedule details from table *
* SPFLI. *
*"--------------------------------------------------------------------*
data:
begin of fs_spfli,
carrid type spfli-carrid, " Airline code
connid type spfli-connid, " Flight connection number
cityfrom type spfli-cityfrom, " Departure city
cityto type spfli-cityto, " Arrival city
end of fs_spfli.
*"--------------------------------------------------------------------*
* Field string declaration to hold selected carrid and connid details *
*"--------------------------------------------------------------------*
data:
begin of fs_flight,
carrid type spfli-carrid,
connid type spfli-connid,
end of fs_flight.
*"--------------------------------------------------------------------*
* Field string declaration to hold basic list table records *
* line numbers from output list *
*"--------------------------------------------------------------------*
data:
begin of fs_lnum,
lnumber type i, " Line number
end of fs_lnum.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
data:
w_checkbox type c. " Checkbox
*"--------------------------------------------------------------------*
* Internal table to hold flight schedules data *
*"--------------------------------------------------------------------*
data
t_spfli like
standard table
of fs_spfli.
*"--------------------------------------------------------------------*
* Internal table declaration to hold selected carrid & connid details *
*"--------------------------------------------------------------------*
data:
t_flight like
standard table
of fs_flight.
*"--------------------------------------------------------------------*
* Internal table to hold basic list output line numbers *
*"--------------------------------------------------------------------*
data:
t_lnum like
standard table
of fs_lnum.
*"--------------------------------------------------------------------*
* START-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
start-of-selection.
perform get_spfli_data.
*"--------------------------------------------------------------------*
* END-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
end-of-selection.
set pf-status 'FLIGHT'.
perform display_spfli_data.
*"--------------------------------------------------------------------*
* AT USER-COMMAND EVENT *
*"--------------------------------------------------------------------*
at user-command.
case sy-ucomm.
when 'FDETIALS'.
perform send_flight_ids.
endcase. " CASE SY-UCOMM
*&--------------------------------------------------------------------*
*& Form GET_SPFLI_DATA
*&--------------------------------------------------------------------*
*This subroutine retrieves specified records from SPFLI Table
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
form get_spfli_data .
select carrid " Airline Code
connid " Flight Connection Number
cityfrom " Departure City
cityto " Arrival City
into table t_spfli
from spfli
where carrid in s_carrid.
endform. " GET_SPFLI_DATA
*&--------------------------------------------------------------------*
*& Form DISPLAY_SPFLI_DATA
*&--------------------------------------------------------------------*
* This subroutine displays t_spfli internal table records
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
form display_spfli_data .
loop at t_spfli into fs_spfli.
at first.
skip.
write:
/10 'CARRIER ID'(002),
30 'CONNECTION ID'(003),
50 'CITY FROM'(004),
70 'CITY TO'(005).
write:
/8 sy-uline+0(75).
endat.
write:
/02 w_checkbox as checkbox,
10 fs_spfli-carrid,
30 fs_spfli-connid,
50 fs_spfli-cityfrom,
70 fs_spfli-cityto.
clear fs_lnum.
fs_lnum-lnumber = sy-linno.
append fs_lnum to t_lnum.
endloop. " LOOP AT T_SPFLI
endform. " DISPLAY_SPFLI_DATA
*&---------------------------------------------------------------------*
*& Form send_flight_Ids
*&---------------------------------------------------------------------*
* This subroutine sends the selected spfli carrid and connid values
*----------------------------------------------------------------------*
* No interface parameters
*----------------------------------------------------------------------*
form send_flight_ids .
data:
lw_currline type i, " Current Line Counter
lw_lines type i. " Total Lines
describe table t_spfli lines lw_lines.
do lw_lines times.
clear:
fs_lnum,
fs_spfli.
clear fs_spfli.
read table t_lnum into fs_lnum index sy-index.
lw_currline = fs_lnum-lnumber.
read line lw_currline field value
w_checkbox into w_checkbox
fs_spfli-carrid into fs_spfli-carrid
fs_spfli-connid into fs_spfli-connid.
if sy-subrc eq 0.
if w_checkbox eq 'X'.
fs_flight-carrid = fs_spfli-carrid.
fs_flight-connid = fs_spfli-connid.
append fs_flight to t_flight.
endif. " IF W_CHECKBOX EQ 'X'
endif. " IF SY-SUBRC EQ 0
enddo. " DO LW_LINES TIMES
endform. " send_flight_Ids
*---------------------------------------------------------------------*
* End Of Program *
*---------------------------------------------------------------------*
Hope this would solve your issue..
Regards
Narin Nandivada.
‎2008 Jul 10 6:18 AM
HI,
its like parameters: p_field like check box, ...
PARAMETERS show_all AS CHECKBOX USER-COMMAND flag.
and goon with at user command functionality.....hope it helps
‎2008 Jul 10 6:26 AM
thanx for ur reply..
my problem is that i have one field in my internal table as follows:
check(1),
matnr,
matkl.
in the report i want as follows:
X matnr matkl
matnr matkl
matnr matkl
then user can check and uncheck and i need to get all the record for which my checkbox is checked
X denotes checkbox.
‎2008 Jul 10 6:19 AM
HI,
PARAMETERS p_field AS CHECKBOX USER-COMMAND flag.
hope this should help
‎2008 Jul 10 6:21 AM
Hi Nishant,
Check this following link which have the program on handling checkboxes in a report:
http://abapreports.blogspot.com/2008/06/handling-check-box-in-alv-report-in-sap.html
Hope this helps you.
Regards,
Chandra Sekhar
‎2008 Jul 10 6:22 AM
hi,
parameters : a type c as checkbox.
if a = 'X'.
write:/ 'Checked'.
else.
write:/ 'Unchecked'.
endif.
just a sample code...hope it helps...
madan.
‎2008 Jul 10 6:23 AM
Hi,
data : ch1 type c value 'X'.
write : ch1 as checkbox,'abcd' .
In output you will be getting the check box default selected...
if you want to get the secoundary list based on the check box value you need to use ..
at line selection ..
if CH1 = X.
then do some operation......
endif.
Reward Points if useful
Raghunath.S
9986076729
‎2008 Jul 10 6:25 AM
Hi,
Go as follows..
DATA:
w_checkbox type c.
w_currline type i.
write:
/2 w_checkbox as checkbox, " Displays the check box.
read line w_currline field value
w_checkbox into w_checkbox.
Check the below code if not clear...
*"Table declarations...................................................
tables:
spfli, " Flight schedule
sflight. " Flight details
*"Selection screen elements............................................
selection-screen begin of block blck1 with frame title text-001.
select-options
s_carrid for spfli-carrid. " Airline carrier id
selection-screen end of block blck1.
*" Field string declarations...........................................
*"--------------------------------------------------------------------*
* Field string declaration to hold flight schedule details from table *
* SPFLI. *
*"--------------------------------------------------------------------*
data:
begin of fs_spfli,
carrid type spfli-carrid, " Airline code
connid type spfli-connid, " Flight connection number
cityfrom type spfli-cityfrom, " Departure city
cityto type spfli-cityto, " Arrival city
end of fs_spfli.
*"--------------------------------------------------------------------*
* Field string declaration to hold selected carrid and connid details *
*"--------------------------------------------------------------------*
data:
begin of fs_flight,
carrid type spfli-carrid,
connid type spfli-connid,
end of fs_flight.
*"--------------------------------------------------------------------*
* Field string declaration to hold basic list table records *
* line numbers from output list *
*"--------------------------------------------------------------------*
data:
begin of fs_lnum,
lnumber type i, " Line number
end of fs_lnum.
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
data:
w_checkbox type c. " Checkbox
*"--------------------------------------------------------------------*
* Internal table to hold flight schedules data *
*"--------------------------------------------------------------------*
data
t_spfli like
standard table
of fs_spfli.
*"--------------------------------------------------------------------*
* Internal table declaration to hold selected carrid & connid details *
*"--------------------------------------------------------------------*
data:
t_flight like
standard table
of fs_flight.
*"--------------------------------------------------------------------*
* Internal table to hold basic list output line numbers *
*"--------------------------------------------------------------------*
data:
t_lnum like
standard table
of fs_lnum.
*"--------------------------------------------------------------------*
* START-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
start-of-selection.
perform get_spfli_data.
*"--------------------------------------------------------------------*
* END-OF-SELECTION EVENT *
*"--------------------------------------------------------------------*
end-of-selection.
set pf-status 'FLIGHT'.
perform display_spfli_data.
*"--------------------------------------------------------------------*
* AT USER-COMMAND EVENT *
*"--------------------------------------------------------------------*
at user-command.
case sy-ucomm.
when 'FDETIALS'.
perform send_flight_ids.
endcase. " CASE SY-UCOMM
*&--------------------------------------------------------------------*
*& Form GET_SPFLI_DATA
*&--------------------------------------------------------------------*
*This subroutine retrieves specified records from SPFLI Table
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
form get_spfli_data .
select carrid " Airline Code
connid " Flight Connection Number
cityfrom " Departure City
cityto " Arrival City
into table t_spfli
from spfli
where carrid in s_carrid.
endform. " GET_SPFLI_DATA
*&--------------------------------------------------------------------*
*& Form DISPLAY_SPFLI_DATA
*&--------------------------------------------------------------------*
* This subroutine displays t_spfli internal table records
*---------------------------------------------------------------------*
* No interface parameters
*---------------------------------------------------------------------*
form display_spfli_data .
loop at t_spfli into fs_spfli.
at first.
skip.
write:
/10 'CARRIER ID'(002),
30 'CONNECTION ID'(003),
50 'CITY FROM'(004),
70 'CITY TO'(005).
write:
/8 sy-uline+0(75).
endat.
write:
/02 w_checkbox as checkbox,
10 fs_spfli-carrid,
30 fs_spfli-connid,
50 fs_spfli-cityfrom,
70 fs_spfli-cityto.
clear fs_lnum.
fs_lnum-lnumber = sy-linno.
append fs_lnum to t_lnum.
endloop. " LOOP AT T_SPFLI
endform. " DISPLAY_SPFLI_DATA
*&---------------------------------------------------------------------*
*& Form send_flight_Ids
*&---------------------------------------------------------------------*
* This subroutine sends the selected spfli carrid and connid values
*----------------------------------------------------------------------*
* No interface parameters
*----------------------------------------------------------------------*
form send_flight_ids .
data:
lw_currline type i, " Current Line Counter
lw_lines type i. " Total Lines
describe table t_spfli lines lw_lines.
do lw_lines times.
clear:
fs_lnum,
fs_spfli.
clear fs_spfli.
read table t_lnum into fs_lnum index sy-index.
lw_currline = fs_lnum-lnumber.
read line lw_currline field value
w_checkbox into w_checkbox
fs_spfli-carrid into fs_spfli-carrid
fs_spfli-connid into fs_spfli-connid.
if sy-subrc eq 0.
if w_checkbox eq 'X'.
fs_flight-carrid = fs_spfli-carrid.
fs_flight-connid = fs_spfli-connid.
append fs_flight to t_flight.
endif. " IF W_CHECKBOX EQ 'X'
endif. " IF SY-SUBRC EQ 0
enddo. " DO LW_LINES TIMES
endform. " send_flight_Ids
*---------------------------------------------------------------------*
* End Of Program *
*---------------------------------------------------------------------*
Hope this would solve your issue..
Regards
Narin Nandivada.
‎2008 Jul 10 6:41 AM
hi
Take that checkbox field as char(1), as it stores only 1 char value either 'X' or ' '.
then loop at the internal table, and read the records based on the checkbox value.
loop at itab into wa where checkboxname = 'X'.
read record....
endloop.
‎2008 Jul 10 6:44 AM
u need to use Cl_gui_alv_grid for that and create a method where in u can select all the check box fileds with data_changed->mt_mod_cells and loop it to check the number of fields checked and use them for fuether process