Page tree
Skip to end of metadata
Go to start of metadata

For the fields if we change any thing, without saving it if we keep the system without operating for some time then it will automatically saves the data with the option called AUTOSAVE.
 
With the help of JavaScript we can set the AUTOSAVE option to the application.

Following is the code for the auto saves. 
Step1: Create a BSP application.

Step2: Right click on the application name and select create->page. Give the page name and save.

Step3: Double-click on the page and select LAYOUT tab. 
Write the code for AUTOSAVE in JavaScript and assign a button id to it.








Step4: Go to Page Attributes tab and declare all the variables.

Step5: Go to Type Definitions tab and declare

Step6: Now go to EventHandler.Select On Initialization event and write code as * event handler for data retrieval
SELECT * FROM zart_programmer INTO TABLE t_emp.

IF w_index NE 0.
  READ TABLE t_emp INTO fs_emp INDEX w_index.
  w_empno = fs_emp-emno.
  w_dob2 = fs_emp-dob.
  w_doj2 = fs_emp-doj.
  w_salary = fs_emp-salary.

  fs_flag = 1.
  CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
    EXPORTING
      date_internal            = w_dob2
    IMPORTING
      date_external            = w_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_doj2
    IMPORTING
      date_external            = w_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.
Step7: Select OnInputProcessing event and write code as.
* event handler for checking and processing user input and
* for defining navigation
data:
 w_event    type ref to cl_htmlb_event,
  w_eventid  type string,
  w_object   type ref to object,
  w_fieldid  type string,
  w_in_field type ref to cl_htmlb_inputfield,
  w_in_value type string,
  w_employee type zart_programmer-emno,
  w_dofb     type char10,
  w_dofj     type char10,
  w_esalary  type zart_programmer-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      = 'empno'
    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      = '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      = '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      = 'salary'
    receiving
      data    = w_object.

  w_in_field ?= w_object.
  w_in_value = w_in_field->value.
  w_esalary = w_in_value.

  update zart_programmer set emno   = w_employee
                              dob    = w_dofb
                              doj    = w_dofj
                              salary = w_esalary
                          where emno = w_employee.      

endif.

Step8: Select OnRequest event and write code as.
* 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      = 'emp' ).

        data: tv_data type ref to cl_htmlb_event_tableview.
        tv_data = selrow->data.

        w_index = tv_data->selectedrowindex.

      when 'OTHERS'.
    endcase.
When we execute the application then it displays like.

Double-click on any record then it displays ,change the entries you want keep the application for 1 Min without doing anything then automatically with the AUTOSAVE option it saves in the database.