Friday, May 28, 2021

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

}



Monday, May 24, 2021

python - Strings

Strings: 

The string is a data type in Python. A string is a sequence of characters enclosed in quotes.

We can primarily, write a string in three ways:

Single quoted strings : a = ‘sri’

Double quoted strings : b = “sri”

Triple quoted strings : c = ‘’’ sri‘’’

String Slicing/Accessing Values in Strings:

To access substrings, use the square brackets for slicing along with the index or indices to obtain your substring. For example −

Index starts with 0 and goes till string (length - 1).

var1 = 'Hello World!'
var2 = "Python Programming"
print(var1[0]) # 1st character
print(var2[1:5]) # 2nd character to 4th one

output:

H

ytho

Negative Indices: Negative indices can also be used .-1 corresponds to the (length-1) index, -2 to (length-2).

var1 = 'Hello World!'
print(var1[-1])
print(var1[-8:])

output:

!

o World!

Slicing with skip value:

We can provide a skip value as a part of our slice like this:

word = “amazing”

print(word[1:6:2] )         # It will return ’mzn’


Other advanced slicing techniques:

word = ‘amazing’

word[:7] or word[0:7]      #It will return ‘amazing’

word[0:] or word[0:7]      #It will return ‘amazing’


String Functions:

Some of the mostly used functions to perform operations on or manipulate strings are:

len() function : It returns the length of the string.

len(‘harry’)               #Returns 5

endswith(“rry”) : This function tells whether the variable string ends with the string “rry” or not. If string is “harry”, it returns for “rry” since harry ends with rry.

count(“c”) : It counts the total number of occurrences of any character.

capitalize() : This function capitalizes the first character of a given string.

find(word) : This function finds a word and returns the index of first occurrence of that word in the string.

replace(oldword, newword) : This function replaces the old word with the new word in the entire string.

Escape Sequence Characters:

Sequence of characters after backslash ‘\’ [Escape Sequence Characters]

Escape Sequence Characters comprises of more than one character but represents one character when used within the string.

Examples: \n (new line), \t (tab), \’ (single quote), \\ (backslash), etc.

String Special Operators:

Assume string variable a holds 'Hello' and variable b holds 'Python', then −

Operator Description Example

+ Concatenation -

 Adds values on either side of the operator a + b will give HelloPython

* Repetition - 

Creates new strings, concatenating multiple copies of the same string a*2 will give -HelloHello

[] Slice - 

Gives the character from the given index a[1] will give e

[ : ] Range Slice - 

Gives the characters from the given range a[1:4] will give ell

in Membership - 

Returns true if a character exists in the given string H in a will give 1

not in Membership - 

Returns true if a character does not exist in the given string M not in a will give 1

r/R Raw String - 

Suppresses actual meaning of Escape characters. The syntax for raw strings is exactly the same as for normal strings with the exception of the raw string operator, the letter "r," which precedes the quotation marks. The "r" can be lowercase (r) or uppercase (R) and must be placed immediately preceding the first quote mark. print r'\n' prints \n and print R'\n' prints \n

% Format - 

Performs String formatting.


String Formatting Operator:

One of Python's coolest features is the string format operator %. Following is a simple example −

print("My name is %s and my age is %d"%('srinanda',33))

output:

My name is srinanda and my age is 33

List of formatters:

Format Symbol Conversion

%c character

%s string conversion via str() prior to formatting

%i signed decimal integer

%d signed decimal integer

%u unsigned decimal integer

%o octal integer

%x hexadecimal integer (lowercase letters)

%X hexadecimal integer (UPPERcase letters)

%e exponential notation (with lowercase 'e')

%E exponential notation (with UPPERcase 'E')

%f floating point real number

%g the shorter of %f and %e

%G the shorter of %f and %E

Practice:

Write a program to fill in a letter template given below with name and date.

letter = ‘’’ Dear <|NAME|>,


                        You are selected!


                        <|DATE|>

from datetime import date
letter ='''Dear <|NAME|>,\n\tYoy are selected!\n<|DATE|>'''
name=input("Enter your Name:")
dt=str(date.today())
letter=letter.replace('<|NAME|>',name)
letter=letter.replace('<|DATE|>',dt)
print(letter)

output:

Enter your Name:srinanda

Dear srinanda,

        Yoy are selected!

2021-05-24

Write a program to detect double spaces in a string.

st="My name is  srinanda das"
resultst.find("  ")
temp = False
if(result != '-1'):
    temp=True
    print("It contains double spaces: ",temp)
else:
    print("It does not contain double spaces: ",temp)
if(temp == True):
    print("at position:",result).


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...