cycle()

Purpose

Cycle through parent's child records. This function is regarded as obsolete in 4.500 and from 4.620 is no longer included in the DP4 C library (the source is on the DP4 CD Rom if you require it for maintaining old programs.

Syntax

int cycle(child_rec, par_rec, role)

Parameters

short* child_rec

Pointer to child's L field

 

short* par_rec

Pointer to parent's L field

 

char* role

Role of parent - child index

Description

The cycle() function can be used to cycle through the children of a record. This is an old function and explicit use of the rec_fetch() function is the preferred method.

This function is implemented using the functions copy2child() and ftch2nd().

It uses the global variables firstitem and itemsdone to control its action. To use this function, set up the key fields in the parent record and set firstitem to TRUE.

Cycle will return FALSE when there are no more records to fetch (itemsdone is then set to TRUE.)

Return values

Returns TRUE if a child record has been found, otherwise FALSE

See also

reach()

Example

/*
C Functions Reference Manual
----------------------------
Filename: CYCLE.C
Example: cycle
Purpose: cycle through order header for a
customer
*/

/*
#db salesord
#c
#tables customer,
order_header;
#end
*/
#include "dp4.h"
#include "cycle.h"
/* generate this file by running LIBMAKE */
/* prototypes */
int get_customer(void);
void disp_order(void);
void process()
{
map_datamap(1);
map_datamap(2);
while (get_customer())
disp_order();
}

int get_customer()
/* get a customer from user */
{
for (;;)
{
if (askf_n(2,1,&customer.customer_number))
return FALSE;
if (rec_fetch_main(EQUAL,&customer.l))
return TRUE;
else map_remark(4);
}
}

void disp_order()
/* display orders one at a time */
{
firstitem = TRUE;
while (cycle(&order_header.l,&customer.l,"")
&& abort_code != ESCAPE)
{
map_draw(3,RETAIN);
show_l(3,1,order_header.order_number);
show_n(3,2,order_header.order_value);
show_d(3,3,&order_header.delivery_date);
jump = FALSE;
askf_special(3,4,0);
}
}
>