Monday, January 27, 2014

How to Use Traffic Signals in ALV Report ABAP Source Code


abap-code-to-display-traffic-signals-in-alv-report
How to Use Traffic Signals in ALV Report ABAP Source Code, SAP ABAP program to display traffic signals in ALV report.







ABAP Source Code to Display Traffic Signals in ALV Report


Here sapabapiq.com presenting a post on how to display traffic signals in ALV report using classes. This post will help ABAP technical programmers who are looking for the same kind of functionality. We suggest you to go through the post and read the complete article and copy the ABAP source code to editor and try to debug and understand the functionality of the program.


Program to Display Traffic Signals in ALV Report using ABAP



Source code begins here:


*&---------------------------------------------------------------------*
*& Report  ZALV_SAMPLE_CLASS
*&
*&---------------------------------------------------------------------*


REPORT  ZALV_SAMPLE_CLASS.


*******************************************************
**Types Declaration
*******************************************************


TYPES: BEGIN OF TY_CUST,
       CUSTID     TYPE ZCUST_MASTER4-CUSTID,
       CUSTNAME   TYPE ZCUST_MASTER4-CUSTNAME,
       ADDRESS    TYPE ZCUST_MASTER4-ADDRESS,
       CITY       TYPE ZCUST_MASTER4-CITY,
       STATE      TYPE ZCUST_MASTER4-STATE,
       COUNTRY    TYPE ZCUST_MASTER4-COUNTRY,
       PHNUM      TYPE ZCUST_MASTER4-PHNUM,
       EMAIL      TYPE ZCUST_MASTER4-EMAIL,
       FAX        TYPE ZCUST_MASTER4-FAX,
       STATUS     TYPE ZCUST_MASTER4-STATUS,
       LIGHTS(1)  TYPE C,
       END OF TY_CUST.


*******************************************************
**Data Declaration
*******************************************************


DATA: ALV_CONTAINER  TYPE REF TO CL_GUI_DOCKING_CONTAINER.
DATA: ALV_GRID       TYPE REF TO CL_GUI_ALV_GRID.
DATA: LAYOUT    TYPE LVC_S_LAYO.
DATA: FIELDCAT  TYPE LVC_T_FCAT.
DATA: WT_CUST TYPE STANDARD TABLE OF TY_CUST,
      WA_CUST TYPE TY_CUST.
DATA: VARIANT TYPE  DISVARIANT.
DATA: REPID TYPE SY-REPID.  REPID = SY-REPID.
PARAMETERS: P_CHECK.


*******************************************************
**Initialization Declaration
*******************************************************


INITIALIZATION.

***To Get data from the database table

  PERFORM GET_DETAILS.
  VARIANT-REPORT = SY-REPID.
  VARIANT-USERNAME = SY-UNAME.

***Perform to design the layout

  PERFORM LAYOUT.

*********************************************************
**Create object alv container
*********************************************************


  CHECK ALV_CONTAINER IS INITIAL.
  CREATE OBJECT ALV_CONTAINER
    EXPORTING
      REPID                       = SY-REPID
      DYNNR                       = SY-DYNNR
      SIDE                        = ALV_CONTAINER->DOCK_AT_LEFT
      EXTENSION                   = 1550
    EXCEPTIONS
      CNTL_ERROR                  = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      LIFETIME_ERROR              = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5
      OTHERS                      = 6.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


*********************************************************
**Create object alv Grid
*********************************************************


  CREATE OBJECT ALV_GRID
    EXPORTING
      I_PARENT = ALV_CONTAINER.

***Perform to d3esign field catalog

  PERFORM FIELDCATATALOG.

*********************************************************
**Call method set table for first display
*********************************************************


  CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
      I_STRUCTURE_NAME              = 'WT_CUST'
      IS_VARIANT                    = VARIANT
      I_SAVE                        = 'U'
      IS_LAYOUT                     = LAYOUT
    CHANGING
      IT_OUTTAB                     = WT_CUST
      IT_FIELDCATALOG               = FIELDCAT
    EXCEPTIONS
      INVALID_PARAMETER_COMBINATION = 1
      PROGRAM_ERROR                 = 2
      TOO_MANY_LINES                = 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.
  ENDIF.


*******************************************************
**Start-of-selection Declaration
*******************************************************


START-OF-SELECTION.

*&amp;---------------------------------------------------------------------*
*&amp;      Form  GET_DETAILS
*&amp;---------------------------------------------------------------------*
*       To get the data from th database table ZCUST_MASTER4
*----------------------------------------------------------------------*

FORM GET_DETAILS .
  SELECT * FROM ZCUST_MASTER4 INTO CORRESPONDING FIELDS OF TABLE WT_CUST.
  IF SY-SUBRC = 0.
    SORT WT_CUST ASCENDING  BY CUSTID.
  ENDIF.
ENDFORM.                    " GET_DETAILS

*&---------------------------------------------------------------------*
*&      Form  FIELDCATATALOG
*&---------------------------------------------------------------------*
*       Building Fieldcatlog for ALV
*----------------------------------------------------------------------*

FORM FIELDCATATALOG .
  DATA: LS_FCAT TYPE LVC_S_FCAT.
  REFRESH: FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Signal'.
  LS_FCAT-FIELDNAME  = 'LIGHTS'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '20'.
  LS_FCAT-COL_POS    = '1'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Customer Id'.
  LS_FCAT-FIELDNAME  = 'CUSTID'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '10'.
  LS_FCAT-FIX_COLUMN = 'X'.
  LS_FCAT-KEY        = 'X'.
  LS_FCAT-COL_POS    = '2'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'CustomerName '.
  LS_FCAT-FIELDNAME  = 'CUSTNAME'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '30'.
  LS_FCAT-FIX_COLUMN = 'X'.
  LS_FCAT-KEY        = 'X'.
  LS_FCAT-COL_POS    = '3'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Address'.
  LS_FCAT-FIELDNAME  = 'ADDRESS'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '40'.
  LS_FCAT-COL_POS    = '4'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'City'.
  LS_FCAT-FIELDNAME  = 'CITY'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '15'.
  LS_FCAT-COL_POS    = '5'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'State'.
  LS_FCAT-FIELDNAME  = 'STATE'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '15'.
  LS_FCAT-COL_POS    = '6'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Country'.
  LS_FCAT-FIELDNAME  = 'COUNTRY'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '15'.
  LS_FCAT-FIX_COLUMN = 'X'.
  LS_FCAT-KEY        = 'X'.
  LS_FCAT-COL_POS    = '7'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Phone number'.
  LS_FCAT-FIELDNAME  = 'PHNUM'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '14'.
  LS_FCAT-FIX_COLUMN = 'X'.
  LS_FCAT-KEY        = 'X'.
  LS_FCAT-COL_POS    = '8'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Email'.
  LS_FCAT-FIELDNAME  = 'EMAIL'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '50'.
  LS_FCAT-COL_POS    = '9'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Fax'.
  LS_FCAT-FIELDNAME  = 'FAX'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '15'.
  LS_FCAT-COL_POS    = '10'.
  APPEND LS_FCAT TO FIELDCAT.
  CLEAR: LS_FCAT.
  LS_FCAT-REPTEXT    = 'Status'.
  LS_FCAT-FIELDNAME  = 'STATUS'.
  LS_FCAT-REF_TABLE  = 'WT_CUST'.
  LS_FCAT-OUTPUTLEN  = '20'.
  LS_FCAT-COL_POS    = '11'.
  APPEND LS_FCAT TO FIELDCAT.
ENDFORM.                    " FIELDCATATALOG

*&amp;---------------------------------------------------------------------*
*&amp;      Form  LAYOUT
*&amp;---------------------------------------------------------------------*
*       Designing of ALV Layout
*----------------------------------------------------------------------*

FORM LAYOUT .

***If the customer's status is 'Inactive' the traffic signal will be 1 i.e,RED
***If the customer's status is 'Active'  the traffic signal will be 3 i.e, GREEN

  LOOP AT WT_CUST INTO WA_CUST.
    IF WA_CUST-STATUS = 'INACTIVE'.
      WA_CUST-LIGHTS  = '1'.
    ELSEIF WA_CUST-STATUS = 'ACTIVE'.
      WA_CUST-LIGHTS  = '3'.
    ENDIF.
    MODIFY WT_CUST FROM WA_CUST TRANSPORTING LIGHTS.
  ENDLOOP.
  LAYOUT-EXCP_FNAME = 'LIGHTS'.
ENDFORM.                    " LAYOUT

"You found the information helpful and want to say thanks? Your donation is enough to inspire us to do more. Thanks a bunch!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Categories

ABAP (1) ABAP Interview Questions (112) ABAP Open SQL Statements (1) ABAP Syntax Rules (6) ABAP WORKBENCH (2) ABAP-Interview-Questions (52) ALE IDOC (6) ALE IDOC Interview Questions (6) ale-idoc (6) ALE-IDOC-Interview-Questions (19) ALV Interview Questions (5) ALV-Interview-Questions (22) BADI (2) BAPI (1) BAPI Interview Questions (1) BAPI-Interview-Questions (14) BDC (6) BDC Interview Questions (6) BDC-Interview-Questions (9) big data (2) big data interview questions (1) Classical Reports Interview Question (3) Classical-Reports-Interview-Questions (22) Conditional Statements (1) Cross Applications (3) Cross-Applications (14) Data Dictionary (22) Data Type Questins (1) Data types (1) Data-Dictionary (48) Data-Type-Questins (6) Dialog programming (5) Dialog Programming Interview Questions (4) Dialog-Programming (30) DOMAIN Interview Questions (1) Domain-Interview-Questions (8) Function Module (2) hadoop (2) hadoop interview questions (2) hdfs (1) IDoc Tutorials (6) Interactive Report Interview Questions (4) Interactive-Reports-Interview-Questions (22) Internal Tables (1) interview questions (1) Lock Object Interview Questions (1) Lock-Objects-Interview-Questions (10) Logical Database (1) Modularization Interview Questions (4) Modularization-Interview-Questions (25) Module Pool Programming (5) Module-Pool-Programming (39) modules in sap (1) Object Oriented ABAP (19) Object Oriented ABAP Interview Questions (15) object-oriented-abap (2) Object-Oriented-ABAP-Interview-Questions (34) OOABAP (9) Reports (14) Reports Interview Questions (9) Reports-Interview-Questions (19) RFC (1) RFC Interview Questions (1) RFC-Interview-Questions (14) RICEF (1) RICEF Objects (1) SAP (4) SAP ABAP (4) SAP ABAP Interview Questions (42) SAP ABAP Introduction (46) SAP ABAP Message Types (2) SAP BADI Interview Questions (2) SAP Basics (71) SAP Books (2) SAP Certification (1) SAP CONSULTANTS (5) SAP CRM (1) SAP ENHANCEMENTS (3) SAP EXITS (2) SAP EXITS ( SAP ENHANCEMENTS ) Interview Questions (1) SAP Free Books (1) SAP HR (2) SAP Lock Object (1) sap modules (2) SAP Open SQL Statements (1) SAP R/3 Architecture (4) SAP Search help (1) SAP Smartforms (1) SAP Smartforms Interview Questions (2) SAP Tables (5) SAP Tcodes (10) SAP Views (1) SAP Webdynpro ABAP (12) SAP Work Processors (2) SAP Workflow (3) SAP-BADI-Interview-Questions (11) SAP-Enhancements (39) SAP-Exits (39) SAP-Exits-Enhancements-Interview Questions (3) SAP-HANA (1) SAP-HANA-Interview-Questions (1) SAP-Smartforms-Interview-Questions (2) SAP-Workflow (3) Scripts (3) Scripts Interview Questions (2) Scripts-Interview-Questions (32) Search Help Interview Questions (1) Search-Help-Interview-Questions (9) Smartforms (1) Table Maintenance Generator (1) Table-Maintenance-Generator (4) Tables in SAP (2) Tables Interview Questions (3) Tables-Interview-Questions (3) Type Group Interview Questions (1) Type-Group-Interview-Questions (7) Variable Declaration (1) Views Interview Questions (1) Views-Interview-Questions (5) Webdynpro (12) what is big data (1)

Protected Blog

 
This blog is not affiliated to SAP AG |SAP is trademark of SAP AG |The information collected from various sources use information with your own risk.