if and else starement and Pro*c
Im new to C and im having some problem filtering out the data.
The scenario as below..
Code:
#Date range 20110225 0600 - 20110225 0700
Revision 1
Action randomize
Lot AUP05078.1
Operation Pst-PSD-Imp-RsStrp-Random.0
Suboperation GA_PSDImRS
actualqty 25
equipment D1HNNT01
device ARODINA-AU1B
technology C16
Date 20110225 064924000
Employee som
%wafer orig_slot orig_cass in_house_scribe vendor_scribe final_slot final_cass
wafer 5 6594 AUP05078.1. UXJZ3031SHC1 24 6594
wafer 18 6594 AUP05078.1.18 UXJZ3035SHE3 3 6594
wafer 12 6594 AUP05078.1.25 UXJZ3036SHB2 6 6594
wafer 19 6594 AUP05078.1. UXJZ3117SHD0 12 6594
wafer 8 6594 AUP05078.1.9 UXJZ3197SHC1 5 6594
wafer 16 6594 AUP05078.1.13 UXJZ3202SHF7 9 6594
wafer 20 6594 AUP05078.1.16 UXJZ3203SHC6 10 6594
wafer 9 6594 AUP05078.1.15 UXJZ3204SHH0 11 6594
wafer 23 6594 AUP05078.1.20 UXJZ3205SHD7 18 6594
wafer 25 6594 AUP05078.1.21 UXJZ3206SHA6 8 6594
wafer 21 6594 AUP05078.1.19 UXJZ3207SHF0 19 6594
wafer 2 6594 AUP05078.1.14 UXJZ3208SHB7 22 6594
wafer 24 6594 AUP05078.1.17 UXJZ3209SHG1 15 6594
wafer 14 6594 AUP05078.1.12 UXJZ3210SHB7 16 6594
wafer 4 6594 AUP05078.1.11 UXJZ3211SHG1 23 6594
wafer 17 6594 AUP05078.1. UXJZ3213SHH2 2 6594
wafer 10 6594 AUP05078.1.10 UXJZ3216SHF2 7 6594
wafer 11 6594 AUP05078.1. UXJZ3264SHE4 14 6594
wafer 15 6594 AUP05078.1.8 UXJZ3265SHB3 13 6594
wafer 3 6594 AUP05078.1.7 UXJZ3267SHC4 17 6594
wafer 6 6594 AUP05078.1.1 UXJZ3268SHG6 20 6594
wafer 7 6594 AUP05078.1. UXJZ3271SHD5 1 6594
wafer 13 6594 AUP05078.1.24 UXJZ3281SHA6 4 6594
wafer 1 6594 AUP05078.1.22 UXJZ3282SHF0 25 6594
wafer 22 6594 AUP05078.1.23 UXJZ3283SHB7 21 6594
My code should filter out if its find this null value and write the entire file in different directory.
Attach is my code:
Code:
/************************************************************
* Function: Generate_SA_Report(char* startDate, -- Beginning of date range
* char* endDate, -- End of date range
* struct parameters*) -- Structure holding configurable parameters
*
* Purpose: Get lot data those were performed Inline Sorter Action
* in the specified period
* 1. Get lot list with 'TrackIn' / 'Reposition' transaction;
* 2. Filter lot by Recipe value to get list with Sorter Actions;
* 3. Loop:
* 3.1 Get lot info those will be written in header part
* 3.2 Get slot-map information
* 3.2.1 Before transaction
* 3.2.2 After transaction
* 3.3 write data into file
*
* Returns: The number of files created.
*
************************************************************/
int Generate_SA_Report(
char* startDate,
char* endDate,
struct parameters* parms)
{
/***************************************************
* Preparation
***************************************************/
/* Variable declaration */
int skipLotCntr = 0;
int numOfFiles = 0;
int compQty = 0;
int indexOfComp = 0;
int indexOfCarHistRecord = 0;
vc2_LotSK lot_sk;
vc2_TxnSK txn_sk;
vc2_Operation action;
vc2_LotId lot;
vc2_StepId stepId;
vc2_StepId sorterAction;
vc2_Stage stage;
vc2_Recipe recipe;
vc2_Operation operation;
vc2_Operation subOperation;
vc2_WaferQty qtyIn;
vc2_WaferQty qtyOut;
vc2_WaferQty actualQty;
vc2_EqpId eqpId;
vc2_Device device;
vc2_Technology tech;
vc2_DateTime toTime;
vc2_DateTime tiTime;
vc2_DateTime createTime;
vc2_UserId employee;
vc2_CarrierId carrierId;
vc2_LotId finalLotId;
vc2_GroupHistKey groupHistKey;
vc2_PlanId planId;
vc2_SlotPosition slot;
vc2_CarrierId origCass;
vc2_VScriberId inHouseScribe;
vc2_VScriberId vendorScribe;
vc2_VScriberId POSITION;
vc2_CarrierId finalCass;
vc2_SlotPosition origSlotArray[MAX_WAFERQTY_PER_LOT];
vc2_CarrierId origCassArray[MAX_WAFERQTY_PER_LOT];
vc2_VScriberId inHouseScribeArray[MAX_WAFERQTY_PER_LOT];
vc2_VScriberId vendorScribeArray[MAX_WAFERQTY_PER_LOT];
vc2_VScriberId POSITIONArray[MAX_WAFERQTY_PER_LOT];
vc2_SlotPosition finalSlotArray[MAX_WAFERQTY_PER_LOT];
vc2_CarrierId finalCassArray[MAX_WAFERQTY_PER_LOT];
vc2_VScriberId scribeId;
vc2_SysId carHistSysId;
vc2_SysId carHistTxnTime;
vc2_SysId carHistSysIdArray[MAX_CARHISTRECORD_NUM];
vc2_SysId carHistTxnTimeArray[MAX_CARHISTRECORD_NUM];
int finalFlag = FALSE;
char currDateTime[20];
char* pTmp = NULL;
/* Reset memory */
memset(scribeId, 0, sizeof(scribeId));
memset(currDateTime, 0, sizeof(currDateTime));
memset(carHistSysId, 0, sizeof(carHistSysId));
memset(carHistTxnTime, 0, sizeof(carHistTxnTime));
memset(carHistSysIdArray, 0, sizeof(carHistSysIdArray));
memset(carHistTxnTimeArray, 0, sizeof(carHistTxnTimeArray));
#ifdef DEBUG
printf("%s: Start to retrieve Sorter Action Information\n", GetCurrDateTime(currDateTime));
printf(" Start Date [%s] ~ End Date [%s]\n", startDate, endDate);
#endif
/***************************************************
* Query data
***************************************************/
/* Get 'Sorter Action' lot (lot_sk, txn_sk) list */
EXEC SQL DECLARE wsSaCursor CURSOR FOR
SELECT wip.lot_sk, wip.txn_sk
FROM hdbxuser.fwhdbwipstephistory@hdbsil sh,
hdbxuser.fwhdbwiptransaction@hdbsil wip
WHERE wip.wipstep_sk = sh.wipstep_sk
AND wip.activity = 'TrackIn'
AND wip.txntime = sh.trackintime
AND sh.trackouttime BETWEEN :startDate AND :endDate;
/* Open cursor */
EXEC SQL OPEN wsSaCursor;
/* Loop, fetching all salesperson's statistics.
* Cause the program to break the loop when no more
* data can be retrieved on the cursor.
*/
EXEC SQL WHENEVER NOT FOUND DO break;
for( ; ;)
{
/* Reset memory */
memset(lot_sk, NULL, sizeof(lot_sk));
memset(txn_sk, NULL, sizeof(txn_sk));
memset(action, NULL, sizeof(action));
memset(lot, NULL, sizeof(lot));
memset(stepId, NULL, sizeof(stepId));
memset(sorterAction, NULL, sizeof(sorterAction));
memset(stage, NULL, sizeof(stage));
memset(recipe, NULL, sizeof(recipe));
memset(operation, NULL, sizeof(operation));
memset(subOperation, NULL, sizeof(subOperation));
memset(qtyIn, NULL, sizeof(qtyIn));
memset(qtyOut, NULL, sizeof(qtyOut));
memset(actualQty, NULL, sizeof(actualQty));
memset(eqpId, NULL, sizeof(eqpId));
memset(device, NULL, sizeof(device));
memset(tech, NULL, sizeof(tech));
memset(toTime, NULL, sizeof(toTime));
memset(tiTime, NULL, sizeof(tiTime));
memset(createTime, NULL, sizeof(createTime));
memset(employee, NULL, sizeof(employee));
memset(carrierId, NULL, sizeof(carrierId));
memset(finalLotId, NULL, sizeof(finalLotId));
memset(groupHistKey, NULL, sizeof(groupHistKey));
memset(planId, NULL, sizeof(planId));
memset(origSlotArray, NULL, sizeof(origSlotArray));
memset(origCassArray, NULL, sizeof(origCassArray));
memset(inHouseScribeArray, NULL, sizeof(inHouseScribeArray));
memset(POSITIONArray,NULL,sizeof(POSITIONArray));
memset(vendorScribeArray, NULL, sizeof(vendorScribeArray));
memset(finalSlotArray, NULL, sizeof(finalSlotArray));
memset(finalCassArray, NULL, sizeof(finalCassArray));
/* Get txn_sk */
EXEC SQL FETCH wsSaCursor INTO :lot_sk, :txn_sk;
/* Skip it if no data found */
EXEC SQL WHENEVER NOT FOUND GOTO NOTFOUND;
/* To check whether the lot perform 'Sorter Action' or not */
EXEC SQL SELECT LOWER (recipe), transportid, stage, device
INTO :recipe, :carrierId, :stage, :device
FROM (SELECT lotrecipe.attrvalue recipe,
lottransportid.attrvalue transportid, lotstage.attrvalue stage,
lotdevice.attrvalue device
FROM hdbxuser.fwhdbwiplotattrinstance@hdbsil lotrecipe,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lotstage,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lottransportid,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lotdevice
WHERE lotrecipe.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotrecipe.startsequence AND lotrecipe.stopsequence
AND lotrecipe.attrname = 'Recipe'
AND ( LOWER (lotrecipe.attrvalue) LIKE '%verify%'
OR (LOWER (lotrecipe.attrvalue) LIKE '%random%')
OR (LOWER (lotrecipe.attrvalue) LIKE '%reorder%')
)
AND lotstage.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotstage.startsequence AND lotstage.stopsequence
AND lotstage.attrname = 'Stage'
AND lottransportid.lot_sk = :lot_sk
AND :txn_sk BETWEEN lottransportid.startsequence
AND lottransportid.stopsequence
AND lottransportid.attrname = 'transportId'
AND lotdevice.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotdevice.startsequence AND lotdevice.stopsequence
AND lotdevice.attrname = 'partProgId'
UNION ALL
SELECT lotsorteraction.attrvalue recipe,
lottransportid.attrvalue transportid, lotstage.attrvalue stage,
lotdevice.attrvalue device
FROM hdbxuser.fwhdbwiplotattrinstance@hdbsil lotsorteraction,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lotstage,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lottransportid,
hdbxuser.fwhdbwiplotattrinstance@hdbsil lotdevice
WHERE lotsorteraction.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotsorteraction.startsequence
AND lotsorteraction.stopsequence
AND lotsorteraction.attrname = 'SorterAction'
AND lotsorteraction.attrvalue IN ('REORDER', 'VERIFY')
AND lotstage.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotstage.startsequence AND lotstage.stopsequence
AND lotstage.attrname = 'Stage'
AND lottransportid.lot_sk = :lot_sk
AND :txn_sk BETWEEN lottransportid.startsequence
AND lottransportid.stopsequence
AND lottransportid.attrname = 'transportId'
AND lotdevice.lot_sk = :lot_sk
AND :txn_sk BETWEEN lotdevice.startsequence AND lotdevice.stopsequence
AND lotdevice.attrname = 'partProgId');
/* Get lot detail information */
EXEC SQL SELECT wipin.lotid, wipout.userid, wipin.txntime, wipin.lotqtyout,
wipout.txntime totime, wipout.lotid finallotid, wipin.grouphistkey,
sh.LOCATION, sh.stepid, sh.planid, sh.productname tech,
lot.createtxntime
INTO :lot, :employee, :tiTime, :actualQty, :toTime, :finalLotId, :groupHistKey,
:eqpId, :stepId, :planId, :tech, :createTime
FROM hdbxuser.fwhdblot@hdbsil lot,
hdbxuser.fwhdbwipstephistory@hdbsil sh,
hdbxuser.fwhdbwiptransaction@hdbsil wipout,
hdbxuser.fwhdbwiptransaction@hdbsil wipin
WHERE lot.lot_sk = wipin.lot_sk
AND wipout.grouphistkey = wipin.grouphistkey
AND wipout.activity = 'TrackOut'
AND sh.wipstep_sk = wipout.wipstep_sk
AND wipin.txn_sk = :txn_sk;
/* Get component Id list */
EXEC SQL DECLARE comp_Cursor CURSOR FOR
SELECT lot.lotid || '.' || comp.POSITION inhousescribe,
comp.componentid vendorscribe,
comp.POSITION
FROM hdbxuser.fwhdblot@hdbsil lot,
hdbxuser.fwhdbwipcomponent@hdbsil comp
WHERE lot.lot_sk = comp.originallot_sk
AND comp.lot_sk = :lot_sk
AND :txn_sk BETWEEN startsequence AND stopsequence
AND comp.status <> 'Scrapped'
ORDER BY comp.componentid;
EXEC SQL OPEN comp_Cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
indexOfComp = 0;
for(; ;)
{
memset(inHouseScribe, NULL, sizeof(inHouseScribe));
memset(vendorScribe, NULL, sizeof(vendorScribe));
memset (POSITION,NULL,sizeof (POSITION));
EXEC SQL FETCH comp_Cursor INTO :inHouseScribe, :vendorScribe, :POSITION;
strcpy(inHouseScribeArray[indexOfComp], inHouseScribe);
strcpy(vendorScribeArray[indexOfComp], vendorScribe);
strcpy (POSITIONArray[indexOfComp],POSITION);
indexOfComp++;
}
compQty = indexOfComp;
EXEC SQL CLOSE comp_Cursor;
/*
* The following is to retrieve component Id slot-map
* information: orignal -- final position
*
* 1. Get SysId/TxnTime list from FwCarrierHistory in desc order;
* Time range: create time ~ to time
* SysId list is stored in an array that size is 10.
* 2. Loop: wafer by wafer
* 2.1 Get final position (FwCarrierHistory_PN2M)
* 2.1.1 Make sure TxnTime is between TiTime and ToTime
* 2.1.2 Get final position by using the lastest sysId
* 2.2 Get original position by using the latest SysId;
* 2.2.1 Make sure TxnTime is earlier TiTime.
* If not, skip to previous record (SysId);
* 2.2.2 Get original position by using SysId. If not found,
* skip to previous record (SysId)
*/
/* VERY IMPORTANT */
/* Minus 1 min (60 seconds) to create time */
/* We may fail to get data if using create time in some cases
* because CARRIER transaction is done eariler than WIP.
* For example, one child is created (split) in '20090806 152152000',
* but the Assign Component happen in 20090806 152151000
*/
AddSeconds( createTime, -60 );
/* Get SysId/TxnTime list from FwCarrierHistory */
EXEC SQL DECLARE carhist_Cursor CURSOR FOR
SELECT sysid, txntime
FROM caruser.fwcarrierhistory
WHERE carrierid = :carrierId
AND activity IN
('FwCarrierAssignComponentTxn',
'FwCarrierModifyComponentPositionTxn',
'ReAssociateTo'
)
AND txntime BETWEEN :createTime AND :toTime
ORDER BY txntime DESC;
EXEC SQL OPEN carhist_Cursor;
EXEC SQL WHENEVER NOT FOUND DO break;
memset(carHistSysIdArray, 0, sizeof(carHistSysIdArray));
memset(carHistTxnTimeArray, 0, sizeof(carHistTxnTimeArray));
for(indexOfCarHistRecord = 0; indexOfCarHistRecord < MAX_CARHISTRECORD_NUM; indexOfCarHistRecord++)
{
memset(carHistSysId, 0, sizeof(carHistSysId));
memset(carHistTxnTime, 0, sizeof(carHistTxnTime));
EXEC SQL FETCH carhist_Cursor INTO :carHistSysId, :carHistTxnTime;
strcpy(carHistSysIdArray[indexOfCarHistRecord], carHistSysId);
strcpy(carHistTxnTimeArray[indexOfCarHistRecord], carHistTxnTime);
}
EXEC SQL CLOSE carhist_Cursor;
/* To get final & original position for each wafer */
for (indexOfComp = 0; indexOfComp < compQty; indexOfComp++)
{
finalFlag = FALSE;
memset(scribeId, NULL, sizeof(scribeId));
strcpy(scribeId, vendorScribeArray[indexOfComp]);
/* Loop: to find original-final slot position */
for(indexOfCarHistRecord = 0; indexOfCarHistRecord < MAX_CARHISTRECORD_NUM; indexOfCarHistRecord++)
{
memset(slot, NULL, sizeof(slot));
memset(carHistSysId, 0, sizeof(carHistSysId));
strcpy(carHistSysId, carHistSysIdArray[indexOfCarHistRecord]);
EXEC SQL WHENEVER NOT FOUND CONTINUE;
EXEC SQL SELECT valdata slot
INTO :slot
FROM caruser.fwcarrierhistory_pn2m
WHERE fromid = :carHistSysId AND linkname = 'components'
AND keydata = :scribeId;
if (strlen(slot) > 0)
{
if (strcmp(carHistTxnTimeArray[indexOfCarHistRecord], tiTime) > 0)
{
/* Finalflag is to make sure to get the correst slot position (latest).
* To handle abnormal case: namely that there are multiple slot
* mapping changes during the period of Track-In and Track-Out.
*/
if (finalFlag == FALSE)
{
/* Final position */
strcpy(finalSlotArray[indexOfComp], slot);
strcpy(finalCassArray[indexOfComp], carrierId);
finalFlag = TRUE;
}
}
else
{
/* Original position */
strcpy(origSlotArray[indexOfComp], slot);
strcpy(origCassArray[indexOfComp], carrierId);
/* If final position value is NULL, it is assumed that
* the slot position does not change, same as original one */
if (strlen(finalSlotArray[indexOfComp]) == 0)
{
strcpy(finalSlotArray[indexOfComp], slot);
strcpy(finalCassArray[indexOfComp], carrierId);
}
break;
}
}
}
}
/* Assign value to 'action', 'operation', 'suboperation' */
if (strstr(recipe, "random"))
{
strcpy(action, OPERATION_RANDOMIZE);
strcpy(operation, stepId);
/* Strip out XX stage stuff/sortorder in stage name */
pTmp = strchr(stage, ':');
if (pTmp != NULL)
strcpy(subOperation, Trim_End(++pTmp));
else
strcpy(subOperation, stage);
}
else if (strstr(recipe, "reorder"))
{
strcpy(action, OPERATION_REORDER);
strcpy(operation, "reorder");
strcpy(subOperation, "reorder");
}
else if (strstr(recipe, "verify"))
{
/*
if (strstr(stepId, "SorterAction"))
{
strcpy(action, OPERATION_VERIFY);
}
else
{
strcpy(action, OPERATION_INLINEVERIFY);
}
*/
strcpy(action, OPERATION_VERIFY);
strcpy(operation, "verify");
strcpy(subOperation, "verify");
}
else
{
strcpy(action, recipe);
strcpy(operation, recipe);
strcpy(subOperation, recipe);
}
#ifdef DEBUG
printf("indexOfComp=%d, compQty=%d\n", indexOfComp, compQty);
printf("inHouseScribeArray[indexOfComp]='%s' length=%d\n",inHouseScribeArray[indexOfComp],strlen(inHouseScribeArray[indexOfComp]));
printforigSlotArray[indexOfComp]='%s' length=%dorigSlotArray[indexOfComp],strlenorigSlotArray[indexOfComp]));
#endif
if ((strlen(inHouseScribeArray[indexOfComp]) > 0) && (strlen(origSlotArray[indexOfComp]) > 0) && (strlen(origCassArray[indexOfComp]) > 0)&& (strlen(finalCassArray[indexOfComp]) >0)
&& (strlen(vendorScribeArray[indexOfComp])> 0) && (strlen(finalSlotArray[indexOfComp]) > 0 )&& (strlen(POSITIONArray [indexOfComp]) > 0))
{
Write_SA_DataFile(startDate, endDate, action, lot, operation, subOperation,
actualQty, eqpId, device, tech, toTime, employee, origSlotArray,
origCassArray, inHouseScribeArray, vendorScribeArray, finalSlotArray,
finalCassArray, parms);
}
else
{
Write_PR_DataFile(startDate, endDate, action, lot, operation, subOperation,
actualQty, eqpId, device, tech, toTime, employee, origSlotArray,
origCassArray, inHouseScribeArray, vendorScribeArray, finalSlotArray,
finalCassArray, parms);
}
numOfFiles++;
#ifdef DEBUG
printf(" #%d lot data is extracted\n", numOfFiles);
#endif
continue;
NOTFOUND:
skipLotCntr++;
#ifdef DEBUG
printf(" #%d lot is skipped\n", skipLotCntr);
#endif
;
}
/* Close cursor */
EXEC SQL CLOSE wsSaCursor;
#ifdef DEBUG
printf(" %d 'Sorter Action' data files are created successfully\n", numOfFiles);
printf("%s: Complete retrieving 'Sorter Action' Information\n", GetCurrDateTime(currDateTime));
#endif
return(numOfFiles);
} /* Generate_SA_Report */
Kindly help how i can able to filter out the data if one of the com.position is NULL write the entire output to the different log file,,Im using unix environement to run the code and need help..