自己编写了Oracle EBS程序自动移植脚本

前言

Oracle EBS的二次开发主要针对Forms开发和Package开发(报表、公共包、逻辑包等),因此移植程序也主要针对Forms(.fmb)和Package(.pck)。但是我们知道,在移植Forms的时候,如果有用户在界面上,那么该用户就会被强制剔除(包括同时打开多个界面的情况),这样会造成用户可能在处理单据,或者录入数据,造成数据未保存,或者数据状态处于不一致状态;Package的移植虽然不会把用户剔除,但是如果Froms引用了该Package,Forms也会报错,无法继续操作。

因此作为技术开发员移植程序一般需要等到晚上的时候才能移植。

Oracle EBS的请求除了可以调用PLSQL包代码,还可以调用JAVA代码。我们可以通过JAVA代码遍历某个目录,调用LINUX SHELL脚本的方式来实现程序定时每日自动编译程序。

步骤

1.新建JAVA代码

JAVA代码的作用是遍历某个目录,处理.fmb,.pck扩展名的文件,然后调用对应的SHELL脚本进行编译。

package oracle.apps.fnd.cp.request.cux;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;

import oracle.apps.fnd.cp.request.*;

public class CuxCompile implements JavaConcurrentProgram {

    public void runProgram(CpContext ctx) {
        String path = "/u01/prod/apps/apps_st/appl/cux/12.0.0/forms/programs/DAYCOMPILE";
        Boolean sucFlag;

        // get reference to Out and Log files
        OutFile out = ctx.getOutFile();
        LogFile log = ctx.getLogFile();

        out.writeln("文件路径:" + path);
        out.writeln("!-----------------------------------------------------!");

        File fileDir = new File(path);
        File[] files = fileDir.listFiles();
        Calendar cd = Calendar.getInstance();

        int fileNum = 0;
        for (File file : files) {
            if (file.isFile() && file.getName().indexOf(".fmb") > 0) {
                int dot = file.getName().lastIndexOf('.');
                String command = "sh " + path + "/compile.sh "
                        + file.getName().substring(0, dot);
                fileNum++;
                sucFlag = false;
                try {
                    out.writeln("编译文件" + fileNum + ":"+file.getName());
                    log.writeln("编译文件" + fileNum + ":\n" + command,log.STATEMENT);


                    Process pr = Runtime.getRuntime().exec(command);

                    //输出信息
                    InputStreamReader ir = new InputStreamReader(
                            pr.getInputStream());
                    BufferedReader input = new BufferedReader(ir);

                    String line;

                    while ((line = input.readLine()) != null) {
                        if (line.indexOf("Created form file /u01/prod/apps/apps_st/appl/cux") >=0){
                            sucFlag = true;
                            out.writeln("编译文件" + fileNum + ":"+file.getName()+"成功。");
                        }
                        log.writeln(line,log.STATEMENT);
                    }

                    //错误信息
                    ir = new InputStreamReader(pr.getErrorStream());

                    input = new BufferedReader(ir);
                    while ((line = input.readLine()) != null) {
                        if (line.indexOf("Created form file /u01/prod/apps/apps_st/appl/cux") >=0){
                            sucFlag = true;
                            out.writeln("编译文件" + fileNum + ":"+file.getName()+"成功。");
                        }
                        out.writeln(fileNum+line);
                    }
                    log.writeln("编译文件" + fileNum + ":"+file.getName()+"结束。",log.STATEMENT);


                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    log.writeln("编译文件" + fileNum + ":"+file.getName()+"结束。",log.STATEMENT);
                    e.printStackTrace();

                }finally{
                    if (!sucFlag){
                        out.writeln("<b>ERROR:编译文件" + fileNum + ":"+file.getName()+"失败!</b>");
                    }
                    out.writeln("!-----------------------------------------------------!");
                }

            }
        }

        int sucNum; 
        //编译package
        for (File file : files) {
            if (file.isFile() && file.getName().indexOf(".pck") > 0) {
                int dot = file.getName().lastIndexOf('.');
                String command = "sh " + path + "/package.sh "
                        + file.getName();
                fileNum++;
                sucNum = 0;
                try {
                    out.writeln("编译文件" + fileNum + ":"+file.getName());
                    log.writeln("编译文件" + fileNum + ":\n" + command,log.STATEMENT);


                    Process pr = Runtime.getRuntime().exec(command);

                    //输出信息
                    InputStreamReader ir = new InputStreamReader(
                            pr.getInputStream());
                    BufferedReader input = new BufferedReader(ir);

                    String line;

                    while ((line = input.readLine()) != null) {
                        if (line.indexOf("Package created.") >=0){
                            sucNum++;
                        }

                        if (line.indexOf("Package body created.") >=0 && sucNum==1){
                            sucNum++;
                            out.writeln("编译文件" + fileNum + ":"+file.getName()+"成功。");
                        }
                        log.writeln(line,log.STATEMENT);
                    }

                    //错误信息
                    ir = new InputStreamReader(pr.getErrorStream());

                    input = new BufferedReader(ir);
                    while ((line = input.readLine()) != null) {
                        if (line.indexOf("Package created.") >=0){
                            sucNum++;
                        }

                        if (line.indexOf("Package body created.") >=0 && sucNum==1){
                            sucNum++;
                            out.writeln("编译文件" + fileNum + ":"+file.getName()+"成功。");
                        }
                        out.writeln(fileNum+line);
                    }
                    log.writeln("编译文件" + fileNum + ":"+file.getName()+"结束。",log.STATEMENT);


                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    log.writeln("编译文件" + fileNum + ":"+file.getName()+"结束。",log.STATEMENT);
                    e.printStackTrace();

                }finally{
                    if (sucNum!=2){
                        out.writeln("<b>ERROR:编译文件" + fileNum + ":"+file.getName()+"失败!</b>");
                    }
                    out.writeln("!-----------------------------------------------------!");
                }

            }
        }


        // get concurrent program Request Details
        ReqDetails rDet = ctx.getReqDetails();
        String userName = rDet.getUserInfo().getUserName();

        // write username to the Out File
        // out.writeln("User Name = " + userName);

        // Success message to the Concurrent Manager
        ctx.getReqCompletion().setCompletion(ReqCompletion.NORMAL, "Completed");
    }

    public static void main(String[] args) {
        File file = new File("");
        File[] files = file.listFiles();


    }

}

注释:
1.通过输出字符串是否包含Created form file /u01/prod/apps/apps_st/appl/cux判断编译Forms是否成功。
2.通过字符串“Package created.”与“Package body created.”来判断Package是否编译成功。
3.把java代码复制到$JAVA_TOP/oracle/apps/fnd/cp/request/cux/下,并编译。

2.Forms编译代码

compile.sh

source ~/.bash_profile
cd $CUX_TOP/forms/programs/DAYCOMPILE

export FORMS_PATH=.:$FORMS_PATH:$AU_TOP/forms/ZHS
frmcmp_batch $CUX_TOP/forms/programs/DAYCOMPILE/$1.fmb apps/apps output_file=$CUX_TOP/forms/US/$1.fmx
cp $CUX_TOP/forms/US/$1.fmx $CUX_TOP/forms/ZHS/$1.fmx

#删除文件到HIS文件夹
mv $CUX_TOP/forms/programs/DAYCOMPILE/$1.fmb ./hisfmb/
cp $CUX_TOP/forms/US/$1.fmx $CUX_TOP/forms/programs/DAYCOMPILE/hisfmx/

3.Package编译代码

package.sh

source ~/.bash_profile
cd $CUX_TOP/forms/programs/DAYCOMPILE
expect compilepck.sh $1
mv $CUX_TOP/forms/programs/DAYCOMPILE/$1 $CUX_TOP/forms/programs/DAYCOMPILE/hispck/

compilepck.sh

#!/usr/bin/expect 
set timeout 20
spawn sqlplus apps/apps
expect "SQL> "
send "set define off\n"
expect "SQL> "
send "@[lindex $argv 0]\n"
expect "SQL> "
send "exit\n"
interact

注释:
1.把以上文件复制到应用服务器$CUX_TOP/forms/programs/DAYCOMPILE目录。
2.要移植的fmb,pck文件也放到该目录下(注意pck的编码,我这边使用UTF8 无BOM)。
 

4.新建并发程序

自己编写了Oracle EBS程序自动移植脚本_第1张图片
自己编写了Oracle EBS程序自动移植脚本_第2张图片

5.定义程序每日自动运行,结束

你可能感兴趣的:(oracle,ebs)