Friday, October 20, 2017

Call Stored Procedure from Python Script

from __future__ import with_statement
from com.ziclix.python.sql import zxJDBC
from itertools import chain
import sys,os,csv
import re
#import urllib2
import wget

d, u, p, v = "jdbc:oracle:thin:@//host:1521/dbName", "apps", "password", "oracle.jdbc.driver.OracleDriver"
db = zxJDBC.connect(d, u, p, v)
c = db.cursor()
c.execute("BEGIN AppName.ProcName();END;")
c.close()
db.commit()
db.close()


file name would be: file.py

/**

select row and
insert row to table


#--select row from db table;fetch only one row
c.execute("select user_id from fnd_user where user_name='VIJAY'")
   swissUser = c.fetchone()
print swissUser
#--convert int to string --
swissUser = str(int(swissUser[0]))

   print "SWISS USER-->"+str(swissUser[0])

#--insert Row to database table
statement = "insert into APP.TBL_BALANCE_CON(FILE_LINE_NUMBER, ACCOUNTING_DATE, CURRENCY_CODE,) Values  ('1', TO_DATE('15-"+row[0]+"', 'DD-MON-YY'), 'STAT')"
print statement
c.execute(statement)

#fetch all rows in database table
c.execute("select line_number,to_char(accounting_date, 'mm/dd/yyyy') from  APP.TBL_BALANCES_CONVERSION")
       rowsLeftout = c.fetchall()
       lineFailed=lineFailed+" <tr>    <th>Line Number</th><th>Accounting Date</th><th>Period Name</th><th>Segment1</th><th>Segment3</th><th>Entered_Dr</th><th>Entered_Cr</th></tr>"
       for rowL in rowsLeftout:
          
          lineFailed=lineFailed"<tr>    <td>"+str(rowL[0])+"</td><td>"+str(rowL[1])+"</td><td>"+str(rowL[2])+"</td><td>"
       lineFailed=lineFailed+"</table> "
       print lineFailed






**/

Call Python Script from Shell Script

#!/bin/bash
export PATH=/home/app/jython2.7.0/bin:$PATH
export CLASSPATH=/home/app/jython2.7.0/javalib/ojdbc14.jar:$CLASSPATH
export JAVA_HOME=/appName/WL12c/app/oracle/jdk1.7.0_15

jython /home/app/jython2.7.0/bin/startProcess.py
~

How to create Cron jobs UNIX/LINUX

$crontab -l
//shows/prints existing cronjob

$crontab -e
//create a cronjob

$crontab -r 
//removes all cronjobs



below code writes test********** to testCronLog file every 1 min


  • */1 * * * * echo "test***********" >>/home/app/testCronLog
--below runs every 3 mins and prints output to appLog file
  • */3 * * * * /home/app/startProcess.sh >>/home/app/appLog




Actually, it's not recommended to handle those files by hand. Per crontab man page:
Each user can have their own crontab, and though
these are files in /var/spool/cron/crontabs, they are not
intended to be edited directly.
Files under /var/spool are considered temporary/working, that's why they probably get deleted during an upgrade, though a closer look at the cron package's upgrade scripts may shed some light on this.
Anyway, it's always a good practice to back up your cron entries or keep them in a file in your home directory.
I assume you're using crontab -e to create crontab files on the fly. If so, you can get a "copy" of your crontab file by doing crontab -l. Pipe that to a file to get a "backup":
crontab -l > my-crontab
Then you can edit that my-crontab file to add or modify entries, and then "install" it by giving it to crontab:
crontab my-crontab
This does the same syntax checking as crontab -e.



Reference:
https://docs.oracle.com/cd/E23824_01/html/821-1451/sysrescron-24589.html
https://www.taniarascia.com/setting-up-a-basic-cron-job-in-linux/
https://askubuntu.com/questions/216692/where-is-the-user-crontab-stored
https://kb.iu.edu/d/afiz

Friday, October 13, 2017

Avoid refresh of af:table to recalculate other rows ADF


  • If the now of rows are static set the range size of the Iterator to exact no. of rows.
  • Also have the fetch size to range size or exact no. of rows 

Tuesday, October 3, 2017

Groovy Expression to get Absolute Value at View Object Expression ADF

if(AmountNew!=0 && AmountNew!=null)
((AmountOld-AmountNew)/(AmountNew).abs())*100