Showing posts with label ebs. Show all posts
Showing posts with label ebs. Show all posts

Oracle EBS - Java - Creating csv File from Database for Oracle Apps Java Concurrent Program


Introduction

Oracle EBS provide the functionality to leverage Java into action. When you love java and to feel in your EBS environment.


I am sharing here a sample java class code that will will be used for Oracle EBS Concurrent program executable and perform the tasks of fetching data from database with power of JDBC and will create a csv file on application server file system.


I have used a string variable to hold string content you as payload to create file



Java Code


package oracle.apps.fnd.cp.request;

 

 

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.PrintWriter;

import java.io.StringWriter;

 

import java.security.NoSuchProviderException;

 

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

 

import java.text.SimpleDateFormat;

 

import java.util.Date;

 

import oracle.apps.fnd.util.ParameterList;

 

import oracle.jdbc.OracleCallableStatement;

 

 

public class GeneratePaymentFile implements JavaConcurrentProgram {

    String pDate;

    String directory_path = "/Top Directory Path";

 

    public GeneratePaymentFile() {

    }

 

    public void runProgram(CpContext pCpContext) {

        Connection mJConn = pCpContext.getJDBCConnection();

 

        ReqCompletion lRC = pCpContext.getReqCompletion();

 

        OutFile lOF = pCpContext.getOutFile();

 

        LogFile lLF = pCpContext.getLogFile();

 

 

        try {

 

            Date date1 = new Date();

 

            String shortDate = 

                new SimpleDateFormat("dd-MMM-yyyy").format(date1);

 

            String lQuery = 

                "SELECT * \n" + "from XX_PAYMENT_V \n" + " where upper(APPROVAL_STATUS) = 'APPROVED' "; // modify you sql query to pick required rows to prepare file

 

 

            lOF.writeln("+-------------------------------+");

            lOF.writeln("Generating Payment File ");

            lOF.writeln("+--------------------------------+");

            lOF.writeln("");

 

 

            lOF.writeln("Running for Date : " + shortDate);

            lOF.writeln("");

 

            PreparedStatement lStmt = mJConn.prepareStatement(lQuery);

            ResultSet lRs = lStmt.executeQuery();

 

            String txtLines = "";

 

 

            FileWriter fw;

            int record_count = 0;

 

            Date time1 = new Date();

 

            String mDateTimeStr = 

                new SimpleDateFormat("ddMMMyy").format(date1).toUpperCase();

            mDateTimeStr = 

                    mDateTimeStr + new SimpleDateFormat("HHmmss").format(time1);

 

            String file_name = "/Request/TEST_FILE_NAME_" + mDateTimeStr;

 

 

            try {

                while (lRs.next()) {

 

                    if ((txtLines.length()) > 0) {

                        txtLines = txtLines + "\r\n";

                    }

 

                    txtLines = 

                            txtLines + checkNull(lRs.getString("VALUE_DATE")) + 

                            "|" + checkNull(lRs.getString("CURRENCY_CODE")) + 

                            "|" + lRs.getString("AMOUNT") + "|" + 

                            checkNull(lRs.getString("DEBIT_BANK_ACCOUNT_NUM")) + 

                            "|" + "OUR|" + 

                            checkNull(lRs.getString("DEBIT_BANK_ACCOUNT_NUM")) + 

                            "|" + "|" + lRs.getString("CHECK_ID");

 

 

                    try {

 

                        OracleCallableStatement eStmt = null;

 

 

                        String stmt = 

                            "Update xx_Payment_tbl \n" + "Set STATUS = 'Sent', " + 

                            "where CHECK_ID = ?";

 

 

                        eStmt = 

                                (OracleCallableStatement)mJConn.prepareCall(stmt);

                        eStmt.setString(1, lRs.getString("CHECK_ID"));

 

                        eStmt.execute();

                        eStmt.close();

 

                    } catch (SQLException e) {

                        lOF.writeln("Please check the log for error details)");

                        e.printStackTrace();

 

                        lRC.setCompletion(ReqCompletion.ERROR, e.toString());

                    }

 

 

                    record_count++;

                }

 

                if (txtLines.length() > 0) {

 

 

                    lLF.writeln("File Name : " + file_name, LogFile.STATEMENT);

 

                    fw = 

 new FileWriter(new File(directory_path + file_name + ".csv"));

 

                    fw.write(txtLines);

 

                    fw.close();

 

                } else {

                    lOF.writeln("No data found, file not created");

                }

 

            } catch (IOException ex) {

                lStmt.close();

                lOF.writeln("Please check the log for error details)");

                lOF.writeln(ex.getStackTrace().toString());

 

                lRC.setCompletion(ReqCompletion.ERROR, ex.toString());

 

            }

 

            lOF.writeln("");

            lOF.writeln("+--------------------------------------+");

            lOF.writeln("ayment File created");

            lOF.writeln("+---------------------------------------+");

 

 

            lStmt.close();

            lRC.setCompletion(ReqCompletion.NORMAL, 

                              "Request Completed Normal");

        } catch (SQLException e) {

 

 

            StringWriter errors = new StringWriter();

            e.printStackTrace(new PrintWriter(errors));

 

            lOF.writeln(errors.toString());

 

            lRC.setCompletion(ReqCompletion.ERROR, e.toString());

 

 

        } finally {

 

            pCpContext.releaseJDBCConnection();

        }

    }

 

 

    String checkNull(String m) {

 

        if (m == null) {

            return "";

        } else {

            return m;

        }

 

    }

 

}

 Thank for reaching to my blog. 


How to - Oracle HRMS API: Create Positions API



Oracle HRMS Employee Create API Script




DECLARE

   l_eff_start_date            date;
   l_eff_end_date              date;
   l_effective_date            date := SYSDATE;
   l_job_id                    per_positions.job_id%TYPE;
   l_pos_org_id                per_positions.position_id%TYPE;
   l_validate_mode             boolean := FALSE;
   l_pos_type                  fnd_lookup_values.lookup_code%TYPE;
   l_avail_id                  per_shared_types.shared_type_id%TYPE;
   l_fte                       number;
   l_max_persons               number;
   l_probation_period          number;
   l_probation_unit_desc       varchar2 (500);
   l_business_group_id         number := 82;
   l_segment1                  varchar2 (20);
   l_orcl_pos_title_code       fnd_lookup_values.lookup_code%TYPE;
   l_orcl_pos_title_code_num   number;
   l_attribute8                hr_all_positions_f.attribute8%TYPE;
   l_attribute9                hr_all_positions_f.attribute9%TYPE;
   l_grade_id                  hr_all_positions_f.entry_grade_id%TYPE;
   l_barg_unit_cd              hr_all_positions_f.bargaining_unit_cd%TYPE;
   l_attribute6                hr_all_positions_f.attribute6%TYPE;
   l_working_hours             hr_all_positions_f.working_hours%TYPE;
   l_frequency                 hr_all_positions_f.frequency%TYPE;
   l_position_id               per_positions.position_id%TYPE;
   l_object_version_number     hr_all_positions_f.object_version_number%TYPE;
   l_position_definition_id    number;
   l_pos_name                  per_positions.name%TYPE;
   l_location_id               number;
   l_count                     NUMBER := 0;
   l_error                     NUMBER;
   l_error_msg                 VARCHAR2 (4000);

   CURSOR c1
   IS
      SELECT   DISTINCT
               POSITION,
               (SELECT   LOOKUP_CODE
                  FROM   FND_LOOKUP_VALUES
                 WHERE       LOOKUP_TYPE = 'HR_POSITION_NAME'
                         AND LANGUAGE = 'US'
                         AND MEANING = POSITION)
                  POSITION_1,
               JOB,
               (SELECT   pj.job_id
                  FROM   per_jobs pj, per_job_definitions pjd
                 WHERE       pj.job_definition_id = pjd.job_definition_id
                         AND BUSINESS_GROUP_ID = 82
                         AND pj.NAME = JOB)
                  job_id,
               ORGANIZATION,
               (SELECT   organization_id
                  FROM   hr_all_organization_units
                 WHERE   UPPER (NAME) LIKE UPPER (ORGANIZATION)
                         AND business_group_id = 82)
                  org_id
        FROM   XXHRL_MY_ASSIGNMENTS
       WHERE   NVL (pos_process_flag, 'N') = 'N';
BEGIN
   l_orcl_pos_title_code_num := 10001;

   FOR i IN c1
   LOOP
      BEGIN
         DBMS_OUTPUT.put_line ('In Loop');

         l_error := 0;
         l_pos_type := 'NONE';
         l_avail_id := 1;
         l_position_id := NULL;
         l_object_version_number := NULL;
         l_eff_start_date := NULL;
         l_eff_end_date := NULL;
         l_position_definition_id := NULL;
         l_pos_name := NULL;
         l_location_id := 145;                          --Location_code = XXXX

         hr_position_api.create_position (
            p_validate                 => FALSE,
            p_position_id              => l_position_id,
            p_effective_start_date     => l_eff_start_date,
            p_effective_end_date       => l_eff_end_date,
            p_position_definition_id   => l_position_definition_id,
            p_name                     => l_pos_name,
            p_object_version_number    => l_object_version_number,
            p_job_id                   => i.JOB_ID,
            p_organization_id          => i.ORG_ID,
            p_effective_date           => '01-Jan-1992',
            p_date_effective           => '01-Jan-1992',
            p_language_code            => 'US',
            p_availability_status_id   => l_avail_id,
            p_business_group_id        => 82,
            p_location_id              => l_location_id,
            p_position_type            => 'NONE',
            p_segment1                 => TO_CHAR (l_orcl_pos_title_code_num),
            p_segment2                 => i.POSITION_1
         );


         DBMS_OUTPUT.put_line ('l_pos_name: ' || l_pos_name);

         UPDATE   XXHRL_MY_ASSIGNMENTS
            SET   POS_PROCESS_FLAG = 'Y', POS_PROCESS_MESSAGE = 'Loaded'
          -- POS_SEQ_NO = l_orcl_pos_title_code_num
          WHERE   POSITION = i.POSITION;

         l_orcl_pos_title_code_num := l_orcl_pos_title_code_num + 1;
         l_count := l_count + 1;
      EXCEPTION
         WHEN OTHERS
         THEN
            l_error := 1;
            l_error_msg := 'Exception ' || SQLERRM;
      DBMS_OUTPUT.put_line (SQLERRM);

 END;

      IF l_error = 1
      THEN
         UPDATE   XXHRL_MY_ASSIGNMENTS
            SET   POS_PROCESS_FLAG = 'N', POS_PROCESS_MESSAGE = l_error_msg
          WHERE   POSITION = i.POSITION;
      END IF;

      l_error := 0;
      l_error_msg := NULL;
   END LOOP;
EXCEPTION
   WHEN OTHERS
   THEN
      DBMS_OUTPUT.put_line (SQLERRM);
END;