Jython script analysis on commas

I use an import script to import a file with records similar to the one below.

Entity, CR_Amt, DR_Amt, Custom1, account

' 100 ',' 2000 ',' 300 ',' 17,000,000.00 ',.

'400', '5000', '600', '28,000.00.

My script is on the DR_Amt and CR_Amt fields is as follows:

def AMOUNT_CSV (strfield, strrec):

arrRecords = strrec.split(',')

strDr = arrRecords [4]

strCr = arrRecords [5]

dr_str = strDr.replace('"','')

Cr_str = strCr.replace('"','')

If dr_str is None or dr_str == "" or dr_str == 0:

End_str = floating fenΩtre (Cr_str) *-1

Another thing:

End_str = float (dr_str)

return End_str

The script seems to work fine except that it scans my fields amount on the comma separator.  For example, the first record will return at 17.00 and the second field will return 28.00.  Is there a way to get around this?

It seems that regular import module expression or csv import scripts does not work correctly...

Python/jython is very powerful, you might also have a solution using list function for a list of positions for the character "and then get the amount of CR based on the last two positions.

def parseDoubleQuotesDRCR (strfield, strrec):

If strfield is None or strfield.strip () == ' ' or strfield == 0:

# Sample line-> ""400","5000","600","28,000.00.

# Get a list of the positions of the characters in double quotation marks

# Ex: [0, 4, 6, 11, 13, 17, 20, 30]

listposquotes = [i i, in enumerate (strrec) so ltr ltr == "'"]

"# Get the position of the first character after the double quotes after the last '.

# CR is stored between 20 and 30-> strrec [21:30]

crstart = listposquotes [(len (listposquotes)-2)] # + 1 post 21

crend = listposquotes [(len (listposquotes)-1)] # 30 Position

Separator to replace thousands of # to avoid conversion problems

amount = float (str(strrec[crstart:crend]).replace (',', ")) *-1

Another thing:

quantity = float (strfield.replace(',',''))

return the amount

Tags: Business Intelligence

Similar Questions

  • FDMEE Jython Script help

    My load the import data were thrown a curve ball. I used to have a 1 or 2 digits in the card. If it's a digit, I simply added a zero at the beginning (i.e. FillL convert 1 01). But now I have a leader 4 digits and a hyphen. So instead of '1', I have 2500-1, instead of "12", I now 2500-12. I need to remove what is to the right of the dash and then add a zero not significant if it is not already 2 digits. Does anyone know the script that would achieve this?

    Your help is very appreciated.

    FA

    Hello

    You can create this jython script and assign import format:

    def customFill (strField, strRecord):

    return ('0' + strField.split("-") [1]) [-2:]

    This function divides your strField using "-" as the delimiter, then him concatenate '0' with the second element ([1] in the table starts in position 0) and finally to take the last two characters [-2:]

    If you have 1 number after the hyphen you will get 0 x. On the other hand, if you have already a 2-digit, you will get xx

    Hope says.

  • How to assign the value to the variable of project in the Jython script

    Hello

    I want to assign a value to the variable of project in the jython script.
    I tried to assign the following, but it is throwing some errors.

    < @.
    int noOfRecords = 10;
    #var1 = noOfRecords;
    @ >


    Can you please help me in this regard.

    Concerning
    Shyam

    Perfect! Good to know that!

    Please, don't forget to close the thread and assign the status to 'correct' or 'comfortable' to each response that helped you!

    Thank you

    Cezar Santos
    http://odiexeperts.com

  • Using .split on an import script with a comma delimited data file

    Hi everyone-

    Any attempt to create a script to import amount field to remove the apostrophes (') of a description field to account in a .csv data import file (any folder with an apostrophe will be rejected during the import phase).  Now if it was a file delimited by semicolons (or other separators and more by commas), I could remove all the apostrophes recording with a string.replace command, then return the amount with a command of string.split.  Unfortunately, there is a problem with this solution when using comma delimiters. My data file is comma-delimited .csv file with several amount fields that have commas in them.   Even if the fields are surrounded in quotes, the .split ignores the quotes and treats the commas in fields amount as delimiters.  Therefore, the script does not return the correct amount field.

    Here is an example of a record of reference data:

    "", "0300-100000", "description of the account with an apostrophe ' ', '$1 000.00",' $1 000.00 "," $1 000.00 ","$1 000.00"," $1 000,00 "" "

    My goal is to remove the apostrophes from field 3 and return the amount in field 8.

    Some things to note:

    • If possible, I would like to keep this as an import script for amounted to simplify administration - but am willing to undertake the event script BefImport if this is the only option or more frank than the import script-based solution.
    • I tried using regular expressions, as seems to be conceptually the simplest option to respect the quotes as escape character, but think that I am not implementing properly and impossible to find examples of regex for FDMEE.
    • I know that we cannot use the jython csv on import the script by Francisco blog post - fishing with FDMEE: import scripts do not use the same version of Jython as event/Custom scripts (PSU510). This may be a factor to go with a script of the event instead.
    • It's probably a little more engineering solution, but I have considered trying to write a script to determine where to start all the quotes and the end.  Assuming that there are no quotation marks on the inside of my description of account (or I could remove them before that), I could then use the positioning of the quotes to remove commas inside those positions - leaving the commas for the delimiters as is.  I could then use the .split as the description/amount fields have no commas.  I think it may be better to create a script of the event rather than down this solution from the point of view to keep administration as simple as possible
    • Yes, we could do a search and replace in the excel file to remove the apostrophes before import, but it's no fun

    Thanks for any advice or input!

    Dan

    Hi Dan,.

    If your line is delimited by comma and quote qualified, you can consider the delimiter as QuoteCommaQuote or ', ' because it comes between each field.  Think about it like that, then simply divided by this value:

    split("\",\"")

    Here's something I put together in Eclipse:

    '''

    Created on Aug 26, 2014

    @author: robb salzmann

    '''

    import re

    strRecord = "\"\",\"0300-100000\",\"Account description with an apostrophe ' \",\"$1,000.00\",\"$1,000.00\",\"$1,000.00\",\"$1,001.00\",\"$1,002.00\""

    strFields = strRecord.split("\",\"")

    strDescriptionWithoutApos =  strFields[2].replace("'", "")   'remove the apostrophe

    strAmountInLastCol = strFields[-1:].replace("\"", "")        'You'll need to strip off the last quote from the last field

    print strDescriptionWithoutApos

    print strAmountInLastCol

    Account with an apostrophe description

    ' $1 002,00

  • FDMEE import Jython Script - field Split function

    Hi people,

    I have to admit, this Jython gives me a heavy headache!

    In fact, it's a simple mistake, but I'm fighting around with it for hours now. Maybe one of you guys can help.

    I want to create a Script of Import in FDMEE 11.1.2.3.500.17. The source file (separator: tab) contains a column with the following entries:

    Capture1.JPG

    What I want to achieve at first is to import the figure after the first point. For example, hours - 00275. 3. 4.1 I want to import 3.

    I wrote a script to import, based on an example of written script in FDMEE admin guide (page 273):

    Capture2.JPG

    I assigned this script to the respective column in the Import Format:

    Capture3.JPG

    Seems easy. But for some reason, it does not. The problem is: even the log file is not help, because it seems to be growing constantly when I want to open it (after becoming 30 MB I cancelled). By the way: without this script works import.

    Any ideas? Help is very appreciated!

    See you soon

    Carmonte

    I wasn't talking about the script file extension, as you say is irrelevant, your file name of the script was eGRCcISPA (without the extension) and your function called eGRCsISPA (in the body of the script). They were different and should be the same. They are the same today? Also when you say that this does not work, what do you mean?

    (1) import runs successfully, but represented for that field values are not what you expect the rest of the script is running?

    (2) the mistakes of import process when using that import format?

  • FDMEE mapping &lt; white &gt; does not / Jython Script

    Hi all

    Has anyone got the < white > mapping work?  I put it in my SIMILAR mapping and it does nothing.  Any help would be appreciated.

    As a solution, I tried to add an import script to my base file import format.  I want it all empty fields in PKI to convert in [no PIC].  Keep logs process details (see below) gives me an error.  He doesn't seem to like dealing with NULL values.  Here is my script to import of Jython:

    def OracleEBS_ICPNone (strField, strrecord):

    If strfield is not nothing and len (strfield) > 0:

    return "[ICP None]"

    Another thing:

    return strfield

    Error log:

    2014-06-03 14:57:18, 892 [AIF] DEBUG: 105039:EPMERPI - error expression evaluation: OracleEBS_ICPNone (", 725, 100151_C, 000, 16434308.16')

    result: null

    2014-06-03 14:57:18, ERROR 894 [AIF]: 105039:EPMERPI - 105042:EPMERPI - error evaluating script.

    null

    THX,

    Mike

    How are your values of source?

    does not refer to NULL.

    This will work only if the value of your source has a blank space.

    So if you have a map as --> [no PIC]

    and your source is an empty string... it won't

    It won't work if it has a white space (' ')

    For you the script:

    def OracleEBS_ICPNone (strField, strrecord):

    If strfield is not nothing and len (strfield) > 0:

    return "[ICP None]"

    Another thing:

    return strfield

    Jython is case-sensitive: strField <> strfield

    If you want to capture values empty source in PKI:

    def OracleEBS_ICPNone (strField, strRecord):

    # You can cut your source, remove the whitespace on the left/right and then check if the length is zero

    If len (strField.strip () == 0:

    return "[ICP None]"

    Another thing:

    return strField

  • Import of Jython Script if Stmt

    I have a Jython import the script I'm debugging.  I proved that everything works properly until my if stmt.  That's what I want to do... If the DR_str field is null, then returns the CR_str field; otherwise the return DR_str field.

    This script in its current state will import all records where DR_str is not null.  He will ignore the fields where the DR_Str is null

    def AMOUNT_CSV_12 (strfield, strrec):

    arrRecords = strrec.split(',')

    DR_str = arrRecords [12]

    CR_str = arrRecords [13]

    If DR_str is None or DR_str == "or DR_str == 0:

    End_str = float (CR_str)

    Another thing:

    End_str = float (DR_str)

    return End_str

    Hi 898555,

    The return statement is indented in this clause else for now so it'll never return a value for End_str, when the else clause works. This cut from the version of your function to the return in four spaces returns 9999.0

    def AMOUNT_CSV_12():

    DR_str = 0

    CR_str = 9999

    If DR_str is None or DR_str == "or DR_str == 0:

    End_str = float (CR_str)

    Another thing:

    End_str = float (DR_str)

    return End_str

  • Jython script to remove the quotes

    All,

    I created the following script as an event script before import to remove the quotes around member names in our source file.  Everything seems to work except the last step of deleting and renaming the file (os.remove and os.rename).  I can see the ".out" file and it seems OK, but the original file is still there.  Any help is greatly appreciated.

    If fdmContext ["LOCNAME'] == 'TecLabor_TO_RSA ':

    fdmAPI.logInfo (fdmContext ["LOCNAME"])

    Try:

    filename = fdmContext ["FILENAME"]

    Inbox = fdmContext ["INBOXDIR"]

    #filedir = fdmContext ['FILEDIR']

    fdmAPI.logInfo (filename)

    fdmAPI.logInfo (inbox)

    file = inbox + '\\TecLabor_TO_RSA\\' + filename

    file_out = inbox + "\\TecLabor_TO_RSA\\" + file name ".out".

    #file = inbox '-' + filedir + "\\"+filename. "

    #file_out = inbox + "\" + filedir + "\\"+filename + «.out "»

    fdmAPI.logInfo (file)

    end = open (file, "r")

    who cares = open (file_out, "w")

    for the end line:

    Line = Line.Replace ('"'," ")

    care. Write (Line)

    end. Close()

    care. Close()

    except IOError, err:

    fdmAPI.logError ("My error" + str (err))

    OS. Remove (file)

    OS. Rename (file_out, leader)

    So you're saying that the os.rename and os.remove of commands do not work? If so make sure have included you the following import statement at the top of your script - import bones

  • How to use a SELECT QUERY using fdmAPI.executeDML in the Jython Script FDMEE?

    Hello

    Is just the way we use DELETE and INSERT statement using fdmAPI.executeDML, possible to run a SELECT statement and get the result in the variables?

    I want to refrain from using import java.sql and enter the connection information in a script. I would rather use SELECT directly if possible. I want to read the TDATASEG. DATAKEY column and use it for some custom in a custom table process

    Thank you!

    Try RS.next instead of RS. Next

  • Jython scripts may rely on values alphanumeric vs. alpha?

    I have a column of data that includes alpha and alpha numeric values of different length and having the prefix "ABC". I want the prefix removed in the case of alpha or alpha numeric values. For numeric values, I want just the right numbers 6 and the following script works:

    def SAP_PC (strField, strRecord): return strField [-6:]

    Digital alpha values can be of any length, and I want the whole chain less the prefix. Does anyone know of a way to do this?

    Thank you

    FA

    You can also used the isalpha function without casting to unicode:

    def SAP_PC (strField, strRecord):

    suffix = strField [3:]

    If suffix.isalpha ():

    return the suffix

    Another thing:

    return strField [-6:]

  • Script to remove commas from a csv file

    Hi all

    I have the following output to a csv file:

    VM, VI-SVC-VM014, 0000ed, 0000ee,
    VM, VI-SVC-VM103, 0000f3, 0000f2,
    VM, VI-SVC-VM104, 0000f6, 0000f6,
    LDEV, SVC PROD Cluster01, 0000e2, 0x04
    LDEV, SVC PROD Cluster01, 0000de, 0x00
    LDEV, SVC PROD Cluster01, 0000df, 0x01
    LDEV, SVC PROD Cluster01, 0000e2, 0x04

    I'm looking to remove commas end so that the output looks like this:

    VM, VI-SVC-VM014, 0000ed, 0000ee
    VM, VI-SVC-VM103, 0000f3, 0000f2
    VM, VI-SVC-VM104, 0000f6, 0000f6
    LDEV, SVC PROD Cluster01, 0000e2, 0x04
    LDEV, SVC PROD Cluster01, 0000de, 0x00
    LDEV, SVC PROD Cluster01, 0000df, 0x01
    LDEV, SVC PROD Cluster01, 0000e2, 0x04

    The column length for each line (given the number of objects), modular in this output. By this, I mean that some outputs will be like this:

    VM, VI-SVC-VM014, 0000ed, 0000ee, 0000ef
    VM, VI-SVC-VM104, 0000f6, 0000f6

    VI-SVC-VM104, 0000f6, 0000f5, 0000f7, VM, 0000f4
    LDEV, SVC PROD Cluster01, 0000e2, 0x04
    LDEV, SVC PROD Cluster01, 0000de, 0x00

    Is it possible to import the data (get-content), delete all non alpha-numeric end of line? Maybe there is an easier way.

    Thank you

    Rob.

    Try something like

    Get-Content file.csv | %{
      $_.TrimEnd(',')
    } | Set-Content newfile.csv
    
  • PowerCLI script - analysis output screen to CSV

    Hi all

    I am completely new to scripting, so apologies for noob Q.

    I'm fighting to set up a simple script. Basically I need/want to output the results to a CSV file and send it to me.

    Required information:

    Search the events of snapshot in the last X days and return time created, user and the virtual computer name. I can do it for display on the screen, but struggling to the export-csv and email.

    I have until now (thanks to Alan Renouf plugins as the basis of this revised script)

    $author = 'myuser '.

    $MaxSampleVIEvent = 100
    $VMsNewRemovedAge = 7
    $vmlist = get - VM

    foreach ($vm to $vmlist)
    {
    $vm | Get-VIEvent - maxsamples $MaxSampleVIEvent - beginning (Get-Date). AddDays(-$VMsNewRemovedAge) | where {($_.fullFormattedMessage-correspond à "Créer un instantané de la machine virtuelle") - and ($_ .userName-match "$author")} | Select Createduserid, @{N = 'User'; {E = {$_.userName}}, @{N = 'The virtual computer name'; {E = {$_.vm.name}}
    }

    Output of the (perfect) screen:

    VM Createduserid user_name

    --------------------             -----------------     -----------------------

    28/10/2012 09:55:58 domain\myuser vm1

    26/10/2012 07:05:45 domain\myuser vm1

    etc....................

    How can I get the script to store the results, the output to the CSV file than e-mail me (actually just exit/save to CSV is fine).

    Help is very appreciated.

    RB51

    Please note the difference

    $ (

    )

    who will do a subexpression. Without running in subexpression, you will receive 1 single object as you said: Please copy - paste this code in your powershell window.

    $author = 'myuser '.

    $MaxSampleVIEvent = 100
    $VMsNewRemovedAge = 7
    $vmlist = get - VM

    $(

    foreach ($vm to $vmlist)
    {
    $vm | Get-VIEvent - maxsamples $MaxSampleVIEvent - beginning (Get-Date). AddDays(-$VMsNewRemovedAge) | where {($_.fullFormattedMessage-correspond à "Créer un instantané de la machine virtuelle") - and ($_ .userName-match "$author")} | Select Createduserid, @{N = 'User'; {E = {$_.userName}}, @{N = 'The virtual computer name'; {E = {$_.vm.name}}
    }

    ) | Export-csv c:\report.csv

    Send-mailmessage-to "User01 [email protected]>"-to "User02 [email protected]> ', ' User03 [email protected]>" - topic "Sending the accessory" - body "CSV in the e-mail" - attachment "c:\report.csv" - smtpServer smtp.fabrikam.com

  • FDMEE Jython scripts

    I use fdmContext ['PERIODKEY'] to pull in the PeriodKey and she returned to 2013-11-18 (AAAA-MM-JJ), and I would like to change the format of 201311 (YYYYMM).  Something there suggestions on how this can be accomplished using Jython?

    Thanks in advance.

    Try

    import of java

    print java.text.SimpleDateFormat("yyyyMM").format (java.util.Date ())

  • Jython FDMEE script problem

    Hello

    I have a custom jython script to convert table data into a text file. This works for a table. But I tried to use lists and tables so that I can have several files of several tables. This script, by creating multiple files, retrieves only the data of the last file. All other files remain as 0 KB files with no data. I see here only data for CH, AC in the file is a 0 KB file. If I have the list with "AC" Member, then I see data for AC. Can someone let me know what I'm missing here in logic.


    List = ['AC', 'CH']

    Conn = sql. DriverManager.getConnection (strJDBCURL, strUserName, strPassword)
    for the list item [:]:

    Represented = fdmContext ["INBOXDIR"] + "/" + item + "export.txt"
    SRC = open (represented, "w")
    SqlString = conn.createStatement)

    sqlstmt = 'SΘlectionner the SOURCE, TARGET of TEST_' + point + 'EXPORT '.
    result = sqlstring.executeQuery (sqlstmt)

    While (result. Next()):
    SOURCE = result.getString ("SOURCE")
    TARGET = result.getString ("TARGET")

    Print > > src, SOURCE, TARGET

    CBC. Close()
    Conn.Close)

    Hi, I skimmed the code last night and missed the second loop. I think that the problem actually comes from your indentention that is the while loop is not currently incorporated in the for loop runs but after the because the loop is complete, the code must be

    List = ['AC', 'CH']

    Conn = sql. DriverManager.getConnection (strJDBCURL, strUserName, strPassword)
    for the list item [:]:

    Represented = fdmContext ["INBOXDIR"] + "/" + item + "export.txt"
    SRC = open (represented, "w")
    SqlString = conn.createStatement)

    sqlstmt = 'SΘlectionner the SOURCE, TARGET of TEST_' + point + 'EXPORT '.
    result = sqlstring.executeQuery (sqlstmt)

    While (result. Next()):
    SOURCE = result.getString ("SOURCE")
    TARGET = result.getString ("TARGET")
    print > src, SOURCE, TARGET

    CBC. Close()

    Conn.Close)

    Only try.

  • Using the script, Jython in ODI

    Hello
    I have a requirement where I want to exploit a jython script to solve a business problem (break a string of semicolon separated into tokens). I'll call this script of ODI.

    Do I need to download the jython interpreter to test my script before I use it in ODI?

    How to call the script of ODI?

    N ° the Jython interpreter is built into ODI. You can simply create an ODI procedure, step, assign technology as "Jython" and paste your script in the command on the target. You can then use this procedure as part of a package.

Maybe you are looking for