Understanding Temp-Table Records

HT3

Member
Hi All,

I'm writing a script to do X but before I get to that stage, I've imported the ItemCode into a temp-table so that I can then use it further down the line. However I'm running into an issue with the data stored in the temp table.

I think it's do with my understanding on the REPEAT function (Progress Documentation) but I'm not sure.

Code:
DEFINE VARIABLE cItem AS CHARACTER.
DEFINE VARIABLE cInputFile AS CHARACTER.

ASSIGN cInputFile = "C:\Users\HT\Desktop\ItemUpdate.csv". 

DEFINE STREAM sInput.

DEFINE TEMP-TABLE tt-Item
FIELD ITEM AS CHARACTER.
 
INPUT STREAM sInput FROM VALUE (cInputFile).

REPEAT:                                                                                                                            

IMPORT STREAM sInput DELIMITER "," cItem.

cItem =TRIM(cItem).

IF cItem <>  "" THEN. 

 CREATE tt-item.
 ASSIGN
 tt-item.ITEM = cItem.

DISPLAY tt-item WITH 1 COLUMN SCROLLABLE.      /*************(DISPLAY ONE)**********/

END.

DISPLAY tt-item WITH 1 COLUMN SCROLLABLE.  /*******(DISPLAY TWO) ***********/

INPUT STREAM sInput CLOSE.

/*****(MY CODE ) *****/

/* FOR EACH darwin.ITEM WHERE                           */
/*          darwin.ITEM.ItemCode = cItem.               */
/*                                                      */
/*          IF AVAILABLE darwin.ITEM THEN               */
/*                                                      */
/*          FOR EACH tt-item WHERE                      */
/*          tt-item.ITEM = "".                          */
/*                                                      */
/*          ASSIGN darwin.ITEM.ItemCode = tt-item.ITEM. */
/*                                                      */
/*          DISPLAY tt-item WITH 1 COLUMN SCROLLABLE.   */
/*   END.                                               */

When DISPLAY ONE appears I have all 174 records that I need, when DISPLAY TWO appears then only the last item appears.

After ending the creation of the Temp-Table, I thought all 174 records would appear\be available. I can then close my stream and continue on with my code to do X using the item from the temp-table.

However that's not happening .... So my question is do I need to place my code to do x between DISPLAY ONE and the end statement?

Why does the second display only show my last item?

FYI the my code section isn't what I'm doing it's just me playing and as you can see I've commented it out for the time being.

Thanks,
Hassam
 

Osborne

Active Member
Because DISPLAY ONE is appearing in the REPEAT block and straight after you create the temp-table it will display the current temp-table created thus you see all the temp-table records and numbers being created from 1 to 174.

For DISPLAY TWO it is not in any block and is just displaying a single temp-table record which in this case will be the last one as this is the last one that was created.

Best option to display all temp-table records is remove DISPLAY ONE and instead have this after the REPEAT block:

Code:
REPEAT:
   ...
END.

FOR EACH tt-item:
   DISPLAY tt-item WITH 1 COLUMN SCROLLABLE.
END.
 

HT3

Member
Thank you so much.... they all display now.

I thought telling it to display tt-item would have the same effect.
 

x_jeferson

New Member
With this import (repeat/csv), you create this new temporary table, your DISPLAY ONE shows all the items, as it is inside the repeat loop (repeat). For DISPLAY TWO what happens is that the temp-table is positioned in the last item of the Repeat, for this reason it presents the last record.
In place of DISPLAY TWO you can replace it with:


Code:
FOR EACH tt-item:

       DISPLAY tt-item WITH 1 COLUMN SCROLLABLE.  /*******(DISPLAY TWO) ***********/

END.

For a better understanding, I took the liberty of including in (MY CODE), for each item that you carried out the import (csv), you will try to position this item in the ITEM table:
Code:
FOR EACH tt-item:
    FOR EACH darwin.ITEM NO-LOCK
        WHERE darwin.ITEM.ItemCode = tt-item.ITEM:
        DISPLAY darwin.ITEM WITH 1 COLUMN SCROLLABLE.
    END.
END.
 

TomBascom

Curmudgeon
Aside from the DISPLAY question that others have answered, this snippet is probably not doing what you think it is doing:
Code:
IF cItem <>  "" THEN.

 CREATE tt-item.
 ASSIGN
 tt-item.ITEM = cItem.

You probably wanted to code that as:
Code:
IF cItem <>  "" THEN
  do:

   CREATE tt-item.
   ASSIGN
     tt-item.ITEM = cItem
    .

  end.

In general your code isn't indented to reflect the block structure. Like most languages, and unlike Python, in Progress 4gl indentation is just for readability. But even though it has no syntactical purpose good indentation goes a long way towards making your code understandable.
 

TomBascom

Curmudgeon
Missing DO/END pairs is not style - that has an actual impact on program correctness.

In your sample code the IF statement does nothing and you will execute the CREATE and the ASSIGN with every iteration of the REPEAT regardless of whether cItem is blank or not blank. That is not a matter of different developers having differing opinions over indentation.
 
Top