dc_setrelation question

This forum is for eXpress++ general support.
Message
Author
BruceN
Posts: 280
Joined: Thu Jan 28, 2010 7:46 am
Location: Slidell, LA

dc_setrelation question

#1 Post by BruceN »

I've used dc_setrelation a few times previously, always with the indexed field on parent being the link field. Like: dc_SetRelation("Calls", {||reg1->r_r_serno} )

How do I do it when the link field is NOT the indexed field?

If I have 2 files REG and CALLS, Calls is the parent and I want to look up r_name in REG based on matching calls->c_serno == reg->r_serno, but the active index in calls is c_date... what would be the proper syntax of the codeblock to do that?

thanks
There are only 10 kinds of people - those who understand binary and those who don't :)

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: dc_setrelation question

#2 Post by skiman »

Hi,

Relation only works if there is an index active with the key. Same as using a scope.

Best regards,
Chris Andries
Best regards,

Chris.
www.aboservice.be

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: dc_setrelation question

#3 Post by rdonnay »

DC_SetRelation() is basically a wrapper function that uses dbSetRelation().
This performs a seek based on the currently selected order of the relational database.
Why do you want to select a different index tag than the one needed for the seek?
The eXpress train is coming - and it has more cars.

BruceN
Posts: 280
Joined: Thu Jan 28, 2010 7:46 am
Location: Slidell, LA

Re: dc_setrelation question

#4 Post by BruceN »

What I'm trying to do is view records from CALLS sorted in date order. But I need to look up values in the related file REG (linked with c_serno == r_serno) to display on the form and/or browse grid.

I could with every navigation button (next, prev, first, last) perform a dbseek() as part of the ACTION code block. I guess I could do the same with a browse. I was hoping to have a 'slicker', more automatd method of doing it. dc_setrelation seemed to offer that solution... but I guess it won't work.

Is there a better way than my thought?

As always... grasshopper humbly learn at feet of masters.
There are only 10 kinds of people - those who understand binary and those who don't :)

User avatar
RDalzell
Posts: 205
Joined: Thu Jan 28, 2010 6:57 am
Location: Alsip, Illinois USA

Re: dc_setrelation question

#5 Post by RDalzell »

Within your DCBROWSE use a codeblock to perform information retrieval

Code: Select all

  DCBROWSECOL   DATA {|| WaiverDesc(WaiverMst->W_Code) }        HEADER ';Waiver Description'                   WIDTH 20  PARENT oBrowse
Then

Code: Select all

STATIC FUNCTION WaiverDesc(cWcode)

  nSelect := SELECT()
  SELECT CodeMst
  SET ORDER TO 1
  SEEK cWcode
  IF Eof()
    cWaiverDesc := cWcode
  ELSE
    cWaiverDesc := Trim(CodeMst->CmDesc)
  ENDIF
  SELECT (nSelect)

RETURN(cWaiverDesc)

User avatar
rdonnay
Site Admin
Posts: 4729
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: dc_setrelation question

#6 Post by rdonnay »

Sometimes "automated" just doesn't cut it and a little programming is required.

Rick Dalzell's solution looks pretty "slick" to me.
The eXpress train is coming - and it has more cars.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: dc_setrelation question

#7 Post by skiman »

Hi,

Any reason why you don't use an extra index? If the key is c_serno+dtos(date) you have your speed and within a serialnumber a sorted list by date.

I don't know if your child contains multipe records for each parent? In that case a scope would be the best solution.

I don't understand how you would perform a dbseek() if your indexkey is the date?

If the way Rick is doing it is a solution for you, you could do this in one codeblock.
{|| reg->(dbseek(calls->c_serno)),iif( reg->(eof()) , " show this" , "or this") } But of course, this way you need the key in the index, which you don't have?

Without indexkey on c_serno yu can't find your record fast. If your file is little, you can use locate, but this is working VERY slow if your file grows!
Best regards,

Chris.
www.aboservice.be

BruceN
Posts: 280
Joined: Thu Jan 28, 2010 7:46 am
Location: Slidell, LA

Re: dc_setrelation question

#8 Post by BruceN »

THanks guys.. I REALLY appreciate the suggations and help!

Chris: I don't think that would work for my stuation. I want to show records for all serial numbers sorted by date... and lookup the company name in REG for whatever the serial number in the CALLS record is. As I understand it your method would only be useful to show records for a single serial number in date order - I do that elsewhere and, in fact, that is the actual index I use for it (great minds think alike - so do ours)!

The only way I could think to do it was conceptually the same as Rick's method - but I'm sure my version of the code would not be nearly as elegant (a fancier for for slick) as his. I was hoping to find some way to 'auto-track' like a setrelation(), but I guess that idea isn't feasable.

I'm going to use Rick's code and be happy that it works!

thanks again...
There are only 10 kinds of people - those who understand binary and those who don't :)

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: dc_setrelation question

#9 Post by skiman »

Hi,

I'm rather confused about the difference between Ricks code and my codeblock. I don't see it.

However the most important is that your problem is solved.
Best regards,

Chris.
www.aboservice.be

User avatar
RDalzell
Posts: 205
Joined: Thu Jan 28, 2010 6:57 am
Location: Alsip, Illinois USA

Re: dc_setrelation question

#10 Post by RDalzell »

It's very simple Chris, yours has an accent...

Post Reply