Dynamic_columns

anonymous

New Member
Hi all,

I want to generate dynamic columns based on the user input. i am trying to display a header with 'n' fields, the number of times the user wants it to be displayed. The first temp table has static fields, and the second is a dynamic temp table with a header containing 'n' fields. this dynamic temp table has to be repeated , the number of times the user chooses.

If my approach to this issue is correct please help me in arriving at the solution, if it is not, please suggest a better approach.

Any response will be highly appreciated.

Thanks,
Sarah.


DEFINE VARIABLE cReadField AS CHARACTER format "x(15)" EXTENT 3 NO-UNDO.
DEFINE VARIABLE ttTable AS HANDLE NO-UNDO.
DEFINE VARIABLE bttTable AS HANDLE NO-UNDO.
DEFINE VARIABLE qttTable AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE iNumTimes AS INTEGER NO-UNDO.
DEFINE VARIABLE iTmp AS INTEGER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE iNumFields AS INTEGER NO-UNDO.
DEFINE VARIABLE li_i AS INTEGER NO-UNDO.
DEFINE TEMP-TABLE t1
Field t1_item like pt_part
Field t1_type like pt_part_type
Field t1_desc1 like pt_desc1.
DEFINE FRAME frm_a WITH SIDE-LABELS CENTERED
WIDTH 80.
DEFINE FRAME frm_b WITH NO-LABELS WIDTH 120.
DEFINE FRAME frm_e WITH NO-LABELS WIDTH 70.
FORM
iNumTimes label "Enter the number of times u want the columns to repeat"
With frame frm_a.
FORM
t1_item label "Item" space(1)
t1_type label "Type" space(1)
t1_desc1 label "Desc" with frame frm_e row 5.
FORM HEADER
"Site" SPACE(10)
"Desc" SPACE(10)
"Status" label "Item Desc" with frame frm_b column 55 row 5.

ASSIGN iNumFields = 3.

Update iNumTimes with frame frm_a.

{mfselprt.i "printer" 80}


for each pt_mstr where pt_part = "0.001.3701.0"
no-lock:
CREATE t1.
ASSIGN t1_item = pt_part
t1_type = pt_part_type
t1_desc1 = pt_desc1.
END.

DO li_i = 1 to iNumTimes:
for each si_mstr where si_site = "babd" no-lock:
ASSIGN
cReadField[1] = si_site
cReadField[2] = si_desc
cReadField[3] = si_status.

CREATE TEMP-TABLE ttTable.
DO iTmp = 1 TO iNumFields:
ttTable:ADD-NEW-FIELD(cReadField[iTMP],"CHARACTER").
END.

/* put here as much entries is needed to cover all the fields */

ttTable:TEMP-TABLE-PREPARE("ResultSet").
bttTable = ttTable:DEFAULT-BUFFER-HANDLE.
END.

END.

bttTable:BUFFER-CREATE().
FOR EACH si_mstr no-lock:
ASSIGN
cReadField[1] = si_site
cReadField[2] = si_desc
cReadField[3] = si_status.
DO iTmp = 1 TO iNumFields:
bttTable:BUFFER-FIELD(iTmp):BUFFER-VALUE = cReadField[iTmp].
END.

END.
/* Here I want to display the temp-table */
for each t1 no-lock:
display t1 with frame frm_e ROW 5.
end.
DO li_i = 1 TO iNumTimes:
CREATE QUERY qttTable.
qttTable:SET-BUFFERS(bttTable).
qttTable:QUERY-PREPARE("for each " + ttTable:NAME).
qttTable:QUERY-OPEN().
hBuffer = qttTable:GET-BUFFER-HANDLE(1).
qttTable:GET-FIRST().
DO WHILE NOT qttTable:QUERY-OFF-END:
DO iTmp = 1 TO hBuffer:NUM-FIELDS:
Display cReadField[1] cReadField[2] cReadField[3] with frame frm_b.
/*DISPLAY hBuffer:BUFFER-FIELD(iTmp):BUFFER-VALUE with frame frm_b.*/
END.
qttTable:GET-NEXT().
END.
DELETE OBJECT qttTable.
DELETE OBJECT ttTable.
END.
{mfreset.i}
 
Back
Top