Extract value from construct variable
Posted in 2009
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
SE 7.25.UC6R1 C4GL 7.32.UC4 I'm looking for a way to extract a value from a 4GL construct variable. Is using substrings the only way to do this? define lv_s1, lv_s2 char(1024) construct lv_s1 on item.tran_dt, customer.stmt_cycle from sr.* let lv_s2 = lv_s1[51,1024] What I want to extract is the part of the construct after "customer.stmt_cycle" which could be "=value", "<>values", "in (value1,value2)" etc... I'm going to then use those values in another select statement unrelated to the one that this construct is used for. This new select does not use the columns listed in the construct, but the values the user enters into the form for customer.stmt_cycle are the same values that i want to use in the second select. Problem is I'm making an assumption of the position of the substrings, there must be a better way to do this.
> -----Original Message----- > From: informix-list-bounces@iiug.org [mailto:informix-list-bounces@iiug.org] > On Behalf Of loc > Sent: Thursday, August 13, 2009 2:11 PM > To: informix-list@iiug.org > Subject: Extract value from construct variable > > SE 7.25.UC6R1 > C4GL 7.32.UC4 > > I'm looking for a way to extract a value from a 4GL construct > variable. Is using substrings the only way to do this? > > define lv_s1, lv_s2 char(1024) > > construct lv_s1 > on item.tran_dt, > customer.stmt_cycle > from sr.* > > let lv_s2 = lv_s1[51,1024] > Try this: construct lv_s1 on item.tran_dt, customer.stmt_cycle from sr.* after field stmt_cycle let my_variable = GET_FLDBUF(stmt_cycle) end construct --EEM > What I want to extract is the part of the construct after > "customer.stmt_cycle" which could be "=value", "<>values", "in > (value1,value2)" etc... I'm going to then use those values in another > select statement unrelated to the one that this construct is used > for. This new select does not use the columns listed in the > construct, but the values the user enters into the form for > customer.stmt_cycle are the same values that i want to use in the > second select. Problem is I'm making an assumption of the position of > the substrings, there must be a better way to do this. > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list
On 13 Aug, 20:11, loc <c320...@gmail.com> wrote: > SE 7.25.UC6R1 > C4GL 7.32.UC4 > > I'm looking for a way to extract a value from a 4GL construct > variable. Is using substrings the only way to do this? > > define lv_s1, lv_s2 char(1024) > > construct lv_s1 > on item.tran_dt, > customer.stmt_cycle > from sr.* > > let lv_s2 = lv_s1[51,1024] > > What I want to extract is the part of the construct after > "customer.stmt_cycle" which could be "=value", "<>values", "in > (value1,value2)" etc... I'm going to then use those values in another > select statement unrelated to the one that this construct is used > for. This new select does not use the columns listed in the > construct, but the values the user enters into the form for > customer.stmt_cycle are the same values that i want to use in the > second select. Problem is I'm making an assumption of the position of > the substrings, there must be a better way to do this. You could use AFTER CONSTRUCT and GET_FLDBUF as per the 4gl reference manual to get the contents of the field. if you want the part of the predicate in the where clause then you will have to parse the generated select statement.
Everett Mills <Everett.Mills@nationalbeef.com> wrote: > > >> -----Original Message----- >> From: informix-list-bounces@iiug.org > [mailto:informix-list-bounces@iiug.org] >> On Behalf Of loc >> Sent: Thursday, August 13, 2009 2:11 PM >> To: informix-list@iiug.org >> Subject: Extract value from construct variable >> >> SE 7.25.UC6R1 >> C4GL 7.32.UC4 >> >> I'm looking for a way to extract a value from a 4GL construct >> variable. Is using substrings the only way to do this? >> >> define lv_s1, lv_s2 char(1024) >> >> construct lv_s1 >> on item.tran_dt, >> customer.stmt_cycle >> from sr.* >> >> let lv_s2 = lv_s1[51,1024] >> > Try this: > > > construct lv_s1 on item.tran_dt, customer.stmt_cycle from sr.* > > after field stmt_cycle > let my_variable = GET_FLDBUF(stmt_cycle) > > end construct > > --EEM I should have mentioned that I thought about using get_fldbuf() but the problem with that is what if the user types in something like value1|value2, !=value, etc... get_fldbuf() returns a character string which will include the operators used. > >> What I want to extract is the part of the construct after >> "customer.stmt_cycle" which could be "=value", "<>values", "in >> (value1,value2)" etc... I'm going to then use those values in another >> select statement unrelated to the one that this construct is used >> for. This new select does not use the columns listed in the >> construct, but the values the user enters into the form for >> customer.stmt_cycle are the same values that i want to use in the >> second select. Problem is I'm making an assumption of the position of >> the substrings, there must be a better way to do this. >> _______________________________________________ >> Informix-list mailing list >> Informix-list@iiug.org >> http://www.iiug.org/mailman/listinfo/informix-list
Not that it helps - but you can do this sort of thing in Aubit4GL using CONSTRUCT callbacks. The idea is that the callback function is called for each field - and you return the value to use for the constructs generated string.. Heres an example from our regression tests to give you the idea... main define a record a char(10), b char(20) end record define lv_str char(200) open window w1 at 1,1 with form "f1" # Here - we want to use a callback function in the # construct to allow us to amend the CONSTRUCT string # before the construct returns it. # # This can be used (for example) to automatically add # '*' around the string, or to search an address # (by doing something like '( addr1 MATCHES .. OR addr2 MATCHES ...)' etc etc # construct lv_str on a,b from a,b via c_callback display lv_str end main function c_callback(lv_tabname, lv_colname, lv_string,lv_dtype, lv_dtypelength) define lv_tabname char(18) define lv_colname char(18) define lv_string char(300) define lv_dtype,lv_dtypelength integer # you return with no values - the construct will complain with an error in field... if lv_colname="a" and lv_string="456" then return end if # Normally - we'd want to generate the construct portion - but with maybe different column names # In this callback we want to map 'a' to be 'blah'... # if lv_colname="a" then # aclfgl_get_construct_element takes 5 parameters # tablename, column name, search string, datatype and datatype length(eg for decimal or character length) let lv_string=aclfgl_get_construct_element(lv_tabname , "blah", lv_string , lv_dtype, lv_dtypelength) else let lv_string=aclfgl_get_construct_element(lv_tabname , lv_colname , lv_string , lv_dtype, lv_dtypelength) end if return lv_string end function 2009/8/13 loc <c320sky@gmail.com> > Everett Mills <Everett.Mills@nationalbeef.com> wrote: > > > > > >> -----Original Message----- > >> From: informix-list-bounces@iiug.org > > [mailto:informix-list-bounces@iiug.org] > >> On Behalf Of loc > >> Sent: Thursday, August 13, 2009 2:11 PM > >> To: informix-list@iiug.org > >> Subject: Extract value from construct variable > >> > >> SE 7.25.UC6R1 > >> C4GL 7.32.UC4 > >> > >> I'm looking for a way to extract a value from a 4GL construct > >> variable. Is using substrings the only way to do this? > >> > >> define lv_s1, lv_s2 char(1024) > >> > >> construct lv_s1 > >> on item.tran_dt, > >> customer.stmt_cycle > >> from sr.* > >> > >> let lv_s2 = lv_s1[51,1024] > >> > > Try this: > > > > > > construct lv_s1 on item.tran_dt, customer.stmt_cycle from sr.* > > > > after field stmt_cycle > > let my_variable = GET_FLDBUF(stmt_cycle) > > > > end construct > > > > --EEM > > I should have mentioned that I thought about using get_fldbuf() but the > problem with that is what if the user types in something like > value1|value2, !=value, etc... get_fldbuf() returns a character string > which will include the operators used. > > > > > >> What I want to extract is the part of the construct after > >> "customer.stmt_cycle" which could be "=value", "<>values", "in > >> (value1,value2)" etc... I'm going to then use those values in another > >> select statement unrelated to the one that this construct is used > >> for. This new select does not use the columns listed in the > >> construct, but the values the user enters into the form for > >> customer.stmt_cycle are the same values that i want to use in the > >> second select. Problem is I'm making an assumption of the position of > >> the substrings, there must be a better way to do this. > >> _______________________________________________ > >> Informix-list mailing list > >> Informix-list@iiug.org > >> http://www.iiug.org/mailman/listinfo/informix-list > _______________________________________________ > Informix-list mailing list > Informix-list@iiug.org > http://www.iiug.org/mailman/listinfo/informix-list >