Wednesday, 31 July 2013

Displaying HTML file in SAP

CALL SCREEN 0100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  DATA :gt_html type w3htmltab,
         gv_title TYPE sy-title.
  DATA : gr_html TYPE REF TO cl_gui_html_viewer,
         gr_cont TYPE REF TO cl_gui_custom_container.
*DATA: html TYPE w3htmltab.
DATA: html TYPE ZCHAR6000_T.
DATA: LV_HTML TYPE string.
DATA: lf_html TYPE string.
  PERFORM HTML.
SET PF-STATUS 'HTML'.
SET TITLEBAR 'HTML_TITLE'." WITH gv_title.

DATA: lv_url TYPE char255.
CREATE OBJECT GR_CONT
  EXPORTING
*    PARENT                      = PARENT
    CONTAINER_NAME              = 'HTML_CONT'
*    STYLE                       = STYLE
*    LIFETIME                    = LIFETIME_DEFAULT
*    REPID                       = SY-REPID
*    DYNNR                       = SY-DYNNR
*    NO_AUTODEF_PROGID_DYNNR     = NO_AUTODEF_PROGID_DYNNR
  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 gr_html
  EXPORTING
*    shellstyle         = shellstyle
    PARENT             = GR_CONT
*    lifetime           = '1'
*    saphtmlp           = 'X'
*    uiflag             = '6'
*    name               = name
*    saphttp            = saphttp
*    query_table_disabled = 'X'
  EXCEPTIONS
    cntl_error         = 1
    cntl_install_error = 2
    dp_install_error   = 3
    dp_error           = 4
    others             = 5
    .
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CALL METHOD gr_html->load_data(
*  EXPORTING
*    url                  = LV_URL
*    type                 = 'HTML'
*    subtype              = 'HTML'
*    size                 = 100
*    encoding             = encoding
*    charset              = charset
*    language             = 'E'
  IMPORTING
    ASSIGNED_URL         = LV_URL
  CHANGING
    DATA_TABLE           = HTML
  EXCEPTIONS
    dp_invalid_parameter = 1
    dp_error_general     = 2
    cntl_error           = 3
       ).
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


GR_HTML->SHOW_URL(
  EXPORTING
    URL                    = LV_URL
*    FRAME                  = FRAME
*    IN_PLACE               = ' X'
  EXCEPTIONS
    cntl_error             = 1
    cnht_error_not_allowed = 2
    cnht_error_parameter   = 3
    dp_error_general       = 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.
ENDMODULE" STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'EXIT' OR 'CANCEL' or 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'PRINT'.
 call method GR_HTML->execwb(
  EXPORTING
    cmd_id     = GR_HTML->wb_cmdid_print
*    cmd_opt    = '2'
*    result     = result
  EXCEPTIONS
    cntl_error = 1
       ).
IF sy-subrc <> 0.
      message e003(cnht) raising html_print_error.
ENDIF.

ENDCASE.
ENDMODULE" USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*&      Form  HTML
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form HTML .

DATA : LV_NETWR TYPE C LENGTH 20.
PERFORM STYLE CHANGING LV_HTML.
  LF_HTML = LV_HTML.
  CLEAR LV_HTML.
 DATA : lv_date TYPE  CSAP_MBOM-DATUV.
   CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'
     EXPORTING
       input         = SY-DATUM
    IMPORTING
      OUTPUT        = LV_DATE
             .
   CONDENSE LV_DATE.
 LOOP AT IT_HEADER INTO WA_HEADER.
   PERFORM HEADER USING WA_HEADER LV_DATE CHANGING LV_HTML.
   CONCATENATE LF_HTML LV_HTML INTO LF_HTML SEPARATED BY SPACE.
   CONDENSE LF_HTML.
   CLEAR LV_HTML.
 LOOP AT IT_CON INTO WA_CON WHERE MATNR = WA_HEADER-MATNR AND WERKS = WA_HEADER-WERKS.
   PERFORM CON USING WA_CON CHANGING LV_HTML.
   CONCATENATE LF_HTML LV_HTML INTO LF_HTML SEPARATED BY SPACE.
   CONDENSE LF_HTML.
   CLEAR LV_HTML.
 ENDLOOP.
CLEAR COUNT.

LOOP AT IT_EKPO INTO WA_EKPO WHERE MATNR = WA_HEADER-MATNR AND WERKS = WA_HEADER-WERKS.
  PERFORM EKPO USING WA_EKPO CHANGING LV_NETWR LV_DATE LV_HTML.
  CONCATENATE LF_HTML LV_HTML INTO LF_HTML SEPARATED BY SPACE.
  CONDENSE LF_HTML.
  CLEAR LV_HTML.
ENDLOOP.
 IF COUNT IS NOT INITIAL.
  CONCATENATE LF_HTML '</table>' INTO LF_HTML SEPARATED BY SPACE.
 ENDIF.
CLEAR COUNT.
ENDLOOP.

CONCATENATE LF_HTML
'</body>'
'</html>'
INTO lf_html SEPARATED BY space.
*CONDENSE lf_html.

DATA subrc TYPE c VALUE 'X'.
DATA len TYPE i.

DATA line TYPE ZCHAR6000.
WHILE subrc = 'X'.
len = strlen( lf_html ).
IF len > 29900.
line = lf_html+0(29900).
APPEND line TO html.
SHIFT lf_html BY 29900 PLACES.
ELSE.
line = lf_html.
APPEND line TO html.
CLEAR subrc.
ENDIF.
CLEAR line.
ENDWHILE.
*HTML[] = t_html[].
endform.                    " HTML
*&---------------------------------------------------------------------*
*&      Form  STYLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_LF_HTML  text
*----------------------------------------------------------------------*
FORM STYLE  CHANGING P_LF_HTML.
CONCATENATE
*'<!DOCTYPE html>'
'<html>'
'<head>'
'<style type="text/css">'
'h1 {'
'color:#EFAB00;'
'font-family:tahoma,helvetica,sans-serif;'
'font-size:160%;'
'font-weight:bold;'
'margin-bottom:8px;'
'margin-top:8px;'
'text-decoration:none;'
'text-transform:uppercase;'
'}'
'h2 {'
'color:#666666;'
'font-family:tahoma,helvetica,sans-serif;'
'font-size:140%;'
'font-weight:normal;'
'margin-bottom:15px;'
'margin-top:10px;'
'text-decoration:none;'
'text-transform:uppercase;'
'}'
'h3, h4, h5, h6 {'
'color:#44697D;'
'font-family:verdana,helvetica,sans-serif;'
'font-size:110%;'
'font-weight:bold;'
'margin-bottom:3px;'
'text-decoration:none;'
'}'
'p {'
'color:#333333;'
'font-family:tahoma,helvetica,sans-serif;'
'font-size:80%;'
'margin-bottom:4px;'
'margin-top:4px;'
'}'
'strong, b {'
'font-family:tahoma,helvetica,sans-serif;'
'font-weight:bold;'
'}'
'</style>'
'<title>Price Trend</title>'
'</head>'
'<body bgcolor="#B9DCF9">'
INTO P_LF_HTML SEPARATED BY SPACE.
ENDFORM.                    " STYLE

*&---------------------------------------------------------------------*
*&      Form  HEADER
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_HEADER  text
*      -->P_LV_DATE  text
*      <--P_LV_HTML  text
*----------------------------------------------------------------------*
FORM HEADER  USING    P_WA_HEADER LIKE WA_HEADER
                       P_LV_DATE LIKE CSAP_MBOM-DATUV
              CHANGING P_LV_HTML.
CONCATENATE
'<p><b>Material Number :  </b>' P_WA_HEADER-MATNR '<b>    Plant :</b>  ' P_WA_HEADER-WERKS
   '<b>    BUOM :  </b>' P_WA_HEADER-MEINS '    <b>Date :</b>  ' P_LV_DATE '</p>'
INTO P_LV_HTML SEPARATED BY space.
ENDFORM.                    " HEADER1
*&---------------------------------------------------------------------*
*&      Form  CON
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_CON  text
*      <--P_LV_HTML  text
*----------------------------------------------------------------------*
FORM CON  USING    P_WA_CON LIKE WA_CON
          CHANGING P_LV_HTML.
 IF COUNT = 0.
 CONCATENATE
'<br>'
'<p><b>Consumption Trend</b></p>'
'<br>'
'<table border="0">'
 '<tr>'
INTO P_LV_HTML SEPARATED BY space.
 ENDIF.
      IF COUNT = 6.
     CONCATENATE P_LV_HTML
      '</tr>'
      '<tr>'
      '<td><p><b>' P_WA_CON-MONTH_T ': </b>' P_WA_CON-QTY  '</p></td>'
      INTO  P_LV_HTML SEPARATED BY space.
   ELSE.
     CONCATENATE P_LV_HTML
      '<td><p><b>' P_WA_CON-MONTH_T ':</b>' P_WA_CON-QTY  '</p></td>'
      INTO  P_LV_HTML SEPARATED BY space.
   ENDIF.
     IF COUNT = 11.
    CONCATENATE P_LV_HTML
    '</tr>'
    '</table>'
    INTO P_LV_HTML SEPARATED BY space.
     ENDIF.
  COUNT = COUNT + 1.
ENDFORM.                    " CON
*&---------------------------------------------------------------------*
*&      Form  EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_LV_NETWR  text
*      -->P_LV_DATE  text
*      <--P_LV_HTML  text
*      <--P_ENDLOOP  text
*----------------------------------------------------------------------*
FORM EKPO  USING    P_WA_EKPO LIKE WA_EKPO
            CHANGING P_LV_NETWR
                     P_LV_DATE
                     P_LV_HTML.

*   CLEAR :P_LV_NETWR, P_LV_DATE.
   COUNT = COUNT + 1.
   IF COUNT = 1.
    CONCATENATE
    '<p><b>Price History</b></p>'
    '<br>'
    '<table border="1">'
     '<tr>'
*     '<tr>'
     '<th><p>Vendor</p></th>'
     '<th><p>InfoRecord</p></th>'
     '<th><p>Purchase Order</p></th>'
     '<th><p>PO Item</p></th>'
     '<th><p>PO Date</p></th>'
     '<th><p>Price</p></th>'
     '</tr>'
    INTO P_LV_HTML SEPARATED BY space.

*   ELSEIF COUNT = 49.
*     P_LV_HTML = '</table>'.
*     EXIT.
   ENDIF.
   P_LV_NETWR = P_WA_EKPO-NETWR.
   CONDENSE P_LV_NETWR.
   CALL FUNCTION 'CONVERSION_EXIT_PDATE_OUTPUT'
     EXPORTING
       input         = P_WA_EKPO-BEDAT
    IMPORTING
      OUTPUT        = P_LV_DATE
             .
   CONCATENATE P_LV_HTML
    '<tr>'
    '<td><p>' P_WA_EKPO-LIFNR '</p></td>'
    '<td><p>' P_WA_EKPO-INFNR '</p></td>'
    '<td><p>' P_WA_EKPO-EBELN '</p></td>'
    '<td><p>' P_WA_EKPO-EBELP '</p></td>'
    '<td><p>' P_LV_DATE '</p></td>'
    '<td><p>' P_LV_NETWR '</p></td>'
    '</tr>'
INTO P_LV_HTML SEPARATED BY space.

endform.                    " EKPO

No comments:

Post a Comment