Show TOC

Background documentationClass CL_BSP_SERVER_SIDE_COOKIE Locate this document in the navigation structure

 

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:

  • as a field or

  • as a structure or

  • as an internal table.

Caution 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.

End of the caution.

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 Note

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

End of the note.

Class CL_BSP_SERVER_SIDE_COOKIE is contained in the package SBSP_RUNTIME.

Inheritance Hierarchy/Interface Composition
Implemented Interface

-

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 Note

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

End of the note.
Method get_server_cookie

Signature

Syntax Syntax

  1. method GET_SERVER_COOKIE
      exporting
        NAME
        EXPIRY_TIME
        EXPIRY_DATE
        SESSION_ID
        USERNAME
        APPLICATION_NAMESPACE
        APPLICATION_NAME
        DATA_NAME
        DATA_VALUE
    
End of the source code.

Description

This method gets a server cookie

Parameters

EXPIRY_TIME

Validity date (time): To time

EXPIRY_DATE

Validity date (time): To date

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

Syntax Syntax

Example:

  1. 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.
    
    
End of the source code.
Method delete_server_cookie

Signature

Syntax Syntax

  1. method DELETE_SERVER_COOKIE
      exporting
        NAME
        APPLICATION_NAME
        APPLICATION_NAMESPACE
        USERNAME
        SESSION_ID
    
End of the source code.

Description

This method deletes a server cookie

Parameters

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

Syntax Syntax

Example:

  1. 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.
    
    
End of the source code.
Method set_server_cookie

Signature

Syntax Syntax

  1. 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
    
End of the source code.

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

End of the note.

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

End of the note.

EXPIRY_DATE_REL

Validity duration in days

APPLICATION_NAMESPACE

Namespace of the BSP application

APPLICATION_NAME

Name of BSP Application

NAME

Name of cookie

Syntax Syntax

Example:

  1. 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.
    
    
End of the source code.
Method get_last_error

Signature

Syntax Syntax

  1. method GET_LAST_ERROR
      importing
        RC
    
End of the source code.

Description

This method returns the return code of the last call

Parameters

RC

Return Code

Syntax Syntax

  1. data: rc  type i,
          txt type string.
    
    rc = cl_bsp_server_side_cookie=>get_last_error( ).
    
    
End of the source code.
Method get_last_error_name

Signature

Syntax Syntax

  1. method GET_LAST_ERROR_NAME
      importing
        NAME
    
End of the source code.

Description

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

Parameters

NAME

Internal error text

Syntax Syntax

Example:

  1. 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.
    
    
End of the source code.
Method get_server_cookie_info

Signature

Syntax Syntax

  1. method GET_SERVER_COOKIE_INFO
      exporting
        COOKIES
        APPLICATION_NAMESPACE
        APPLICATION_NAME
        SESSION_ID
        USERNAME
        NAME
    
End of the source code.

Description

This method returns information about server cookies

Parameters

COOCIES

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

Syntax Syntax

Example:

  1. 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 .
    
    
End of the source code.
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.