2011/06/24

Android端末でのレポート表示 その2 (Android Part 2)

せっかくですので、AndroidからBI Publisherのレポートを呼び出すユーザ・インターフェイスを作成してみました。

選択されたレポートのレポート・リンクを呼び出すだけの仕様です。リストされるレポートはハードコードしているため、固定です。
また、ゲスト・ログインを有効にし、認証は省略します。

Figure 1: Scott Viewer on the home menu

レポートを選択するメニューは以下の画面です
Figure 2: Report select menu

レポートは以下の様に表示されます。
Figure 3: Report in HTML format


ヘッダおよびコントロールを非表示とし、レポートのHTMLだけが表示される仕様とすることで挙動は安定します。
※Android上での動作の障害になっているのは主にADFであると考えられますので、この使用方法であれば問題ないと考えられます。

ソース部分が非常に少ないため、参考にはなりませんが、プロジェクトのアーカイブはこちらからダウンロードできます。


[Summary]
The figures above shows the sample of Android application. You can retrieve report by tapping the corresponding list item.  onItemClick event of the list opens each report link.  


Notes:
The report names in the list are hard-coded (fixed).
To skip authentication, guest login is set enabled in BI Publisher configuration. And the reports are placed in the guest folder.


The archive of this sample is available here.



2011/06/22

Android端末でのレポート表示 (Android)

スマートフォンでの BI Publisher の挙動を確認します。

【端末環境】
物理端末ではなく、Android のエミュレータを使用します。
  • クライアントOS: Android Virtual Devices
  • Androidバージョン: Android 3.0
  • APIレベル: 11
  • 端末解像度: WVGA (800 x 480)


【Android端末からBI Publisherサーバへ接続】
ブラウザからログインします。画面下部の言語選択のドロップダウンリストは使用できません(タップしても動作しません)。


ログイン後、カタログ画面は通常通り表示できます。ここまでの画面遷移には問題ありませんが、いくつかのメニューは操作できません。


HTML形式であればレポートも表示できます。


ログイン画面からレポート表示まで、形だけは最低限動きます。しかしながら、ドロップダウンリストが使用できない等、実運用には残念ながら耐えられないと言えます(そもそもサポートされた環境ではありません)。



[Summary]
The screen shots above are BI Publisher user interface on Android browser. As far as I've checked, most of pull-down menus don't work.  It is not a good idea to use BI Publisher on Android so far.


[Client specs]
The client is emulator. The specifications are:

  • Client OS: Android Virtual Devices
  • Android Version: Android 3.0
  • API Level: 11
  • Resolution: WVGA (800 x 480)



[Screen shots]
Please see Figure 1 - 3.

2011/06/20

LOVの文字列とコード

BI Publisher の値リスト(LOV: List of Values)と、値リストを用いたメニュー式のパラメータについて説明します。

マニュアルには明確な記述が見受けられませんが、固定値だけでなく、SQL問い合わせでも、「ラベル」と「値」を定義できます。

【値リストの設定】
タイプに「SQL問い合わせ」を選択し、ラベルと値に相当する2つの列をSELECT句に指定します。1列目がリストに表示される名称、2列目がデータソースに実際に渡される値となります。
select dname, deptno from dept order by deptno
Figure 1: LOV setting


【出力結果】
出力結果は以下の通りです。パラメータに表示されるメニュー項目にはdnameが表示され、抽出にはdeptnoが用いられています。
Figure 2: How the LOV appears, and how it is used in the query



念のため確認しましたが、10g (10.1.3.4) および 11g(11.1.1.3) 共に動作します。

元ネタ:
http://forums.oracle.com/forums/thread.jspa?threadID=2238724


[Summary]
You can determine the label-value set in List of Values (LOV) with SQL.
select dname, deptno from dept order by deptno


The values of the first column (dname) come up on the drop down list. The values of second column (deptno) are the actual values to be passed to the data set.  Please see the figure 1 and 2.


For your reference:
http://forums.oracle.com/forums/thread.jspa?threadID=2238724

2011/06/10

to_numberの使用 (to_number)

OTNにて、数値の変換が取り上げられていました。
http://forums.oracle.com/forums/thread.jspa?threadID=2192044

解決策としては、データソース側で算出すべき、というそもそも論と、以下の様にto_numberを使用する方法が提案されています。
<?xdoxslt:to_number(BEGIN_SEATS) + xdoxslt:to_number(MIN_SCHOOL2_BEG_SEATS) + xdoxslt:to_number(MAX_SCHOOL2_BEG_SEATS)?>

上記の構文は以下の様に記述することもできます。全体をxdofxで囲うことで、記述が若干ですがシンプルになります。
<?xdofx:(to_number(BEGIN_SEATS) + to_number(MIN_SCHOOL2_BEG_SEATS) + to_number(MAX_SCHOOL2_BEG_SEATS))?>


[Summary]
to_number is available in two ways.  In OTN, you can find the following formula:

<?xdoxslt:to_number(BEGIN_SEATS) + xdoxslt:to_number(MIN_SCHOOL2_BEG_SEATS) + xdoxslt:to_number(MAX_SCHOOL2_BEG_SEATS)?>


With Extended SQL function, you can rewrite it as follow.  In this syntax, you need to place xdofx at its beginning only.

<?xdofx:(to_number(BEGIN_SEATS) + to_number(MIN_SCHOOL2_BEG_SEATS) + to_number(MAX_SCHOOL2_BEG_SEATS))?>


OTN thread:



2011/06/09

条件文 (IF, CHOOSE and DECODE)

BI Publisher では、条件文の記載方法に幅があります。以下に、IF、CHOOSE、DECODE、およびその他の関数の構文を一覧します。

【IF文】
XSL文法の構文は以下の通りです。
<xsl:if test="expression"></xsl:if>

BI Publisher 文法の構文は以下の通りです。
<?if:expression?><?end if?>

拡張SQL関数の構文は以下の通りです。
<?xdofx:if expression then result1 else result2 end if?>

拡張XSL関数では以下の構文も使用できます。
<?xdoxslt:ifelse(expression ,true result, false result)?>


【CHOOSE文】
XSL文法の構文は以下の通りです。
<xsl:choose>
  <xsl:when test="expression"></xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>

BI Publisher文法の構文は以下の通りです。
<?choose?>
  <?when:expression?><?end when?>
  <?when:expression?><?end when?>
  <?otherwise?><?end otherwise?>
<?end choose?>


【DECODE関数】
decodeも使用できます。
<?xdofx:decode(string1, string2', string3, ...)?>


【LIKEに相当する関数】
文字列の部分一致を判定するには、starts-with またはcontainsを使用します。
<?if:starts-with(string1, string2)?><?end if?>
<?if:contains(string1, string2)?><?end if?>


【参考】
サンプルやより詳細な情報のため、以下にいくつかのURLを記載します。
日本語マニュアル
http://download.oracle.com/docs/cd/E17159_01/doc/bi.1013/b51053/T421739T481158.htm

OTNスレッド
http://forums.oracle.com/forums/thread.jspa?messageID=3928083
http://forums.oracle.com/forums/thread.jspa?messageID=9564511

containsやstarts-withに関する情報
http://blogs.oracle.com/xmlpublisher/entry/wildcards

XPath文字列関数の一覧
http://www.quackit.com/xml/tutorial/xpath_string_functions.cfm


[Summary]
There are many ways to write condition with BI Publisher.  I list the formula of IF, CHOOSE and other functions.


[IF statement]
XSL syntax:
<xsl:if test="expression"></xsl:if>


BI Publisher syntax:
<?if:expression?><?end if?>


Expression in Extended SQL function:
<?xdofx:if expression then result1 else result2 end if?>


Expression in Extended XSL function:
<?xdoxslt:ifelse(expression ,true result, false result)?>




[CHOOSE statement]
XSL syntax:
<xsl:choose>
  <xsl:when test="expression"></xsl:when>
  <xsl:otherwise></xsl:otherwise>
</xsl:choose>


BI Publisher syntax:
<?choose?>
  <?when:expression?><?end when?>
  <?when:expression?><?end when?>
  <?otherwise?><?end otherwise?>
<?end choose?>




[DECODE function]
With Extended SQL function, you can use decode.
<?xdofx:decode(string1, string2', string3, ...)?>




[LIKE Equivalent]
starts-with and contains functions are available.
<?if:starts-with(string1, string2)?><?end if?>
<?if:contains(string1, string2)?><?end if?>




[Reference]
For more details and samples, please see the following URL.


Manual (English):
http://download.oracle.com/docs/cd/E10383_01/doc/bip.1013/b40017/T421739T481158.htm


OTN threads:
http://forums.oracle.com/forums/thread.jspa?messageID=3928083
http://forums.oracle.com/forums/thread.jspa?messageID=9564511


contains and starts-with
http://blogs.oracle.com/xmlpublisher/entry/wildcards


XPath functions:
http://www.quackit.com/xml/tutorial/xpath_string_functions.cfm

2011/06/07

ログインユーザの取得 (Display the login user ID)

BI PublisherにログインしているユーザのIDを取得する方法について説明します。過去に数回、OTNで取り上げられています。
http://forums.oracle.com/forums/thread.jspa?threadID=1773888

ユーザIDおよびその他の情報の取得方法について、ここで整理します。

【SQLで指定する方法】
既存のSQLにxdo_user_nameを埋め込むことで取得できます。以下の例では、ログインユーザのIDで部門(deptno)を特定し、ユーザの所属する部門のデータのみを出力する様、制限をかけています。
select * from emp where deptno = (select deptno from emp where empno = :xdo_user_name)

主となるデータソースがSQLでない場合、以下のSQLを別途データセットに定義します。
select :xdo_user_name as user_id from dual
Figure 1: data source for 'xdo_user_name'


その後、作成したデータセットを以下の様に本体のデータソースと結合します。以下の例では、エクセルのデータと結合を行い、ログインしたユーザのIDがEMPNOと合致するレコードだけを抽出します。
Figure 2: data source join


なお、ユーザID以外にも以下の項目を取得することができます。
  • xdo_user_roles
  • xdo_user_report_oracle_lang
  • xdo_user_report_locale
  • xdo_user_ui_oracle_lang
  • xdo_user_ui_locale


以下のブログも併せて参照して下さい。
http://blogs.oracle.com/xmlpublisher/entry/who_is_on_first_but_what_langu



[Summary]
xdo_user_name provides current user name. The SQL below shows the record which belongs to the same deptno with current user.
select * from emp where deptno = (select deptno from emp where empno = :xdo_user_name)


In case when your data source is not SQL, you can join the following SQL with your data source (Figure 1 and Figure 2).
select :xdo_user_name as user_id from dual

Also, the following items are available.
  • xdo_user_roles
  • xdo_user_report_oracle_lang
  • xdo_user_report_locale
  • xdo_user_ui_oracle_lang
  • xdo_user_ui_locale
For details, please refer to the following links:

2011/06/06

シェイプによるグラフ描画 その2 (Graph and shape part 2)

シェイプのサイズや位置を変更してグラフを表現するサンプルや事例は多数あります。以下のURLでは、シェイプの用法の参考になるサンプルが説明されています。
http://blogs.oracle.com/xmlpublisher/entry/competent_shapes_1
http://blogs.oracle.com/xmlpublisher/entry/shape_up

今回はこれらのメジャーな機能ではなく、シェイプの利用の中でもあまり注目されることの無い「回転 (rotate)」を取り上げます。
そもそも回転の使用は通常、稀です。今回、かなり無理をして検討しましたが、独自デザインのゲージを作成する以外には用途が思い当たりませんでした。

【カスタムゲージ】
以下のサンプルでは、半円のシェイプを使用しています。下半分には、白色で塗りつぶした同一サイズの半円シェイプを前面に配置しています。
<?shape-rotate:(SAL div 5000)*180; 'center/center'?>
Figure 1: Custom gauge drawing 


下半分の白色の半円を赤く縁取って再度以下に示します。
Figure 2: Custom gauge drawing (red dots: hidden shapes)


【カスタムゲージ その2】
以下のサンプルでは、図と直線を組み合わせて燃料計に似たゲージを描画します。在庫量、各種のパフォーマンスなどを視覚的に一覧する際、採用を検討してみてください。
<?shape-rotate:(SAL div 5000)*90; 'right/bottom'?>


テンプレートはこちらからダウンロードできます。


[Summary]
There are many blogs that explain shape drawing on rtf template.  The most commons are:


Apart from those major blogs, we focus on shape-rotate.  I suppose none of you have paid attention on it.
The sample above shows how to draw the custom gauge with shape-rotate.  Please see Figure 1 and 2.  Figure 3 is the sample of bitmap image with line shape.


The rtf template is available here.

2011/06/03

シェイプによるグラフ描画 (Graph and shape)

BI Publisher はMS-Wordのシェイプをサポートしています。シェイプを使用したグラフ描画はマニュアルや各種のブログにも紹介されています。
以下のマニュアルを参照して下さい。
http://download.oracle.com/docs/cd/E21764_01/bi.1111/e13881/T421739T481157.htm#T481174


【基本的な使用方法】
シェイプのプロパティを開き、Webタブにサイズを割合で設定します。以下の例は、シェイプのX幅をSAL/5000 の値で変化させます。
<?shape-size-x:SAL div 5000?>

シェイプを組み合わせることで、ある程度のグラフ表現が可能になります。以下に描画の例を示します。
Figure 1: Shape drawing sample


テンプレートはこちらからダウンロードできます。


[Summary]
BI Publisher supports MS-Word shape drawing.  By controlling the size of shape, you can show simple graph inside data table (or anywhere).


The manual describes this feature in detail.
http://download.oracle.com/docs/cd/E21764_01/bi.1111/e13881/T421739T481157.htm#T481174

The basic usage is very simple.  Open the property of shape, then put the following code in its web tab.


Figure 1 is my sample.  You can download the rtf template from here.

2011/06/02

エクセル出力について (Export in Excel format)

BI Publisher に限らず、帳票ツールにとってエクセル出力は鬼門と言えます。

結論から言えば、BI Publisher のエクセル形式での出力にはそれほど期待しないほうがよいでしょう。BI Publisherが「エクセル形式」として出力しているのは実際にはMHTMLであり、表現力は非常に限られたものになります。「オンラインで、簡易的にエクセル形式で出力する」程度の使用が限度であり、複雑な帳票の出力には到底耐えられません。

また、BI Publisherに限らず、バッチ処理であればエクセル形式での出力要件に対しては帳票ツールや開発言語の統一にとらわれず、「エクセルで実装する」ことについての検討を行うことをお勧めします。エクセルはそもそも単体で帳票ツールとしてのプラットフォームであり、外部のツールや言語から敢えて(機能制限があるにもかかわらず)操作する意義は薄いと言えます。
帳票ツールの導入や開発言語の統一は、プロジェクト全体の開発効率や保守性の向上が本来の目的であり、ツールや言語の統一を行うことは手段に過ぎません。この点については開発チームに話を降ろす前の段階で、管理者レベルで方針を出すことが重要です。

【2011-10-18追記】
BI Publisher 11.1.1.5 から、エクセル2007形式での出力が実装されました。この機能についての検証は別途行いたいと思います。
http://blogs.oracle.com/xmlpublisher/entry/bi_publisher_11g_11_1

また、エクセルの出力については、C#からエクセルファイルを出力するサンプル、および性能検証を以下の記事で説明しています。併せて参照ください。
http://blog-koichiro.blogspot.com/search/label/Excel


[Summary]
If you got the requirement with complicated Excel report, it is better NOT to implement it with BI Publisher.  It is not native Excel format file that BI Publisher outputs, but it is MHTML.  You may face many difficulties and regulations soon.
(*)If it is online and the report format is simple enough, then I may consider to use BI Publisher.


For the heavy requirements, I suggest to consider to develop with Excel (VBA), if it's batch report.  Excel is completed report platform.


[October, 18, 2011: append]
The latest release of BI Publisher (11.1.1.5) allows sending BI Publisher reports directly into native Excel 2007 format file.

http://blogs.oracle.com/xmlpublisher/entry/bi_publisher_11g_11_1


Following posts explains how to generate the Excel files via C#.  The result of performance test is also available.
http://blog-koichiro.blogspot.com/search/label/Excel

2011/06/01

ページ合計 (Page total)

ページ合計の表示にはadd-page-totalを使用します。使用方法はOTNでもたびたび紹介されている他、以下のURLでもサンプルを見ることができます。
http://winrichman.blogspot.com/2010/01/page-total.html


基本的な使用例は以下の通りです。以下の例では、SAL列のページ合計をvTotalにて集計します。
<?add-page-total:vTotal;'SAL'?>

add-page-totalはページ単位の合計を集計・出力する他、以下の様に集計対象に定数を指定することでカウントを行うこともできます。
<?add-page-total:vCount;1?>

また、ifと組み合わせることで、条件に該当するレコード件数を出力することもできます。以下の例では、SALが2000より大きいレコードをページ単位でカウントします。
<?if:SAL>2000?>
  <?add-page-total:vCondCount;1?>
<?end if?>

ページ合計の出力はヘッダまたはフッタにshow-page-totalを記述します。なお、最後の引数は書式をあらわします。書式はオラクル書式です。
<?show-page-total:vTotal;'99G999G999D00'?>



[Summary]
The following URL explains the basic usage of add-page-total and show-page-total.

http://winrichman.blogspot.com/2010/01/page-total.html


By setting the static number '1', instead of column name, you can get the count of the record in each page.
<?add-page-total:vCount;1?>


You can use if clause with add-page-total. The following example counts the record with SAL higher than 2000.
<?if:SAL>2000?>
  <?add-page-total:vCondCount;1?>
<?end if?>