Hello,

This has been going on for sometime now. I not being able to solve it.

I am sorry for a repost, as I had posted this problem before but I couldn’t get anything that was able to make my script to work. I am getting very frustrated. This is my last and final try.

I have a perl script which calls a stored procedure which produces 7 resultsets, which I need to put in a .csv file. I have been trying to do it for a week now, but not being able to get the job done.

The full script to generate the csv file never works.

a) Either it stops after providing a few rows of data from the first resultset and never proceeds to the next resultset.
b) Or the header row is missing sometimes.
c) Or it prints the 1st resultset skips the 2nd resultset and then prints the 3rd resultset.
d) Then it runs into an infinite loop and keep running.
I getting frustrated with this and don’t know how to solve it.

My Perl code is as follows:

#!/cluster/uapp/perl/bin/perl -w use DBI; use strict; use DBAccess; use DBD::CSV; use MIME::Lite; use Net::SMTP; use Data::Dumper; use Text::CSV_XS; my @ret_values = undef; ##Parameters to connect to the Database here##### # Run stored proc my $sp = "lv..check_tax_lot"; $_read_dbi = ###Make Database Connection here### my $_read_sth = $_read_dbi->prepare($sp); if($DBI::err) { handle_error_and_exit("**ERROR preparing $sp: " . $DBI::errstr +); } $_read_sth->execute(); if($DBI::err) { handle_error_and_exit( "**ERROR executing $sp: " . $DBI::errst +r); } while (my $row = $_read_sth->fetchall_arrayref) { my $csv = Text::CSV_XS->new ({ binary => 1, eol => "\r\n" }); print @{$_read_sth->{NAME}}; while (my $r = $_read_sth->fetch) { $csv->print (*STDOUT, $r); } }
When I run the above script I get the following output:

#####Missing the following line????##### #### Encumberances to look into: ####### ####No Return After the First Header Row???#### AccountSymbolSedolSecurity NameEncumberedEnc. qtyBorrow Acct15140EQJP_ +55121,"DD UN",2018175,"DU PONT (E.I.) DE NEMOURS","BO data mismatch", +275000.0,98027EQJP_54981 15140EQJP_55121,"AFL UN",2026361,"AFLAC INC","BO data mismatch",100000 +.0,29075EQJP_54301 15140EQJP_55121,"SLM UN",2101967,"SLM CORP","BO data mismatch",180000. +0,98002EQJP_54161 15140EQJP_55121,"CMI UN",2240202,"CUMMINS INC","BO data mismatch",1000 +00.0,98059EQJP_53421 15140EQJP_55121,"DOW UN",2278719,"DOW CHEMICAL","BO data mismatch",175 +000.0,98027EQJP_54981 #####Missing Second Resultset all together only printed the first line + below, no headers even printed.:####### "Position integrity:" ##### In the Third Resultset only the first line printed with no heade +rs, but the output is printed..:####### "91 - LOAN-IP - Loan in progress inconsistencies:" "No loan in progress inconsistencies found" ##### In the Fourth Resultset only the first line printed with no head +ers, but the output is printed..:####### "Loan IP tax_lot without open order?" "No missing open orders found." ##### In the Fifth Resultset only the first line is printed, no header + row neither the data is printed.####### "Loan tax_lot without loan account (user_field_6) or ""LV Transaction +ID"" (user_field_4):" ##### In the Sixth Resultset only the first line is missing but the he +ader rows and data is printed without a return character at the end o +f the header row####### accountsymbolsedolsecurity_namequantity28963EQJP_55441,"2379 TT",60514 +22,"REALTEK SEMICONDUCTOR CORP",-37000.0 15140EQJP_55121,"2379 TT",6051422,"REALTEK SEMICONDUCTOR CORP",-83379. +0 15140EQJP_55121,"1301 TT",6348544,"FORMOSA PLASTICS CORP",-1246101.0 15140EQJP_55121,"1326 TT",6348715,"FORMOSA CHEMICALS & FIBRE",-1223781 +.0 28963EQJP_55441,"BHP AU",6144690,"BHP BILLITON LTD",-873876.0 ##### In the Seventh Resultset only the first line printed with no hea +ders, but the output is printed..:####### "Encmbered quantity differs from quantity on taxlot:" "No faulty encumbrances found."



Now if you compare the above output with the output below which is generated when I run the stored procedure by connecting to the database through a tool like DB Artisan or Rapid SQL, you will instantly see the difference in the generated outputs and formats.

################################Result Set 1########################## +#######################3 Encumberances to look into: Account Symbol Sedol Security Name Encumbered Enc. qty Borrow Acct 15140EQJP_55121 AFL UN 2026361 AFLAC INC BO data mismatch 100000 29075 +EQJP_54301 15140EQJP_55121 SLM UN 2101967 SLM CORP BO data mismatch 180000 98002E +QJP_54161 15140EQJP_55121 CMI UN 2240202 CUMMINS INC BO data mismatch 100000 980 +59EQJP_53421 15140EQJP_55121 DOW UN 2278719 DOW CHEMICAL BO data mismatch 175000 98 +027EQJP_54981 15140EQJP_55121 GCI UN 2360304 GANNETT CO BO data mismatch 137300 3284 +7EQJP_55601 15140EQJP_55121 GCI UN 2360304 GANNETT CO BO data mismatch 2900 32847E +QJP_55601 15140EQJP_55121 GCI UN 2360304 GANNETT CO BO data mismatch 39800 32847 +EQJP_55601 15140EQJP_55121 MFC CT 2492519 MANULIFE FINANCIAL CORP BO data mismatc +h 150000 29075EQJP_54301 #######################################Result Set 2################### +################### Position integrity: lender_account borrow_account sedol symbol security_name encumbered lo +aned diff 15140EQJP_55121 98003EQJP_54181 6497071 000700 KP HANJIN SHIPPING 2500 +0 0 25000 15140EQJP_55121 98003EQJP_54181 6494997 005880 KP KOREA LINE CORP 8160 + 0 8160 15140EQJP_55121 98003EQJP_54181 6405869 011200 KP HYUNDAI MERCHANT MAR +INE 76030 0 ######################################Result Set 3#################### +############### 91 - LOAN-IP - Loan in progress inconsistencies: tax_lot_id lender_account borrow_account sedol symbol security_name or +der_id block_id encumbered quantity_ordered quantity_confirmed quanti +ty_closed quantity_executed unsent_executions quantity_left diff No loan in progress inconsistencies found ########################################Result Set 4################## +################ Loan IP tax_lot without open order: account symbol sedol security_name tax_lot_id security_id position_typ +e_code quantity encumbered_quantity No missing open orders found. ######################################Result Set 5#################### +###################### Loan tax_lot without loan account (user_field_6) or "LV Transaction ID +" (user_field_4): account symbol sedol security_name Enc. qty Loan Account LV Transactio +n ID 15140EQJP_55121 FIC UN 2330299 FAIR ISAAC CORP 1105 [NULL] ###########################################Result Set 6############### +######################## Negative tax_lots on index account (Over-encumbered??): account symbol sedol security_name quantity 28963EQJP_55441 2379 TT 6051422 REALTEK SEMICONDUCTOR CORP -37000 15140EQJP_55121 2379 TT 6051422 REALTEK SEMICONDUCTOR CORP -83379 #######################################Result Set 7################### +##################### Encmbered quantity differs from quantity on taxlot: account symbol sedol security_name quantity encumbered_quantity encumb +ered_type description No faulty encumbrances found.

Please please please help me out of this…….

Any further information you need please feel free to ask.

In reply to Please help.. by sudip_dg77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.