×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Using a value if it is found in an array

Using a value if it is found in an array

Using a value if it is found in an array

(OP)
I am reading one table and creating an array that will be used many times.

The second Select returns values, if the pay-sum-grp value is found in the array I need to add the wage-amount to the variable $vGrossRG. I loop through all of the entries in this table for any match to a value in the array RG2.

The grep statement

if (grep {$_ eq $Element} @RG2) {
my $vGrossRG = ($vGrossRG + $dat9e[1]);
}
}
appears to not be working correctly.

I know I am not the expert that many of you are. Can somebody please tell me what I am am doing wrong?

CODE --> Perl

## read table LAWSON.EMPLOYEE and process each entry
use DBI;

$dbh=DBI->connect('dbi:ODBC:LawDEV', $user, $pass,
		{RaiseError => 1, odbc_cursortype => 2}) or die;

## build the current array of RG2 pay-sum-grp values
    $st9a = $dbh->prepare("SELECT PAY_SUM_GRP FROM PSGRELATE WHERE
	  		COMPANY   = '" . $vComp . "' and
			PAY_CLASS = 'RG2'") or die "select 9a: " . $db9a->errstr;

    @dat9a;
	@RG2;

    $r9a = $st9a->execute or die "Couldn't exe 9a: " . $st9a->errstr;

    while (@dat9a = $st9a->fetchrow_array()) {

        push(@RG2, $dat9a[0]);
		}

 	$st9a->finish;

	$string1 = join(", ",@RG2);

##	print $string1 . "\n";	

        	$st9e = $dbh->prepare("SELECT PAY_SUM_GRP, WAGE_AMOUNT 
				FROM PRTIME WHERE
		  		COMPANY    = '" . $vComp . "' and
		  		EMPLOYEE   = '" . $vEmp . "' and
          		CHECK_ID   = '" . $vChkId . "'") 
				or die "select 9e: " . $db9e->errstr;

        	my @dat9e;
			my $Element = $dat9e[0];
			my $vGrossRG = 0;

        	my $r9e = $st9e->execute or die "Couldn't exe 9e: " . $st9e->errstr;

        	while (@dat9e = $st9e->fetchrow_array()) {
       	        if (grep {$_ eq $Element} @RG2) {
        			my $vGrossRG = ($vGrossRG + $dat9e[1]);
					}
				}

 		    $st9e->finish;

			$Tag01 = "<GrossBaseEarnings>";
			$Tag02 = "<\/GrossBaseEarnings>";

            $sLine = $Tag01 . $vGrossRG . $Tag02 . "\n";
            print $sLine; 

RE: Using a value if it is found in an array

SQL is powerful, why not use it? Mine is rusty, but something like this should chop out most of that code:

CODE --> SQL

SELECT SUM(T.WAGE_AMOUNT)
FROM PSGRELATE R, PRTIME T
WHERE R.PAY_SUM_GRP = T.PAY_SUM_GRP
AND R.PAY_CLASS = 'RG2'
AND R.COMPANY = '$vComp'
AND T.COMPANY = '$vComp'
AND T.EMPLOYEE = '$vEmp'
AND T.CHECK_ID = '$vChkId' 

Annihilannic
tgmlify - code syntax highlighting for your tek-tips posts

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close