Class CL_BSP_SERVER_SIDE_COOKIE 
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
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.
-
-
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 |
Note
All of the methods are in the visibility section public section.
Signature |
End of the 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
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.
Signature |
End of the 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
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.
Signature |
End of the 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
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
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
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.
Signature |
End of the code. |
|
Description |
This method returns the return code of the last call |
|
Parameters |
RC |
Return Code |
Syntax
data: rc type i,
txt type string.
rc = cl_bsp_server_side_cookie=>get_last_error( ).
Signature |
End of the code. |
|
Description |
This method returns the internal name of the exception of the last call |
|
Parameters |
NAME |
Internal error text |
Syntax
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.
Signature |
End of the 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
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 .
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.