Sunday, 11 August 2013

Disable Copy Paste Option for input fields in ABAP

Disable Copy Paste Option for input fields in ABAP

REPORT  ZKKK_DISABLE_COPY_PASTE.
  DATA : gr_html TYPE REF TO cl_gui_html_viewer,
         gr_cont TYPE REF TO cl_gui_custom_container.
DATA: lv_url TYPE char255.
DATA: html TYPE ZCHAR6000_T.
DATA: LV_HTML TYPE string.

DATA: lf_html TYPE string.
   CALL SCREEN 0100.

*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  PERFORM HTML.
SET PF-STATUS 'HTML'.
SET TITLEBAR 'HTML_TITLE'." WITH gv_title.


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 .
CONCATENATE
'<html>'
'<head>'
'<style type="text/css">'
'h1 {'
'color:#EFAB00;'
'font-family:tahoma,helvetica,sans-serif;'
'font-size:160%;'
'font-weight:bold;'
'margin-bottom:0px;'
'margin-top:0px;'
'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:60px;'
'margin-top:1px;'
'}'
'strong, b {'
'font-family:tahoma,helvetica,sans-serif;'
'font-weight:bold;'
'}'
'</style>'
'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'
'<title>Disabling cut, copy, paste, right click and context menu using Javascript </title>'
'<script type="text/javascript"> '
'document.oncontextmenu=new Function("return false");'
'document.onselectstart=new Function ("return false"); '
'if (window.sidebar){'
'document.onmousedown=new Function("return false"); '
'document.onclick=new Function("return true") ; '
'document.oncut=new Function("return false"); '
'document.oncopy=new Function("return false"); '
'document.onpaste=new Function("return false"); }'
'</script>'
'</head>'
'<body bgcolor="#CBDCE9" style="font-family:arial;font-size:90%;overflow:hidden">'
*'<body bgcolour = "#CBDCE9">'"style="font-family:arial;font-size:90%;overflow:hidden">'
'<p align="Center">89632543215.000</p>'

'</body>'
'</html>'
INTO lf_html SEPARATED BY space.
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.
endform.                    " HTML


Out Put