Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
C - EXEC WHENEVER NOT FOUND GO TO error
Old 03-21-2009, 10:21 PM C - EXEC WHENEVER NOT FOUND GO TO error
Junior Talker

Posts: 1
Name: Ali
Trades: 0
Hello all,
I am programming in C and...
I am having errors while compiling. The problem is that for some reason, the compiler is complaining that I am calling a label which is not in the function (instead is in the function above). I have been trying to de-bug this for past 4 hours, and have not had any success.

Since I have suspect about the following cursor, what is wrong with this cursor:

EXEC SQL CONNECT TO db2data;
EXEC SQL BEGIN DECLARE SECTION;
char host_someDate7[20];
sqlint32 host_total7;
EXEC SQL END DECLARE SECTION;
printf("Please enter a date (i.e. 10/15/2008)\n");
scanf("%s",&host_someDate7);
EXEC SQL DECLARE cursorfive CURSOR FOR
SELECT :host_someDate7 AS DATE, sum(PRICE) AS TOTAL
FROM (SELECT OUTGOINGORDERS.ORDERNUM, DEPT, TYPE, QUANTITY, (QUANTITY * UNITPRICE) AS PRICE FROM OUTGOINGORDERS,ORDERPRODUCTID, INVENTORYTABLE WHERE ORDERDATE = :host_someDate7 AND OUTGOINGORDERS.ORDERNUM = ORDERPRODUCTID.orderNum AND OrderProductID.PRODUCTID = INVENTORYTABLE.PRODUCTID) AS X
ORDER BY ORDERNUM;

And now I will now post the code and the compiler output.
The code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include </opt/IBM/db2/V8.1/include/sqlenv.h>
#include </opt/IBM/db2/V8.1/include/sqlcodes.h>
#include <sqlenv.h>
#include <sqlcodes.h>
#include </opt/IBM/db2/V8.1/include/sqladef.h>
#include <sys/time.h>
EXEC SQL INCLUDE SQLCA;
void salesOptions(void);
void initializer(void);
void mainMenu(void);
void initializer(void)
{
int a;
for (a=0;a<2;a++)
{
EXEC SQL CONNECT TO db2data;
EXEC SQL ALTER TABLE inventorytable ADD CONSTRAINT levelcheck CHECK (numatwarehouse >= 0);
EXEC SQL CONNECT RESET;
EXEC SQL CONNECT TO db2data;
EXEC SQL CREATE TRIGGER INVENTORY_UPDATE AFTER INSERT ON OrderProductID REFERENCING NEW ROW
AS R FOR EACH ROW UPDATE InventoryTable SET numatwarehouse=numatwarehouse-R.quantity WHERE productID=R.productID;
EXEC SQL CONNECT RESET;
}
printf("hello\n");
}
void salesOptions(void)
{
int salesChoice1;
printf( "\n\nSalesperson's Menu: \n");
printf( "1. Look up a product ID for inventory. \n");
printf( "2. Look up a customer. \n");
printf( "3. Enter a new customer. \n");
printf( "4. Book a new order. \n");
printf( "5. Delete a order. \n");
printf( "6. Check outgoing orders. \n");
printf( "7. Return to Main Menu. \n");
printf( "Please make your choice (1-7): \n");
scanf("%d",&salesChoice1);
if ( salesChoice1 == 1 )
{
EXEC SQL CONNECT TO db2data;

EXEC SQL BEGIN DECLARE SECTION;
sqlint32 host_x;
sqlint32 host_productID;
char host_dept[15];
char host_itemName[20];
sqlint32 host_unitPrice;
sqlint32 host_numAtWarehouse;
EXEC SQL END DECLARE SECTION;
printf( "Please enter a product ID: \n");
scanf("%d",&host_x);
EXEC SQL DECLARE empcsr CURSOR FOR
SELECT productID, dept, itemName, unitPrice, numAtWarehouse
FROM inventorytable
WHERE productID = :host_x;
EXEC SQL OPEN empcsr;
EXEC SQL WHENEVER NOT FOUND GO TO close_empcsr;
/* Loop indefinitely (the WHENEVER NOT FOUND statement
will cause the loop to be terminated when the end of the
table is encountered. */
do {
EXEC SQL FETCH empcsr
INTO :host_productID, :host_dept, :host_itemName, :host_unitPrice, :host_numAtWarehouse;
/* Print host_name and host_emp_number */
printf("\nProduct ID: %d\n",host_productID);
printf("Department: %s\n",host_dept);
printf("Item Name: %s\n",host_itemName);
printf("Unit Price: %d\n",host_unitPrice);
printf("Number at warehouse: %d\n",host_numAtWarehouse);
} while(1);
close_empcsr:
EXEC SQL CLOSE empcsr;
EXEC SQL CONNECT RESET;
salesOptions();
}
else if (salesChoice1 == 7)
{
mainMenu();
}

}
void totalSales(void)
{
EXEC SQL CONNECT TO db2data;
EXEC SQL BEGIN DECLARE SECTION;
char host_someDate7[20];
sqlint32 host_total7;
EXEC SQL END DECLARE SECTION;
printf("Please enter a date (i.e. 10/15/2008)\n");
scanf("%s",&host_someDate7);
EXEC SQL DECLARE cursorfive CURSOR FOR
SELECT :host_someDate7 AS DATE, sum(PRICE) AS TOTAL
FROM (SELECT OUTGOINGORDERS.ORDERNUM, DEPT, TYPE, QUANTITY, (QUANTITY * UNITPRICE) AS PRICE FROM OUTGOINGORDERS,ORDERPRODUCTID, INVENTORYTABLE WHERE ORDERDATE = :host_someDate7 AND OUTGOINGORDERS.ORDERNUM = ORDERPRODUCTID.orderNum AND OrderProductID.PRODUCTID = INVENTORYTABLE.PRODUCTID) AS X
ORDER BY ORDERNUM;

EXEC SQL OPEN cursorfive;
EXEC SQL WHENEVER NOT FOUND GO TO close_cursorfive;
do {
EXEC SQL FETCH cursorfive
INTO :host_someDate7, :host_total7;

/* Print host_name and host_emp_number */
printf("\nDate: %s\n",host_someDate7);
printf("Total: %s\n",host_total7);
} while(1);

close_cursorfive:
EXEC SQL CLOSE cursorfive;
EXEC SQL CONNECT RESET;
}
void accountantOptions(void)
{
int theChoice2;

printf("\n\nAccountant's Menu:\n");
printf("1. Total sales for some date.\n");
printf("2. Detailed daily report.\n");
printf("3. Detailed report for a period.\n");
printf("4. Main Menu.\n");
printf("Please make your choice (1-4):\n");
scanf("%d",&theChoice2);
if (theChoice2 == 1 )
{
//totalSales();

}
else if (theChoice2 == 2 )
{
//viewFinancialReport();
printf("hello\n");
}
else if (theChoice2 == 3 )
{
//financialReportPeriod();
printf("yello\n");
}
else if (theChoice2 == 4 )
{
mainMenu();
}
}
int exitProgram(void)
{
exit(0);
}
void mainMenu(void)
{
int theChoice;
top:
printf("\n\nMain Menu:\n");
printf("1. Salesperson's options.\n");
printf("2. Accountant's options.\n");
printf("3. Vice President's options.\n");
printf("4. Clerk's options.\n");
printf("5. Order Dispatcher/Receiver's options.\n");
printf("6. Database Administrator's options.\n");
printf("7. EXIT\n");
printf("Please make your choice (1-7):");
scanf("%d",&theChoice);
if (theChoice == 1)
{
salesOptions();
}
else if (theChoice == 2)
{
accountantOptions();
}
else if (theChoice == 7)
{
exitProgram();
}
else
{
goto top;
}
}
int main(void)
{
initializer();
mainMenu();
}
The compiler output:
Compiling test2 executable\c
.\c
.\c
.\c
test2.sqc: In function `totalSales':
test2.sqc:113: error: label `close_empcsr' used but not defined
.\c
.\c
m23khan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-22-2009, 03:02 AM Re: C - EXEC WHENEVER NOT FOUND GO TO error
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
The problem is that for some reason, the compiler is complaining that I am calling a label which is not in the function (instead is in the function above)
It's a scoping problem. Anything defined inside a function only exist within that function. They are not available to the main routine or other functions.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to C - EXEC WHENEVER NOT FOUND GO TO error
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.34054 seconds with 12 queries