YPRACTICE_301

<< Click to Display Table of Contents >>

Navigation:  All About ABAP Technique > ABAP Source Code >

YPRACTICE_301

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

*& Report  YPRACTICE_301                                               *

*&                                                                     *

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

*&                                                                     *

*&                                                                     *

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

 

REPORT  ypractice_301                           .

 

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

* Tables

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

TABLES : mara, makt, t006a.

 

 

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

*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  LIKE STANDARD TABLE OF makt WITH HEADER LINE,

      gi_t006a LIKE 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.

 

* Html Report Required

TYPES: BEGIN OF gy_html_code,

         line_code(1000),

       END OF gy_html_code.

DATA: gi_html_code TYPE TABLE OF gy_html_code WITH HEADER LINE.

 

DATA: cc_report_display TYPE REF TO cl_gui_html_viewer,

      web_container TYPE REF TO cl_gui_custom_container.

 

DEFINE write_code1.

  clear gi_html_code.

  gi_html_code-line_code = &1.

  append gi_html_code.

END-OF-DEFINITION.

 

DEFINE write_code2.

  clear gi_html_code.

  concatenate &1 &2 into gi_html_code-line_code.

  append gi_html_code.

END-OF-DEFINITION.

 

DEFINE write_code3.

  clear gi_html_code.

  concatenate &1 &2 &3 into gi_html_code-line_code.

  append gi_html_code.

END-OF-DEFINITION.

 

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

*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

 

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

*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.

 

*======================================================================*

*MAIN PROGRAM

*Execute after Input Screen

*======================================================================*

START-OF-SELECTION.

  gv_width = 113.

  PERFORM fm_collect_data.

  PERFORM fm_process_data.

  PERFORM fm_display_data.

 

END-OF-SELECTION.

 

 

*======================================================================*

*SUB PROGRAM / SUB ROUTINE

*======================================================================*

 

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

*&      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.

 

*  "For SAP 4.6C

*  DATA : lv_total_data type i.

*  DESCRIBE TABLE gi_header LINES lv_total_data.

*  IF lv_total_data > 0.

 

  IF LINES( gi_header ) > 0." For SAP 4.7 above

*  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.

  ENDIF.

 

* Notes :

*  Avoid using inner join

 

ENDFORM.                    "FM_COLLECT_DATA

 

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

*&      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

 

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

*&      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

 

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

*&      Form  fm_initialization

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

*       text

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

FORM fm_initialization.

  IF cc_report_display IS INITIAL.

 

    CREATE OBJECT web_container

        EXPORTING

            container_name = 'CC_REPORT_DISPLAY'.

 

    CREATE OBJECT cc_report_display

         EXPORTING

              parent    = web_container.

    IF sy-subrc NE 0.

*

    ENDIF.

  ENDIF.

ENDFORM.                    "fm_initialization

 

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

*&      Form  fm_create_css

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

*       text

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

*      -->FV_CSS     text

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

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

 

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

*&      Form  fm_create_temp_html

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

*       text

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

*      -->FI_FILE    text

*      -->FV_URL     text

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

FORM fm_create_html_file TABLES fi_file STRUCTURE gi_html_code USING fv_url.

  CONDENSE fv_url NO-GAPS.

 

  CALL FUNCTION 'WS_DOWNLOAD'

    EXPORTING

      filename            = fv_url

      filetype            = 'ASC'

    TABLES

      data_tab            = fi_file

    EXCEPTIONS

      file_open_error     = 1

      file_write_error    = 2

      invalid_filesize    = 3

      invalid_table_width = 4

      invalid_type        = 5

      no_batch            = 6

      unknown_error       = 7

      OTHERS              = 8.

 

ENDFORM.                    "fm_create_temp_html

 

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

*&      Form  fm_load_html

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

*       text

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

*      -->URL        text

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

FORM fm_load_html USING fv_url.

  CALL METHOD cc_report_display->show_url

    EXPORTING

      url = fv_url.

ENDFORM.                    "fm_load_html

 

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

*&      Module  STATUS_2000  OUTPUT

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

*       text

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

MODULE status_2000 OUTPUT.

  SET PF-STATUS 'ST_2000'.

*  SET TITLEBAR 'xxx'.

 

ENDMODULE.                 " STATUS_2000  OUTPUT

 

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

*&      Module  USER_COMMAND_2000  INPUT

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

*       text

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

MODULE user_command_2000 INPUT.

  save_ok = ok_code.

  CLEAR ok_code.

 

  CASE save_ok.

    WHEN 'BACK'.

      LEAVE TO SCREEN 0.

    WHEN OTHERS.

 

  ENDCASE.

 

  CLEAR ok_code.

ENDMODULE.                 " USER_COMMAND_2000  INPUT