Show TOC

Class CL_BSP_SERVER_SIDE_COOKIELocate this document in the navigation structure

Use

Class CL_BSP_SERVER_SIDE_COOKIE provides methods for setting, getting, deleting, and managing cookies on the server.

Server-side cookies are persistent data, similar to the usual client-side cookies. However, while on the client-side, there are restrictions that limit the size of cookies to around 4 kilobytes per cookie, the number of cookies to 300 in total and 20 per server or domain, server-side cookies are not subject to any of these restrictions. A server-side cookie is stored on the database.

For technical reasons, each individual cookie can be stored in one of the following ways:

  • as a field

  • as a structure

  • as an internal table

Caution

When you get a cookie, please note that it must be returned to the same data structure. Otherwise, an error will occur, which you can query using an error method.

The parameters username and session_id deserve special attention. Setting username to sy-user is ambiguous in cases where an application is started by an anonymous user stored on the server. It would be better to use session_id (see example) since runtime->session_id indicates the browser session.

When you design an application, you should give careful consideration to whether the application should be stateless and the required context data be retained from page to page in cookies (client-side or server-side), or whether the application should be stateful. A stateful application makes sense when there is a large amount of context data that would otherwise have to be read from or written to the database using cookies and thus slow down performance (see also Stateful or Stateless Programming?).

The program BSP_SHOW_SERVER_COOKIES provides an overview of all of the cookies set in the system. The program BSP_CLEAN_UP_SERVER_COOKIES deletes all expired cookies to the day.

Note

The system administrator should schedule the program BSP_CLEAN_UP_SERVER_COOKIES to run in the background on a regular basis.

Class CL_BSP_SERVER_SIDE_COOKIE is contained in the package SBSP_RUNTIME.

Inheritance Hierarchy/Interface Composition
Implemented interfaces -
Super Class -
Attributes

Attribute Name

Declaration Type

Description

CC_OK

Constant

Action was successful

CC_WRONG_DATA_OBJECT

Constant

The data object of the cookie to be read does not match the data object of the set cookie

CC_PARAMETER_MISSING

Constant

Call parameters are missing

CC_NOT_EXISTS

Constant

Cookie does not exist

Methods
Note

All of the methods are in the visibility section public section.

Method get_server_cookie

Signature

method GET_SERVER_COOKIE
  exporting
    NAME
    EXPIRY_TIME
    EXPIRY_DATE
    SESSION_ID
    USERNAME
    APPLICATION_NAMESPACE
    APPLICATION_NAME
    DATA_NAME
    DATA_VALUE

                           

Description

This method gets a server cookie

Parameter EXPIRY_TIME

Valid from time: To

EXPIRY_DATE

Valid from date: To

DATA_NAME

Data object name

SESSION_ID

Session ID

USERNAME

Name of the user

APPLICATION_NAMESPACE

Namespace of the BSP application

APPLICATION_NAME

Name of BSP Application

NAME

Name of cookie

DATA_VALUE

Data object content

Example
data: sorders type sales_orders,
    edate   type d,
    etime   type t,
    usr     type string.

clear sorders.

call method cl_bsp_server_side_cookie=>get_server_cookie
  exporting 
      name                  = 'SALESORDER_GETLIST'
      application_namespace = runtime->application_namespace
      application_name      = runtime->application_name
      username              = usr
      session_id            = runtime->session_id
      data_name             = 'SORDERS'
  importing
      expiry_date        = edate
      expiry_time        = etime
  changing
      data_value         = sorders.


            
Method delete_server_cookie

Signature

method DELETE_SERVER_COOKIE
  exporting
    NAME
    APPLICATION_NAME
    APPLICATION_NAMESPACE
    USERNAME
    SESSION_ID

                           

Description

This method deletes a server cookie

Parameter

NAME

Name of cookie

APPLICATION_NAME

Name of BSP Application

APPLICATION_NAMESPACE

Namespace of the BSP application

USERNAME

Name of the user

SESSION_ID

Session ID

Example
data: usr  type string.

call method cl_bsp_server_side_cookie=>delete_server_cookie
  exporting 
      name                  = 'SALESORDER_GETLIST'
      application_namespace = runtime->application_namespace
      application_name      = runtime->application_name
      username              = usr
      session_id            = runtime->session_id.


            
Method set_server_cookie

Signature

method SET_SERVER_COOKIE
  importing
    DATA_VALUE
  exporting
    EXPIRY_DATE_ABS
    EXPIRY_TIME_ABS
    DATA_NAME
    SESSION_ID
    USERNAME
    EXPIRY_TIME_REL
    EXPIRY_DATE_REL
    APPLICATION_NAMESPACE
    APPLICATION_NAME
    NAME

                           

Description

This method sets a server cookie

Parameter

DATA_VALUE

Data object content

EXPIRY_DATE_ABS

Valid to date

EXPIRY_TIME_ABS

Absolute validity duration

Note

If you do not specify a value, as of SAP Web Application Server 6.20 the system sets the absolute validity duration to 23.59.

DATA_NAME

Data object name

SESSION_ID

Session ID if required

USERNAME

Name of user, and e-mail address

EXPIRY_TIME_REL

Relative validity duration in seconds

Note

If you do not specify a value, as of SAP Web Application Server 6.20 the system sets the relative validity duration to an hour.

EXPIRY_DATE_REL

Validity duration in days

APPLICATION_NAMESPACE

Namespace of the BSP application

APPLICATION_NAME

Name of BSP Application

NAME

Name of cookie

Example
data: sorders type sales_orders,
      edate   type d,
      usr     type string.

call function 'BAPI_SALESORDER_GETLIST' destination 'ABC'
  exporting
    customer_number                = '0000001000'
  tables
    sales_orders                   = sorders.

edate = sy-datum.

add 1 to edate.              "gültig für einen Tag

call method cl_bsp_server_side_cookie=>set_server_cookie
  exporting
    name                  = 'SALESORDER_GETLIST'
    application_namespace = runtime->application_namespace
    application_name      = runtime->application_name
    username              = usr
    session_id            = runtime->session_id
    expiry_date_abs       = edate
    expiry_time_abs       = sy-uzeit
    data_name             = 'SORDERS'
    data_value            = sorders.


            
Method get_last_error

Signature

method GET_LAST_ERROR
  importing
    RC

                           

Description

This method returns the return code of the last call

Parameter

RC

Return Code

Example
data: rc  type i,
      txt type string.

rc = cl_bsp_server_side_cookie=>get_last_error( ).


            
Method get_last_error_name

Signature

method GET_LAST_ERROR_NAME
  importing
    NAME

                           

Description

This method returns the internal name of the exception of the last call

Parameter

NAME

Internal error text

Example
data: rc  type i,
      txt type string.

rc = cl_bsp_server_side_cookie=>get_last_error( ).

if rc ne 0.

  txt = cl_bsp_server_side_cookie=>get_last_error_name( ).

endif.


            
Method get_server_cookie_info

Signature

method GET_SERVER_COOKIE_INFO
  exporting
    COOKIES
    APPLICATION_NAMESPACE
    APPLICATION_NAME
    SESSION_ID
    USERNAME
    NAME

                           

Description

This method returns information about server cookies

Parameter

COOKIES

List of all cookies

APPLICATION_NAMESPACE

Namespace of the BSP application

SESSION_ID

Session ID

USERNAME

Name of the user

NAME

Name of cookie

APPLICATION_NAME

Name of BSP Application

Example
data: usr         type string,
      cookie_info type tsscookiei.

call method cl_bsp_server_side_cookie=>get_server_cookie_info
  exporting
    application_name = runtime->application_name
    username         = usr
  importing
    cookies          = cookie_info .


            

Methods get and set

Shorts forms for get_server_cookie and set_server_cookie.

These methods are wrapper methods that wrap the relevant long methods. This reduces the number of coding lines that a developer has to write.