BSP checkboxes using HTML and the OnInputProcessing BSP Event
If you have not created a BSP before you might want to have a look at this example of creating a simple BSP application just to get an
understanding of the basic components. The below steps will then take you though the steps required to implement a BSP web page containing multiple
checkboxes and capturing which have been checked by the user.
TYPES: begin of t_ekko, ebeln type ekko-ebeln, checkbox(1) type c, end of t_ekko. TYPEs: tt_ekko type STANDARD TABLE OF t_ekko.
Next use this table type to create a table to store your rows of data within the 'Page Attributes' tab, ALso
create a table which will be used to reference the HTML fields and capture the users input.
<%@page language="abap"%>
<%@extension name="htmlb" prefix="htmlb"%>
<%
* Data declarations used in layout section
data: ld_datetext type string,
ld_tabix type string.
data wa_ekko like line of it_ekko.
%>
<html>
<head>
<link rel="stylesheet" href="../../sap/public/bc/bsp/styles/sapbsp.css">
<title>SAP checkbox bsp </title>
</head>
<body>
<h1>BSP to display checkbox</h1>
<p>
<% select ebeln
up to 10 rows
from ekko
into table it_ekko.
%>
<form method="post" name="form" id="form" >
<table>
<%
loop at it_ekko into wa_ekko.
ld_tabix = sy-tabix.
%>
<tr>
<td>
<%=wa_ekko-ebeln%>
</td>
<td>
<input align="right" value="X" name="ekko_fields[<%=ld_tabix%>]-checkbox" type="checkbox">
</td>
</tr>
<% endloop. %>
<tr><td colspan="2">
<input name="OnInputProcessing(submit)" type="submit"
id="submit" value="Go">
</td></tr>
</table>
</body>
</html>
Step 4 - Test code as it stands
* event handler for checking and processing user input and
* for defining navigation
data: gd_check type string,
ld_checkname type string,
ld_checkcount(3) type n,
ld_tabix type i,
wa_ekko like line of it_ekko.
case event_id.
when 'submit'.
clear: ld_checkcount.
* If it_ekko is empty at this point, ensure BSP is set to statefull, or
* alternatively re-select data.
LOOP AT it_ekko INTO wa_ekko.
ld_tabix = sy-tabix.
ld_checkcount = ld_checkcount + 1.
CONCATENATE 'checkname' ld_checkcount into ld_checkname.
navigation->set_parameter( name = ld_checkname ).
gd_check = navigation->get_parameter( name = ld_checkname ).
if not gd_check is INITIAL. "= 'on' or ' '
endif.
endloop.
endcase.
Step 7 - Demonstrate functionality
---Layout
<form method="post" name="form" id="form" >
<% DATA: ld_tabix type string.
loop at it_ekko into wa_ekko.
ld_tabix = sy-tabix.
%>
<input align="right" value="X" name="check<%=ld_tabix%>" type="checkbox">
<%endloop.%>
<input name="OnInputProcessing(submit)" type="submit" id="submit" value="Go">
</form>
---Event (OnInputProcessing)
DATA: it_fields TYPE tihttpnvp,
wa_fields TYPE ihttpnvp,
ld_tabix type string.
CALL METHOD request->get_form_fields
CHANGING
fields = it_fields.
loop at it_ekko into wa_ekko.
ld_tabix = sy-tabix.
LOOP AT it_fields INTO wa_fields WHERE name CS 'check'.
if wa_fields-name CS ld_tabix.
" Checkbox for this row is checked
else.
* Checkbox for this row is NOT checked
endif.
endloop.
endloop.
Single Checkbox
<form method="post" name="form" id="form" >
<% loop at it_ekko into wa_ekko.
ld_tabix = sy-tabix.
%>
<input align="right" value="X" name="ekko_checkbox" type="checkbox">
<%endloop.%>
<input name="OnInputProcessing(submit)" type="submit" id="submit" value="Go">
</form>
|
||||