BSP checkboxes using HTML and the OnInputProcessing BSP Event
In-order to implement shopping basket functionality into an SAP BSP I have decided to use an application class to store the actual
data tables. This is the easiest method of allowing tables populated in one page to be accessed by other pages. The below steps will
take you though the steps required to implement the shopping cart functionality into a SAP BSP application.
<%@page language="abap"%%gt;
<%@extension name="htmlb" prefix="htmlb"%%gt;
<%
* Data declarations used in layout section
data: ld_tabix type sy-tabix,
ld_index type sy-index,
ld_basketid type string,
ld_basketname type string,
ld_count type i,
ld_basketcount(3) type n.
data: wa_ekko like line of application-%gt;it_ekko,
wa_basket like line of application-%gt;IT_BASKET.
%%gt;
<html%gt;
<head%gt;
<link rel="stylesheet" href="../../sap/public/bc/bsp/styles/sapbsp.css"%gt;
<title%gt;SAP shopping basket bsp </title%gt;
</head%gt;
<body%gt;
<h1%gt;SAP BSP Shopping basket</h1%gt;
<p%gt;
<% select *
up to 10 rows
from ekko
into table application-%gt;it_ekko.
%%gt;
<table%gt;
<%
loop at application-%gt;it_ekko into wa_ekko.
%%gt;
<tr%gt;<td%gt;
<%=wa_ekko-ebeln%%gt;
</td%gt;
<td%gt;
<form method="post" name="form" id="form" %gt;
<p%gt;
<%
ld_basketcount = ld_basketcount + 1.
ld_count = ld_count + 1.
CONCATENATE 'basketid' ld_basketcount into ld_basketid.
CONCATENATE 'basketname' ld_basketcount into ld_basketname.
read table application-%gt;it_basket into wa_basket with key ebeln = wa_ekko-ebeln.
if sy-subrc eq 0.
ld_basketname = ld_count.
CONCATENATE 'OnInputProcessing(del' ld_basketname ')' into ld_basketname.
%%gt;
<input align="right" name="<%=ld_basketname%%gt;" type="submit" id="delete" value="Remove from basket"%gt;
<%
else.
ld_basketname = ld_count.
CONCATENATE 'OnInputProcessing(add' ld_basketname ')' into ld_basketname.
%%gt;
<input align="right" name="<%=ld_basketname%%gt;" type="submit" id="add" value="Add to basket"%gt;
<%
endif.
ld_basketname = ld_count.
CONCATENATE 'OnInputProcessing(now' ld_basketname ')' into ld_basketname.
%%gt;
</p%gt;
</td%gt;</tr%gt;
<%
endloop.
%%gt;
</table%gt;
</form%gt;
</body%gt;
</html%gt;
Step 4 - Test code as it stands
data: ld_basketname type string,
ld_basketcount(3) type n,
ld_tabix type i,
wa_ekko like line of it_ekko.
case event_id.
when others.
if event_id(3) eq 'add'.
read table application->it_ekko into wa_ekko index event_id+3.
append wa_ekko to application->it_basket.
elseif event_id(3) eq 'del'.
read table application->it_ekko into wa_ekko index event_id+3.
delete application->it_basket where ebeln eq wa_ekko-ebeln.
endif.
endcase.
Step 6 - test functionality
Website Navigation to related information
|
||||||||||