can any one help me out . i need to extract data of certain fields which is listed in a temp-table filed ( like a ttable.f2 )
tttable.f2 ->
pt_part
pt_desc1
pt_desc2
etc
all these are presnt in filed f2 of temptable ttable sequentially
i need to extract data present in master file for all these fields
there could be any no of fields present in ttable.f2 and can be from any master table. here in this case it is pt_mstr
while searching from net i have got a code which ectracts data for the whole master table . but i require only for few fields which are listed in ttable.f2
programs accepts table name and extracts the data from all fields
/* Dynamic Query to buffer-copy records from */
/* Dynamic DB Table to Dynamic Temp-table */
define variable qry_hndl as handle no-undo.
define variable qry_hndl2 as handle no-undo.
define variable tablbuf_hndl as handle no-undo.
define variable tablbuf_hndl2 as handle no-undo.
define variable v_tablename as char format "x(10)" no-undo.
define variable v_space as char init " " no-undo.
define variable v_fldcnt as inte init "1" no-undo.
define variable i as integer no-undo.
create query qry_hndl.
create query qry_hndl2.
/* Temp-table Definition */
define variable tt_target as handle.
create temp-table tt_target.
/* Accept input DB Table */
update v_tablename.
/* Buffer for DB Table */
CREATE BUFFER tablbuf_hndl FOR TABLE v_tablename.
qry_hndl:SET-BUFFERS(tablbuf_hndl).
qry_hndl:QUERY-PREPARE("for each" + v_space + v_tablename).
qry_hndl:QUERY-OPEN().
/* Create Dynamic Temp-table like the Input table */
tt_target:CREATE-LIKE(v_tablename).
tt_target:TEMP-TABLE-PREPARE(v_tablename).
/* Buffer for Temp-Table */
tablbuf_hndl2 = tt_targetEFAULT-BUFFER-HANDLE.
/* main logic */
output to "source.prn".
mainloop:
repeat:
qry_hndl:GET-NEXT().
IF qry_hndl:QUERY-OFF-END THEN LEAVE.
DO i = 1 to tablbuf_hndl:NUM-FIELDS:
put unformatted
tablbuf_hndl:BUFFER-FIELD(i):NAME v_space + " " +
tablbuf_hndl:BUFFER-FIELD(i):BUFFER-VALUE() skip.
end.
/* Buffer-copy */
tablbuf_hndl2:BUFFER-CREATE.
tablbuf_hndl2:BUFFER-COPY(tablbuf_hndl).
leave. /* need just one record */
end. /* repeat */
output close.
/* Show records from Temp-table */
qry_hndl2:SET-BUFFERS(tablbuf_hndl2).
qry_hndl2:QUERY-PREPARE("for each" + v_space + v_tablename).
qry_hndl2:QUERY-OPEN().
i = 0.
output to "target.prn".
repeat:
qry_hndl2:GET-NEXT().
IF qry_hndl2:QUERY-OFF-END THEN LEAVE.
DO i = 1 to tablbuf_hndl2:NUM-FIELDS:
put unformatted tablbuf_hndl2:BUFFER-FIELD(i):NAME + " " +
tablbuf_hndl2:BUFFER-FIELD(i):BUFFER-VALUE() skip.
end.
leave.
end.
output close.
qry_hndl:QUERY-CLOSE().
qry_hndl2:QUERY-CLOSE().
DELETE OBJECT qry_hndl.
DELETE OBJECT qry_hndl2.
DELETE OBJECT tablbuf_hndl.
-------------------------------------------------------------------
can any one suggest me changes i should made in above code
or is there any alternate solution
tttable.f2 ->
pt_part
pt_desc1
pt_desc2
etc
all these are presnt in filed f2 of temptable ttable sequentially
i need to extract data present in master file for all these fields
there could be any no of fields present in ttable.f2 and can be from any master table. here in this case it is pt_mstr
while searching from net i have got a code which ectracts data for the whole master table . but i require only for few fields which are listed in ttable.f2
programs accepts table name and extracts the data from all fields
/* Dynamic Query to buffer-copy records from */
/* Dynamic DB Table to Dynamic Temp-table */
define variable qry_hndl as handle no-undo.
define variable qry_hndl2 as handle no-undo.
define variable tablbuf_hndl as handle no-undo.
define variable tablbuf_hndl2 as handle no-undo.
define variable v_tablename as char format "x(10)" no-undo.
define variable v_space as char init " " no-undo.
define variable v_fldcnt as inte init "1" no-undo.
define variable i as integer no-undo.
create query qry_hndl.
create query qry_hndl2.
/* Temp-table Definition */
define variable tt_target as handle.
create temp-table tt_target.
/* Accept input DB Table */
update v_tablename.
/* Buffer for DB Table */
CREATE BUFFER tablbuf_hndl FOR TABLE v_tablename.
qry_hndl:SET-BUFFERS(tablbuf_hndl).
qry_hndl:QUERY-PREPARE("for each" + v_space + v_tablename).
qry_hndl:QUERY-OPEN().
/* Create Dynamic Temp-table like the Input table */
tt_target:CREATE-LIKE(v_tablename).
tt_target:TEMP-TABLE-PREPARE(v_tablename).
/* Buffer for Temp-Table */
tablbuf_hndl2 = tt_targetEFAULT-BUFFER-HANDLE.
/* main logic */
output to "source.prn".
mainloop:
repeat:
qry_hndl:GET-NEXT().
IF qry_hndl:QUERY-OFF-END THEN LEAVE.
DO i = 1 to tablbuf_hndl:NUM-FIELDS:
put unformatted
tablbuf_hndl:BUFFER-FIELD(i):NAME v_space + " " +
tablbuf_hndl:BUFFER-FIELD(i):BUFFER-VALUE() skip.
end.
/* Buffer-copy */
tablbuf_hndl2:BUFFER-CREATE.
tablbuf_hndl2:BUFFER-COPY(tablbuf_hndl).
leave. /* need just one record */
end. /* repeat */
output close.
/* Show records from Temp-table */
qry_hndl2:SET-BUFFERS(tablbuf_hndl2).
qry_hndl2:QUERY-PREPARE("for each" + v_space + v_tablename).
qry_hndl2:QUERY-OPEN().
i = 0.
output to "target.prn".
repeat:
qry_hndl2:GET-NEXT().
IF qry_hndl2:QUERY-OFF-END THEN LEAVE.
DO i = 1 to tablbuf_hndl2:NUM-FIELDS:
put unformatted tablbuf_hndl2:BUFFER-FIELD(i):NAME + " " +
tablbuf_hndl2:BUFFER-FIELD(i):BUFFER-VALUE() skip.
end.
leave.
end.
output close.
qry_hndl:QUERY-CLOSE().
qry_hndl2:QUERY-CLOSE().
DELETE OBJECT qry_hndl.
DELETE OBJECT qry_hndl2.
DELETE OBJECT tablbuf_hndl.
-------------------------------------------------------------------
can any one suggest me changes i should made in above code
or is there any alternate solution