Skip to main content

Display Traffic Light System in ALV Report

In the context of SAP ALV (ABAP List Viewer), a traffic light system is a visual representation used to indicate the status of certain data points. Typically, it uses color-coded indicators similar to traffic lights (red, yellow, green) to convey different states or conditions of the data. The traffic light system is used to quickly convey information at a glance, making it easier for users to understand the status of data without having to analyze detailed numbers or descriptions.

Steps

1. ALV needs to be displayed using FM ''REUSE_ALV_GRID_DISPLAY"
2. One field needs to be included to hold traffic light value in the internal table structure (type C length     1). Value 1 will be assigned for red light, 2 will be assigned for yellow light and 3 will be assigned         for green light.
            Example:
                    ***If the field is defined as ICON and included in internal table structure
                            ***For condition 1:
                                        ICON = 1. "Red Traffic Light
                            ***For condition 2:
                                        ICON = 2. "Yellow Traffic Light
                            ***For condition 3:
                                        ICON = 3. "Green Traffic Light
                         
3. One work area needs to be defined using 'SLIS_LAYOUT_ALV' structure.
            Example:
                      DATA: wa_layout TYPE SLIS_LAYOUT_ALV.

4. Now assign the internal table structure field (ICON) into layout work area (wa_layout) field "LIGHTS_FIELDNAME"
            Example:
                    wa_layout-lights_fieldname = 'ICON'.

5. Assign exporting parameters of the FM "IS_LAYOUT" as wa_layout.

            Example:
                    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
                            EXPORTING
                                    is_layout          = wa_layout

Code Example:
TYPE-POOLS: slis.  " SLIS contains all the ALV data types
*&---------------------------------------------------------------------*
*& Data Types
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_sbook.
        INCLUDE STRUCTURE sbook.
TYPES: icon TYPE c,  " Add field to hold traffic light value
       END OF ty_sbook.
*&---------------------------------------------------------------------*
*& Data Declaration
*&---------------------------------------------------------------------*
DATA: it_sbook     TYPE TABLE OF ty_sbook.
DATA: wa_sbook     TYPE ty_sbook.
DATA: it_fieldcat  TYPE slis_t_fieldcat_alv,
      wa_fieldcat  TYPE slis_fieldcat_alv.
DATA: is_layout    TYPE slis_layout_alv.
DATA: g_repid      TYPE sy-repid.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.
  g_repid = sy-repid.
*Fetch data from the database
  SELECT * UP TO 20 ROWS FROM sbook INTO TABLE it_sbook.

*Assign different traffic lights to each row based on condition
  LOOP AT it_sbook INTO wa_sbook.
    IF wa_sbook-luggweight LE 0.
      wa_sbook-icon = 1.  " Red Traffic Light
    ELSEIF wa_sbook-luggweight LE 10.
      wa_sbook-icon = 2.  " Yellow Traffic Light
    ELSE.
      wa_sbook-icon = 3.  " Green Traffic Light
    ENDIF.
    MODIFY it_sbook FROM wa_sbook TRANSPORTING icon.
    CLEAR: wa_sbook.
  ENDLOOP.

*Build field catalog
  wa_fieldcat-fieldname  = 'CARRID'.    " Fieldname in the data table
  wa_fieldcat-seltext_m  = 'Airline'.   " Column description in the output
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'CONNID'.
  wa_fieldcat-seltext_m  = 'Con. No.'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FLDATE'.
  wa_fieldcat-seltext_m  = 'Date'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'BOOKID'.
  wa_fieldcat-seltext_m  = 'Book. ID'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURAM'.
  wa_fieldcat-seltext_m  = 'Price'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'FORCURKEY'.
  wa_fieldcat-seltext_m  = 'Currency'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'LUGGWEIGHT'.
  wa_fieldcat-seltext_m  = 'Weight'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

  wa_fieldcat-fieldname  = 'WUNIT'.
  wa_fieldcat-seltext_m  = 'Unit'.
  APPEND wa_fieldcat TO it_fieldcat.
  CLEAR wa_fieldcat.

*Fill layout info.
*Fill traffic lights field name in the ALV layout
  is_layout-lights_fieldname = 'ICON'.

*Pass data and field catalog to ALV function module to display ALV list
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = g_repid
      is_layout          = is_layout
      it_fieldcat        = it_fieldcat
    TABLES
      t_outtab           = it_sbook
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.
     

Comments

Popular posts from this blog

Adding New Input Fields to SAP Confirmations Screen (CO11N/COR6N) Without Coding

It is possible to add additional input fields in the SAP production order confirmation screen without coding. We can do this just adding fields to a structure which is included in AFRU table (Confirmation table). Process Steps Step 1:   Go to below customizing path. SIMG > Production > Shop Floor Control > Operations > Confirmation > Single Screen Entry > Define Single Screen Entry for Confirming Production Order Step 2:  Double click on the standard profile. Add "Customer Specific Fields of CI_AFRU" in the detail area. Step 3:  Go to default tab. Select an option from the "Customer Specific Fields" area. Then click on save button. Step 4:  Go to transaction code "SE11". Select database table and put "AFRU" and click on change button. Step 5:  Go to the include marked in the screenshot and double click on the data element of the include. Step 6:  Double click on "CI_AFRU". Step 7:  Click on "Yes" in the pop u

SAP Fiori Data Migration Cockpit Freezing Problem

SAP Data Migration Cockpit is a tool that is used to migrate data from legacy systems to SAP systems. It provides a user-friendly interface for data migration, allowing users to extract, transform, and load data from different sources. Problem Sometimes we face problem during uploading data through data migration cockpit. Problem is data migration cockpit get stuck or frozen while executing a specific task.  Solution To solve this problem we have to execute a program manually through SAP GUI. Step 1: Go to SAP transaction code SE38 Step 2: Paste the program name "/LTB/JOB_DISPATCHER" and then press the execute button. Step 3: Now check the migration cockpit. Problem solved.

SAP Production Order Confirmation Table List

SAP Production Order Confirmation is a process that enables companies to confirm the completion of production orders in the SAP system. The confirmation process allows companies to track and manage the progress of production orders, as well as record the actual quantities of materials used and the time taken to complete the production order. Production order confirmation tables are listed here. AFFW                     Goods Movements with Errors from Confirmation AFFWPRO           Log of deleted AFFW entries AFRC                     Incorrect cost calculations from confirmation AFRD                     Default values for collective confirmation AFRH                     Header information for confirmation pool AFRH_DEL           Backup Copy of Header Information for Conf AFRP0                     Table of planned changes for confirmation AFRP1                   Table of planned changes to conf.: Automatic AFRP2                   Table of planned changes for confirmation AFRP3