Simple BSP application to Create, Modify and Delete the database entries
...Previous
STEP 10: On the click of create button, we set the
fl_flag as 2, that can be used to display create layout with an insert button on
the same page. Further, on click of insert button, values of all input fields
are processed and inserted into database using a simple INSERT query.
Add the
following code in OnInputProcessing;
ELSEIF w_eventid EQ 'create'.
fl_flag = 2.
Now, add this
piece of code in the layout;
<%
elseif fl_flag eq 2.
%>
<center>
<table bgcolor="ivory">
<tr>
<td>
<htmlb:label for = "ip_emno"
labelType = "MEDIUM"
text = "Employee Number" />
</td>
<td>
<htmlb:inputField id = "ip_emno”
disabled = "FALSE" />
</td></tr>
<tr>
<td>
<htmlb:label for = "ip_dob"
labelType = "MEDIUM"
text = "Date of Birth" />
</td>
<td>
<htmlb:inputField id = "ip_dob"
/>
</td></tr>
<tr>
<td>
<htmlb:label for = "ip_doj"
labelType = "MEDIUM"
text = "Date of Joining" />
</td>
<td>
<htmlb:inputField id = "ip_doj"
/>
</td></tr>
<tr>
<td>
<htmlb:label for = "ip_salary"
labelType = "MEDIUM"
text = "Salary" />
</td>
<td>
<htmlb:inputField id = "ip_salary"
/>
</td></tr>
<tr><td colspan = "2">
<center>
<htmlb:button id = "insert"
tooltip = "Create a New Record"
text = "INSERT"
onClick = "OnInputProcessing()" />
</center>
</td></tr>
</table>
STEP
11:
Now attach an action to insert button;
ELSEIF w_eventid EQ 'insert'.
CALL METHOD cl_htmlb_manager=>get_data
EXPORTING
request = runtime->server->request
name = 'inputfield'
id = 'ip_emno'
RECEIVING
data = w_object.
w_in_field ?= w_object.
w_in_value = w_in_field->value.
w_employee = 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 = 'ip_dob'
RECEIVING
data = w_object.
w_in_field ?= w_object.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = w_in_field->value
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = w_dofb
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR: w_object,w_in_field,w_in_value.
CALL METHOD cl_htmlb_manager=>get_data
EXPORTING
request = runtime->server->request
name = 'inputfield'
id = 'ip_doj'
RECEIVING
data = w_object.
w_in_field ?= w_object.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = w_in_field->value
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = w_dofj
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CLEAR: w_object,w_in_field,w_in_value.
CALL METHOD cl_htmlb_manager=>get_data
EXPORTING
request = runtime->server->request
name = 'inputfield'
id = 'ip_salary'
RECEIVING
data = w_object.
w_in_field ?= w_object.
w_in_value = w_in_field->value.
w_esalary = w_in_value.
fs_progmr-emno = w_employee.
fs_progmr-dob = w_dofb.
fs_progmr-doj = w_dofj.
fs_progmr-salary = w_esalary.
INSERT zart_programmer FROM fs_progmr.
NOTE: We
have to convert date-fields to internal format before inserting them in
database, or else unformatted date will be inserted into database.
EXTERNAL
FORMAT: 28.02.2009
INTERNAL
FORMAT WITHOUT CONVERSION: 28.02.20
EXTERNAL
FORMAT FOR DISPLAY WITHOUT CONVERSION: 20.2..28.0
To
avoid these discrepancies, we use CONVERT_DATE_TO_INTERNAL and
CONVERT_DATE_TO_EXTERNAL function modules.
Now save, activate and test the page:
![[SCM]actwin,-4,-4,1028,742;Main Page - Microsoft Internet Explorer
iexplore.exe
2/28/2009 , 12:40:10 PM](Page3.13.gif)
No sooner insert button is clicked, entries are pushed into
the database table and page shows updated database status, since SELECT query is
given in OnInitialization event.
Entries are very well inserted into the database table, we
now make innovations to the same page to modify and delete entries.
STEP 12: Add the following piece of code in OnInitialization.
IF w_index IS NOT INITIAL.
READ TABLE t_progmr INTO fs_progmr INDEX w_index.
w_emno = fs_progmr-emno.
w_dob = fs_progmr-dob.
w_doj = fs_progmr-doj.
w_salary = fs_progmr-salary.
fl_flag = 1.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = w_dob
IMPORTING
date_external = w_ext_dob
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
EXPORTING
date_internal = w_doj
IMPORTING
date_external = w_ext_doj
EXCEPTIONS
date_internal_is_invalid = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
We use highlighted work-variables to store selected row
data.
Click
here to continue...
|