If you think of JDB_OpenTable or JDB_OpenView as the SELECT statement and JDB_SetSelectionX as the WHERE clause it might makes things clearer.
In your example you do not need to do a where clause such as F4201.doco == F4211.doco since you define that in your business view. So you can kind of think of JDB_OpenView as as a SELECT statment with JOIN statements. The best thing to do is turn on your debug log and review the SQL that gets generated for various JDB api combinations. However, using your example to further illustrate, lets say you want to see all order lines where the shipping branch plant matches the header branch plant (F4201.shmcu = F4211.sdmcu) OR some arbitray value say '1234', What you want is the following sql (full sales order keys ommitted in example)
select shdoco, shan8, shshan, shmcu, sdlnid, sditm
from f4201
inner join f4211 on f4201.shdoco = f4211.sddoco
where f4201.shmcu = f4211.sdmcu OR f4211.sdmcu = 1234
You would create a BV that joins F4201 to F4211 on the order keys (doco) then create the following C code:
nSelIdx = 0;
jdeNIDcpy( dsSelect[nSelIdx].Item1.szDict, NID_MCU);
jdeNIDcpy( dsSelect[nSelIdx].Item1.szTable, NID_F4201 );
dsSelect[nSelIdx].Item1.idInstance = (ID)0;
jdeNIDcpy( dsSelect[nSelIdx].Item2.szDict, NID_MCU);
jdeNIDcpy( dsSelect[nSelIdx].Item2.szTable, NID_F4211);
dsSelect[nSelIdx].Item2.idInstance = (ID)0;
dsSelect[nSelIdx].lpValue = NULL;
dsSelect[nSelIdx].nValues = 0;
dsSelect[nSelIdx].nCmp = JDEDB_CMP_EQ;
dsSelect[nSelIdx].nAndOr = JDEDB_ANDOR_AND;
dsSelect[nSelIdx++].nParen = JDEDB_PAREN_NONE;
jdeNIDcpy( dsSelect[nSelIdx].Item1.szDict, NID_MCU);
jdeNIDcpy( dsSelect[nSelIdx].Item1.szTable, NID_F4201 );
dsSelect[nSelIdx].Item1.idInstance = (ID)0;
jdeNIDcpy( dsSelect[nSelIdx].Item2.szDict, _J(""));
jdeNIDcpy( dsSelect[nSelIdx].Item2.szTable, _J(""));
dsSelect[nSelIdx].Item2.idInstance = (ID)0;
dsSelect[nSelIdx].lpValue = &mnOrderNum; // order 1234
dsSelect[nSelIdx].nValues = 1;
dsSelect[nSelIdx].nCmp = JDEDB_CMP_EQ;
dsSelect[nSelIdx].nAndOr = JDEDB_ANDOR_OR;
dsSelect[nSelIdx++].nParen = JDEDB_PAREN_NONE;
if(JDB_OpenView(hUser, ID_BV564201A, (JCHAR *)NULL, &hReq) != JDEDB_PASSED || //SELECT, JOIN clause
JDB_SetSelectionX(hReq, dsSelect, nSelIdx, JDEDB_SET_REPLACE) != JDEDB_PASSED || //WHERE clause
JDB_SelectKeyed(hReq, (ID)0, (void *)NULL, (short)0) != JDEDB_PASSED) //execute sql statment
{
//error handling code
}
while(JDB_Fetch(hReq, (void *)&dsRec, 0) == JDEDB_PASSED)
{
//loop records
}