Report (303)

<< Click to Display Table of Contents >>

Navigation:  All About ABAP Technique > English > ABAP Report > Html >

Report (303)

Objective

Creating Report

Result

Source Code

Transaction Code

SE38 - ABAP Editor

Tables

BKPF - Accounting Document Header

VBAK - Sales Order Header

Support

Chart Example Code

Contributor

Ervan Prayogo ( ervan.prayogo@gmail.com )

 

Sometimes in addition to reports in the form of tabular data, we also need a report in the form of charts or graphs. Report in the form of graphs simplify the management to see visually from numeric values. In any case, representing data in a graph can make easy to compare data, analyze trends, visualize results. There is several chart reporting tools such as Fushionchart, JPGraph,  Jasper Report, etc. In this session, chart report will created in HTML using web reporting tools : FusionChart.

 

Prerequisite File.

1. Download source of Chart Example Code.

2. Copy folder grafik contains Fusioncharts files into directory C:\.

 

Creating Report

1.Open SE38

2.Copy Program "YPRACTICE_301" to "YPRACTICE_303"

ar0296

3.Select All Object.

ar0297

 

Click Local Object to save in local object.

ar0298

 

4.Change Program "YPRACTICE_303"

5.Open Goto > Attributes, and change Title with "303 – Report Sales Graphical"

6.Modified Report Declaration

Before

REPORT  ypractice_301.

After

REPORT  ypractice_303.

 

7.Modified Tables.

Before.

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

* Tables                                                                            *

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

TABLES : mara, makt, t006a.

 

After.

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

* Tables                                                                             *

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

TABLES : bkpf, vbak.

 

8.Modified Global variables.

 

Before.

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

*GLOBAL VARIABLE DECRALATION                                                        *

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

TYPES: BEGIN OF ty_header,

        matkl LIKE mara-matkl,  " Material Group

        matnr LIKE mara-matnr,  " Material Number

        maktx LIKE makt-maktx,  " Material Descriptiop

        bismt LIKE mara-bismt,  " Old material number

        meins LIKE mara-meins,  " Base Unit of Measure

        mseht LIKE t006a-mseht, " Unit of Measurement Text

      END OF ty_header.

 

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,

          gi_makt TYPE STANDARD TABLE OF makt WITH HEADER LINE,

          gi_t006a TYPE STANDARD TABLE OF t006a WITH HEADER LINE.

 

DATA: gv_width TYPE i.  " Width of list

 

DATA: ok_code LIKE sy-ucomm,

save_ok TYPE sy-ucomm.

 

After.

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

* GLOBAL VARIABLE DECRALATION                                                   *

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

TYPES: BEGIN OF ty_header,

        bulan TYPE n LENGTH 2,

        total LIKE vbak-netwr,

      END OF ty_header.

 

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,

           gi_vbak LIKE STANDARD TABLE OF vbak WITH HEADER LINE.

 

DATA: gv_width TYPE i.  " Width of list

 

DATA: ok_code LIKE sy-ucomm,

      save_ok TYPE sy-ucomm.

 

 

9.Change the Input Screen / Selection.

Before.

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

*Input Screen/Selection

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

SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101. "Declare Group Box 1

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(14) text_102 FOR FIELD so_matkl.

SELECT-OPTIONS so_matkl FOR mara-matkl OBLIGATORY DEFAULT '001'.

SELECTION-SCREEN END OF LINE.

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(14) text_103 FOR FIELD so_matnr.

SELECT-OPTIONS so_matnr FOR mara-matnr.

SELECTION-SCREEN END OF LINE.

 

SELECTION-SCREEN END OF BLOCK groupbox1.                              "End Group Box 1

 

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201. "Declare Group Box 2

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname.

PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT 'C:\abap_report_01.html'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK groupbox2.                              "End Group Box 2

 

After.

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

*Input Screen/Selection

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

SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101. "Declare Group Box 1

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(14) text_102 FOR FIELD so_gjahr.

SELECT-OPTIONS so_gjahr FOR bkpf-gjahr OBLIGATORY DEFAULT '2000' NO-EXTENSION NO INTERVALS.

SELECTION-SCREEN END OF LINE.

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(14) text_103 FOR FIELD so_waerk.

SELECT-OPTIONS so_waerk FOR vbak-waerk OBLIGATORY DEFAULT 'USD' NO-EXTENSION NO INTERVALS.

SELECTION-SCREEN END OF LINE.

 

SELECTION-SCREEN END OF BLOCK groupbox1.                              "End Group Box 1

 

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201. "Declare Group Box 2

 

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname.

PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT 'C:\grafik\grafik_test.html'.

SELECTION-SCREEN END OF LINE.

 

SELECTION-SCREEN END OF BLOCK groupbox2.                              "End Group Box 2

 

 

10.Change the initialization.

Before.

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

*INITIALIZATION

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

INITIALIZATION.

  text_101 = 'Selection Parameter'.

  text_102 = 'Material Group'.

  text_103 = 'Material Number'.

 

  text_201 = 'Save Html File'.

  text_202 = 'File Location'.

 

  PERFORM fm_initialization.

 

After.

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

*INITIALIZATION

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

INITIALIZATION.

  text_101 = 'Selection Parameter'.

  text_102 = 'Year'.

  text_103 = 'Currency'.

 

  text_201 = 'Save Html File'.

  text_202 = 'File Location'.

 

  PERFORM fm_initialization.

 

 

11.Change form collect data.

Before.

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

*&      Form  fm_collect_data

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

*       text

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

FORM fm_collect_data.

*  Collect Master Material

  SELECT matnr matkl bismt meins

    INTO CORRESPONDING FIELDS OF TABLE gi_header

  FROM mara

  WHERE

    matkl IN so_matkl AND

    matnr IN so_matnr.

 

*  Collect Material Decription

  SELECT matnr maktx

    INTO CORRESPONDING FIELDS OF TABLE gi_makt

  FROM makt

    FOR ALL ENTRIES IN gi_header

  WHERE

    matnr = gi_header-matnr AND

    spras = sy-langu.

 

*  Collect Measurement Text

  SELECT msehi mseht

    INTO CORRESPONDING FIELDS OF TABLE gi_t006a

  FROM t006a

    FOR ALL ENTRIES IN gi_header

  WHERE

    msehi = gi_header-meins AND

    spras = sy-langu.

 

* Notes :

*  Avoid using inner join

 

ENDFORM.                    "FM_COLLECT_DATA

 

After.

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

*&      Form  fm_collect_data

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

*       text

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

FORM fm_collect_data.

  DATA : lv_low LIKE sy-datum,

         lv_high LIKE sy-datum.

 

  CONCATENATE so_gjahr-low '01' '01' INTO lv_low.

  CONCATENATE so_gjahr-low '12' '31' INTO lv_high.

 

*  Collect

  SELECT vbeln audat netwr waerk

    INTO CORRESPONDING FIELDS OF TABLE gi_vbak

  FROM vbak

  WHERE

    ( audat BETWEEN lv_low AND lv_high ) AND

    waerk IN so_waerk.

 

 

ENDFORM.                    "FM_COLLECT_DATA

 

12.Change fm_process_data

Before.

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

*&      Form  FM_PROCESS_DATA

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

*       text

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

FORM fm_process_data.

*Get other requirement information

  LOOP AT gi_header.

*    Get Material Description

    READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.

    IF sy-subrc = 0.

      gi_header-maktx = gi_makt-maktx.

    ENDIF.

 

*    Get Measurement Text

    READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.

    IF sy-subrc = 0.

      gi_header-mseht = gi_t006a-mseht.

    ENDIF.

 

    MODIFY gi_header.

  ENDLOOP.

 

ENDFORM.                    "FM_PROCESS_DATA

 

After.

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

*&      Form  FM_PROCESS_DATA

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

*       text

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

FORM fm_process_data.

  DATA : lv_date1 LIKE sy-datum,

         lv_date2 LIKE sy-datum,

         lv_bulan TYPE n LENGTH 2,

         lv_total LIKE vbak-netwr.

 

  DO 12 TIMES.

    ADD 1 TO lv_bulan.

    CONCATENATE so_gjahr-low lv_bulan '01' INTO lv_date1.

    CALL FUNCTION 'SG_PS_GET_LAST_DAY_OF_MONTH'

      EXPORTING

        day_in            = lv_date1

      IMPORTING

        last_day_of_month = lv_date2.

 

    CLEAR : gi_header, lv_total.

    SORT gi_vbak BY audat.

    LOOP AT gi_vbak WHERE audat BETWEEN lv_date1 AND lv_date2.

      ADD gi_vbak-netwr TO lv_total.

    ENDLOOP.

 

    gi_header-bulan = lv_bulan.

    gi_header-total = lv_total.

    APPEND gi_header.

 

  ENDDO.

 

ENDFORM.                    "FM_PROCESS_DATA

 

13.Change fm_display_data.

Before.

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

*&      Form  fm_display_data

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

*       text

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

FORM fm_display_data.

  REFRESH gi_html_code.

 

  PERFORM fm_create_css.

  write_code1 '<body>'.

  write_code1 '<table width="100%" border="0" cellspacing="2" cellpadding="0">'.

 

*  Create Header Text

  write_code1 '  <tr bgcolor="#999999" class="styleHeader">'.

  write_code1 '    <td>Mat. Group</td>'.

  write_code1 '    <td>Mat. No.</td>'.

  write_code1 '    <td>Description</td>'.

  write_code1 '    <td>Old Mat. No.</td>'.

  write_code1 '    <td>Base Unit of Measure</td>'.

  write_code1 '    <td>Measure</td>'.

  write_code1 '  </tr>'.

 

 

*  Display Data to Screen

  LOOP AT gi_header.

    write_code1 '  <tr bgcolor="#EBEBEB">'.

    write_code3 '    <td class="style1">' gi_header-matkl '</td>'.

    write_code3 '    <td class="style1">' gi_header-matnr '</td>'.

    write_code3 '    <td class="style2">' gi_header-maktx '</td>'.

    write_code3 '    <td class="style2">' gi_header-bismt '</td>'.

    write_code3 '    <td class="style1">' gi_header-meins '</td>'.

    write_code3 '    <td class="style2">' gi_header-mseht '</td>'.

    write_code1 '  </tr>'.

  ENDLOOP.

 

*  End of Line

  write_code1 '</table>'.

  write_code1 '</body>'.

 

  PERFORM fm_create_html_file TABLES gi_html_code USING p_fname.

  PERFORM fm_load_html USING p_fname.

 

  CALL SCREEN 2000.

 

ENDFORM.                    "fm_display_data

 

After.

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

*&      Form  fm_display_data

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

*       text

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

FORM fm_display_data.

 

  DATA : lv_total(20),

         title(50),

         lv_bulan TYPE n LENGTH 2.

 

  DATA : li_tmp LIKE STANDARD TABLE OF gi_html_code WITH HEADER LINE.

 

  REFRESH gi_html_code.

  CONCATENATE 'Report Grafik Penjualan Tahun &nbsp' so_gjahr-low INTO title.

 

*  Create Header Text and referencing source of JQuery

  write_code1 '<html>'.

  write_code1 '<head>'.

  write_code1 '<script type="text/javascript" src="JS/jquery-1.4.js"></script>'.

  write_code1 '<script type="text/javascript" src="JS/jquery.fusioncharts.js"></script>'.

  perform  fm_create_css.

  write_code1 '</head>'.

  write_code1 '<body>'.

  write_code1 '<center>'.

  write_code3 '<h2>' title '</h2>'.

 

*  Display Data to Screen

  write_code1 '<table id="myHTMLTable" border="1" align="center" class="table_data">'.

  write_code1 '<tr><th>&nbsp;</th>'.

 

  DO 12 TIMES.

    ADD 1 TO lv_bulan.

    write_code3 '                 <th>' lv_bulan '</th>'.

  ENDDO.

 

  write_code1 '</tr>'.

  write_code3 '                <tr> <th>' so_gjahr-low '</th>'.

 

  LOOP AT gi_header.

    REFRESH : li_tmp.

 

* Eliminate thousand separator and change decimals separator

    WRITE gi_header-total TO lv_total CURRENCY so_waerk-low.

    REPLACE ALL OCCURRENCES OF '.' IN lv_total WITH ''.

    CONDENSE lv_total.

    REPLACE ALL OCCURRENCES OF ',' IN lv_total WITH '.'.

 

    write_code3 '                 <th>' lv_total '</th>'.

  ENDLOOP.

 

  write_code1 '            </tr>'.

  write_code1 '        </table>'.

 

 

*  Java Script for retrieving data from HTML tables.

  write_code1 '        <script type="text/javascript">'.

  write_code1 '        $("#myHTMLTable").convertToFusionCharts({'.

  write_code1 '                swfPath: "",'.

  write_code1 '                type: "MSColumn3D",'.

  write_code1 '                data: "#myHTMLTable",'.

  write_code1 '                dataFormat: "HTMLTable",'.

  write_code1 '             width: "600",'.

  write_code1 '             height: "300"'.

  write_code1 '        });'.

  write_code1 '        </script>'.

 

*  End of Line

  write_code1 '        </center>'.

  write_code1 '</body>'.

  write_code1 '</html>'.

 

  PERFORM fm_create_html_file TABLES gi_html_code USING p_fname.

  PERFORM fm_load_html USING p_fname.

  CALL SCREEN 2000.

 

ENDFORM.                    "fm_display_data

 

14.Now change the CSS style on fm_create_css.

Before.

FORM fm_create_css.

  write_code1 '<style type="text/css">'.

  write_code1 '<!--'.

  write_code1 '.styleHeader {'.

  write_code1 '        font-family: Arial, Helvetica, sans-serif;'.

  write_code1 '        font-size: 12px;'.

  write_code1 '        font-weight: bold;'.

  write_code1 '        text-align: center;'.

  write_code1 '                                  }'.

  write_code1 '.style1 {'.

  write_code1 '        font-family: Arial, Helvetica, sans-serif;'.

  write_code1 '        font-size: 12px;'.

  write_code1 '        text-align: center;'.

  write_code1 '                                  }'.                                        

  write_code1 '.style2 {'.

  write_code1 '        font-family: Arial, Helvetica, sans-serif;'.

  write_code1 '        font-size: 12px;'.

  write_code1 '        text-align: left;'.

  write_code1 '                                  }'.                                                

  write_code1 '-->'.

  write_code1 '</style>'.

ENDFORM.                    "fm_create_css

 

After.

FORM fm_create_css.

  write_code1 '<style type="text/css">'.

  write_code1 '<!--'.

  write_code1 '.table_data {'.

  write_code1 '        font-family: Arial, Helvetica, sans-serif;'.

  write_code1 '        font-size: 12px;'.

  write_code1 '      border: 1px solid #909090;'.

  write_code1 '      border-collapse: collapse;'.

  write_code1 '                                  }'.

  write_code1 '-->'.

  write_code1 '</style>'.

ENDFORM.

 

15.Activate and run.

16.Create T-code YP303

17.Finished.

 

Result.

Input Selection

ar0299

Output

ar0300