BSP Application to insert data into database table and to delete record from table :
Go to Transaction se80->
Give the program name
Click on Yes to create BSP Application program
Check the object name
Right click on object name and create a page
Save page and activate it.
To write code click on page.
Click on Layout
Layout contains the following code
:
In event Handler tab -> On Initialization:
* event handler for data retrieval
select * from yhtable into table fs_emp.
if w_index <> 0.
read table fs_emp into t_emp index w_index.
w_empid = t_emp-empid.
w_fname = t_emp-fname.
w_sname = t_emp-sname.
w_age = t_emp-age.
w_address = t_emp-address.
w_salary = t_emp-salary.
w_flag = 1.
endif.
* the handler is called whenever a request is made for a particular page
* it is used to restore the internal data structures from the request
class cl_htmlb_manager definition load.
case event_id.
when cl_htmlb_manager=>event_id.
data:
event type ref to if_htmlb_data,
selrow type ref to cl_htmlb_tableview.
event = cl_htmlb_manager=>get_event_ex( request ).
selrow ?= cl_htmlb_manager=>get_data( request = request
name = 'tableView'
id = 'Employee' ).
data: tv_data type ref to cl_htmlb_event_tableview.
tv_data = selrow->data.
w_index = tv_data->selectedrowindex.
endcase
data:
w_event type ref to cl_htmlb_event,
w_object type ref to object,
w_inputfield type ref to cl_htmlb_inputfield,
w_eventid type string,
w_fieldid type string,
w_in_field type string,
w_in_value type string,
w_empid1 type yhtable-empid,
w_fname1 type yhtable-fname,
w_sname1 type yhtable-sname,
w_age1 type yhtable-age,
w_address1 type yhtable-address,
w_salary1 type yhtable-salary.
call method cl_htmlb_manager=>get_event
exporting
request = runtime->server->request
receiving
event = w_event.
w_eventid = w_event->id.
if w_eventid eq 'save'.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id = 'empid'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_empid = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name
='inputfield'
id = 'FNAME'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_fname = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id = 'LNAME'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_sname = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id = 'AGE'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_age = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id = 'ADDRESS'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_address = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id = 'SALARY'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_salary = w_in_value.
update yhtable set empid = w_empid1
fname = w_fname1
sname = w_sname1
age = w_age1
address = w_address1
salary = w_salary1
where empid = w_empid1.
elseif w_eventid = 'insert'.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name
='inputfield'
id = 'w_empid'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_empid = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name ='inputfield'
id = 'w_fname'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_fname = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name ='inputfield'
id = 'w_sname'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_sname = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name ='inputfield'
id = 'w_age'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_age = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name ='inputfield'
id = 'w_address'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_address = w_in_value.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name ='inputfield'
id = 'w_salary'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_salary = w_in_value.
clear: w_object,w_in_field,w_in_value.
t_emp-empid = w_empid.
t_emp-fname = w_fname.
t_emp-sname = w_sname.
t_emp-age = w_age.
t_emp-address = w_address.
t_emp-salary = w_salary.
insert yhtable from t_emp.
elseif w_eventid eq 'create'.
w_flag = 2.
elseif w_eventid eq 'delete'.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id
='empid'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_empid1 = w_in_value.
. clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id ='fname'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_fname1 = w_in_value.
. clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id ='lname'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_sname1 = w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id ='address'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_address1 = w_in_value.
.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id ='age'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_age1 = w_in_value.
.
clear: w_object,w_in_field,w_in_value.
call method cl_htmlb_manager=>get_data
exporting
request = runtime->server->request
name = 'inputfield'
id ='salary'
receiving
data = w_object.
w_inputfield ?= w_object.
w_in_value = w_inputfield->value.
w_salary1 = w_in_value.
t_emp-empid = w_empid1.
t_emp-fname = w_fname1.
t_emp-sname = w_sname1.
t_emp-age = w_age1.
t_emp-address = w_address1.
t_emp-salary = w_salary1.
delete yhtable from t_emp.
elseif w_eventid eq 'Employee'.
data:
event type ref to if_htmlb_data,
selrow type ref to cl_htmlb_tableview.
event = cl_htmlb_manager=>get_event_ex( request ).
selrow ?= cl_htmlb_manager=>get_data( request = request
name = 'tableView'
id = 'Employee' ).
data: tv_data type ref to cl_htmlb_event_tableview.
tv_data = selrow->data.
w_index = tv_data->selectedrowindex.
endif.
In Types definition tab :
types:
wa_emp type table of yhtable.
Define Page Attributes as follows:
OUTPUT:
Click on Create to insert a record:
Enter the values in all fields:
You can see the inserted record:
Select a record to delete :
Click on delete:
Selected record was deleted.