New in Progress, modifiyng another programmer's code. Temp Table - Array

PanicProgress

New Member
Hi everybody! :) my first post:

I'm a newbie. I've been reading programs written in Progress for about a year and I can understand how it works, the tables, the objective; and I'm doing some adjust of my own. In a report, I need to interchange the last and
the last - 1 records of a Temp Table.

How can it be done?:confused:

This "reports" are an output to a window or printer.

I'm thinking in doing a copy of the Temp Table to an array, and read this new array so when I reach the variable record-count -1 , print the last and after that print the last - 1 .

But I'm not sure if the idea is ok, or if there's another way to reach my goal...

I know that I should modify the order of the Temp-Table when this is being filled with data, but, the problem is that the code would become a little bit ( a lot) more complex if I try to do that, because I did not write the program and I do not have the level to re-order in that moment :(.

Any sugestions are welcome.
 
Hi PanicProgress,
Please find below one way of achieving ur requirement. I know it's more primitive (me too a newbie) but still it will work.

Logic:
1. Calculate the total number of records in the temp table
2. Print all the records except the (last - 1) record (instead create another temporary record in that loop)
3. Now print the (last - 1) record.

Below is a sample program to print the first 5 records in customer table as per your requirement.


DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.


OUTPUT TO "C:\test.txt".

DEFINE BUFFER bfcustomer FOR customer.
DEFINE TEMP-TABLE ttcustomer LIKE customer.


/* Get the total count of your records first */
FOR EACH customer NO-LOCK WHERE cust-num < 6:
i = i + 1.
END.


FOR EACH customer FIELDS (cust-num NAME ) NO-LOCK WHERE cust-num < 6 :
j = j + 1.
IF j = i - 1 THEN DO: /* Do not print the last - 1 record */
FIND LAST bfcustomer WHERE bfcustomer.cust-num < 6 NO-ERROR.
FIND PREV bfcustomer.

CREATE ttcustomer . /* instead create a temporary record for last - 1 record*/
BUFFER-COPY customer TO ttcustomer.
END.
ELSE
PUT UNFORMATTED customer.cust-num SPACE customer.NAME SKIP .
IF j = i THEN
DO:
FIND FIRST ttcustomer NO-LOCK NO-ERROR .
IF AVAILABLE ttcustomer THEN
PUT UNFORMATTED ttcustomer.cust-num SPACE ttcustomer.NAME SKIP . /* Print it at the end */
END.
END.



Output:
1 Lift Line Skiing
2 Urpon Frisbee
3 Hoops Croquet Co.
5 Match Point Tennis
4 Go Fishing Ltd

Hi All,
Please let me know your comments. In the mean time let me work around for a better code.

Regards,
kutti.
 
How is the existing temp-table ordered?

Does it have a line# or some other field that defines the sequence?

It seems like it must have such a field if the order is anything other than blind luck. And if it is just blind luck then why would switching the last 2 rows matter to anyone?

If it does have such a field then just change the values of the last two rows to reflect your new ordering. Something like this horribly hacked together example:

Code:
define variable x as integer no-undo.
define variable y as integer no-undo.

define buffer ttbuf for tt.

find last tt by tt.lineNumber.
x = tt.lineNumber.
find last ttbuf by tt.lineNumber.
find prev ttbuf by tt.lineNumber.
y = ttbuf.lineNumber.

assign
  ttbuf.lineNumber = x
  tt.lineNumber = y
.
 
Hi Tom,

I tried to make my code a bit better (atleast i would say). Any comments ??? It would be helpful for my learning.

DEFINE VARIABLE bhcustomer AS HANDLE NO-UNDO.
DEFINE VARIABLE qh AS HANDLE NO-UNDO.
DEFINE VARIABLE qString AS CHARACTER NO-UNDO.

DEFINE VARIABLE icount AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
DEFINE BUFFER bfcustomer FOR customer.
DEFINE TEMP-TABLE ttcustomer LIKE customer.

OUTPUT TO "C:\New Folder\test.txt".
bhcustomer = BUFFER customer:HANDLE.

qString = "PRESELECT EACH " + bhcustomer:NAME + " NO-LOCK WHERE cust-num < " + '6' .
IF VALID-HANDLE(bhcustomer) THEN DO:

CREATE QUERY qh.
qh:SET-BUFFERS(bhcustomer).
qh:QUERY-PREPARE(qString).
qh:QUERY-OPEN().
END.

icount = qh:NUM-RESULTS. /*get the count of records*/
loop:
DO WHILE TRUE:
IF NOT qh:GET-NEXT() THEN LEAVE loop.
j = j + 1.
IF j = icount - 1 THEN DO:
FIND LAST bfcustomer WHERE bfcustomer.cust-num < 6 NO-ERROR.
FIND PREV bfcustomer.
CREATE ttcustomer .
BUFFER-COPY customer TO ttcustomer.
END.
ELSE
PUT UNFORMATTED bhcustomer:BUFFER-FIELD("cust-num"):BUFFER-VALUE SPACE bhcustomer:BUFFER-FIELD("name"):BUFFER-VALUE SKIP .
IF icount = J THEN
DO:
FIND FIRST ttcustomer NO-LOCK NO-ERROR .
IF AVAILABLE ttcustomer THEN
PUT UNFORMATTED ttcustomer.cust-num SPACE ttcustomer.NAME SKIP .
END.
END.


Regards,
Kutti.
 
Hi everyone!

Thanks for replies! I'm taking notes.

I'll try to make some sense about my situation:
This report is the final report of the year, there are perceptions
and deductions, both reports need to be printed in paper, separately,
but, only the first column of deduccions is needed.

Each column have a number (with more numbers inside, the number
of concepts to group in that column). In Perceptions goes from
100 up to 199 and in Deduccions goes from 200 up to 300; so I thinked
why not to bring the column with group number 200 to the report
of Perceptions? (And print only one report, saving paper)

The code said " >= 100 and < 200" and I added
"<=200". :) But the report looked like this:

Group 100 | Group 180 | Group 199 | Group 200 | Total
100 100 100 50 350

This is wrong because the Group 200 it's not a Perception, but a Deducction, so the report have to be like this

Group 100 | Group 180 | Group 199 | Total | Group 200
100 100 100 300 50
100 100 100 300 50
100 100 100 300 50

Total 300 300 300 900 150

The column Total have not a Group number, it's the result of adding
the quantity of each column.

To make things worst, (or better, because I learned more,) there are
subtotals for each n rows, and for kind of row, and the last Total.

So It got solved more or less as this:
"For Each Row break by Group-number :
If not Last-Of ( group number)
then print quantity and add to Total - here goes Group 100 - 199
else print Total then print Group 200"

The subtotals are created and stored in Temporal Tables, and there I did:
"i-count = 0.
For each Subtotal
 
Hi everyone!

Thanks for replies! I'm taking notes.

I'll try to make some sense about my situation:
This report is the final report of the year, there are perceptions
and deductions, both reports need to be printed in paper, separately,
but, only the first column of deduccions is needed.

Every column have a number, In Perceptions goes from
100 up to 199 and in Deduccions goes from 200 up to 300; so I thinked
why not to bring the column with group number 200 to the report
of Perceptions? (And print only one report, saving paper)

The code said " >= 100 and < 200" and I added
"<=200". :) But the report looked like this:

Group 100 | Group 180 | Group 199 | Group 200 | Total Perc.
.......100......... 100............. 100 ......... 50............ 350

This is wrong because the Group 200 it's not a Perception, but a Deducction, so the report have to be like this

......Group 100 | Group 180 | Group 199 | Total Perc. | Group 200
..........100 ............100.............100.......... 300 ............ 50 ...
..........100 ............100.............100.......... 300 ............ 50 ...
...........100 ...........100.............100.......... 300 ............ 50 ...
______________________________________________________
Total ... 300 ...........300............. 300 ........900 ............150

The column Total have not a Group number, it's the result of adding
the quantity of every column.

To make things worst, (or better, because I learned more,) there are
subtotals for each n rows, and for kind of row, and the last Total.

So It got solved more or less as this:
"For Each Row break by Group-number :
If not Last-Of ( group number)
then print quantity and add to Total - here goes Group 100 - 199
else print Total then print Group 200"

The Subtotals of every column are created and stored in local Temporal Tables, and there I said:
"Total-count = 0.
For each Subtotal
Total-count = Total-count + 1. "

When printing subtotals:
if i-count < Total-Count then Print Subtotal Column and add to
Subtotal of Perceptions - Group Column 100-199
else
print Subtotal for Perceptions and print Subtotal for Group C. 200

A received help from the man I call my Teacher, who lives in another city,
(he's an expert I think), I'm grateful with him.

It took me almost two weeks to finish the report but I'm happy because I learned lot's of things, and I validated the report vs "the normal report" and it's ok :biggrin:

Thanks again for your atention!
 
Back
Top