Status Icons 

Status icons are display elements that you can use to represent the state of a program graphically. It is possible to use any SAPgui icon. However, in practice, you should only use the icons for status display listed in the SAP Style Guide.

You can only create status icons in the graphical Screen Painter. When you create one, you assign a name and a screen field, called a status field, to it. The visible length of the screen field determines the amount of space that the icon can take up on the screen. As well as the icon itself, you can also place text in the field. The actual length (defLg) of the status field must be long enough for the internal representation of the icon, plus any text and quickinfo text that you specify. When you create the status icon in the Screen Painter, a placeholder appears on the screen. You must specify the icon itself and its text and quickinfo text in the PBO event of your ABAP program.

In order to define the icon in your ABAP program, you must create a field with the same name as the status field on the screen and the ABAP Dictionary type ICONS-TEXT. You can then fill this field with the required technical information in the PBO event. When the screen is displayed, the information is transferred to the status field and the icon appears.

To fill the field in your ABAP program, use the function module ICON_CREATE. It has the following import parameters:

The name of the required icon. These are listed in the SAP Style Guide, in the include program <ICON>, or the corresponding input help in the Screen Painter or Menu Painter.

This parameter allows you to enter a text that will appear after the icon on the screen.

In this parameter, you can specify a quickinfo text, which appears whenever the mouse pointer is positioned over the icon.

This flag switches the quickinfo display on or off.

The function module converts these parameters into a single string, which is returned in the export parameter RESULT. When you assign the RESULT parameter to the status field, it contains all the information required to display the status icon.

Status icons

REPORT DEMO_DYNPRO_STATUS_ICONS.

DATA VALUE TYPE I VALUE 1.

DATA: STATUS_ICON TYPE ICONS-TEXT,
      ICON_NAME(20),
      ICON_TEXT(10).

CALL SCREEN 100.

MODULE SET_ICON OUTPUT.

  SET PF-STATUS 'SCREEN_100'.

CASE VALUE.
    WHEN 1.
      ICON_NAME = 'ICON_GREEN_LIGHT'.
      ICON_TEXT =  TEXT-003.
    WHEN 2.
      ICON_NAME = 'ICON_YELLOW_LIGHT'.
      ICON_TEXT =  TEXT-002.
    WHEN 3.
      ICON_NAME = 'ICON_RED_LIGHT'.
      ICON_TEXT =  TEXT-001.
  ENDCASE.

  CALL FUNCTION 'ICON_CREATE'
       EXPORTING
            NAME                  = ICON_NAME
            TEXT                  = ICON_TEXT
            INFO                  = 'Status'
            ADD_STDINF            = 'X'
      IMPORTING
            RESULT                =  STATUS_ICON
      EXCEPTIONS
            ICON_NOT_FOUND        = 1
            OUTPUTFIELD_TOO_SHORT = 2
            OTHERS                = 3.

  CASE SY-SUBRC.
    WHEN 1.
      MESSAGE E888(BCTRAIN) WITH TEXT-004.
    WHEN 2.
      MESSAGE E888(BCTRAIN) WITH TEXT-005.
    WHEN 3.
      MESSAGE E888(BCTRAIN) WITH TEXT-006.
  ENDCASE.

ENDMODULE.

MODULE CANCEL INPUT.
  LEAVE PROGRAM.
ENDMODULE.

MODULE CHANGE.
CASE VALUE.
    WHEN 1.
      VALUE = 2.
    WHEN 2.
      VALUE = 3.
    WHEN 3.
      VALUE = 1.
  ENDCASE.
ENDMODULE.

The next screen (statically defined) for screen 100 is itself, and it has the following layout:

The screen contains a status field called STATUS_ICON with a visible length of 12 and defined length 26. The status icon and the space for the text are represented by placeholders in the Screen Painter.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.
  MODULE SET_ICON.

PROCESS AFTER INPUT.
  MODULE CANCEL AT EXIT-COMMAND.
  MODULE CHANGE.

The dialog module SET_ICON passes various values to the function module ICON_CREATE, depending on the values of the fields in the program. The status field STATUS_ICON is filled with the contents of the export parameter RESULT of the function module. The corresponding icon with its text and quickinfo is then displayed on the screen. When the user chooses Continue, the contents of the field VALUE are changed in the PAI, and consequently a new icon is defined in the PBO event. The following icons and texts are displayed:

  Low

  Middle

  High

The quickinfo text is ‘Status’ for all of the icons.