Hash table type

Hello

I'm trying to sort a hastable that contains the key and values.

The keys are New york, los angles, Texas, port Aerizona

And values are 60.123, 34.3434, 56.4544, 67.565, 56.7878

Now, I want to sort the hash table based on the values which is lesser in value.

I tried comparer class using vector simplesorting, but I can only adjust the values but the keys remains unchanged in its position.

Please help me how to sort hastable with keys and values

I want the output of this title

34,3434 losangles

Texas 56.4544

port 56.7878

nwyork 60.123

aerizona 67.565

Thanks in advance

I suggest that you check out all the hastable keys and add to a SimpleSortingVector. You can them iterate thought the sorted keys, by using the keys to retrieve objects from the hash table.

Tags: BlackBerry Developers

Similar Questions

  • Defeated by tri-objet in the hash Table

    Hi guys, I need someone who is smarter than me to help please, suck for 3 days now.

    The Script below uses a CSV file as a database to pull total VMs in my vcenter in a bar chart, showing the trend upward. . My boss wants it as soon as possible.

    I can not however the $HT variable to sort by date (sorting and tri-objet doesn't seem to work, sort of NAME or WEEK)

    Need help please, I'm stumped.

    Note, tips cut off when I pasted it, like}'s and impossible.

    # Created by ELMO

    Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue

    $Date = Get-Date -Format yyyy/MM/dd

    $VCRUN = ' Ma Blanked to vCenter '

    $Report = @()

    $USER = "Ma Blanked user"

    $PWD = "Ma Blanked on pwd"

    Write-Host ' Connection to $VCRUN"" "".

    VIserver disconnect -Confirm:$false

    Se connect-VIServer -Server $VCRUN -User $USER -Password $PWD -wa 0

    $VMsON = Get-VM | Where-Object {$_. PowerState -eq "PoweredOn"}

    $VMsTotal = $VMsON. County

       $Row = "" | Select Week, VMsTotal

       $Row . Week = $Date

       $Row . VMsTotal = $VMsTotal

       $Report += $Row

       $ReportView = $Report | Export-Csv -Path C:\PS\Output\VMTrendDB.csv -Append -NoTypeInformation #-Append the data at the bottom of the existing file

    $MyData = Import-Csv C:\PS\Output\VMTrendDB.csv | Select-Object week ,VMsTotal

    $HT = @{}

    foreach ($Data in $MyData) {

    $HT. Add($Data. Week , $Data . VMsTotal)

    }

    $HT = $HT | Tri # read on the Technet site as tri-objet does not change the actual table, but only the output. Thus uses only sort. $HT = HT Triedd | Sort = Name object AND object week type, they do not change my picture on the order of dates

     

    Function Créer-Chart() {

    Param(

      [String] $ChartType ,

    [String]$ChartTitle,

      [String] $FileName ,

    [,String]$XAxisName,

      [String] $YAxisName ,

    [Int]$ChartWidth,

    [Int]$ChartHeight,

    [HashTable]$DataHashTable

    [Sub] [Reflection.Assembly]:LoadWithPartialName ("System.Windows.Forms"( )

    [Sub] [Reflection.Assembly]:LoadWithPartialName ('System.Windows.Forms.DataVisualization'( )

    #Create our graphic object

    $Chart = new-object System.Windows.Forms.DataVisualization.Charting.Chart

    $Chart. Width = $ChartWidth

    $Chart. Height = $ChartHeight

    $Chart. Left = 10

    $Chart. Top = 10

    #Create a chartarea to profit and add this to the table

    $ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea

    $Chart. ChartAreas . Add ($ChartArea)

    [void]$Chart. Series . Add("Data")

    $Chart. ChartAreas [0]. AxisX . Interval of = '1' #Set to 1 (default is auto) and allows all the values of the X axis appears correctly

    $Chart. ChartAreas [0]. AxisX . IsLabelAutoFit = $false;

    $Chart. ChartAreas [0]. AxisX . LabelStyle . Angle = "-45"

    #Add real data to our table

    $Chart. Series ["Data"]. Points . DataBindXY ($DataHashTable. ) Key , $DataHashTable. Values)

    if (($ChartType -eq "Pie") -or ($ChartType -eq "pie")) {

    $ChartArea. AxisX . Title = $XAxisName

    $ChartArea. AxisY . Title = $YAxisName

    $Chart. Series ["Data"]. ChartType = [System.Windows.Forms.DataVisualization.Charting.SeriesChartType]:Pie

    $Chart. Series ['Data'] ['PieLabelStyle'] = "Outside"

    $Chart. Series [« Data »] [« PieLineColor »] = "Black"

    $Chart. Series ['Data'] ['PieDrawingStyle'] = "Concave"

    ($Chart. Series ["Data"]. Points . FindMaxByValue()) ["Exploded"] = $true

    $Chart. Series ["Data"]. Label = ' #VALX = #VALY\n ' # make a X & Y Label of the data in the (useful for Pie chart) plot area (display the axis labels, use: Y = # ControlChars.LF = #VALX)

    elseif (($ChartType -eq "Bar") -or ($ChartType -eq "bar")) {

    #$Chart.Series ["Data"]. Sort ([System.Windows.Forms.DataVisualization.Charting.PointSortOrder]: descendant, "Y")

    $ChartArea. AxisX . Title = $XAxisName

    $ChartArea. AxisY . Title = $YAxisName

    # Find point with max/min values and change color

    $maxValuePoint = $Chart. Series ["Data"]. Points . FindMaxByValue()

    $maxValuePoint. Color = [System.Drawing.Color]:Red

    $minValuePoint = $Chart. Series ["Data"]. Points . FindMinByValue()

    $minValuePoint. Color = [System.Drawing.Color]:Green

    # make the bars in the 3d cylinders

    $Chart. Series [« Data »] [« DrawingStyle »] = "Cylinder"

    $Chart. Series ["Data"]. Label = '#VALY' # Label Y to the data in the plot (useful for the diagram bar) area

    else {

    Write-Host "no Chart Type has been defined. Try again and enter Pie or Bar for the ChartType parameter. The table will be created in the form of standard bar graphic chart for now. " -ForegroundColor Cyan

     

    #Set the title of the chart for the date and time

    $Title = new System.Windows.Forms.DataVisualization.Charting.Title

    $Chart. Titles . Add($Title)

    $Chart. Titles [0]. Text = $ChartTitle

    Graphic to a file #Save

    $FullPath = ($FileName + ".png")

    $Chart. SaveImage ($FullPath 'png'( )

    Write-Host ' saved chart in $FullPath"" " -ForegroundColor Green .

    back $FullPath

     

    Create Chart -ChartType bar ChartTitle - "machines virtual VMware in DC1" -FileName C:\inetpub\ELMO\Graphic\VMsTrendChart -XAxisName 'Date' -YAxisName 'number of VMs' -ChartWidth 800 -ChartHeight 800 -DataHashTable $HT

    All by setting the variable $HT, you define it as a Table of hash, sort or Sort-Object does not work on hash Tables, they work on arrays. Your definition is

    $HT = @ {}

    Use $HT = @)

    Instead, which will create a table and you would be able to define objects and then use the Sort-Object there. With Hash Tables, since they hold any objects you can not sort using Sort-Object.

  • PageContext.forwardimmediatly works not when the hash table is used.

    Hello

    I try to use as below:

    HashMap hm = new HashMap (1);
    HM.put ("conc_called", "Yes");

    pageContext.forwardImmediately ("OA.jsp?page=/XXX/xxPG",
    NULL,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    NULL,
    GMC
    true,
    "N");

    But I get an error message indicating that the method does not exist. Any suggestion would be appreciated.

    Thank you
    PK

    Make sure the hash table is of the type com.sun.java.util.collections.HashMap and not java.util.HashMap

  • Hash table returns null

    It's the stumping me. I add a key and a value in a hash table, pass in the key and retrieve the value. Basic enough, but when I go to retrieve the value a second time (after the restart of the application), it returns null.

    If it isn't exactly the code that would be the basic scheme:

    class A
    {
         private static Hashtable table = new Hashtable();
    
         public static Object getObject(Class clazz)
         }
              return A.table.get(clazz);
         }
    
         public static void setObject(Class clazz, Object obj)
         }
              A.table.put(clazz, obj);
         }
    
         //Code stuff...
    }
    
    class B
    {
         public static void main(String[] args)
         {
              A.setObject(C.class, new C());
              Object obj = A.getObject(C.class); //This works
         }
    
         //Code stuff...
    }
    
    class C
    {
         //Code stuff...
    }
    

    What happens on the 9550 Simulator and is fixed after restarting the Simulator but work always and only the first time through. If the app is closed, then reopened, then it returns null, even if the hash table was always the same items.

    Ah. When you run the application a second time, he rebuilt serializers to persistent store. Unfortunately, your objects of the class are new instances, so that they cannot be used as persistent hash keys. I suggest you use class names as keys rather than objects of class themselves.

  • Returns a copy of the hash table

    I have problems by returning a copy of a hash that is normally stored in the persistent store table.

    final class SyncCentres {
        private static Hashtable syncCentres;
        private static PersistentObject persist;
        private static final long ID=0xdfeab99e040a223aL;
    
        static{
            persist=PersistentStore.getPersistentObject(ID);
            syncCentres=(Hashtable)persist.getContents();
            synchronized(persist){
                if(syncCentres==null){
                    syncCentres=new Hashtable(4);
                    persist.setContents(syncCentres);
                    persist.commit();
                }
            }
        }
    
        static Hashtable getSyncCentres(){
            return syncCentres;
        }
    
    } // Class
    

    When I get the hash table in another class by using the static method.

    Hashtable hash=SyncCentres.getSyncCentres();
    

    It turns out that it is not a copy. Change the hash variable will edit the SyncCentres class as well. Is this normal? How can I get a copy of it?

    Java, copy and pass the reference by value, not the object.
    See
    http://www.Yoda.arachsys.com/Java/passing.html
    or
    http://www.JavaWorld.com/JavaWorld/javaqa/2000-05/03-QA-0526-pass.html
    If you want a true copy of the hash table you need to clone and each of its objects.
    You can also copy all objects to a new hash table, but these are always references to the same objects as in the first hash table.

  • ListField using the hash table

    Hi guys, new here so please, be gentle.

    I was wondering if there is way to a ListField (or something similar) but using a hash instead of a vector table. I searched through the forums without success. And if it is would it be possible to display the incredible list. (List in the hash table and sort by alphabetical order, via the keys)

    The hash table structure K = String (name of player), V = object reader.

    If this can be done using a hash table, is there a way to do this using a vector. So that I could search the data structure for a players name and return the object.

    Sorry if it's confusing or vague. I'm not not used to describe my problems!

    Thank you very much for the help.

    You can also move forward and persist in the hash table, and then build an index using a few stores of SimpleSortingVector who keys in order.

    There are a lot of options... you just need to decide which is best for you.

  • Error in initialization of multilevel nested table type

    Hello

    Database version: Oracle 11 g R2

    I am creating a complex process I need to create complex nested table types and use them in code.

    {code}

    CREATE or REPLACE TYPE ws_data_compare_rt

    AS AN OBJECT

    (

    external_web_service_id NUMBER (10),

    service_code VARCHAR2 (30),

    ws_bridging_id NUMBER (10),

    ws_attribute_name VARCHAR2 (64).

    ws_attribute_value VARCHAR2 (32767).

    in_source_attribute VARCHAR2 (30),

    in_source_value VARCHAR2 (32767).

    comparison_rule VARCHAR2 (100)

    );

    CREATE or REPLACE TYPE ws_data_compare_tt IS TABLE OF THE ws_data_compare_rt;

    CREATE or REPLACE TYPE ws_data_compare_master_rt

    AS AN OBJECT

    (

    key_attribute_1 VARCHAR2 (30),

    NUMBER of key_attribute1_value

    key_attribute_2 VARCHAR2 (30),

    NUMBER of key_attribute2_value

    m_ws_data_compare_tt ws_data_compare_tt

    );

    /

    CREATE or REPLACE TYPE ws_data_compare_master_tt IS TABLE OF THE ws_data_compare_master_rt;

    {code}

    The objects have been created successfully. However when I use it in my code, I need to initialize them, but I get an error for the variable of ws_data_compare_master_tt type initialization.

    {code}

    ...

    g_ws_data_compare_rt ws_data_compare_rt: = ws_data_compare_rt (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);

    g_ws_data_compare_tt ws_data_compare_tt: = ws_data_compare_tt();

    g_ws_data_compare_master_rt ws_data_compare_master_rt: = ws_data_compare_master_rt (NULL, NULL, NULL, NULL, g_ws_data_compare_tt);

    g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();

    ...

    {code}

    I'm unable to initialize the variable g_ws_data_compare_master_tt of type ws_data_compare_master_tt that I get the below error.

    For PACKAGE BODY UTL compile errors. PKG_WS_UTIL

    Error: PLS-00222: no function with name 'WS_DATA_COMPARE_MASTER_TT' does exist in this scope

    Line: 28

    Text: g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();

    Error: PL/SQL: ignored element

    Line: 28

    Text: g_ws_data_compare_master_tt ws_data_compare_master_tt: = ws_data_compare_master_tt();

    Can someone help me to find out what is the problem?

    Thanks in advance.

    Kind regards

    Natarajan

    Ah, I found the problem on my own. It was because of a bad statement similarly variable g_ws_data_compare_master_tt in a table in the specification of the package that was trouble. However I wonder the error returned Oracle was not fully exposed.

    Kind regards

    Natarajan

  • Use of hash Tables

    HI guys,.

    I have a script that takes a list of VM and collects various pieces of information on the

    • Name, host name, CPU Num, Num disks, IP info, etc...

    The script works fine, but I still need to load the data into Excel and manipulate manually until the data can be used with other scripts. I wonder if there is a way to eliminate this manual work?

    Specifically, for each computer virtual, the script determines the number of hard drives and returns the following for each disk

    1. HDDx name
    2. HDDx data store
    3. Path of HDDx (file and hard in the data store name)

    I can be left with dozens of lines for all virtual machines in the hash table, and each virtual computer might have multiple entries for each of the 3 items above.

    E.g. HDD1, HDD2, HDD3 Datastore, DataStore DataStore...

    What I want to do is take all the 'HDDx DataStore' entries in the hash table and return only the unique entries so that I can then turned off and get specific on these specific data stores information, number of virtual machines, the names of the machines virtual etc...

    I tried to use wildcards, which of the statements, etc... I can't make it work.

    Fill script I use is attached.

    This is the closest that I just get this work but, it is still not add all the information from the data store in the hash table second $dsReport

    In the attached script, I have highlighted the lines of $dsReport

    $report = @)
    $dsReport = @)
    ...
    ...
    $hdd = 1
    $Computer | Get-hard drive | {foreach}
    Name of $GeneralProp.Add ("HDD$ ($hdd) ', $_.") Name)
    $GeneralProp.Add ("HDD$ ($hdd) data store", $_. ") FileName.split("") [0]. TrimStart("["). TrimEnd("]"))
    $GeneralProp.Add ("HDD$ ($hdd) path', $_.") FileName.split("") [1]. TrimStart("["). TrimEnd("]"))
    Capacity of $GeneralProp.Add ("HDD$ ($hdd) ', $_.") CapacityGb)
    $dsProp=@{Name = $_. FileName.split("") [0]. TrimStart("["). TrimEnd("]")}
    $hdd ++
    }

    ...

    ...

    $dsReport | SELECT name - Unique

    Any help is appreciated

    Thank you


    Something like that?

    Get - vm | {foreach}

    $disks = @)

    $_ | Get-hard drive | {foreach}

    $dsname = $_. Filename.Split("") [0]. TrimStart("["). TrimEnd("]")

    $disks += $_. Add-Member - MemberType NoteProperty - name DatastoreName - $dsname - PassThru of value

    }

    $disks | Group-object - property DatastoreName

    }

  • Custom hash table object

    Hi I have the following script which should provide an array with the names of vm and the datastorecluster they are on: -.

    $hashT = @ {}

    $vmlist = import-Csv "C:\vmMove\vm3.csv".

    foreach ($vm to $vmlist)

    {

    $vmname = get - vm $vm.name

    $dscname = get-datastorecluster - vm $vm.name

    $hashT = @ {}

    VMNAME = $vmname

    DSCLUSTER = $dscname

    }

    }

    $props = New-Object psobject-property $hashT

    $props | FT - AutoSize

    There are four hosts listed in the csv file, but when I run this table only wrote a line for the last host does not include the first three hosts.  What I am doing wrong? Why can't that get the hash table to view details for all hosts contained in csv.

    I have spent the better part of a day on this and just can't see where I'm wrong - thank you

    If you want just a table with these objects in there, you could do

    $hashT = @)

    $vmlist = import-Csv "C:\vmMove\vm3.csv".

    foreach ($vm to $vmlist)

    {

    $vmname = get - vm $vm.name

    $dscname = get-datastorecluster - vm $vm.name

    $hashT += new-Object PSObject - property @ {}

    VMName = $vm. Name

    DscCluster = $dscname

    }

    }

    $hashT

  • PLS-00201 in the table type declaration

    Hello world

    I want to create a line of some of my table type table type.

    For example:

    create or replace type tmp_Road is table of the XUXUEHAN.tbl_Road%rowtype

    But I PLS-00201: identifier 'XUXUEHAN.tbl_Road' must be declared.

    Where am I wrong? Thank you :-)

    Hi, rp0428.

    I read your page

    But, the way I called the function package-"select * from table (text_x.get('1')); -It's like the way you did-' select * from table (pkg4.get_emp (20));

    But the compiler tell me "types of data not valid."  I don't really understand why. Please help me, thanks :-)

  • Selection of one-dimensional Array objects in a hash table

    Suppose I have a hash table with a list of names of virtual machine.  I also have a variable array containing objects of virtual machine and all of their properties.  I want to scroll the array variable and delete all virtual machine names that do not exist in the hash table.  How do I would accomplish this?

    Thank you

    If your table is called $inArray and your hash table is called $hashTab, you could do something like that

    $outArray = $inArray | %{

    If ($hashTab.ContainsKey ($_.)) VMName)) {}

    $_

    }

    }

    The selected objects will be $outArray table.

  • Removal of the strings in a hash table

    Hello to all PowerCLI'ers out there.  This is what, I hope, will be an easy one for you guys.

    I built a hash named $hostInfo table that contains information about our VMHosts.  According to the information when displayed in a table format Name, UsedMemoryGB, TotalMemoryGB, FreeMemoryPct.

    The release of "Format-Table" looks like this:

    Name UsedMemoryGB TotalMemoryGB FreeMemoryPct
    ---------                                                               -----------------------             ------------------------                        -----------------------
    us1esx0201.company.local 89.07421875 95.989414215087890625 92.79587700202785441462201182
    us1esx0209.company.local 84.8193359375 95.989414215087890625 88.36321862267168020854706439
    us1esx0211.company.local 83.681640625 95.989414215087890625 87.17798864517570982753322143
    us1esx0205.company.local 83.3310546875 95.989414215087890625 86.81275468644519191613067240
    us1esx0403.company.local 96.3408203125 111.989383697509765625 86.02674390344222204017427325
    us1esx0401.company.local 95.689453125 111.989383697509765625 85.44511092539192491691602221
    US1-vmhesx - p0515.company.local 81.6171875 95.989383697509765625 85.02730651672824441211219264
    us1esx0303.company.local 95.1884765625 111.989383697509765625 84.99776802023479984310570319
    US1-vmhesx - p0512.company.local 81.4462890625 95.9893798828125 84.84927099428367955541142883
    us1esx0113.company.local 81.3212890625 95.98944091796875 84.71899438605549341860543489

    Here is the code snippet that generates the hash table:

    $hostInfo = get-VMHost |

    Select name "

    @{N = "UsedMemoryGB"; E={$_. MemoryUsageGB}} '

    @{N = "TotalMemoryGB"; E={$_. MemoryTotalGB}} '

    @{N = "FreeMemoryPct"; E={(($_. MemoryUsageGB / $_. {{(MemoryTotalGB) * 100)}} |

    Sort-Object-descending - property 'FreeMemoryPct ' | Select - 10 first

    Here is my challenge... I want to remove the '. '. company.local"of all entries in the"Name"column and only let the real host name.  How would I go about iterate the key 'Name' and deleting only this part of the chain?

    Any help is appreciated as always!

    -jSun311

    You can create the table in the right format with just the name of the host if you change the second line of your script in:

    Select @{N = "Name"; E={$_. Name.Split('.') [0]}},

    If you want to change the variable $hostinfo, then you can use:

    $NewHostinfo = $hostinfo | Select-Object - property @{N = "Name"; E={$_. Name.Split('.') [0]}}, UsedMemoryGB, TotalMemoryGB, FreeMemoryPct

  • Not able to manage the value 'Table Type' in my procedure, humble need help here

    Hi all

    I am facing a problem with below pl/sql block. The time I run it it works fine, but when I run the procedure only from the exact values (hardcoded), it throws error as below.

    [Error] Execution (38: 1): ORA-06550: line 2, column 1:

    PLS-00306: wrong number or types of arguments in the call to 'CREATE_ABNORMAL_BY_TRADER '.

    ORA-06550: line 2, column 1:

    PL/SQL: Statement ignored

    What I understand problem is, I use a Type of table herewhich works very well with my Pl/Sql block, but do not work when I run the same procedure of the value hard-coded.

    Please guide me how to handle this situation.

    Pl/Sql block [works absolutely well]:

    Declare

    lv_eff_from_dt DATE;
    lv_eff_to_date DATE;
    v_severity_codes_wl param_tbl: = param_tbl();
    lv_algo_id_wl sagedbo.alerts.algo_id%TYPE;

    Begin

    lv_eff_from_dt: = sage_utility.get_transaction_date('EFF_FROM_DATE');  -' 05-Aug-2013. '
    lv_eff_to_date: = sage_utility.get_transaction_date('EFF_TO_DATE');       -' 04-sep-2013. '

    lv_algo_id_wl: = sage_utility.get_code_values('ALERT_MODELS','GRAY_LIST');  -GLABNORMAL

    v_severity_codes_wl: = sage_utility.get_multi_parameter_value(1,'SEVERITY_CODE_WL'); -4.5

    SONARDBO.sage_generate_alert.create_abnormal_by_trader (lv_algo_id_wl, v_severity_codes_wl, lv_eff_from_dt, lv_eff_to_date, 'US');

    End;

    Pl/Sql block [does not] (by the way the same values but hard)

    Begin

    SONARDBO.sage_generate_alert.create_abnormal_by_trader ('GLABNORMAL', '4', 5, 5 August 2013 ', ' 04-Sep-2013', 'US');

    End;

    Error PLS-00306: wrong number or types of arguments in the call to 'CREATE_ABNORMAL_BY_TRADER '.

    I'm sorry that my question is not so generic, you cannot run on your computer. How should just guide me with the concept, I treat the values in table hardcodedly? (For testing of use)

    Thank you very much

    If your passage of type table, then you will need to run as below

    Begin

    SONARDBO.sage_generate_alert.create_abnormal_by_trader ("GLABNORMAL", param_tbl (' 4 ', ' 5'), August 5, 2013 ', ' 04-Sep-2013', 'US');

    End

    Means that you must call with the table type ("' hard coded values"). Here is the simple test. Take a look at this

    SQL > CREATE or REPLACE the TYPE nt_tab IS TABLE OF VARCHAR2 (50);

    2.

    Type of creation.

    SQL > CREATE OR REPLACE PROCEDURE test_proc (p_nttab nt_tab)

    2 AS

    3 v_nttab nt_tab: = p_nttab;

    4 BEGIN

    5 FOR me in 1.v_nttab. COUNTY

    6 LOOP

    7 DBMS_OUTPUT. Put_line (v_nttab (i));

    8 END OF LOOP;

    9 END;

    10.

    Created procedure.

    -Perform the procedure with only one value of type table

    SQL > EXEC test_proc (nt_tab ('KING'));

    KING

    PL/SQL procedure successfully completed.

    -Run procedure with the multi-value table type

    SQL > EXEC test_proc (nt_tab ('KING', 'AAAA', 'BBBB'));

    KING

    ABDELKADER

    BENAMER

    PL/SQL procedure successfully completed.

    Post edited by: 000000

    Post edited by: 000000

  • The assignment of values of Table type error

    Hello

    I'm trying to insert values for a Collection type, while doing that I am faced with an error.
    " PLS-00306: wrong number or types of arguments in call to
     'XXSCP_AVL_CSP_SQR_O_TP' "
    My statement of collection type PFB and and assignment.

    Object type:
    TYPE XXSCP_AVL_CSP_SQR_O_TP AS                  
    OBJECT  (                                       
                PLAN_ID             NUMBER,         
                SR_INSTANCE_ID      NUMBER,         
                INVENTORY_ITEM_ID   NUMBER,         
                BASE_ITEM_ID        NUMBER,              
                 ITEM_NAME           VARCHAR2(50),       
                 SUPPLIER_ID         NUMBER,             
                SUPPLIER_SITE_ID    NUMBER,         
                NORMAL_BUY_USAGE    VARCHAR2(5),    
                AVAILABLE_QUANTITY  NUMBER ,        
                SPL_PEG_FLAG        VARCHAR2(10),   
                SQR_LINE_ID         VARCHAR2(2000), 
                SQR_NUMBER          VARCHAR2(2000), 
                SQR_MOQ             NUMBER,         
                BPA_PO_LINE_ID      NUMBER,         
                SUGG_BPA_NUMBER     VARCHAR2(30),   
                BPA_BUY_PRICE_BASIS VARCHAR2(10),   
                BPA_LINE_NUM        NUMBER,         
                BPA_PO_LINE_LOC_ID  NUMBER,         
                BPA_CURRENCY_CODE   VARCHAR2(10),   
                BPA_PRICE           NUMBER,         
                BPA_PO_HEADER_ID    NUMBER,         
                BPA_EXPIRATION_DATE DATE,           
                BPA_QUANTITY        NUMBER,         
                ORIG_AVAILABLE_QTY  NUMBER          
            );        
    
    Table type :
    
    TYPE XXSCP_AVL_CSP_SQR_C_TP AS TABLE OF XXSCP_AVL_CSP_SQR_O_TP;
    Statement:
     l_tab_avl_csp_sqr   XXSCP_AVL_CSP_SQR_C_TP := XXSCP_AVL_CSP_SQR_C_TP();
    Assignment to the body:
    l_tab_avl_csp_sqr.EXTEND(1);
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT) := XXSCP_AVL_CSP_SQR_O_TP();
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).plan_id           := l_tab_planorders (i).l_num_plan_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).sr_instance_id    := l_tab_planorders (i).l_num_sr_instance_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).inventory_item_id := l_tab_planorders (i).l_num_inventory_item_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).base_item_id      := l_tab_planorders (i).l_num_base_item_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).item_name         := l_tab_planorders (i).l_chr_item_name;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).supplier_id       := l_tab_planorders (i).l_num_supplier_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).supplier_site_id  := l_tab_planorders (i).l_num_supplier_site_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).available_quantity := l_rec_pegged_list (j).remaining_aval_qty;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).spl_peg_flag       := 'Y';
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).sqr_line_id        := l_rec_pegged_list (j).sqr_line_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).sqr_number         := l_rec_pegged_list (j).sqr_number;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).sqr_moq            := l_rec_pegged_list (j).sqr_moq;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_po_line_id     := l_rec_pegged_list (j).bpa_po_line_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).sugg_bpa_number    := l_rec_pegged_list (j).bpa_number;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_buy_price_basis := l_rec_pegged_list (j).bpb_type;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_line_num        := l_rec_pegged_list (j).bpa_line_num;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_po_line_loc_id  := l_rec_pegged_list (j).bpa_lloc_id;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_currency_code   := l_rec_pegged_list (j).bpa_curr_code;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_price           := l_rec_pegged_list (j).bpa_price;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_expiration_date := l_rec_pegged_list (j).bpa_expiration_date ;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).bpa_quantity        := l_rec_pegged_list (j).bpa_quantity ;
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT).orig_available_qty  := l_rec_pegged_list (j).remaining_aval_qty ;
    Can anyone help with this.

    Thanks in advance,
    Rakesh

    Published by: Vincent Rakesh on April 24, 2013 12:18 AM

    You must add a vacuum-arg set constructor to your type to use, user l_tab_avl_csp_sqr (l_tab_avl_csp_sqr. "COUNTY): = XXSCP_AVL_CSP_SQR_O_TP();

    create or replace
    TYPE XXSCP_AVL_CSP_SQR_O_TP AS
    OBJECT  (
                PLAN_ID             NUMBER,
                SR_INSTANCE_ID      NUMBER,
                INVENTORY_ITEM_ID   NUMBER,
                BASE_ITEM_ID        NUMBER,
                 ITEM_NAME           VARCHAR2(50),
                 SUPPLIER_ID         NUMBER,
                SUPPLIER_SITE_ID    NUMBER,
                NORMAL_BUY_USAGE    VARCHAR2(5),
                AVAILABLE_QUANTITY  NUMBER ,
                SPL_PEG_FLAG        VARCHAR2(10),
                SQR_LINE_ID         VARCHAR2(2000),
                SQR_NUMBER          VARCHAR2(2000),
                SQR_MOQ             NUMBER,
                BPA_PO_LINE_ID      NUMBER,
                SUGG_BPA_NUMBER     VARCHAR2(30),
                BPA_BUY_PRICE_BASIS VARCHAR2(10),
                BPA_LINE_NUM        NUMBER,
                BPA_PO_LINE_LOC_ID  NUMBER,
                BPA_CURRENCY_CODE   VARCHAR2(10),
                BPA_PRICE           NUMBER,
                BPA_PO_HEADER_ID    NUMBER,
                BPA_EXPIRATION_DATE DATE,
                BPA_QUANTITY        NUMBER,
                ORIG_AVAILABLE_QTY  NUMBER,
    /*
    Constructor
    */
                constructor function XXSCP_AVL_CSP_SQR_O_TP return self as result
            );        
    
    create or replace
    TYPE body XXSCP_AVL_CSP_SQR_O_TP AS
    /*
    Constructor
    */
                constructor function XXSCP_AVL_CSP_SQR_O_TP return self as result
                is
                begin
                  return;
                end;
    end;        
    

    You can also assign your attributes that you construct your instance:

    l_tab_avl_csp_sqr.EXTEND(1);
    l_tab_avl_csp_sqr(l_tab_avl_csp_sqr.COUNT) := new XXSCP_AVL_CSP_SQR_O_TP(
      l_tab_planorders (i).l_num_plan_id,
      l_tab_planorders (i).l_num_sr_instance_id.
      l_tab_planorders (i).l_num_inventory_item_id,
      l_tab_planorders (i).l_num_base_item_id,
      l_tab_planorders (i).l_chr_item_name,
      l_tab_planorders (i).l_num_supplier_id,
      l_tab_planorders (i).l_num_supplier_site_id,
      l_rec_pegged_list (j).remaining_aval_qty,
      'Y',
      l_rec_pegged_list (j).sqr_line_id,
      l_rec_pegged_list (j).sqr_number,
      l_rec_pegged_list (j).sqr_moq,
      l_rec_pegged_list (j).bpa_po_line_id,
      l_rec_pegged_list (j).bpa_number,
      l_rec_pegged_list (j).bpb_type,
      l_rec_pegged_list (j).bpa_line_num,
      l_rec_pegged_list (j).bpa_lloc_id,
      l_rec_pegged_list (j).bpa_curr_code,
      l_rec_pegged_list (j).bpa_price,
      l_rec_pegged_list (j).bpa_expiration_date,
      l_rec_pegged_list (j).bpa_quantity,
      l_rec_pegged_list (j).remaining_aval_qty );
    

    Gerard

    Published by: gaverill on April 23, 2013 12:12

  • Asynchronous tasks, hash tables, and berries - best way to do this!

    I'm working with a colleague on a script that will deploy a very large number of virtual machines to a CSV file.  We started with a purely synchronous process that was very slow by using a simple foreach loop to deploy a virtual machine, configure, a technique of customization and start all this according to the CSV data.

    The obvious bottleneck in the process is waiting for the clone operation is completed before you perform the remaining tasks.  The synchronous line of New - VM in a foreach loop, it is very slow.

    We have since changed to deploy an asynchronous virtual machine using the foreach loop according to the CSV data in a table.  Once the foreach loop started all clonings, he finishes and then a monitoring task loop 'while' kickoff and then perform the rest tasks.  The while loop is based on code from the LucD found here: http://www.lucd.info/2010/02/21/about-async-tasks-the-get-task-cmdlet-and-a-hash-table/ (thanks Luke!).

    Now code Luke used a hash table, so it had to be modified to use the CSV table at best.  Table CSV contained information to perform the configuration and customization of the virtual machine.  I couldn't really find a way for this very cleanly, I'm looking for suggestions on making it a little better.

    Right now I use a simple counting mechanism to browse table to determine if the cloning operation is complete or not.  The problem with this is that if there are 100 VM being cloned, and I walk through the table one row at a time so he could take a long time between the success of the clone operation and monitoring loop actually pick up on it.  It would be nice to have a way to identify which line in the table has data customization and configuration required without walking through it in a loop, rather referring to an item in the table (TaskID) using another method (is this one?-still find such things powershell).

    Here is the modified version of the code of Luke:

    # $csv is the array in question with the required data.
     
    # Used to count which line in the array
    $csvline = 0
     
    # Count all the running tasks to feed into the while loop
    $tasks = $csv | %{$_.TaskID} | ?{$_ -match "Task"}
    $runningTasks = $tasks | measure | %{$_.count}
     
    while($runningTasks -gt 0){
     
    # Completion Meter
    $percomplete = (1 / $runningTasks)*100
    Write-Progress -activity 'Waiting for cloning operation to complete' -status 'Please wait...' -percentComplete ($percomplete)
     
    # Here is where it starts to get messy, there has to be a better way than using $csv[$csvline] and walking though
    if ((get-task | select id,state | ?{$_.id -eq $csv[$csvline].TaskId}).state -eq "Success"){
    Set-VM $csv[$csvline].name -NumCpu $csv[$csvline].vcpu -MemoryMB $csv[$csvline].MemoryMB -Description $csv[$csvline].Notes -Confirm:$false
    Get-vm -name $csv[$csvline].name | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $csv[$csvline].Network -StartConnected:$true -Confirm:$false
    Get-VM $csv[$csvline].name | Start-VM -RunAsync -Confirm:$false
    $csv[$csvline].TaskId = ""
    $runningTasks--
    }
    elseif ((get-task | select id,state | ?{$_.id -eq $csv[$csvline].TaskId}).state -eq "Error"){
    $csv[$csvline].TaskId = ""
    $runningTasks--
    }
     
     
    # Increment $csvline
    $csvline++
     
    # Wash rinse repeat over and over (not very pretty)
    # Reset $CSV array line counter when greater than count of lines (minus 1 because the array/count starts at zero).
    if ($csvline -gt ($csv.count - 1)){
    $csvline = 0
    }
     
    # Slow down the runningTasks loop since we are waiting for cloning operations to complete.
    # IMPACT: If you deploy 100 VM's it could take up to 200 seconds AFTER a VM is finished cloning before being noticed by the while loop
    Start-Sleep -Seconds 2
    }
    
    
    

    It would be nice to create a Get-task monitoring loop who does not walk in the table.  But shoot any 'Sucess' ful tasknames and determine which line in the table of $csv it is (using the TaskId element).

    Is it possible to do another nesting a foreach ($line in $csv) inside the Get task monitoring loop and compare the TaskId values?  (It's perhaps faster without worrying - have not yet tested).

    I hope that I have explained things clearly enough.

    Thanks for your time.

    Andy

    Andy, have a look at the thread called error with Get-OsCutomizationNicMapping, he does something similar to what you want to do I guess.

    Inside the loop of Import-Csv, the new virtual machine is created in Async and the Id of the task as well as some specific values of the CSV stored in the part of the value of the hash table.

    Later, these values are used to configure the new virtual machine further.

Maybe you are looking for