Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Display Information's in Chart with Interactive Functionality

$
0
0

Hi,

 

Display the information's in Chart Format, In the below Program i used Pie Chart with 3D to display the Material Information.

There are 19 different types of chart which we can use as per our requirement but the logic will be the same for all.

 

Here I made a very basic program with that I am displaying the material information's based on the given inputs.

 

As the below screen.

 

 

As per the input, the given months Material Quantity will display in Pie chart.

As the below screen.

 

 

 

In output the all materials are display with the area or quantity of information.

 

Once any one of the sector get click or selected by the cursor, the respective sector information will display as a pop-up message. follow the below screen.

as per the requirement we can write the logic here.

 

 

 

Source Code: -

 

REPORT  zprv_mat_info.

TABLES: mkpf, mseg.

 

 

TYPES:    BEGIN OF  s_mat,

            mblnr   TYPE mblnr,

            mjahr   TYPE mjahr,

            budat   TYPE budat,

            usnam   TYPE usnam,

            matnr   TYPE matnr,

            menge   TYPE menge_d,

          END OF    s_mat,

          BEGIN OF  s_info,

            matnr   TYPE matnr,

            menge   TYPE menge_d,

          END OF    s_info,

          BEGIN OF  S_MAKT,

            MATNR   TYPE MATNR,

            MAKTX   TYPE MAKT-MAKTX,

          END OF    S_MAKT.

 

DATA:     git_mat   TYPE STANDARD TABLE OF s_mat,

          git_info  TYPE STANDARD TABLE OF s_info,

          GIT_MAKT  TYPE STANDARD TABLE OF S_MAKT,

          gfl_mat   LIKE LINE OF git_mat,

          gfl_info  LIKE LINE OF git_info,

          GFL_MAKT  LIKE LINE OF GIT_MAKT.

 

DATA:     g_recs    TYPE i,

          G_MSG     TYPE STRING,

          G_STR     TYPE STRING,

          G_MATNR   TYPE MSEG-MATNR,

          g_title   TYPE string VALUE 'Information in Chart with Interactive',

          G_UCOMM   TYPE SY-UCOMM,

          G_LOAD    TYPE C,

          G_YEAR    TYPE MJAHR.

 

DATA:     CL_CONS   TYPE REF TO CL_GUI_PROPS_CONSUMER,

          G_MATX    TYPE CNTL_METRIC_FACTORS.

 

***************************CHART PARAMETERS**************************

DATA:   g_rfc       TYPE char32 VALUE 'IGS_RFC_DEST',

        g_bool      TYPE c,

        g_len       TYPE i,

        cl_html     TYPE REF TO cl_gui_html_viewer,

        cl_cart     TYPE REF TO cl_igs_chart,

        git_html    TYPE w3htmltabtype,

        gfl_html    TYPE w3html,

        git_igs     TYPE igs_data_tab,

        gfl_igs     TYPE igs_data,

        g_url       TYPE w3url,

        g_ctype     TYPE w3conttype,

        g_sub       TYPE w3conttype,

        git_mime    TYPE w3mimetabtype,

        git_htm     TYPE w3htmltabtype,

        G_SCRNX     TYPE I,

        G_SCRNY     TYPE I.

 

DATA:   git_event     TYPE cntl_simple_events,

        gfl_event     TYPE cntl_simple_event.

 

 

*----------------------------------------------------------------------*

*       CLASS CL_EVNT DEFINITION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS: cl_evnt DEFINITION.

 

  PUBLIC SECTION.

    METHODS:  m_sapevent           FOR EVENT  sapevent OF cl_gui_html_viewer

                                   IMPORTING  action frame getdata postdata query_table.

 

 

ENDCLASS.                    "CL_EVNT DEFINITION

 

*----------------------------------------------------------------------*

*       CLASS CL_EVNT IMPLEMENTATION

*----------------------------------------------------------------------*

*

*----------------------------------------------------------------------*

CLASS cl_evnt IMPLEMENTATION.

 

  METHOD: m_sapevent.

    G_MATNR = getdata.

    READ TABLE GIT_INFO INTO GFL_INFO WITH KEY MATNR = G_MATNR.

    IF SY-SUBRC EQ 0.

      G_STR = GFL_INFO-MENGE.

      READ TABLE GIT_MAKT INTO GFL_MAKT WITH KEY MATNR = G_MATNR.

      CONCATENATE 'Material ' GFL_MAKT-MAKTX ' Used Quanity in Year-' G_YEAR 'is:' G_STR INTO G_MSG SEPARATED BY SPACE.

      MESSAGE G_MSG TYPE 'I'.

    ENDIF.

  ENDMETHOD.                    "M_SAPEVENT

 

ENDCLASS.                    "CL_EVNT IMPLEMENTATION

 

DATA: cl_event TYPE REF TO cl_evnt.

 

***************************CHART PARAMETERS**************************

 

SELECTION-SCREEN:   BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

 

PARAMETERS:       p_mjahr TYPE mjahr OBLIGATORY.

SELECT-OPTIONS:   s_budat FOR mkpf-budat OBLIGATORY NO-EXTENSION.

 

SELECTION-SCREEN:   END OF BLOCK b1.

 

INITIALIZATION.

  CALL METHOD cl_igs_data=>is_registered_type

    EXPORTING

      destination             = g_rfc

      type                    = cl_igs_chart=>interpreter_type

    RECEIVING

      rval                    = g_bool

    EXCEPTIONS

      rfc_communication_error = 1

      rfc_system_error        = 2

      internal_error          = 3

      OTHERS                  = 4.

  IF sy-subrc <> 0.

    MESSAGE 'No "Chart" interpreter installed on IGS' TYPE 'E'.

  ENDIF.

 

START-OF-SELECTION.

  SELECT f~mblnr f~mjahr f~budat f~usnam g~matnr g~menge FROM mkpf AS f

                                                         INNER JOIN mseg AS g

                                                         ON f~mblnr EQ g~mblnr

                                                         AND f~mjahr EQ g~mjahr

                                                         INTO TABLE git_mat

                                                         WHERE f~mjahr EQ p_mjahr

                                                         AND   f~budat IN s_budat.

 

  DESCRIBE TABLE git_mat LINES g_recs.

  IF g_recs EQ 0.

    EXIT.

  ENDIF.

  LOOP AT git_mat INTO gfl_mat.

    MOVE-CORRESPONDING gfl_mat TO gfl_info.

    COLLECT gfl_info INTO git_info.

  ENDLOOP.

 

  DESCRIBE TABLE GIT_INFO LINES G_RECS.

  IF G_RECS NE 0.

    SELECT MATNR MAKTX FROM MAKT INTO TABLE GIT_MAKT

                       FOR ALL ENTRIES IN GIT_INFO

                       WHERE MATNR = GIT_INFO-MATNR AND SPRAS EQ SY-LANGU.

  ENDIF.

  G_YEAR = P_MJAHR.

END-OF-SELECTION.

  DESCRIBE TABLE git_info LINES g_recs.

  IF g_recs EQ 0.

    EXIT.

  ENDIF.

 

  PERFORM sub_makt_chart_info.

  PERFORM sub_converting_into_chart_info.

  CALL SCREEN 9000.

 

*&---------------------------------------------------------------------*

*&      Form  SUB_MAKT_CHART_INFO

*&---------------------------------------------------------------------*

*      Creating the Chart information based on the Internal Table Data

*----------------------------------------------------------------------*

FORM sub_makt_chart_info .

 

  LOOP AT git_info INTO gfl_info.

    CLEAR: gfl_igs.

    gfl_igs-groupid     = 'PRAVEER'.

    READ TABLE GIT_MAKT INTO GFL_MAKT WITH KEY MATNR = gfl_info-matnr.

    IF SY-SUBRC EQ 0.

      gfl_igs-x           = GFL_MAKT-MAKTX.

    ENDIF.

    gfl_igs-y           = gfl_info-menge.

    CONCATENATE 'href="SAPEVENT:CLICK_ON_ME?' gfl_info-matnr '"' INTO gfl_igs-extension.

    APPEND gfl_igs TO git_igs.

  ENDLOOP.

 

ENDFORM.                    " SUB_MAKT_CHART_INFO

*&---------------------------------------------------------------------*

*&      Form  SUB_CONVERTING_INTO_CHART_INFO

*&---------------------------------------------------------------------*

*       Converting the Chart information in HTML.

*----------------------------------------------------------------------*

FORM sub_converting_into_chart_info .

  IF cl_cart IS INITIAL.

    CREATE OBJECT cl_cart.

  ENDIF.

  PERFORM SUB_GET_SCREEN_RESOLUTION.

  CL_CART->HEIGHT  = G_SCRNY - 200.

  CL_CART->WIDTH   = G_SCRNX - 200.

  cl_cart->type    = cl_igs_chart=>co_type_PIE_3D.

  cl_cart->data = git_igs.

  REFRESH: git_htm, git_mime.

  CALL METHOD cl_cart->send

    IMPORTING

      content_type            = g_ctype

      content_length          = g_len

      content                 = git_mime

      imagemap                = git_htm

    EXCEPTIONS

      rfc_communication_error = 1

      rfc_system_error        = 2

      internal_error          = 3

      OTHERS                  = 4.

  IF sy-subrc NE 0.

    MESSAGE 'ERROR' TYPE 'E'.

  ENDIF.

  SPLIT g_ctype AT '/' INTO g_ctype g_sub.

ENDFORM.                    " SUB_CONVERTING_INTO_CHART_INFO

*&---------------------------------------------------------------------*

*&      Module  STATUS_9000  OUTPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

MODULE status_9000 OUTPUT.

  SET PF-STATUS '9000MENU'.

  SET TITLEBAR '9000TITLE' WITH g_title.

  IF G_LOAD EQ 'X'.

    EXIT.

  ENDIF.

  IF cl_html IS INITIAL.

    CREATE OBJECT cl_html

      EXPORTING

        parent = cl_gui_container=>default_screen.

  ENDIF.

  CALL METHOD cl_html->do_refresh.

  IF git_event IS INITIAL.

    CLEAR: gfl_event.

    gfl_event-eventid     = cl_html->m_id_sapevent.

    gfl_event-appl_event  = 'X'.

    APPEND gfl_event TO git_event.

  ENDIF.

  cl_gfw=>its_rfc_dest  = g_rfc.

 

  REFRESH: git_html.

  CALL METHOD cl_html->load_data

    EXPORTING

      type                   = g_ctype

      subtype                = g_sub

      size                   = g_len

    IMPORTING

      assigned_url           = g_url

    CHANGING

      data_table             = git_mime

    EXCEPTIONS

      dp_invalid_parameter   = 1

      dp_error_general       = 2

      cntl_error             = 3

      html_syntax_notcorrect = 4

      OTHERS                 = 5.

  IF sy-subrc <> 0.

    MESSAGE 'ERROR' TYPE 'E'.

  ENDIF.

 

  CONCATENATE  '<HTML><HEAD><TITLE>Chart By Praveer</TITLE></HEAD>'

     '<BODY BGCOLOR=#DEDEC8>'

     '<MAP NAME = CHART>' INTO gfl_html-line.

  APPEND gfl_html TO git_html.

  APPEND LINES OF git_htm TO git_html.

  CONCATENATE '</MAP>'

              '<IMG SRC="' g_url '" USEMAP=#CHART BORDER=0>'

              '</BODY></HTML>' INTO gfl_html-line.

  APPEND gfl_html TO git_html.

 

  CALL METHOD cl_html->set_registered_events

    EXPORTING

      events = git_event.

  CREATE OBJECT cl_event.

  SET HANDLER cl_event->m_sapevent FOR cl_html.

 

  CALL METHOD cl_html->load_data

    EXPORTING

      type         = 'TEXT'

      subtype      = 'HTML'

    IMPORTING

      assigned_url = g_url

    CHANGING

      data_table   = git_html.

 

  CALL METHOD cl_html->show_url

    EXPORTING

      url = g_url.

  G_LOAD  = 'X'.

ENDMODULE.                 " STATUS_9000  OUTPUT

*&---------------------------------------------------------------------*

*&      Form  SUB_GET_SCREEN_RESOLUTION

*&---------------------------------------------------------------------*

*       Fetching the Using System Screen Resoultion's

*----------------------------------------------------------------------*

form SUB_GET_SCREEN_RESOLUTION .

  CL_CONS = CL_GUI_PROPS_CONSUMER=>CREATE_CONSUMER( ).

  G_MATX = CL_CONS->GET_METRIC_FACTORS( ).

  G_SCRNX = G_MATX-SCREEN-X.

  G_SCRNY = G_MATX-SCREEN-Y.

endform.                    " SUB_GET_SCREEN_RESOLUTION

*&---------------------------------------------------------------------*

*&      Module  USER_COMMAND_9000  INPUT

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

module USER_COMMAND_9000 input.

CASE G_UCOMM.

     WHEN 'BACK'.

    LEAVE TO SCREEN 0.

     WHEN 'EXIT'.

    LEAVE PROGRAM.

ENDCASE.

endmodule.                 " USER_COMMAND_9000  INPUT

 

Create a Screen 9000 and UN-comment all screen code.

 

 

Thanks

Praveer Kumar Sen.


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>