Chinaunix首页 | 论坛 | 博客
  • 博客访问: 205702
  • 博文数量: 54
  • 博客积分: 2056
  • 博客等级: 大尉
  • 技术积分: 568
  • 用 户 组: 普通用户
  • 注册时间: 2007-07-25 12:07
文章分类

全部博文(54)

文章存档

2014年(1)

2013年(1)

2012年(1)

2011年(2)

2010年(1)

2009年(11)

2008年(28)

2007年(9)

我的朋友

分类:

2008-05-12 13:38:28

Entering content frame refer

Background documentation Using the CL_JAVA_SCRIPT Class Locate the document in its SAP Library structure

The areas where the CL_JAVA_SCRIPT class is used can be split up as follows:

Executing JavaScript Programs

You can use the CL_JAVA_SCRIPT class to execute JavaScript programs that, for example, have been loaded from external resources or programmed in an Editor you have written yourself: The following are the methods you use, in the sequence in which they are called:

  1. to create a JavaScript context
  2. to compile a JavaScript source in the current context
  3. to execute a compiled JavaScript
  4. to delete a compiled JavaScript from the context

Methods 2 to 4 are combined in the method .

Binding between JavaScript and the ABAP program

JavaScript programs can access data objects and objects in ABAP programs. This technique is based on two methods:

BIND allows you to link variables and objects in JavaScript with data objects and references to objects in ABAP. Changes made in the JavaScript program also change the objects in ABAP. You can also bind objects from ABAP objects directly using BIND_INSTANCE.

You can also access the public instance attributes of bound objects and call public instance methods.

As well as binding JavaScript objects to ABAP objects, you can set or get values from JavaScript objects directly using the and methods respectively.

Debugging

If you want to include and test JavaScript programs in an ABAP development environment, the following methods are available to support you:

Handling breakpoints

Executing programs step by step

Evaluating the call stack

Example

The ABAP program DEMO_JAVA_SCRIPT_MINI_EDITOR from the Examples Library (transaction ABAPDOCU) is an example of a basic JavaScript Editor, where you can edit, execute, and test JavaScript programs. The program was created using ABAP exclusively and uses the CL_JAVA_SCRIPT class. This mini-editor is only a demonstration for the purposes of this documentation, but it shows what you can do using CL_JAVA_SCRIPT in ABAP.

******************************************

report  DEMO_JAVA_SCRIPT_MINI_EDITOR.

* Selection Screen

selection-screen: begin of screen 500 title SEL_TIT as window,
                  begin of line.
parameters PARA(40) type C lower case.
selection-screen: end of line,
                  end of screen 500.

data FILE_NAME type STRING value `C:\temp\`.
data FIELD_NAME type STRING.


* Processor ------------------------------------------------------------

class EVALUATE definition.
  public section.
    methods CONSTRUCTOR.
    methods PROCESS importing JS_SOURCE type STRING
                              JS_BP_LINE type I optional.
  private section.
    data JS_PROCESSOR type ref to CL_JAVA_SCRIPT.
endclass.                    "EVALUATE DEFINITION


* Class EVALUATE

class EVALUATE implementation.
*
  method CONSTRUCTOR.
    JS_PROCESSOR = CL_JAVA_SCRIPT=>CREATE( ).
  endmethod.
*
  method PROCESS.
    data RETURN_VALUE type STRING.
    data GET_VALUE type STRING.
    JS_PROCESSOR->COMPILE(
                  exporting
                    SCRIPT_NAME = 'JAVASCRIPT.JS'
                    SCRIPT      = JS_SOURCE ).
    if JS_BP_LINE <> 0.
      JS_PROCESSOR->SET_BREAKPOINT(
        SCRIPT_NAME = 'JAVASCRIPT.JS'
        LINE_NUMBER = JS_BP_LINE ).
    endif.
    RETURN_VALUE = JS_PROCESSOR->EXECUTE( 'JAVASCRIPT.JS' ).
    if JS_PROCESSOR->LAST_CONDITION_CODE =
                       CL_JAVA_SCRIPT=>CC_BREAKPOINT.
      message I888(SABAPDOCU) with  'Breakpoint in'
                              JS_PROCESSOR->BREAKPOINT_LINE_NUMBER.
      SEL_TIT = 'Enter field name'.
      PARA = FIELD_NAME.
      call selection-screen 500 starting at 10 10.
      if SY-SUBRC = 0.
        FIELD_NAME = PARA.
        clear GET_VALUE.
        GET_VALUE = JS_PROCESSOR->GET( NAME = FIELD_NAME ).
        if JS_PROCESSOR->LAST_CONDITION_CODE = 0.
          message I888(SABAPDOCU) with FIELD_NAME ':'  GET_VALUE.
          JS_PROCESSOR->STEP( ).
          if JS_PROCESSOR->LAST_CONDITION_CODE =
                           CL_JAVA_SCRIPT=>CC_BREAKPOINT.
            clear GET_VALUE.
            GET_VALUE = JS_PROCESSOR->GET( NAME = FIELD_NAME ).
            if JS_PROCESSOR->LAST_CONDITION_CODE = 0.
              message I888(SABAPDOCU) with FIELD_NAME
                                           ' after single step:'
                                           GET_VALUE.
            endif.
          endif.
        else.
          message I888(SABAPDOCU) with FIELD_NAME ' not accessible'.
        endif.
      endif.
    elseif JS_PROCESSOR->LAST_CONDITION_CODE <> 0.
      message I888(SABAPDOCU) with JS_PROCESSOR->LAST_ERROR_MESSAGE.
    else.
      message I888(SABAPDOCU) with RETURN_VALUE.
    endif.
    JS_PROCESSOR->CLEAR_BREAKPOINTS( ).
    JS_PROCESSOR->DESTROY( 'JAVASCRIPT.JS' ).
  endmethod.
endclass.

* Global Data ---------------------------------------------------------

data SOURCE_LINE(80) type C.
data SOURCE_TABLE like table of SOURCE_LINE.
data SOURCE type STRING.
data AREA   type ref to CL_GUI_CUSTOM_CONTAINER.
data EDITOR type ref to CL_GUI_TEXTEDIT.
data PROCESSOR type ref to EVALUATE.
data CURSOR type I.
data ROW type I.

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

initialization.

  SOURCE_LINE = 'var string = "Hello ABAP";'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = 'function Set_String()'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = '  {'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = '  string += ", this";'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = '  string += " is";'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = '  string += " JavaScript!";'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = '  }'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = 'Set_String();'.
  append SOURCE_LINE to SOURCE_TABLE.
  SOURCE_LINE = 'string;'.
  append SOURCE_LINE to SOURCE_TABLE.


start-of-selection.

  call screen 100.


* Dialog Modules -------------------------------------------------------

module STATUS_0100 output.
  set pf-status 'SCREEN_100'.
  set titlebar  'SCREEN_100'.
  if AREA is initial.
    create object AREA exporting CONTAINER_NAME = 'EDIT_CONTROL'.
  endif.
  if EDITOR is initial.
    create object EDITOR exporting PARENT = AREA.
  endif.
  if PROCESSOR is initial.
    create object PROCESSOR.
  endif.
  EDITOR->SET_WORDWRAP_BEHAVIOR(
    exporting
      WORDWRAP_MODE     = 2
      WORDWRAP_POSITION = 80 ).
  EDITOR->SET_TEXT_AS_R3TABLE(
    exporting
      TABLE = SOURCE_TABLE ).
  if ROW <> 0.
    EDITOR->HIGHLIGHT_LINES(
      exporting
        FROM_LINE = ROW
        TO_LINE   = ROW ).
  endif.
endmodule.

*

module USER_COMMAND_0100 input.
  EDITOR->GET_TEXT_AS_R3TABLE(
    importing
      TABLE = SOURCE_TABLE ).
  clear SOURCE.
  loop at SOURCE_TABLE into SOURCE_LINE.
    if SOURCE is initial.
      SOURCE = SOURCE_LINE.
    else.
      concatenate SOURCE SOURCE_LINE into SOURCE
        separated by CL_ABAP_CHAR_UTILITIES=>CR_LF.
    endif.
  endloop.
  case SY-UCOMM.
    when 'CANCEL'.
      leave program.
    when 'EXECUTE'.
      PROCESSOR->PROCESS(
        exporting
          JS_SOURCE = SOURCE
          JS_BP_LINE = ROW ).
    when 'BREAKPOINT'.
      EDITOR->GET_SELECTION_POS(
        importing
          FROM_LINE = CURSOR ).
      if CURSOR <> ROW.
        ROW = CURSOR.
      else.
        ROW = 0.
      endif.
    when 'JSLOAD'.
      SEL_TIT = 'Enter file name'.
      PARA = FILE_NAME.
      call selection-screen 500 starting at 10 10.
      if SY-SUBRC = 0.
        FILE_NAME = PARA.
        call function 'GUI_UPLOAD'
          exporting
            FILENAME = FILE_NAME
          tables
            DATA_TAB = SOURCE_TABLE
          exceptions
            others   = 4.
        if SY-SUBRC <> 0.
          message I888(SABAPDOCU) with 'Error when loading file'.
        endif.
      endif.
    when 'JSDUMP'.
      SEL_TIT = 'Enter file name'.
      PARA = FILE_NAME.
      call selection-screen 500 starting at 10 10.
      if SY-SUBRC = 0.
        FILE_NAME = PARA.
        call function 'GUI_DOWNLOAD'
          exporting
            FILENAME = FILE_NAME
          tables
            DATA_TAB = SOURCE_TABLE
          exceptions
            others   = 4.
        if SY-SUBRC <> 0.
          message I888(SABAPDOCU) with 'Error when saving file'.
        endif.
      endif.
  endcase.
  clear SY-UCOMM.
endmodule.

 

 

 

Leaving content frame
阅读(1816) | 评论(0) | 转发(0) |
0

上一篇:crm常用词汇大全

下一篇:Creating New Users

给主人留下些什么吧!~~