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

Thursday 18 July 2013

Adding Extra Tab in F4 Help


Adding Plant Wise material in Material F4 (Tcode VA31)

1) Goto  VA31 and press Material F4 help


now i m  adding Plant wise material Tab
2 ) goto se11 here collective search help name is SD_MAT1




















Implementing Exits for Standard Search Help

Summary

Search help exit is used to modify the F4 values at run time before its being displayed as a list to the user for selection. This document explains step by step procedure for implementing a search help exit with an example.

Steps in Search Help

1)       SELONE - in this step FM 'DD_SHLP_GET_DIALOG_INFO' is called to populate the internal description of the fields for search help fields in table  SHLP_TAB
2)       PRESEL1 - in this step the maximum records, internal length, offset attributes of the fields are set
3)       PRESEL - in this step a pop-up is displayed for the user to enter the selection criteria.
4)       SELECT - in this step based on the selection criteria entered by the user data will be selected to RECORD_TAB internal table based on the selection method specified for the search help
5)       DISP - this is the final step before the result list is displayed to the user.

Example Scenario

Consider searching for sales order through VA03, and select sales document not fully confirmed tab, enter customer number and press enter

The result list will be displayed as below,
       

Now say our requirement is to have customer number and customer name in the customer column as '121- BHARAT FORGES'.
We can achieve this by implementing a search help exit and modifying the internal length & output length attributes of the customer field at run time and concatenating customer name to customer number at run time.
For the purpose of this document I have copied search help VMVAC to ZVMVAC and implemented an exit for this search help.
 

Steps in implementing Search Help Exit

1)       Create a function group 'ZVMVAC' using transaction SE80
2)       Create a function module ZVMAC_SHLP_EXIT for search help exit
           
 
3)       Define the interface attributes for the function module as shown below
Changing Parameters
Parameter                     Type spec.                                Associated type
SHLP                             TYPE                                       SHLP_DESCR
CALLCONTROL              TYPE                                       DDSHF4CTRL
   
SHLP- Structure containing search help type, interface and field descriptions of the search help.
CALLCONTROL - Structure containing the current step of the search help process.
Tables Parameters
Parameter                     Type spec.                    Associated type
SHLP_TAB                    TYPE                           SHLP_DESCT
RECORD_TAB              TYPE                            SEAHLPRES
   
                         
SHLP_TAB -contains search help field description, field properties and selection criteria.
RECORD_TAB - contains the search help result list.
In this example we will be modifying RECORD_TAB in control step DISP i.e. display as below
1)       We need to increase the output length of field KUNNR, in addition to increasing the    output length of KUNNR we also need to adjust the offset position of other fields in order to avoid overlapping of Customer data with other fields.
2)       Customer numbers will be available in SHLP, build a range of all the customer numbers which will formulate WHERE condition for selecting customer name.
3)       Select customer name from KNA1 for all the customers.
4)       Modify RECORD_TAB to append customer name to customer number.
Once these steps are done output will appear as below,
Input Customer - 121
        
Output with Customer number and name.
                   

Sample code

 FUNCTION ZVMVAC_SHLP_EXIT.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  TABLES
*"      SHLP_TAB TYPE  SHLP_DESCT
*"      RECORD_TAB STRUCTURE  SEAHLPRES
*"  CHANGING
*"     VALUE(SHLP) TYPE  SHLP_DESCR
*"     VALUE(CALLCONTROL) TYPE  DDSHF4CTRL
*"----------------------------------------------------------------------
DATA: ls_fielddescr TYPE dfies, "loc str for shlp-fielddescr
      ls_selopt TYPE ddshselopt.  "loc str for shlp-selopt
*Local structure for itab record_tab
DATA: BEGIN OF ls_record.
INCLUDE STRUCTURE seahlpres.
DATA: END OF ls_record.
DATA: ls_name1 TYPE name1_gp,
      ls_start TYPE string,
      ls_end TYPE string,
      v_kunnr TYPE kunnr.
*Internal table to store Customer Name
DATA: BEGIN OF gt_kna1 OCCURS 0,
       kunnr LIKE kna1-kunnr,
       name1 LIKE kna1-name1,
      END OF gt_kna1.
RANGES: lr_kunnr FOR kna1-kunnr.  "Ranges for customer number
  CHECK CALLCONTROL-STEP = 'DISP'.
    LOOP AT shlp-fielddescr INTO ls_fielddescr.
      CASE ls_fielddescr-fieldname.
        WHEN 'KUNNR'.
          ls_fielddescr-intlen = ls_fielddescr-outputlen = 45.
          MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
        WHEN 'ERNAM'.
          ls_fielddescr-offset = 63.
          MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
        WHEN 'ERDAT'.
          ls_fielddescr-offset = 75.
          MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
        WHEN 'VBELN'.
          ls_fielddescr-offset = 83.
          MODIFY shlp-fielddescr FROM ls_fielddescr INDEX sy-tabix.
       ENDCASE.
     ENDLOOP.
*Build range for customer number
      LOOP AT shlp-selopt INTO ls_selopt WHERE shlpfield = 'KUNNR'.
        lr_kunnr-sign = ls_selopt-sign.
        lr_kunnr-option = ls_selopt-option.
        lr_kunnr-low = ls_selopt-low.
        lr_kunnr-high = ls_selopt-high.
        APPEND lr_kunnr.
        CLEAR: lr_kunnr.
      ENDLOOP.
*Select Customer name
      SELECT kunnr name1
      FROM kna1
      INTO TABLE gt_kna1
      WHERE kunnr IN lr_kunnr.
*Modify record_tab to append Customer name to customer number
      LOOP AT record_tab INTO ls_record.
        v_kunnr = ls_record-string+18(10).
        READ TABLE gt_kna1 WITH KEY kunnr = v_kunnr.
        IF sy-subrc = 0.
          ls_start = ls_record-string+0(28).
          ls_end = ls_record-string+28( * ).
          CLEAR: ls_record-string.
          ls_record-string+0(28) = ls_start.
          ls_record-string+29(1) = '-'.
          ls_record-string+30(36) = gt_kna1-name1.
          ls_record-string+66( * ) = ls_end.
          MODIFY record_tab FROM ls_record.
          CLEAR: ls_record,ls_start,ls_end,gt_kna1,v_kunnr.
        ENDIF.
      ENDLOOP.
ENDFUNCTION.