Pseudo-Randomization and the logo of the day
In order to fresh up the daily work, a customs control for a picture was created on a dynpro. Details for doing so can be found in the sample report SAP_PICTURE_DEMO.
As it would be boring to watch the same picture (in this case: logo) all the time, ten different versions of the logo were uploaded to the SAP Web Repository using transaction SMW0 (binary objects, file type jpg) with the purpose of randomly selecting one of those ten after each start of the transaction.
The main problem was the random number function of SAP. Despite the fact one can initialize the randomization via calling function module RANDOM_INITIALIZE, each new call of the transaction will produce the same order of “random” numbers, therefore, in my case, always the same logo would be selected and displayed.
Within a session, there would be random numbers. The solution I chose was to add some “salt” by using a pseudo-randomization, based on SY-UZEIT. I limited it to minutes and seconds, so in the worst case, 5959 calls of the random function woud be executed.
The coding for doing this is provided below:
DATA:
gv_url TYPE cndp_url, “URL to logo
cntrl_pict TYPE REF TO cl_gui_picture,
gv_index TYPE datatype-integer2, “Random index for picture
gv_help TYPE i, “Help variable for randomization
gv_objid TYPE w3objid. “Object-ID in SAP-Web-Repository
…
CLEAR gv_index.
gv_help = sy-uzeit+2(4). “Take only minutes and seconds, so max. 5959 calls
DO gv_help TIMES.
CALL FUNCTION ‘RANDOM_I2’ “Select one of ten stored pictures
EXPORTING
rnd_min = 1
rnd_max = 10
IMPORTING
rnd_value = gv_index.
ENDDO.
WRITE gv_index TO gv_objid LEFT-JUSTIFIED NO-SIGN.
IF gv_index < 10.
CONCATENATE ‘RANDOM_PIC_0’ gv_objid INTO gv_objid.
ELSE.
CONCATENATE ”RANDOM_PIC_’ gv_objid INTO gv_objid.
ENDIF.
CALL FUNCTION ‘DP_PUBLISH_WWW_URL’
EXPORTING
objid = gv_objid
lifetime = cndp_lifetime_transaction
IMPORTING
url = gv_url
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
CALL METHOD cntrl_pict->load_picture_from_url_async
EXPORTING
url = gv_url.
ENDIF.