Entering content frameObject documentation Class CL_BSP_SERVER_SIDE_COOKIE Locate the document in its SAP Library structure

Overview

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 subject to no such 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:

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 Interface

-

Superclass

-

Attributes

Attribute Name

Declaration Type

Description

CC_OK

Constants

Action was successful.

CC_WRONG_DATA_OBJECT

Constants

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

CC_PARAMETER_MISSING

Constants

Call parameters are missing.

CC_NOT_EXISTS

Constants

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.

Parameters

EXPIRY_TIME

Validity date (time): to time

EXPIRY_DATE

Validity date (date): to date

DATA_NAME

Data object name

SESSION_ID

Session ID

USERNAME

Name of user

APPLICATION_NAMESPACE

Name space of 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.

Parameters

NAME

Name of cookie

APPLICATION_NAME

Name of BSP application

APPLICATION_NAMESPACE

Name space of BSP application

USERNAME

Name of 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.

Parameters

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, 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, the system sets the relative validity duration to 23.59.

EXPIRY_DATE_REL

Validity duration in days

APPLICATION_NAMESPACE

Name space of 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-date.

add 1 to edate.   "valid for one day

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.

Parameters

RC

Returncode

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.

Parameters

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.

Parameters

COOCIES

List of all cookies.

APPLICATION_NAMESPACE

Name space of BSP application

SESSION_ID

Session ID

USERNAME

Name of 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 .

 

 

Leaving content frame