带你进入SAP BSP系列—实战部分(2)


开始我们的第一个BSP application, 当然, 还是从Hello World开始, 逐渐熟悉BSP的语法以及应用:

1. 进入SE80

2. 选择BSP application, 输入你的application名字

clip_image002

3. 创建一个BSP页面如下

clip_image004

clip_image006

4. OK, 你可以看到一段默认的代码如下:

   1:  <%@page language="abap"%>
   2:  <%@extension name="htmlb" prefix="htmlb"%>
   3:  <htmlb:content design="design2003">
   4:    <htmlb:page title = "First BSP application with Hello World! ">
   5:      <htmlb:form>
   6:        <htmlb:textView     text          = "Hello World!"
   7:                            design        = "EMPHASIZED" />
   8:        <htmlb:button text          = "Press Me"
   9:                      onClick       = "myClickHandler" />
  10:      </htmlb:form>
  11:    </htmlb:page>
  12:  </htmlb:content>

我来简单的解释一下:

<%@page language=”abap”%>: 页面语言定义, 所有BSP程序必须

<%@extension name=”htmlb” prefix=”htmlb”%>: BSP extension的调用, 这个自定义标签库是SAP提供的, 名字为htmlb, 在页面中调用的话, 前缀为htmlb.

<htmlb:content design=”design2003″>: 调用自定义标签”content”, 将其design属性赋值’design2003’.

<htmlb:page …>: 同上, 使用page标签, 定义html标题. 相当于以下html语句:

  <head>
    <title>…….</title>
  </head>

关于标签,到后面我们会慢慢用到并且明白如何去使用.

5. 接下来激活这个BSP程序, 再测试:

clip_image008

clip_image010

6. 看来BSP是很简单的, 我们甚至都没有写一行代码, 就实现了Hello world程序, 那么, 如果摒弃BSP extension不用, 我们是否同样实现呢. 答案当然是肯定的, 只要几行html代码就可以.

   1:  <%@page language="abap"%>
   2:  <html>
   3:    <head>
   4:      <title>Hello world</title>
   5:    </head>
   6:    <body>
   7:      Hello World!
   8:      <input type='button' value='Press Me' />
   9:    </body>
  10:  </html>

测试看一下效果:

clip_image012

虽然外观不同(因为BSP 标签库中做了很多事情), 其他并没有什么分别.

7. 既然我们学的是BSP, 那么肯定离不开ABAP, 看来我们要测试一下abap的使用情况. 案例: 通过循环控制, 打印5个hello world.

实现: 我们选择使用BSP标签库’HTMLB’, 同时嵌套ABAP语句, 因为这是我们以后主要的变成方式. 纯html语句的方式暂时不用.

代码:

   1:  <%@page language="abap"%>
   2:  <%@extension name="htmlb" prefix="htmlb"%>
   3:  <htmlb:content design="design2003">
   4:    <htmlb:page title = "aaa ">
   5:      <htmlb:form>
   6:  <% do 5 times. %>
   7:        <htmlb:textView     text          = "Hello World!"
   8:                            design        = "EMPHASIZED" />
   9:        <br>
  10:  <% enddo. %>
  11:      </htmlb:form>
  12:    </htmlb:page>
  13:  </htmlb:content>

可以看到, 我们再程序中加入了ABAP的控制, 显示5次hello world, 效果如下:

clip_image014

8. 看到上面的效果后, 有的朋友会问, 如果我想控制字体的大小, 颜色等等该如何做呢?很遗憾, htmlb标签中的textView无法实现, 那么我们可以自己写一个script来做这件事情, 代码如下:

   1:  <%@page language="abap"%>
   2:  <%@extension name="htmlb" prefix="htmlb"%>
   3:  <htmlb:content design="design2003">
   4:    <htmlb:page title = "aaa ">
   5:      <htmlb:form>
   6:  <% do 5 times. %>
   7:        <htmlb:textView     text          = "Hello World!"
   8:                            textColor     = "red"
   9:                            design        = "EMPHASIZED" />
  10:        <br>
  11:  <% enddo. %>
  12:  <% data: color type string,
  13:                 int type i.
  14:  do 6 times.
  15:             int = sy-index mod 2.
  16:  if int < 1.
  17:  color = '#0000DD'.
  18:  else.
  19:  color = '#00DD00'.
  20:  endif.%>
  21:             <font color="<%=color%>" size="<%=sy-index%>">
  22:             Hello World!
  23:             </font>
  24:             <br>
  25:  <% enddo.%>
  26:      </htmlb:form>
  27:    </htmlb:page>
  28:  </htmlb:content>

查看效果:

clip_image016

关于Hello World我们就讲这么多, 后面更精彩, 大家多多支持.


About The Author

从事SAP行业有些年头,对SAP技术稍有了解; 如无特别声明,本博客文章为原创,转载请注明; 博主MSN:xuchunbo0901@hotmail.com; 博主邮箱:bob.xu@abaptech.com。

4 Comments

  1. eric 说道:

    請問一下有可能將 PO,PR,SO的輸入全部移到web嗎!
    原本的資料輸入驗證等都可以實作嗎

    • Bob 说道:

      可以,第一种方案,调用bapi创建这些凭证,输入界面设计对应的输入字段,第二种,干脆使用ITS,也就是web gui,对权限上做限制实现。

  2. Bob 说道:

    Hi,in my point, you did not active SICF service for BSP. Please check it, and also check WAS run status, and your J2EE Engine status, hope it helps.

  3. rooob 说道:

    Service cannot be reached

    What has happened?
    URL http://bwtest:8000/sap/bc/bsp/sap/wyan_hello/hello.htm call was terminated because the corresponding service is not available.

    Note
    The termination occurred in system WD1 with error code 403 and for the reason Forbidden.
    The selected virtual host was 0 .

    What can I do?
    Please select a valid URL.
    If you do not yet have a user ID, contact your system administrator.

    ErrorCode:ICF-NF-http-c:000-u:SAPSYS-l:1-i:bwtest_WD1_00-v:0-s:403-r:Forbidden

    HTTP 403 – Forbidden
    Your SAP Internet Communication Framework Team

Leave A Reply


注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。

无觅相关文章插件,快速提升流量