星期二, 十月 23, 2012

比如屏幕旋转90度,Configuration Changes

Configuration Changes

If the configuration of the device (as defined by the Resources.Configuration class) changes, then anything displaying a user interface will need to update to match that configuration. Because Activity is the primary mechanism for interacting with the user, it includes special support for handling configuration changes.

Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle).

This is done because any application resource, including layout files, can change based on any configuration value. Thus the only safe way to handle a configuration change is to re-retrieve all resources, including layouts, drawables, and strings. Because activities must already know how to save their state and re-create themselves from that state, this is a convenient way to have an activity restart itself with a new configuration.

In some special cases, you may want to bypass restarting of your activity based on one or more types of configuration changes. This is done with the android:configChanges attribute in its manifest. For any types of configuration changes you say that you handle there, you will receive a call to your current activity's onConfigurationChanged(Configuration) method instead of being restarted. If a configuration change involves any that you do not handle, however, the activity will still be restarted and onConfigurationChanged(Configuration) will not be called.




Because of this, some developers decide to handle the configuration changes (like screen orientation changes) themselves.  This is done by adding the "configChanges" attribute to the Activity declaration in AndroidManifest.xml
?
1
2
3
4
5
6
7
<activity android:name=".SomeActivity" android:label="@string/app_name"
  android:configChanges="orientation">
 <intent-filter>
  <action android:name="android.intent.action.MAIN"/>
  <category android:name="android.intent.category.LAUNCHER"/>
 </intent-filter>
</activity>

The "configChanges" attribute tells Android Platform that, some of the config changes will be handled by the activity by themselves. Platform does not need to do any special handling for these.

Android Configuration change.

http://developer.android.com/guide/topics/resources/runtime-changes.html

In Android, a configuration change causes the current activity to go away and be recreated.
The application itself keeps on running, but it has the opportunity to change
how the activity is displayed in response to the configuration change.

use onSaveInstanceState(Bundle) to keep state or other runtime data.


root Jelly Bean 4.1.2

root JB 4.1.2

首先必须安装了Android sdk和对应手机的USB驱动。
 android sdk: http://developer.android.com/sdk/index.html
  需要一些工具
 
1.download cmw(ClockworkMod) recover 工具.

 http://www.clockworkmod.com/rommanager
查找对应的设备后面的文件。
Galaxy Nexus 就要下载:
http://download2.clockworkmod.com/recoveries/recovery-clockwork-touch-6.0.1.0-maguro.img

2. download superuser packagae
 http://androidsu.com/superuser/
 下载 Superuser-3.1.3-arm-signed.zip
 
3.连接手机USB,设置为debug模式
   用adb push  Superuser-3.1.3-arm-signed.zip /sdcard/Superuser-3.1.3-arm-
signed.zip
    传送到手机上

4.临时进入cmw recover 并安装superuser 包
 进入window 命令行状态 cmd,进入android sdk安装目录下的android-sdk-windows\
platform-tools目录.
 
  adb reboot bootloader
  fastboot boot recovery-clockwork-touch-6.0.
1.0-maguro.img
 等待3秒出现,安装CMW 安装界面,如果是touch版本,则用手势滚动屏幕,选择安装
  select install zip from sdcard.
  否则用音量上下键移动,电源键确认来选择。
 
 安装完成后,用adb reboot 启动手机即可。

星期四, 九月 20, 2012

Fwd: OSWORKFLOW on JBOSS 4.22 Config.

1.download osworkflow 2.8,2006年以后已不再维护。
   http://java.net/downloads/osworkflow/

2.将osworkflow-2.8.0-example.war展开到jboss 422/server/default/deploy/osworkflow-2.8.0-example.war 目录下。

3.在MYSQL 上建立一个osworkflow的database,并运行osworkflow-2.8.0\src\etc\deployment\jdbc
 \mysql.sql,建立其需要使用的表格.
4.配置JBOSS 数据源
   在
jboss 422/server/default/deploy/mysql-ds.xml里加入数据源:
   <!-- add for osworkflow datasorce -->
  <local-tx-datasource>
    <jndi-name>osworkflow</jndi-name>
   <connection-url>jdbc:mysql://192.1.1.100:3306/osworkflow?autoReconnect=true&amp;useUnicode=TRUE&amp;characterEncoding=utf-8</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password></password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
        <min-pool-size>5</min-pool-size>
        <max-pool-size>10</max-pool-size>
        <idle-timeout-minutes>1</idle-timeout-minutes>
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>


5.进入
jboss 422/server/default/deploy/osworkflow-2.8.0-example.war/WEB-INF/classes下修改配置,加入数据源说明.
  注意Linux table name 有大小写的问题。

  osuser.xml:
<opensymphony-user>
   <provider class="com.opensymphony.user.provider.jdbc.JDBCAccessProvider">
  <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
  <property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
</provider>

<provider class="com.opensymphony.user.provider.jdbc.JDBCCredentialsProvider">
 <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
 </provider>

    <provider class="com.opensymphony.user.provider.jdbc.JDBCProfileProvider">
 <property name="user.table">OS_USER</property>
  <property name="group.table">OS_GROUP</property>
  <property name="membership.table">OS_MEMBERSHIP</property>
<property name="user.name" >username</property>
  <property name="user.password">passwordhash</property>
  <property name="group.name">groupname</property>
  <property name="membership.userName" >username</property>
  <property name="membership.groupName">groupname</property>
  <property name="datasource">java:/osworkflow</property>
 </provider>

 <authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />

</opensymphony-user>

osworkflow.xml:
<osworkflow>
    <!--persistence class="com.opensymphony.workflow.spi.memory.MemoryWorkflowStore"/-->
    <persistence class="com.opensymphony.workflow.spi.jdbc.MySQLWorkflowStore">
 <property key="datasource" value="java:/osworkflow"/>
<property key="entry.sequence"
                      value="SELECT max(id)+1 FROM OS_WFENTRY"/>
 <property key="entry.table" value="OS_WFENTRY"/>
 <property key="entry.id" value="ID"/>
 <property key="entry.name" value="NAME"/>
 <property key="entry.state" value="STATE"/>
 <property key="step.sequence"  value="SELECT max(ID)+1 FROM OS_STEPIDS"/>

 <property key="step.sequence.increment"    value="INSERT INTO OS_STEPIDS (ID) values (null)"/>
 <property key="step.sequence.retrieve"   value="SELECT max(ID) FROM OS_STEPIDS"/>
 <property key="entry.sequence.increment" value="INSERT INTO OS_ENTRYIDS (ID) values (null)"/>
 <property key="entry.sequence.retrieve" value="SELECT max(ID) FROM OS_ENTRYIDS"/>

 <property key="history.table" value="OS_HISTORYSTEP"/>
 <property key="current.table" value="OS_CURRENTSTEP"/>
 <property key="historyPrev.table" value="OS_HISTORYSTEP_PREV"/>
 <property key="currentPrev.table" value="OS_CURRENTSTEP_PREV"/>
 <property key="step.id" value="ID"/>
 <property key="step.entryId" value="ENTRY_ID"/>
 <property key="step.stepId" value="STEP_ID"/>
 <property key="step.actionId" value="ACTION_ID"/>
 <property key="step.owner" value="OWNER"/>
 <property key="step.caller" value="CALLER"/>
 <property key="step.startDate" value="START_DATE"/>
 <property key="step.finishDate" value="FINISH_DATE"/>
 <property key="step.dueDate" value="DUE_DATE"/>
 <property key="step.status" value="STATUS"/>
 <property key="step.previousId" value="PREVIOUS_ID"/>
</persistence>
    <factory class="com.opensymphony.workflow.loader.XMLWorkflowFactory">
        <property key="resource" value="workflows.xml" />
    </factory>
</osworkflow>

 propertyset.xml:
<propertysets>
 <propertyset name="jdbc" class="com.opensymphony.module.propertyset.database.JDBCPropertySet">
  <arg name="table.name" value="OS_PROPERTYENTRY"/>
  <arg name="col.globalKey" value="GLOBAL_KEY"/>
  <arg name="col.itemKey" value="ITEM_KEY"/>
  <arg name="col.itemType" value="ITEM_TYPE"/>
  <arg name="col.string" value="STRING_VALUE"/>
  <arg name="col.date" value="DATE_VALUE"/>
  <arg name="col.data" value="DATA_VALUE"/>
  <arg name="col.float" value="FLOAT_VALUE"/>
  <arg name="col.number" value="NUMBER_VALUE"/>
  <arg name="datasource" value="java:/osworkflow"/>
  <arg name="" value=""/>
 </propertyset>
</propertysets>


至此配置完成,启动JBOSS,从浏览器输入:
http://192.168.1.1:8080/osworkflow-2.8.0-example/

即可查看.



星期二, 九月 18, 2012

Android如何确认一个Intent是否存在呢?


 /**
     * Indicates whether the specified action can be used as an intent. This
     * method queries the package manager for installed packages that can
     * respond to an intent with the specified action. If no suitable package is
     * found, this method returns false.
     *
     * @param context The application's environment.
     * @param action The Intent action to check for availability.
     *
     * @return True if an Intent with the specified action can be sent and
     * responded to, false otherwise.
     *  Example:isIntentAvailable(getApplicationContext(),Intent.ACTION_WEB_SEARCH)
     */
    public static boolean isIntentAvailable(Context context, String action) {
    final PackageManager packageManager = context.getPackageManager();
    final Intent intent = new Intent(action);
    List<ResolveInfo> list =
    packageManager.queryIntentActivities(intent,
    PackageManager.MATCH_DEFAULT_ONLY);
    return list.size() > 0;
    }

星期四, 九月 13, 2012

Android动态改变语言并自动刷新菜单.

Locale locale=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String languageToLoad  = "zh";
         locale = new Locale(languageToLoad);
        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        getBaseContext().getResources().updateConfiguration(config, null);
        //getBaseContext().getResources().getDisplayMetrics()
        Log.v("log:","local is changed!");
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        setContentView(R.layout.activity_main);
         }

星期二, 九月 11, 2012

Andorid xml is binary format in .apk package

All of the resource XML files are compiled to a binary format by aapt at build time.
只有一个例外就是 res/raw下的文件是原始文件,没有做任何处理。

Activity的getString和Activity.getResource().getString的区别是什么呢?

activity的getString下的说明如此:
 localized string from the application's package's default string table

Resource的getString说明如下:
Returns the string value associated with a particular resource ID. It will be stripped of any styled text information

但是查看源代码,发现activity的getString如下:
    public final String getString(int resId) {
        return getResources().getString(resId);
    }

其实是一回事。真不明白为什么说明差异如此之大。

Android classpath access external resource.

Resources.getSystem().getString(android.R.string.somecommonstuff)

星期一, 八月 27, 2012

如何禁止wxWidgets 2.9.x Debug信息

wxWidgets 2.9.1 debugging features are always available by default
在wx/debug.h 里设置
wxDEBUG_LEVEL=0

然后从新编译所有的库文件,再编译应用代码。

REM 清除所有的库文件
mingw32-make -f makefile.gcc  SHARED=0 UNICODE=1 BUILD=release MONOLITHIC=0  USE_STC=0 USE_PROPGRID=1 USE_GUI=1 clean

REM 重新编译所有库
mingw32-make -f makefile.gcc  SHARED=0 UNICODE=1 BUILD=release MONOLITHIC=0  USE_STC=0 USE_PROPGRID=1 USE_GUI=1

禁止 wxWidgets 2.9 调试信息弹出

wxWidgets 2.9.1 debugging features are always available by default

定义wxDEBUG_LEVEL=0 在 IMPLEMENT_APP()  代码前。



星期五, 八月 10, 2012

Dynamic load css definition file.

var CSS = {

        load: /*static*/ function (url_, /*optional*/ media_) {

                // We are preventing loading a file already loaded
                var _links = document.getElementsByTagName("link");
                if (_links.length > 0 && _links["href"] == url_) return;

                // Optional parameters check
                var _media = media_ === undefined || media_ === null ? "all" : media_;
               
                var _elstyle = document.createElement("link");
                _elstyle.setAttribute("rel", "stylesheet");
                _elstyle.setAttribute("type", "text/css");
                _elstyle.setAttribute("media", _media);
                _elstyle.setAttribute("href", url_);

                var _head = document.getElementsByTagName("head")[0];
                _head.element.appendChild(_elstyle);

        }

};

星期三, 七月 25, 2012

如何用SVG显示汉字。只需要注意HTML需要用UTF-8格式保存即可.

<html> 
<body> 
<p><canvas id="canvas" style="border:2px solid black;" width="200" height="200"></canvas> 
<script> 
var canvas = document.getElementById("canvas"); 
var ctx = canvas.getContext("2d"); 
var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" + 
             "<foreignObject width='100%' height='100%'>" + 
               "<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px;color:red'>" + 
                 "<em>I</em> like <span style='color:white; text-shadow:0 0 2px blue;'>网络的上面</span>" + 
               "</div>" + 
             "</foreignObject>" + 
           "</svg>"; 
var svg = new (self.BlobBuilder || self.MozBlobBuilder || self.WebKitBlobBuilder); 
var DOMURL = self.URL || self.webkitURL || self; 
var img = new Image(); 
svg.append(data); 
var url = DOMURL.createObjectURL(svg.getBlob("image/svg+xml;charset=utf-8")); 
img.onload = function() { 
    ctx.drawImage(img, 0, 0); 
    DOMURL.revokeObjectURL(url); 
}; 
img.src = url; 
</script> 
</body> 
</html>

星期一, 七月 16, 2012

tcpdump debug http traffic and dns query.

tcpdump -vvv -s 0 -l port 53

windump -i \Device\NPF_{CDF6DEBB-8C8E-49EF-91D5-CF6A69F1FE81} -n port 80 or port 443 or port 53

adb shell tcpdump -i  wlan0 -n port 80 or port 443 or port 53

星期五, 六月 08, 2012

Android memory usage

2.名词解释
App:Application
VSS - Virtual Set Size 虚拟耗用内存(包含共享库占用的内存)
RSS - Resident Set Size 实际使用物理内存(包含共享库占用的内存)
PSS - Proportional Set Size 实际使用的物理内存(比例分配共享库占用的内存)
USS - Unique Set Size 进程独自占用的物理内存(不包含共享库占用的内存)

tcpdump syntax

http://danielmiessler.com/study/tcpdump/

星期二, 四月 03, 2012

POI 3.7如何实现cell的填充颜色。

类似Excel 右上角填充颜色的效果。
必须在setCellValue之后,再调用setCellStyle的语句。
顺序不能错误,否则效果不如意。
        style = wb.createCellStyle();
        style.setFillForegroundColor(HSSFColor.YELLOW.index);
        style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        cell = row.createCell((short) 2);
        cell.setCellValue("X");
        cell.setCellStyle(style);

如何在JSP里实现Streaming content,流失内容,让内容逐渐显示

<%@page buffer="none"%>
2.在out.println一些之后使用out.flush().

这样在浏览器内就显示出来效果了,逐渐显示,而不是全部一下显示了。


星期二, 三月 06, 2012

如何制作Android显示百分比数字的状态条。

main.xml

<?xml version="1.0" encoding="utf-8"?>
<!--  -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:padding="0dip"
>
<ProgressBar android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:indeterminateOnly="false"
android:layout_height="30dip"  />
<TextView
android:id="@+id/perc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:textColor="#ff0000"
android:textStyle="bold"
/>
</RelativeLayout>

代码:
package wxk.com;

import android.app.Activity;
import android.os.Bundle;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
public class ThreadDemoActivity extends Activity {
    ProgressBar bar;
    TextView percent;
    Handler handler=new Handler() {
    @Override
    public void handleMessage(Message msg) {
    bar.incrementProgressBy(5);
    percent.setText(String.format("%03d%%", bar.getProgress()));
    }
    };
    boolean isRunning=false;
    @Override
    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    bar=(ProgressBar)findViewById(R.id.progress);
    percent=(TextView)findViewById(R.id.perc);
    }
    public void onStart() {
    super.onStart();
    bar.setProgress(0);

    Thread background=new Thread(new Runnable() {
    public void run() {
    try {
    for (int i=0;i<20 && isRunning;i++) {
    Thread.sleep(1000);
    handler.sendMessage(handler.obtainMessage());
    }
    }
    catch (Throwable t) {
    // just end the background thread
    }
    }
    });
    isRunning=true;
    background.start();
    }
    public void onStop() {
    super.onStop();
    isRunning=false;
    }
}

星期五, 二月 24, 2012

Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)

Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc)

The default shell on most Linux operating systems is called Bash. There are a couple of important hotkeys that you should get familiar with if you plan to spend a lot of time at the command line. These shortcuts will save you a ton of time if you learn them. 

 



Ctrl + A Go to the beginning of the line you are currently typing on
Ctrl + E Go to the end of the line you are currently typing on
Ctrl + L               Clears the Screen, similar to the clear command
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Same as backspace
Ctrl + R Let's you search through previously used commands
Ctrl + C Kill whatever you are running
Ctrl + D Exit the current shell
Ctrl + Z Puts whatever you are running into a suspended background process. fg restores it.
Ctrl + W Delete the word before the cursor
Ctrl + K Clear the line after the cursor
Ctrl + T Swap the last two characters before the cursor
Esc + T Swap the last two words before the cursor
Alt + F Move cursor forward one word on the current line
Alt + B Move cursor backward one word on the current line
Tab Auto-complete files and folder names

星期四, 十二月 22, 2011

html 模拟终端效果 style.

pre {
display: block;
width: 95%;
background: #222;
border-left: 6px solid #1664d9;
color: #0c0;
padding: 10px;
overflow:auto;
}

星期二, 十二月 13, 2011

Linux查询网络连接并搜索统计。

lsof -i4 |grep -c -E '10.1.11.12|10.1.11.24'
grep -E 选项可以同时搜索多个字符串,用符号 |隔开。

lsof -i4 只显示TCP IPV4的记录,也就是网络连接数目了。


星期二, 十一月 22, 2011

Android repo sync hang

可以利用:
repo --debug sync -j 12
来看看错误原因。
往往需要多次同步才可以。


星期六, 十月 29, 2011

How to fix problem of incompatibility between GCC 4.6 and Android 2.3

How to fix problem of incompatibility between GCC 4.6 and Android 2.3
http://buildall.wordpress.com/2011/05/27/how-to-fix-problem-of-incompatibility-between-gcc-4-6-and-android-2-3-gingerbread/

Hello everybody. Let's see how we can fix one problem that can happen when you try to compile the Android 2.3 after you already have installed GCC 4.6.

During Android compilation you can receive the following error message:

host Executable: acp (out/host/linux-x86/obj/EXECUTABLES/acp_intermediates/acp)
host SharedLib: libneo_cs (out/host/linux-x86/obj/lib/libneo_cs.so)
host C++: libutils <= frameworks/base/libs/utils/RefBase.cpp
frameworks/base/libs/utils/RefBase.cpp: In member function 'void android::RefBase::weakref_type::trackMe(bool, bool)':
frameworks/base/libs/utils/RefBase.cpp:483:67: error: passing 'const android::RefBase::weakref_impl' as 'this' argument of 'void android::RefBase::weakref_impl::trackMe(bool, bool)' discards qualifiers [-fpermissive]
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libutils_intermediates/RefBase.o] Error 1
make: *** Waiting for unfinished jobs....

To fix that, open a terminal and run (assuming you are in the folder android):

gedit frameworks/base/libs/utils/Android.mk

Change the line:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS)

To:

LOCAL_CFLAGS += -DLIBUTILS_NATIVE=1 $(TOOL_CFLAGS) -fpermissive

After that, save the file and recompile the Android again.

That's it. See you next time.


星期二, 十月 25, 2011

如何安装Guest Addtions 在VirtualBox 和utunbu 11.10。

首先必须安装pae头文件


You can follow the steps below to install the guest additions program on your ubuntu 11.10:

1) Create a temp directory in your home directory
2) Copy the whole file into the temp directory from /media/VBo..
3) Sudo apt-get install linux-headers-3.0.0-12-generic-pae
 *Actually you get to make sure what kernel version on your machine
 *After that, make sure your get "linux-headers-3.0.0-12-generic-pae" tree in "usr/src"
4) Install the guest additions utility.

然后运行autorun.sh 编译并安装对应模块。
具体编译log可以查看/var/log/vboxadd-install.log
/usr/bin/VBoxClient× 系列软件,可以运行。
启动桌面后,即可粘帖了

星期一, 五月 23, 2011

window xp发现所有进程及其命令行参数

WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid



星期五, 五月 06, 2011

Java WebStart和可执行jar文件如何读取外部jar文件包含的资源。

如何使用classLoad 读取外部jar文件中的资源?

网络运行的Java Webstart的JNLP的写法里和可执行的jar文件里,都包含了对外部jar文件的依赖的语法
比如JNLP 语法:
 <jar href="lib/hsqldb.jar"/>

可执行jar文件MANIFEST.MF里包含的语句:
Class-Path:
lib/appframework-1.0.3.jar
lib/swing-worker-1.1.jar

常见的是把图片等其他非class文件组织打包成一个jar文件,方便程序中使用。

在可执行的jar文件中,只需要一行代码就可以得到这些资源。

比如在lib/appframework-1.0.3.jar包含一个打印格式文件jrxml
都放在report/目录下,一个工作单打印文件WorkOrder.jrxml.

 必须使用Thread.currentThread().getContextClassLoader()定制的ClassLoader来调用
  或this.getClass().getClassLoader()

  注意this的意思必须是个运行时的类实例,而不能是静态类的.class.getClass()的方法。

        InputStream test=null;
        try
        {
        test = Thread.currentThread().
getContextClassLoader().getResourceAsStream("report/WorkOrder.jrxml"); 
或者:
        test =new YouCurrentClassName().getClass().getClassLoader().
getResourceAsStream("report/WorkOrder.jrxml"); 
        if(test!=null)
        {  
        InputStreamReader inr=new InputStreamReader(test,"UTF-8");
        BufferedReader br=new BufferedReader(inr);
        String line="";
        while( (line=br.readLine())!=null)
        {
         System.out.println(line);  
        }


另外不在classpath里的jar包的资源调用。

可以使用java.net.URL("jar:file://d:/temp/test.jar!");的语法来读取。
    public JarFile tJar = null;
    public JarURLConnection uc = null;
   String resourcepath="image/log.jpg";

          URL u = new URL("jar:file:lib/ReportResource_jrxml.jar!/");
            uc = (JarURLConnection)u.openConnection();
            tJar = uc.getJarFile();
//            Enumeration entries = tJar.entries();
//            while (entries.hasMoreElements()) {
//                ZipEntry entry = (ZipEntry) entries.nextElement();
//                System.out.println(entry.getName());
//
//            }
            input = tJar.getInputStream(tJar.getEntry(resourcepath));

星期四, 五月 05, 2011

判断内部IP地址和外部IP地址(private IP address or public IP Address)

/*
* Judge IP Address is private or public address
*/

public static boolean isInnerIP(String ipAddress){    
        boolean isInnerIp = false;    
        long ipNum = getIpNum(ipAddress);    
        /**   
        私有IP:A类  10.0.0.0-10.255.255.255   
               B类  172.16.0.0-172.31.255.255   
               C类  192.168.0.0-192.168.255.255   
        当然,还有127这个网段是环回地址   
        **/
   
        long aBegin = getIpNum("10.0.0.0");    
        long aEnd = getIpNum("10.255.255.255");    
        long bBegin = getIpNum("172.16.0.0");    
        long bEnd = getIpNum("172.31.255.255");    
        long cBegin = getIpNum("192.168.0.0");    
        long cEnd = getIpNum("192.168.255.255");    
        isInnerIp = isInner(ipNum,aBegin,aEnd) || isInner(ipNum,bBegin,bEnd) || isInner(ipNum,cBegin,cEnd) || ipAddress.equals("127.0.0.1");    
        return isInnerIp;               
}   

private static long getIpNum(String ipAddress) {    
    String [] ip = ipAddress.split("\\.");    
    long a = Integer.parseInt(ip[0]);    
    long b = Integer.parseInt(ip[1]);    
    long c = Integer.parseInt(ip[2]);    
    long d = Integer.parseInt(ip[3]);    
   
    long ipNum = a * 256 * 256 * 256 + b * 256 * 256 + c * 256 + d;    
    return ipNum;    
}   


private static boolean isInner(long userIp,long begin,long end){    
     return (userIp>=begin) && (userIp<=end);    
}  

星期五, 四月 15, 2011

改变JDE(julian)日期为标准ISO 格式(年-月-日)

这里:WATRDJ  是Order Date.
WASTRT 是Order StartDate,都是6个长度的numberic 的字段。
通过下列表达式可以将其转换为标准的 yyyy-MM-dd格式。

TIMESTAMP(DATE(DIGITS(DEC(WATRDJ + 1900000,7,0))),TIME('00:00:00')) as t1 ,
char(DATE(CHAR(DEC(WASTRT + 1900000,7,0))),iso)

星期五, 三月 25, 2011

如何删除JDialog右上角的X 关闭按钮

<code>
import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Testing
{
public void buildGUI()
{
JDialog.setDefaultLookAndFeelDecorated(true);

JDialog d = new MyDialog();
d.setModal(true);
d.getRootPane().setDefaultButton(null);


JPanel p = new JPanel(new GridBagLayout());

JButton btn = new JButton("Exit");

p.add(btn,new GridBagConstraints());

d.getContentPane().add(p);

d.setSize(400,300);

d.setLocationRelativeTo(null);

btn.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

System.exit(0);

}

});

d.setVisible(true);

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable()
{
public void run(){
new Testing().buildGUI();
}
});
}
}
class MyDialog extends JDialog
{
public MyDialog()
{
System.out.println("....");
removeX(this);
}
public void removeX(Component comp)
{
if (comp instanceof JButton)
{
System.out.println("..."+comp);
Icon i=((JButton)comp).getIcon();
System.out.println("..2."+i.getClass());

//System.out.println("...2"+(AbstractButton)comp.getDefaultIcon());
comp.getParent().remove(comp);
}

if (comp instanceof Container)
{
Component[] comps = ((Container)comp).getComponents();
for(int x = 0, y = comps.length; x < y; x++)
{
removeX(comps[x]);
}
}
}
}
</code>

星期一, 二月 07, 2011

VIM 大小写不敏感搜索.

一个是用全局变量:
:set ic  (:set ignorecase) 忽略大小写
:set noic (:set noignorecase) 大小写敏感

或者使用:
/\cword.用前置模式来搜索,也可以


星期三, 一月 12, 2011

ECL 10.7.1 如何才能正确打印出汉字

ecl.exe>(load "d:\\temp\\foo.lsp" :external-format :CP936)

foo.lsp文件内容
;foo.lsp
(ext::stream-external-format-set *standard-input* :CP936)
(ext::stream-external-format-set *standard-output* :CP936)

(print (length "好吧"))

(print "TEST" *standard-output*)
(princ "好吧" *standard-output*)
(format t "~%汉字来也")

这个代码只能在文件中执行,如果在ecl console里逐行敲入这些代码,反而出现错误:
ECL (Embeddable Common-Lisp) 10.7.1
Copyright (C) 1984 Taiichi Yuasa and Masami Hagiya
Copyright (C) 1993 Giuseppe Attardi
Copyright (C) 2000 Juan J. Garcia-Ripoll
ECL is free software, and you are welcome to redistribute it
under certain conditions; see file 'Copyright' for details.
Type :h for Help.
Top level in: #<process TOP-LEVEL>.
> (ext::stream-external-format-set *standard-input* :CP936)

> (ext::stream-external-format-set *standard-output* :CP936)

> (format t "汉字来也")
鹤酪
NIL
> (format t "汉字来也")
鹤酪
NIL
>

星期四, 一月 06, 2011

LISP在package如何访问TOPLEVEL定义的全局变量(Global Variable)?

如果在一个main.lisp中分别(load "*....lisp"),载入定义的package或者一些全局的数据.
往往会出现如下场景类似的问题:

 CL-USER> (defvar foo 108) FOO CL-USER> foo 108 CL-USER>
CL-USER> (in-package :asdf) #<PACKAGE "ASDF"> ASDF>
The variable FOO is unbound. [Condition of type UNBOUND-VARIABLE]

避免这个情况,就是用如下引用方式:
ASDF> cl-user::foo 108 ASDF>

星期三, 十二月 29, 2010

ECL 10.4.1 在window 用 mingw 3.4.5 编译

ECL 10.4.1 compile under mingw for window.

first download gc 7.2
http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc-7.2alpha4.tar.gz
展开。
然后进入msys
cd d:/gc-7.2alpha4
敲入命令:
1.首先配置
./configure --enable-shared=no --enable-static=yes --enable-cplusplus --enable-large-config --enable-parallel-mark --enable-threads=win32;make
2.开始编译
 make
3.安装到/usr/local目录下,实际的msys local目录下

success then.

cd d:/ecl-10.4.1
//./configure --prefix=/usr/local  --enable-boehm=system --enable-longdouble --enable-gengc --enable-precisegc --enable-threads --enable-unicode  CPPFLAGS=-ID:\\gc-7.2alpha4\\include LDFLAGS=-LD:\\gc-7.2alpha4\\.libs
make clean;./configure --prefix=/usr/local --enable-threads -enable-boehm  --enable-unicode ;make

MSVC:
nmake ECL_UNICODE=1 ECL_DEBUG=0

#include <ecl/ecl.h>
# include <unistd.h>
# include <pthread.h>
int main(int argc, char **argv)  {
  cl_boot(argc, argv);
  cl_object obj=c_string_to_object("\"
Hello world\"");
  cl_pprint(1,obj);
  cl_shutdown();
}
(ext::stream-external-format-
set *standard-input* :utf-8)
(ext::stream-external-format-
set *standard-output* :utf-8)

--build=pentium4-pc-mingw32
如何使用ecl.dll
使用
ecl-config --cflagsecl-config --ldflags 得到你需要传递给你的编译器的变量

发布使用ecl.dll的程序。
必须包含ecl.dll 和ucd.dat 两个文件同执行文件在同一个目录下

ucd.dat
显示汉字:

 cl_object obj=c_string_to_object("\"
Hello world你好\"");
   wxMessageBox(wxString(ecl_
base_string_pointer_safe(obj),wxConvUTF8));

ECL生成独立的可执行文件.
1.新建hello.lisp文件,包含如下代码
  (princ "Hello world!")
 (terpri)
 (quit)
2.生成object文件
(compile-file "hello.lisp" :system-p t) 
3.link成可执行文件
 (c:build-program "hello" :lisp-files '("hello.o"))

4../hello.exe


星期四, 十二月 23, 2010

如何用一个字符串作为Lisp Hashtable的key?

Lisp Hashtable默认的比较是用equa 函数,更换比较函数即可。

(setq table (make-hash-table)) =>  #<HASH-TABLE EQL 0/120 46142754>
 (setf (gethash "one" table) 1) =>  1
 (gethash "one" table) =>  NIL, false

 (setq table (make-hash-table :test 'equal)) =>  #<HASH-TABLE EQUAL 0/139 46145547>
 (setf (gethash "one" table) 1) =>  1
 (gethash "one" table) =>  1, T
 (make-hash-table :rehash-size 1.5 :rehash-threshold 0.7)

Lisp 如何得到函数返回的多个值?

 LISP很多函数返回几个值,默认是得到第一个值。其他的返回值如何得到呢?
比如parse-integer 返回2个值。
如果想的到第二个返回值,可以用(nth-value (parse-integer "20") 1)
得到2,字符串索引。

还有其他函数可以得到所有返回值。

 nth-value [already mentioned and only pertaining to multiple-vals]
 multiple-value-bind [no such thing as multiple-value-let]
 multiple-value-call
 multiple-value-setq
(multiple-value-list (floor 5 2))
得到:(2 1)

星期一, 十二月 20, 2010

Lisp打开跟踪,输出到log文件

(dribble  "c:\\temp\\output.txt") ;打开跟踪文件,所有输出都定位到c:\temp\output.text
(dribble) ;关闭跟踪输出。



星期二, 十二月 14, 2010

健身一次负重的重量如何计算?(比如哑铃,杠铃)

首先要得出你最大能举出的重量。(1RM)
Repetition Maximum
有两个公式可以计算得出1RM的重量:

Brzycki's 公式

  • 重量÷ ( 1.0278 - ( 0.0278 × 重复次数 ) )

另外一个系数的公式

  • 重量 × ( 1 + ( 0.033 × 重复次数 ) )

这样一个体重80公斤的人计划一组重复锻炼动作16次计算得出的1RM是:
Brzycki结果:137公斤
          另外:122公斤

然后利用另外一张 负重和重复 关系表。

   14 to 20RM = 60% of 1RM
    11 to 14RM = 70% of 1RM
    6 to 11RM = 80% of 1RM
    3 to 6RM = 90% of 1RM

得到重复16次相当于60%的 1RM 及137 × 0.6 =82.2 公斤或122* 0.6 = 73.2 公斤
这样就得出每次重复需要举起的实际总量为:82.2/16=5.1375公斤 或73.2/16=4.575公斤

所以锻炼的次数越多,每次需要举起的重量越少。
 
如果你是哑铃锻炼的话,一个体重80KG的人需要准备一个单只 2.5KG的哑铃或杠铃来举重。

% 重量 重复次数 % 重量 重复次数 % 重量
重复次数
60 17 75 10 90 5
65 14 80 8 95 3
70 12 85 6 100 1


实际锻炼中往往根据自己的目的来调整实际重复的次数或RM,这个同锻炼的目的有关系。
下面的表是肌肉锻炼目的和RM的关系,可以自己选择,然后确定实际的重量

    1RM的到3RM - 最大刺激神经肌肉力量
    
4RM以6RM -   最大强度的刺激肌肉肥大
    
6RM到12RM -  肌肉(肥大)力量锻炼合适
    
12RM到20RM - 肌肉体积良好和获得良好的耐力


一个比较好的LISP IDE 工具 lispIDE

下载:http://www.daansystems.com/lispide/
这个同居可以同SBCL Download - Steel Bank Common Lisp 配合一起使用


如图:
第一次运行lispIDE的时候,需要你指定LISP 解释器的位置,如果使用的SBCL
在需要首先新建一个sbcl.bat文件,里面包含如下语句:
D:\sbcl\1.0.37\sbcl.exe --core d:\sbcl\1.0.37\sbcl.core
然后再LISPIDE菜单中选择 Settings /Set Lisp Path指向这个sbcl.bat
则出现上面的运行界面。



星期五, 十二月 10, 2010

动态扩展的数组

如何定义个二维数组。代码

(defvar foo (make-array 1 :fill-pointer 0))
(vector-push-extend (vector 1 2 3) foo)
(vector-push-extend (vector 1 2 3) foo)

星期三, 十一月 24, 2010

如何遍历一个LIST 数组。

在List中vector其实本质上就是一个一维的数组。所以数组函数也是可以用于vector的

简单代码如下,构造一个List数组,然后遍历之。

(defvar alls)
(setf alls (vector '(10 12 14 20 22 26) '(03 05 06 07 11 12)))
(loop for i from 1 to (array-total-size alls)
do(loop for h from 1 to (list-length (svref alls (1- i)))
do(format t "~d," (nth (1- h) (svref alls (1- i))))
)
(format t "~%")
)
效果如图:





星期四, 十一月 11, 2010

MYSQL text column insert into UTF-8 .

注意:
http://dev.mysql.com/doc/refman/5.0/en/blob.html
text is  nonbinary strings is character strings . They have a character set, and values are sorted and compared based on the collation of the character set.

同varchar的行为不同。
table people字段chinese_desc为如下类型
CHINESE_DESC   text          utf8_unicode_ci

所以使用Java查询和插入 UTF-8字段插入汉字需要encoding 为 iso-8859-1
插入代码:
String SQL="update people set chinese_desc='\u9802\u7d44\u5408\u88fd\u9020' where ENG_desc='DJZHZZ' ;";//\u9802\u7d44\u5408\u88fd\u9020
String UTF8=new String(SQL.getBytes("UTF-8"),"ISO-8859-1");
PreparedStatement stmt=conn.prepareStatement("set names latin1");
stmt.execute(UTF8);

读取:

        String value =rset.getString("chinese_desc");   
        String value4 = new String(value.getBytes("ISO-8859-1"),"UTF-8");
      System.out.println(value4+"........");



星期一, 十月 18, 2010

MSSQL 模仿 ROWID 功能

select * from (select *, ROW_NUMBER() OVER (ORDER BY batch_id ASC) AS ROWID from SalesOrder ) as ma where ma.rowid > 1000

星期三, 九月 01, 2010

ABAP Native SQL 里的Host Variables

Host Vairable翻译为宿主变量或者托管变量,似乎都可以.主要是通过冒号: 来表示的。其他用法和普通ABAP变量或其他structure,element等等一样。没什么区别。


Host variables are global or local variables declared in the ABAP program, or variables that are used in operand positions by native SQL statements. For identification purposes, the variable name has a colon (:) directly in front of it. Instead of specifying a variable itself, you can also specify a field symbol to which the variable is assigned. The specification of a dereferenced data reference variable is not possible.

You can use elementary fields and structures with elementary components as host variables. If a structure is listed in a native SQL statement after INTO, it is converted by the native SQL interface as if its components were listed as individual fields separated by commas.

星期四, 八月 12, 2010

ABAP Label for Operands

  • Structured data types or data objects (structure)
    A component comp of a structured data type or a structure struct is accessed using the label struct-comp.
  • Instances of classes (objects)
    The label ref->comp is used to access a component comp of an object. The character -> is the object component selector
  • Classes

    The label class=>comp can be used to access a static component comp of a class without an instance of the class having to be created. The character => is the class component selector.


  • Interfaces

    The label

    intf~comp

    is used to access a component comp of an interface. The character ~ is the interface component selector.

  • Escape character for names
    The character ! can be written directly before a name in order to distinguish it from an ABAP word of the same name in a statement.

星期二, 八月 10, 2010

获取当前登录用户的profile.

data:  C_PROFILE type  table of BAPIPROF    ."STANDARD TABLE OF
DATA: wa_profiles LIKE LINE OF  C_PROFILE.
data  it_prof type BAPIPROF occurs 0.
DATA: it_roles TYPE TABLE OF bapiagr,
wa_roles LIKE LINE OF it_roles.

F_USERNAME = SY-UNAME.

CALL FUNCTION 'BAPI_USER_GET_DETAIL'
  EXPORTING
    USERNAME = F_USERNAME
  IMPORTING
    ADDRESS  = S_ADDRESS
  TABLES
    RETURN   = TAB_RETURN
     profiles = C_PROFILE
     activitygroups = it_roles.

LOOP AT it_roles INTO wa_roles.
 write: /,'Roles:',wa_roles-AGR_NAME.
ENDLOOP.
LOOP AT C_PROFILE INTO wa_profiles.
 write: /,'Profile::',wa_profiles-BAPIPROF,wa_profiles-BAPIPTEXT.
ENDLOOP.

星期四, 八月 05, 2010

SAP IMG的意思

IMG is the short form for Implementation Guide
即:IMG是单词实施指南的意思

星期五, 七月 30, 2010

ABAP 指针。

SAP ABAP--通过Field-symbols修改内表( same as c and c++ point)

 

1.      什么是ABAP指针:
在ABAP里面,field symbol就相当于c语言的指针。如果你定义并且分配了相应的结构或者变量给它,其实它就指

向这个结构或者变量的地址,如果修改了field symbol的值,则相应结构或者变量的值也随之更改。

2.      如何定义指针:
基本形式:FIELD-SYMBOLS <fs>.
附加信息:
  1. ... TYPE :定义一个数据类型,然后定义指针
  2. ... TYPE REF TO :指针指向类或者接口
  3. ... TYPE REF TO :指针指向数据结构
  4. ... TYPE LINE OF :指针内表的行项目
  5. ... LIKE :指针为数据库表类型
  6. ... LIKE LINE OF :指针类型为数据库表的行项目

3.      如何分配指针:
(1). ASSIGN f TO .:分配一个指针,包括以下几种类型
1. ... CASTING ... :主要对unicode系统地操作
  1a. ... CASTING
  1b. ... CASTING TYPE type
  1c. ... CASTING ... DECIMALS dec
  1d. ... CASTING LIKE f1
2. ... TYPE type :直接指定类型
3. ... DECIMALS dec :指定小数点位数
4. ... RANGE range:指定范围
(2). 分配结构中的某个字段给指针
ASSIGN COMPONENT idx  OF STRUCTURE struc TO .
ASSIGN COMPONENT name OF STRUCTURE struc TO .
(3). 分配类的方法给指针
ASSIGN dref->* TO .
(4). 从f开始,是f的n倍长之后的内容分配给指针
ASSIGN f INCREMENT n TO .
(5). 分配局部变量给指针
ASSIGN LOCAL COPY
    3a. ASSIGN LOCAL COPY OF f TO .
    3b. ASSIGN LOCAL COPY OF INITIAL f TO .
    3c. ASSIGN LOCAL COPY OF INITIAL LINE OF itab TO .
    4c. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
(6). ASSIGN dynamicJ:动态分配指针
    4a. ASSIGN (f) TO .
    4b. ASSIGN oref->(f) TO .
    4c. ASSIGN (f1)=>(f2) TO .
    4d. ASSIGN TABLE FIELD (f) TO .
    4e. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO .
    4f. ASSIGN LOCAL COPY OF ... (f) TO .

4.      如何取消分配:
    UNASSIGN .

不清楚内表内表到底是itab还是itab2,但是又要访问内表里的第2个字段。所以在loop的时候不能用to到一个结构体,而要用assigning一个指向ANY的指针,然后进行后面的操作。

IF n = 1.
  ASSIGN itab[] TO <tab_fs>. " <tab_fs>是指向standard table的
ELSE.
  ASSIGN itab2[] TO <tab_fs>.
ENDIF.
LOOP AT <tab_fs> ASSIGNING <wa_fs>.
  ASSIGN COMPONENT 2 OF STRUCTURE <wa_fs> TO <field_fs>. ”filed_fs是ANY的
  WRITE: / <field_fs>.
ENDLOOP.

具体实现:

1.结构的动态查询

DEFINE SELECT_DATA_TO_WA.
  SELECT &1
    FROM &2
    INTO CORRESPONDING FIELDS OF &3
   WHERE (&4).
    EXIT.
  ENDSELECT.
END-OF-DEFINITION.

2.变量的动态查询

DEFINE SELECT_DATA_TO_VARIANT.
  SELECT &1
    FROM &2
    INTO &3
   WHERE (&4).
    EXIT.
  ENDSELECT.
END-OF-DEFINITION.

3.内表的动态查询

DEFINE SELECT_DATA_TO_VARIANT.
  SELECT &1
    FROM &2
    INTO CORRESPONDING FIELDS OF TABLE &3
   WHERE (&4).
    EXIT.
  ENDSELECT.
END-OF-DEFINITION.

具体程序实现:

DATA: L_FIELD(100) TYPE C,
      L_TABLE(10)  TYPE C,
      L_COND(100)  TYPE C.

DATA: I_COND TYPE TALBE OF L_COND.

FIELD-SYMBOLS TYPE ANY.

START-OF-SELECTION.

  CONCATENATE 'CARRID' 'CONNID' 'CITYFROM'
         INTO L_S
  SEPARATE BY SPACE.

  CONCATENATE 'CONNID = ' '0123'
         INTO L_COND.

APPEND COND TO I_COND.

L_TABLE = 'SPFLI'.

IF IS ASSIGNED.

  UNASSIGN .
  ASSIGN SPFLI TO .

ELSE.

  ASSIGN SPFLI TO .

ENDIF.

SELECT_DATA_TO_WA (L_S) (L_TABLE) I_COND.

=================================================================================

FIELD-SYMBOLS CASTING

REPORT z_barry_fs_casting.

TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.

FIELD-SYMBOLS <fs> TYPE t_date.

ASSIGN sy-datum TO <fs> CASTING.

WRITE: / sy-datum,
       / <fs>-year , / <fs>-month, / <fs>-day.

=================================================================================

光标操作

DATA: w_fname(20) TYPE c,
      w_val(10) TYPE c.

PARAMETERS: p1(10) TYPE c,
            p2(10) TYPE c,
            p3(10) TYPE c.

AT SELECTION-SCREEN.
  CHECK sy-ucomm IS INITIAL.
  GET CURSOR FIELD w_fname VALUE w_val.
  CHECK w_val IS INITIAL.   "如果没有输入
  CLEAR w_fname.

AT SELECTION-SCREEN OUTPUT.
  CASE w_fname.
    WHEN 'P1'.
      CLEAR w_fname.
      SET CURSOR FIELD 'P2'.
    WHEN 'P2'.
      CLEAR w_fname.
      SET CURSOR FIELD 'P3'.
  ENDCASE.

  ======================================================================

ABAP--Field Symbol 的Example(来自SAP的样例)

Full type specification

REPORT demo_field_symbols_type .
DATA: BEGIN OF line,
         col1(1) TYPE c,
         col2(1) TYPE c VALUE 'X',
       END OF line.
FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.
WRITE: <fs>-col1, <fs>-col2.


Forcing structures

REPORT demo_field_symbols_structure .
DATA: wa(10) TYPE c VALUE '0123456789'.
DATA: BEGIN OF line1,
         col1(3) TYPE c,
         col2(2) TYPE c,
         col3(5) TYPE c,
      END OF line1.
DATA: BEGIN OF line2,
         col1(2) TYPE c,
         col2 TYPE sy-datum,
      END OF line2.
* obsolete -------------------------------------------------------------
FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,
               <f2> STRUCTURE line2 DEFAULT wa.
* correct --------------------------------------------------------------
FIELD-SYMBOLS <f3> LIKE line1.
ASSIGN wa TO <f3> CASTING.
FIELD-SYMBOLS <f4> LIKE line2.
ASSIGN wa TO <f4> CASTING.
* ----------------------------------------------------------------------
WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,
       / <f2>-col1, <f2>-col2.
SKIP.
WRITE: / <f3>-col1, <f3>-col2, <f3>-col3,
       / <f4>-col1, <f4>-col2. 


Static assign

REPORT demo_field_symbols_stat_assign .
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE i.
DATA: text(20)  TYPE c VALUE 'Hello, how are you?',
      num       TYPE i VALUE 5,
      BEGIN OF line1,
        col1 TYPE f VALUE '1.1e+10',
        col2 TYPE i VALUE '1234',
      END OF line1,
      line2 LIKE line1.
ASSIGN text TO <f1>.
ASSIGN num TO  <f2>.
DESCRIBE FIELD <f1> LENGTH <f2>.
WRITE: / <f1>, 'has length', num.
ASSIGN line1 TO <f1>.
ASSIGN line2-col2 TO <f2>.
MOVE <f1> TO line2.
ASSIGN 'LINE2-COL2 =' TO <f1>.
WRITE: / <f1>, <f2>.


Assign with offset

REPORT demo_field_symbols_stat_as_off .
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: BEGIN OF line,
        string1(10) VALUE '0123456789',
        string2(10) VALUE 'abcdefghij',
      END OF line.
WRITE / line-string1+5.
ASSIGN line-string1+5 TO <fs>.
WRITE / <fs>.
ASSIGN line-string1+5(*) TO <fs>.
WRITE / <fs>.

REPORT demo_field_symbols_stat_as_of2 .
FIELD-SYMBOLS <fs> TYPE ANY.
DATA: BEGIN OF line,
        a TYPE c VALUE '1', b TYPE c VALUE '2',
        c TYPE c VALUE '3', d TYPE c VALUE '4',
        e TYPE c VALUE '5', f TYPE c VALUE '6',
        g TYPE c VALUE '7', h TYPE c VALUE '8',
      END OF line,
      off TYPE i,
      len TYPE i VALUE 2.
DO 2 TIMES.
  off = sy-index * 3.
  ASSIGN line-a+off(len) TO <fs>.
  <fs> = 'XX'.
ENDDO.
DO 8 TIMES.
  off = sy-index - 1.
  ASSIGN line-a+off(1) TO <fs>.
  WRITE <fs>.
ENDDO.


Dynamic assign

REPORT demo_field_symbols_dynami_as_2 .
TABLES sbook.
DATA: name1(20) TYPE c VALUE 'SBOOK-FLDATE',
      name2(20) TYPE c VALUE 'NAME1'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN TABLE FIELD (name1) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
ASSIGN TABLE FIELD (name2) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.


Assigning field symbols

REPORT demo_field_symbols_dynami_as_3 .
DATA: BEGIN OF s,
        a TYPE c VALUE '1', b TYPE c VALUE '2', c TYPE c VALUE '3',
        d TYPE c VALUE '4', e TYPE c VALUE '5', f TYPE c VALUE '6',
        g TYPE c VALUE '7', h TYPE c VALUE '8',
      END OF s.
DATA off TYPE i.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN s-a TO <fs>.
DO 4 TIMES.
  off = sy-index - 1.
  ASSIGN <fs>+off(1) TO <fs>.
  WRITE <fs>.
ENDDO. 


Assigning a structure by component

REPORT demo_field_symbols_assign_comp .
DATA: BEGIN OF line,
        col1 TYPE i VALUE '11',
        col2 TYPE i VALUE '22',
        col3 TYPE i VALUE '33',
      END OF line.
DATA comp(5) TYPE c VALUE 'COL3'.
FIELD-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.
ASSIGN line TO <f1>.
ASSIGN comp TO <f2>.
DO 3 TIMES.
  ASSIGN COMPONENT sy-index OF STRUCTURE <f1> TO <f3>.
  WRITE <f3>.
ENDDO.
ASSIGN COMPONENT <f2> OF STRUCTURE <f1> TO <f3>.
WRITE / <f3>. 


Casting with field symbol type

REPORT demo_field_symbols_casting.
TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.
FIELD-SYMBOLS <fs> TYPE t_date.
ASSIGN sy-datum TO <fs> CASTING.
WRITE / sy-datum.
SKIP.
WRITE: / <fs>-year , / <fs>-month, / <fs>-day. 


Casting with explicit type

REPORT demo_field_symbols_casting_typ.
TYPES: BEGIN OF t_date,
          year(4)  TYPE n,
          month(2) TYPE n,
          day(2)   TYPE n,
       END OF t_date.
FIELD-SYMBOLS: <fs> TYPE ANY,
               <f>  TYPE n.
ASSIGN sy-datum TO <fs> CASTING TYPE t_date.
WRITE / sy-datum.
SKIP.
DO.
  ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <f>.
  IF sy-subrc <> 0.
    EXIT.
  ENDIF.
  WRITE / <f>.
ENDDO. 


Casting with predefined data types

REPORT demo_field_symbols_assign_type .
DATA txt(8) TYPE c VALUE '19980606'.
DATA mytype(1) VALUE 'X'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN txt TO <fs>.
WRITE / <fs>.
SKIP.
* obsolete -------------------------------------------------------------
ASSIGN txt TO <fs> TYPE 'D'.
WRITE / <fs>.
ASSIGN txt TO <fs> TYPE mytype.
WRITE / <fs>.
SKIP.
* correct --------------------------------------------------------------
ASSIGN txt TO <fs> CASTING TYPE d.
WRITE / <fs>.
ASSIGN txt TO <fs> CASTING TYPE (mytype).
WRITE / <fs>. 


Casting decimla places

REPORT demo_field_symbols_assign_deci .
DATA: pack1 TYPE p DECIMALS 2 VALUE '400',
      pack2 TYPE p DECIMALS 2,
      pack3 TYPE p DECIMALS 2.
FIELD-SYMBOLS: <f1> TYPE ANY ,
               <f2> TYPE ANY.
WRITE: / 'PACK1', pack1.
SKIP.
* obsolete -------------------------------------------------------------
ASSIGN pack1 TO <f1> DECIMALS 1.
WRITE: / '<F1> ', <f1>.
pack2 = <f1>.
WRITE: / 'PACK2', pack2.
ASSIGN pack2 TO <f2> DECIMALS 4.
WRITE: / '<F2> ', <f2>.
pack3 = <f1> + <f2>.
WRITE: / 'PACK3', pack3.
<f2> = '1234.56789'.
WRITE: / '<F2> ', <f2>.
WRITE: / 'PACK2', pack2.
SKIP.
* correct --------------------------------------------------------------
ASSIGN pack1 TO <f1> CASTING TYPE p DECIMALS 1.
WRITE: / '<F1> ', <f1>.
pack2 = <f1>.
WRITE: / 'PACK2', pack2.
ASSIGN pack2 TO <f2> CASTING TYPE p DECIMALS 4.
WRITE: / '<F2> ', <f2>.
pack3 = <f1> + <f2>.
WRITE: / 'PACK3', pack3.
<f2> = '1234.56789'.
WRITE: / '<F2> ', <f2>.
WRITE: / 'PACK2', pack2.


Data areas for field symbols

REPORT demo_field_symbols_assign_err .
DATA: text1(10) TYPE c, text2(10) TYPE c, text3(5) TYPE c.
FIELD-SYMBOLS <fs> TYPE ANY.
DO 100 TIMES.                          "Runtime-Error!
  ASSIGN text1+sy-index(1) TO <fs>.
ENDDO. 


Data references

REPORT demo_data_reference.
TYPES: BEGIN OF t_struct,
         col1 TYPE i,
         col2 TYPE i,
       END OF t_struct.
DATA: dref1 TYPE REF TO data,
      dref2 TYPE REF TO data.
FIELD-SYMBOLS: <fs1> TYPE t_struct,
               <fs2> TYPE i.
CREATE DATA dref1 TYPE t_struct.
ASSIGN dref1->* TO <fs1>.
<fs1>-col1 = 1.
<fs1>-col2 = 2.
dref2 = dref1.
ASSIGN dref2->* TO <fs2> CASTING.
WRITE / <fs2>.
GET REFERENCE OF <fs1>-col2 INTO dref2.
ASSIGN dref2->* TO <fs2>.
WRITE / <fs2>. 

===========================================================================

ABAP--通过Field-symbols修改内表

report demo_field_symbols_assign_comp .

DATA: BEGIN OF gs_itab,
      drph(10) ,
      cmsl01(17),
      cmsl02(17),
      sl01(17),
      sl02(17),
      END OF gs_itab.
DATA: gt_ita1 LIKE gs_itab OCCURS 0 WITH HEADER LINE.

data gv_zd(15).

FIELD-SYMBOLS <sl> TYPE c.
FIELD-SYMBOLS <cmsl> TYPE c.
FIELD-SYMBOLS <fs> LIKE LINE OF gt_ita1.

DO 15 TIMES.
  gt_ita1-drph =  SY-INDEX .
  gt_ita1-cmsl01 = 2.
  append gt_ita1.
enddo.

write 'Before Modify:'.
write:/ 'cmsl01','cmsl02','sl01','sl02'.
loop at gt_ita1.
  write:/ '|',gt_ita1-cmsl01,'|',gt_ita1-cmsl02,'|',gt_ita1-sl01,'|' ,gt_ita1-sl02,'|'.
endloop.
loop at gt_ita1 aSSIGNING <fs>.
  ASSIGN COMPONENT 'CMSL01' OF STRUCTURE <fs> TO <cmsl>.
  ASSIGN COMPONENT 'SL01' OF STRUCTURE <fs> TO <sl>.
  move <cmsl>  to  <sl>.
  ASSIGN COMPONENT 'SL02' OF STRUCTURE <fs> TO <sl>.
  move <cmsl>  to  <sl>.
  <fs>-CMSL02 = 'A' .
endloop.

write / 'After Modify:'.
loop at gt_ita1.
  write:/ '|',gt_ita1-cmsl01,'|',gt_ita1-cmsl02,'|',gt_ita1-sl01,'|' ,gt_ita1-sl02,'|'.
endloop. 

注意:ASSIGN TABLE FIELD (f) TO <fs>. 只能用TABLES定义的变量
An important, but frequently misunderstood aspect of ABAP, is the "Field Symbol". But you'll find they aren't mysterious. In fact, they may remind you of some features in popular general-purpose programming languages.
Field symbols allow you to:
** Assign an alias to a data object(for example, a shortened name for data objects structured through several hierarchies
        For Example: <fs>-f instead of rec1-rec2-rec3-f)
** Set the offset and length for a string variably at runtime
** Set a pointer to a data object that you determine at runtime (dynamic ASSIGN)
** Adopt or change the type of a field dynamically at runtime
** Access components of a structure (from Release 4.5A) Point to lines of an internal table (process internal tables without a separate work area)

Field symbols in ABAP are similar to pointers in other programming languages. However, pointers (as used in PASCAL or C) differ from ABAP field symbols in their reference syntax.

The statement ASSIGN f to <fs> assigns the field f to field symbol <fs>. The field symbol <fs> then "points" to the contents of field f at runtime. This means that all changes to the
contents of f are visible in <fs> and vice versa. You declare the field symbol <fs> using the statement FIELD-SYMBOLS: <fs>.

Reference syntax
Programming languages such as PASCAL and C use a dereferencing symbol to indicate the difference between a reference and the object to which it refers; so PASCAL would use p^ for a pointer instead of p, C would use *p instead of p. ABAP does not have any such dereferencing symbol.
** In PASCAL or C, if you assign a pointer p1 to a pointer p2, you force p1 to point to the object to which p2 refers (reference semantics).
** In ABAP, if you assign a field symbol <fs1> to a field  symbol <fs2>, <fs1> takes the value of the data object to which <fs2> refers (value semantics).
** Field symbols in ABAP are always dereferenced, that is, they always access the referenced data object. If you want to change the reference yourself in ABAP, you can use the ASSIGN statement
to assign field symbol <fs1> to field symbol <fs2>.

星期二, 七月 20, 2010

SAP WD IE 8 Hang system,CPU HIGH 100%问题解决。

Sap Web Dynpro for ABAP ,IE 8访问,CPU消耗到100%,并且一直处于挂死状态。

经过google得到方法如下:

设置IE 显示固定在100%,而不让IE 8自己调整。

如图,则问题解决.

IE hang web dynrpo.JPG

星期三, 七月 07, 2010

如何建立sap icm web admin访问地址

进入 D:\usr\sap\SA1\SYS\exe\uc\NTAMD64
icmon -a 新建如下用户.


1.     
As user <sid>adm go to the directory where the executables are kept and call up icmon ‑a pf=<instance profile> .

The following appears:

Maintain authentication file

============================

File name (icmauth.txt):   .

       2.      If you are happy with the default file name, press the enter key, otherwise enter a different file name or path.

       3.      In the next menu choose a (add user to set).

       4.      Enter the user name, then the password twice, the group name, the subject of the X.509 certificate (wildcards allowed, and it can be left empty).

User Name: icmadm

Enter Password: *****

Re-enter Password: *****

Group name: admin

Subject Value of Client Cert: CN=template,*

new entry locally created

The user created is in group admin, the user is therefore an administration user without administration authorization. In particular this user can create further users in the Web admin interface.

If you select another group name other than admin, create a monitoring user that can monitor, but not administrate, the ICM/Web Dispatcher.

If you want a user to be able to log on only with the X.509 client certificate, you can enter an x as the password (with queries), which makes the following entry (in the example) in file:

icmadm:x:admin:CN=muster,*

       5.      Choose s (save changes of set to file), to copy your changes from the local buffer to the authorization file.

       6.      Choose q, to quit the program.

然后然后icmauth.txt复制到 :D:\usr\sap\SA1\SYS\global\security\data


可以 可以在 SAPGUI用 T-CODE :SMICM  然后从点击 display-All (shift+F5)显示 trace 文件

然后 从web http://localhost:8000/sap/admin 输入用户名,再进入管理UI 了





然后

然后



星期五, 七月 02, 2010

SE80删除一个class出现错误:You cannot perform this action in modification/enhancement mode

进入SE37 ,运行FUNCTION OO_INTERFACE_DELETE或 OO_CLASS_DELETE
来删除CLASS.

COMMIT 和FORCE的值设置为'X'

如图


或者关闭 modification assistant,双击打开class后,选择菜单:
edit menu and select modifications and select "switch off modification assistant".

如下图