Friday, May 28, 2021

Python - Dictionary and Sets

 Dictionary is a collection of key-value pairs.

Syntax:

''' a = {“key”: “value”, “marks” : “100”, “list”: [1,2,9]}

a[“key”] # Prints value

a[“list”] # Prints [1,2,9] '''

Properties of Python Dictionaries

  • It is unordered
  • It is mutable
  • It is indexed
  • Cannot contain duplicate keys

Dictionary Methods:

Consider the following dictionary,

a = {“name”: “Sri”,

“from”: “India”,

“marks”: [92,98,96]}

items() : returns a list of (key,value) tuple.

keys() : returns a list containing dictionary’s keys.

update({“friend”: “Sam”}) : updates the dictionary with supplied key-value pairs.

get(“name”) : returns the value of the specified keys (and value is returned e.g. “Sri” is returned here)

More methods are available on docs.python.org


Sets in Python:

Set is a collection of non-repetitive elements.

S= Set()          # No repetition allowed!

S.add(1)

S.add(2)

# or Set = {1,2}

Properties of Sets:

  • Sets are unordered # Elements order doesn’t matter
  • Sets are unindexed # Cannot access elements by index
  • There is no way to change items in sets
  • Sets cannot contain duplicate values

Operations on Sets:

Consider the following set:

S = {1,8,2,3}

Len(s) : Returns 4, the length of the set

remove(8) : Updates the set S and removes 8 from S

pop() : Removes an arbitrary element from the set and returns the element removed.

clear() : Empties the set S

union({8, 11}) : Returns a new set with all items from both sets. #{1,8,2,3,11}

intersection({8, 11}) : Returns a set which contains only items in both sets. #{8}


Practice:

Write a program to create a dictionary of Bengali words with values as their English translation. Provide the user with an option to look it up!

myDict={"sundar":"beautiful","nongra":"dirty","chini":"sugar"}
print("Optoons are sundar, nongra, chini:")
userInput=input("Enter a bengali word to the dictionary:\n")
print("english word is:",myDict[userInput])

Write a program to input eight numbers from the user and display all the unique numbers (once).

Answer: Use set

Can we have a set with 18(int) and “18”(str) as a value in it?

Answer: yes, because both have different types and value.

What will be the length of the following set S:

S = Set()

S.add(20)

S.add(20.0)

S.add(“20”)

What will be the length of S after the above operations?

Answer: 2

S = {}, what is the type of S?

Answer: Empty Dictionary

s={}
print(type(s))

Can you change the values inside a list which is contained in set S

S = {8, 7, 12, “Sri”, [1, 2]}

Answer: No,

Python - Lists and Tuples

Python Lists:

Lists are containers to store a set of values of any data type.

Example, friends = [‘Apple’, ‘Sri’, ‘Sanddy’, 7, False]

The list can contain different types of elements such as int, float, string, Boolean, etc. Above list is a collection of different types of elements.

List Indexing:

A list can be indexed just like a string.

L1 = [7, 9, ‘sri’]

L1[0] – 7

L1[1] – 9

L1[70] – Error

L1[0:2] – [7,9]         (This is known as List Slicing)

List Methods:

Consider the following list:

L1 = [1, 8, 7, 2, 21, 15]

sort() – updates the list to [1,2,7,8,15,21]

reverse() – updates the list to [15,21,2,7,8,1]

append(8) – adds 8 at the end of the list

insert(3,8) – This will add 8 at 3 index

pop(2) – It will delete element at index 2 and return its value

remove(21) – It will remove 21 from the last


Tuples in Python:

A tuple is an immutable (can’t change or modified) data type in Python.

a = ()              #It is an example of empty tuple

a = (1,)           #Tuple with only one element needs a comma

a = (1, 7, 2)   #Tuple with more than one element

Once defined, tuple elements can’t be manipulated or altered.

Accessing Values in Tuples:

To access values in tuple, use the square brackets for slicing along with the index or indices to obtain value available at that index. For example −

tup1 = ('physics', 'chemistry', 1997, 2000);

tup2 = (1, 2, 3, 4, 5, 6, 7 );

print(tup1[0])

print("tup2[1:5])

Output:

physics

[2, 3, 4, 5]

Tuple methods:

Consider the following tuple,

a = (1, 7, 2)

count(1) – It will return number of times 1 occurs in a.

index(1) – It will return the index of first occurrence of 1 in a.

 

Practice:

Write a program to store seven fruits in a list entered by the user.

n1 = input("Enter fruit name 1:")
n2 = input("Enter fruit name 2:")
n3 = input("Enter fruit name 3:")
n4 = input("Enter fruit name 4:")
n5 = input("Enter fruit name 5:")
n6 = input("Enter fruit name 6:")
n7 = input("Enter fruit name 7:")

fruits = [n1,n2,n3,n4,n5,n6,n7]
print(fruits)

Write a program to accept marks of 6 students and display them in a sorted manner.

m1 = input("Enter score 1:")
m2 = input("Enter score 2:")
m3 = input("Enter score 3:")
m4 = input("Enter score 4:")
m5 = input("Enter score 5:")
m6 = input("Enter score 6:")
m7 = input("Enter score 7:")

marks = [m1,m2,m3,m4,m5,m6,m7]
marks.sort()
print(marks)

Check that a tuple cannot be changed in Python.

myTuple =(1,4,7)
myTuple[1]=5
print(myTuple)
TypeError: 'tuple' object does not support item assignment

Write a program to sum a list with 4 numbers.

num=int(input("how many numbers you want to sum:\n"))
i=1
myList=[]
while i <=num:
    value=int(input("Enter number:\n"))
    myList.append(value)
    i+=1
print("your list is:",myList)
sum=0
for x in myList:
    sum+=x
print("sum of" ,num , "numbers:" , sum)

Write a program to count the number of zeros in the following tuple:

a = (7, 0, 8, 0, 0, 9)

a = (708009)
print(a.count(0))

OIC - How to handle error for outbound flow respective to ERP system.

Here i will discuss how we can handle the errors for outbound flow respect to Oracle ERP system.

Use case:

For example, supplier address or cost center or COA details or any reconciliation report are sending from ERP to any other system. Generally in this case, we are crating OTBI report on the ERP db layers and then call the BI report from OIC using BI wsdl service. In this flow, if any error occurs, then we can handle it with creating logs, creating incident or email notifications.

Implementation steps: outboubd flow(ERP to any other system):

Step1: In the scope body

Add "if and otherwise" block as needed after each invoke to sub integration or endpoints or invoking APIs, soap service etc and when if condition fails, sending a throw new fault" with code. Reason and Details.(justified hardcoded details).

For example, suppose , you are calling BI report soap service  and in this case you add a if and otherwise block and logic is if the response from ERP is empty then you are throwing a new fault which will be handled in higer level.






Note: This is best practice to use scope for actions or activites and then handle the fault. You can use one scope or multiple scopes for each business invokes.

Step2: In the body deault scope:

When there is a fault in the body scope or throwing a new fault from body scope, the fault  moves to the default scope level and here we can handle error depending upon our business logic. Like send mail notification, logs the error to a db or logs to S3 or create an incident to Service now etc. So that support guys can get notified and the error can be resolved with ease.

In our project, we did the following:

  • Create and update notify parameters
  • Send all the log and incident details to another sub Integration OIC-Notification.
  • Rethorw fault to Global fault.


Step3: sub integration OIC_Notification sends email, log the details and create incident to servicr now.

For outbound flow we only perform following:

  1. Log the error details to S3.
  2. Create incident to ask now application.

For outbound flow, we have kept global fault as nothing.

Note: you can also use global fault scope and design more things as per your business requirements.


Thursday, May 27, 2021

OIC - ESS job run for delta calculation | Fetch daily Incremental data using ESS job and ess history and property tables

Usecase:

Here, we will discuss the steps how we can use ESS job for delta data or incremental data calculation for outbound data send respective to Oracle ERP.

High level steps:

  1. Create a BI report with bursting query.
  2. In the BI report model, use last_run_date or processstart date (using ess tables fusion.ess_request_history, fusion.ess_request_property) to fetch incremental data.
  3. Create a ESS job and invoke the BI report as Reporting id.
  4. Call that ess job from OIC.


Navigation to check/create/clone your ESS job:

Settings & Actions -- setup and maintenance -- search tasks -- search with "JOB" --select Manage enterprise scheduler job definition and job sets for financials, supplier chain, management and related application-- search with you ess name like '%FIN%'--select your ess job and edit to see or clone to create new ess job.

Following details are needed to create a dummy ess job for delta calculation:

Path: /delta/

Name: ess job name

Report id: /Custom/Integrations/Outbound/AP/FIN<report_name>_BI.xdo

application: application tool kit

Job application: FscmEss

Job type: BIP job type

Allow multiple pending submission: yes

Enable submission from scheduled process : yes


Note:

While the dummy ess job will be ran from the oic, we can see the job and submission time from erp process monitor.

This submission time will be saved in Fusion.ess_request_history table. This last runtime of ess job we use with last update date  to calculate the delta data wih comparing with the respectibe gl_je_lines or other table creation date and also based on event type like for which interface.

Query to fetch Last run date from ess history table:

Select NVL(MAX(erh.processstart), NULL) last_run_date 

FROM ess_request_history erh, ess_request_property erp1 

where 

erh.executable_status ='SUCCEEDED' 

AND erp1.requestid = erh.requestid 

and erp1.name ='submit.argument1' 

and erp1.VALUE =:p_event 

and erh.submitter ='SVC_INTEGRATION_ERP_ACT'

And (erh.definition ='JobDefinition://oracle/apps/ess/custom/delta/FIN_GL_RECON_ERP_BLK_ESS' or erh.definition' = 'JobDefinition://oracle/apps/ess/custom/delta/FIN_GL_RECON_CSV_ERP_BLK_ESS')


Select requestid,processstart,executable_status,submitter,definition from ess_request_history where definition =JobDefinition://oracle/apps/ess/custom/delta/FIN_GL_RECON_ERP_BLK_ESS' or erh.definition'


Select * from ess_request_property where value = :p_event



Main data model BI query example: 

first we populate the last_run_date, then comparing the gl_je_lins creating datw with last_run_date, we can fetch tbe delta daily imcremental data.

Select

Segment1,

Segement2,

Event_type_code,

Last_run_date,

Creation_date,

'1' super_group

from

(select 

to_char(xal.accounting_date, 'MM/DD/YYYY') as effective_date,

glcc.segment1 as segment1,

Glcc.segment2 as segment2,

xe.event_type_code,

Er.last_run_date,

Glb.posted_date creation_date

from

gl_code_combination glcc,

gl_je_lines glje,

gl_je_headers gljeh,

gl_je_batches glb

gl_je_categories gljec

Xla_event xe,

xla_ae_headers xah,

xla_ae_lines xal,

gl_import_references gir,

(

Select NVL(MAX(erh.processstart), NULL) last_run_date 

FROM ess_request_history erh, ess_request_property erp1 

where 

erh.executable_status ='SUCCEEDED' 

AND erp1.requestid = erh.requestid 

and erp1.name ='submit.argument1' 

and erp1.VALUE =:p_event 

and erh.submitter ='SVC_INTEGRATION_ERP_ACT'

And (erh.definition ='JobDefinition://oracle/apps/ess/custom/delta/FIN_GL_RECON_ERP_BLK_ESS' or erh.definition' = 'JobDefinition://oracle/apps/ess/custom/delta/FIN_GL_RECON_CSV_ERP_BLK_ESS')

Er

Where

glje.code_combination_id = glcc.code_combination_id

And glje.je_header_id = gljeh.je_header_id

And gljeh.je_category = gljec.je_category_name

And glje.creation_date > NVL(:p_test_date,NVL(er.last_run_date, SYSDATE - 1))

And xe.event_id = xah.event_id

And xe.entity_id = xah.entity_id

And xah.ae_header_id = xal.ae_header_id

And xah.ledger_id = xal.ledger_id

.

.

.

Group by 

(xal.accounting_date, glcc.segment1,glcc.segment2,xe.event_type_code,er.last_run_date,glb.posted_date))

Union

Select

'Default_Row' segement1,

' ' segement2,

:p_event event_type_code,

Sysdate last_run_date,

Sysdate creation_date

.

.

.

'1' Super_group

From dual

OIC - Fetch name and value params from a input string

Requirement:  

I have a input string called "report path" having multiple paramters appended with semicolon(;). So we have to fetch all name value parameters from the input string and save in a csv formated file for further use.

Example:

Input: abcreport;a=b;c=d

Output:

Csv file

Name= a Value=b

Name=c Value:d

Code steps:

Step1: Assign variable:

  • loopCount= 1.0
  • maxCount=returnCountOfString($reportPath,";")
  • loopCountString= 1.0

Note:oic-javascript-return-count-of-string

Step2: whileCount: loopCount <= maxCount

  • parameterName= returnParamter($reportPath, ";", "=,"Name", $loopCountString)
  • parameterValue = returnParamter($reportPath, ";", "=,"Value", $loopCountString)

Note: use this oic-javascript-find-name-and-value.

Step3: take a stage and Write file:

C1: parameterName

C2: parameterValue

Apend to existing file : yes

Step4: loop increment

If loopCountString = maxCount then

loopCount = loopCount + maxCount

Else

loopCountString = loopCountString +1


Screenshots:
















OIC - Javascript - find name and value parameters from a string

 function returnParameter(value,splitString,indexString,type,count){

var output=value.split(splitString)

var index=output[count].indexOf(indexString);

if(type=='Name'){

var parameter=output[count].substring(0,index);

}

else{

var parameter=output[count].substring(index+1);

}

result=parameter

return result

}

Input:

(abc;a=b,";","=","Name",$loopCountString)

(abc;a=b,";","=","Value",$loopCountString)

output:

Name=a

value=b

here loopCountOfString = the count of ";" the string contains.

OIC- Javascript - return count of string using Regular expression

 Js code: returnCountOfString.js

function returnCountOfString(value,string){

var rgxp = new RegExp(string,"g")

var output = (value.match(rgxp)||[]).length;

return output

}


or 

function returnCountOfString(value,string){

var rgxp = new RegExp(string,"g")

var output = value.match(rgxp).length;

return output

}



Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...