Splash Screen in ABAP using OO
With good tips from top SDN contributor
Thomas Jung
I made 2 function modules to suit my whims.

SAP being a serious Businesss Software you cannot have too many
JPGs floating around! One or two is fun.

In Function group uou need two screens 0806 & 2009 which are
essentially blank.
I put 2 title Bars - 0806 "SAP - JOB in Progress"; 2009 - "SAP - JOB
OVER!!"

Code listing for function: ZJNC_START_SPLASH
Description: Show Splash at Start
--------------------------------------------------------------------------------

FUNCTION zjnc_start_splash.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*" REFERENCE(CALLBACK) TYPE C
*"----------------------------------------------------------------------

* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.
MOVE callback TO piccallback.
TRANSLATE piccallback TO UPPER CASE.

PERFORM getpicurl.

CALL SCREEN 0806.

ENDFUNCTION.


Code listing for function: ZJNC_END_SPLASH
Description: Show Splash at End
--------------------------------------------------------------------------------

FUNCTION ZJNC_END_SPLASH.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(IMAGEFILE) TYPE C DEFAULT 'THANKS.JPG'
*" REFERENCE(WIDTH) TYPE I DEFAULT 415
*" REFERENCE(HEIGHT) TYPE I DEFAULT 274
*" REFERENCE(TIMEOUT) TYPE I DEFAULT 3
*"----------------------------------------------------------------------

* Global data declarations
MOVE imagefile TO g_name.
MOVE width TO picwidth.
MOVE height TO picheight.
MOVE timeout TO pictimeout.

PERFORM getpicurl.

CALL SCREEN 2009.

ENDFUNCTION.


Code listing for: LZUTILTOP

* TOP level Include of Function Group ZUTIL

* Author Jayanta Narayan Choudhuri
* Flat 302
* 395 Jodhpur Park
* Kolkata 700 068
* Email sss@cal.vsnl.net.in
* URL: http://www.geocities.com/ojnc

FUNCTION-POOL zutil. "MESSAGE-ID ..

TYPE-POOLS: abap.

DATA: graphic_url(255),
g_result TYPE i,
g_linesz TYPE i,
g_filesz TYPE i,
g_name(100).

TYPES: t_graphic_line(256) TYPE x.

DATA: graphic_line TYPE t_graphic_line,
graphic_table TYPE TABLE OF t_graphic_line.

DATA: picwidth TYPE i,
picheight TYPE i,
pictimeout TYPE i,
piccallback(60) TYPE c,
first TYPE boolean.


*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN DEFINITION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen DEFINITION.

PUBLIC SECTION.
EVENTS on_close.

METHODS constructor
IMPORTING
!i_num_secs TYPE i DEFAULT 5
!i_url TYPE c
!i_width TYPE i
!i_height TYPE i.

PROTECTED SECTION.

METHODS handle_end_of_timer
FOR EVENT finished OF cl_gui_timer.
PRIVATE SECTION.

DATA container TYPE REF TO cl_gui_dialogbox_container.
DATA image TYPE REF TO cl_gui_picture.
DATA timer TYPE REF TO cl_gui_timer.

ENDCLASS. "ZCL_ES_SPLASH_SCREEN DEFINITION

*---------------------------------------------------------------------*
* CLASS ZCL_ES_SPLASH_SCREEN IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS zcl_es_splash_screen IMPLEMENTATION.
METHOD constructor.

DATA: image_width TYPE i,
image_height TYPE i.

COMPUTE image_width = i_width + 30.
COMPUTE image_height = i_height + 50.

CREATE OBJECT container
EXPORTING
width = 10
height = 10
top = 10
left = 10
name = 'DialogSplash'.


CALL METHOD container->set_caption
EXPORTING
caption = g_name.

CREATE OBJECT image
EXPORTING
parent = container.

CALL METHOD image->load_picture_from_url
EXPORTING
url = i_url.

image->set_display_mode( image->display_mode_normal_center ).

cl_gui_cfw=>flush( ).

container->set_metric( EXPORTING metric = image->metric_pixel ).

DATA: myleft TYPE i,
mytop TYPE i.

COMPUTE myleft = ( 800 - image_width ) / 2.
COMPUTE mytop = ( 600 - image_height ) / 2.

IF myleft < 0.
MOVE 0 TO myleft.
ENDIF.

IF mytop < 0.
MOVE 0 TO mytop.
ENDIF.

container->set_position(
EXPORTING
height = image_height
left = myleft
top = mytop
width = image_width ).

cl_gui_cfw=>update_view( ).

CREATE OBJECT timer.
timer->interval = i_num_secs.

SET HANDLER me->handle_end_of_timer FOR timer.
timer->run( ).
cl_gui_cfw=>flush( ).

ENDMETHOD. "constructor

METHOD handle_end_of_timer.

* I wanted NAMASTE to remain until JOB was complete.
* IF container IS NOT INITIAL.
* container->free( ).
* CLEAR container.
* FREE container.
* ENDIF.
*
* IF timer IS NOT INITIAL.
* timer->free( ).
* CLEAR timer.
* FREE timer.
* ENDIF.
*
* cl_gui_cfw=>flush( ).

RAISE EVENT on_close.

ENDMETHOD. "handle_end_of_timer
ENDCLASS. "ZCL_ES_SPLASH_SCREEN IMPLEMENTATION

*---------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.
CLASS-METHODS: on_close FOR EVENT on_close OF zcl_es_splash_screen.
ENDCLASS. "lcl_event_handler DEFINITION

*---------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_close.
IF sy-dynnr = 2009.
LEAVE PROGRAM.
ELSE.
MOVE abap_false TO first.
PERFORM (piccallback) IN PROGRAM (sy-cprog).Advertisement

ENDIF.
ENDMETHOD. "on_close
ENDCLASS. "lcl_event_handler IMPLEMENTATION

DATA: splash TYPE REF TO zcl_es_splash_screen.

*&---------------------------------------------------------------------*
*& Module STATUS_0806 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_0806 OUTPUT.
IF first IS INITIAL.
first = abap_true.

SET TITLEBAR 'TITLE0806'.

CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.

SET HANDLER lcl_event_handler=>on_close FOR splash.

ENDIF.
ENDMODULE. " STATUS_0806 OUTPUT

*&---------------------------------------------------------------------*
*& Module STATUS_2009 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2009 OUTPUT.
IF first IS INITIAL.
first = abap_true.

SET TITLEBAR 'TITLE2009'.

CREATE OBJECT splash
EXPORTING
i_num_secs = pictimeout
i_url = graphic_url
i_width = picwidth
i_height = picheight.

SET HANDLER lcl_event_handler=>on_close FOR splash.

ENDIF.
ENDMODULE. " STATUS_2009 OUTPUT

*&---------------------------------------------------------------------*
*& Form getpicurl
*&---------------------------------------------------------------------*
FORM getpicurl.

OPEN DATASET g_name FOR INPUT IN BINARY MODE.

REFRESH graphic_table.
CLEAR g_filesz.

DO.
CLEAR graphic_line.
READ DATASET g_name INTO graphic_line ACTUAL LENGTH g_linesz.

ADD g_linesz TO g_filesz.

APPEND graphic_line TO graphic_table.
IF sy-subrc <> 0.
EXIT.
ENDIF.

ENDDO.

CLOSE DATASET g_name.

CLEAR graphic_url.

CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'IMAGE'
subtype = 'GIF'
TABLES
data = graphic_table
CHANGING
url = graphic_url
EXCEPTIONS
dp_invalid_parameter = 1
dp_error_put_table = 2
dp_error_general = 3
OTHERS = 4.


IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.

ENDFORM. "getpicurl