Skipping An Unavailable Record

HT3

Member
Hi Guys,

I've have a block of code which falls over because it's unable to find the cupbackconv.prodgroup.

Code:
   icbccnt = 0.
        FOR each ttcbc no-lock:
            lv_size = "".
            lv_back = "".
            lv_cup = "".

            IF item.backsize <> ""  THEN DO:
                find first cupbackconv no-lock
                where cupbackconv.inentity = "EL"
                and cupbackconv.prodgroup = item.prodgroup
                and cupbackconv.country = ttcbc.cc
                and cupbackconv.systemsize = item.backsize no-error.
                IF available ttcbc THEN DO:
                    lv_back = cupbackconv.displaysize.
                END.
            END.

I just need some assistance with re-writing the block so that it moves on to the next record if the cupbackconv.prodgroup doesn't equal item.prodgroup.

I've tried a few things but can't get it to work, any suggestions I could try?

Let me know if you need anything else that could assist.

Thanks,
Hassam
 
Last edited:

WinningJr

New Member
Do you have a cut and paste issue where you confused ttcbc with the item table or ttcbc with cupbackconv? You are checking if ttcbc is available when inside a FOR EACH ttcbc (it is always available). The item table seems to come out of nowhere. I'm not sure which table you want the next record from....
 

HT3

Member
Hi @WinningJr,

"The item table seems to come out of nowhere."
This is just a block of a much larger piece of code, which is why it seems the item table appears from no where (There are around 500 items).

"You are checking if ttcbc is available when inside a FOR EACH ttcbc (it is always available)."
Who ever wrote this was trying to assign lv_back a value, I assume they thought this was the best way.

"Do you have a cut and paste issue where you confused ttcbc with the item table or ttcbc with cupbackconv?"
No this is how it's supposed to be, this is temp table record that holds the country code.

Hope that helps....

Thanks,
Hassam
 

Stefan

Well-Known Member
A simple available cubpackconv should be sufficient:

Code:
icbccnt = 0.
for each ttcbc no-lock:

   assign
      lv_size = ''
      lv_back = ''
      lv_cup = ''
      .

   if item.backsize > '' then do for cupbackconv:

      find first cupbackconv no-lock
         where cupbackconv.inentity   = 'EL'
         and   cupbackconv.prodgroup  = item.prodgroup
         and   cupbackconv.country    = ttcbc.cc
         and   cupbackconv.systemsize = item.backsize
      no-error.
      if available cupbackconv and available ttcbc then
         lv_back = cupbackconv.displaysize.


end.
 

HT3

Member
Hi @Stefan,

Screen Shot One

1706545275281.png

Screen Shot Two

1706545363738.png


Code:
        icbccnt = 0.
        FOR each ttcbc no-lock:
            lv_size = "".
            lv_back = "".
            lv_cup = "".

            IF item.backsize <> ""  THEN DO:

            DISPLAY ITEM.ItemCode.

                FIND FIRST darwin.cupbackconv WHERE
                           darwin.cupbackconv.inentity = "EL" AND
                           darwin.cupbackconv.country = ttcbc.cc AND
                           darwin.cupbackconv.systemsize = item.backsize AND
                           darwin.cupbackconv.prodgroup = item.prodgroup
                           NO-LOCK.

                           DISPLAY darwin.cupbackconv.country darwin.cupbackconv.prodgroup.
                           
                           IF AVAILABLE cupbackconv AND AVAILABLE ttcbc THEN DO: 
         
                           lv_back = cupbackconv.displaysize.

                           END.

            END.
          END.

I tried what you suggested but it's still failing (See attached error).

I need the colon otherwise it interferes with code below the block you're looking at.

As you can see in screen shot one there is a record without the country or product group.

Thanks,
Hassam
 

Attachments

  • 1706545341995.png
    1706545341995.png
    16.2 KB · Views: 2

Rob Fitzpatrick

ProgressTalk.com Sponsor
IF AVAILABLE cupbackconv AND AVAILABLE ttcbc THEN DO:
You are checking if ttcbc is available when inside a FOR EACH ttcbc (it is always available).
Correct. The AND AVAILABLE ttcbc is equivalent to AND TRUE (unless you were doing something like releasing the ttcbc buffer prior to the if available, which you are not). It doesn't accomplish anything.
Why do you think it is required?

Original:
find first cupbackconv no-lock
Revised:
FIND FIRST darwin.cupbackconv WHERE
Why did you add the qualification of the table name with a database name? This code won't work as you expect if you run it against a database with a different logical name. On the other hand, if the belief that the correct database name is always "darwin" is strong enough to hard-code it, then why specify the database name? Will this session be connected to multiple databases simultaneously, where more than one database has a table named "cupbackconv", and you need the qualifier to make the reference unambiguous? Why do you think the qualifier is required?

I need the colon otherwise it interferes with code below the block you're looking at.
It is not clear what you are referring to with this statement.
 

HT3

Member
Thanks @Rob Fitzpatrick and @Patrice Perrot.

I've resolved the issue....
Code:
        icbccnt = 0.
        FOR each ttcbc no-lock:
            lv_size = "".
            lv_back = "".
            lv_cup = "".

            IF item.backsize <> ""  THEN DO:
           
                FIND FIRST darwin.cupbackconv WHERE
                           darwin.cupbackconv.inentity = "EL" AND
                           darwin.cupbackconv.country = ttcbc.cc AND
                           darwin.cupbackconv.systemsize = item.backsize AND
                           darwin.cupbackconv.prodgroup = item.prodgroup
                           NO-LOCK NO-ERROR.
                         
                                                     
                           IF AVAILABLE cupbackconv AND AVAILABLE ttcbc THEN DO:
                     
                                        lv_back = cupbackconv.displaysize.                 


                           END.
                   
            END.
          END.

I added the NO-ERROR back which supressed the error popping up on screen and it's filling the temp table record where it can rather failing all together.

Correct. The AND AVAILABLE ttcbc is equivalent to AND TRUE (unless you were doing something like releasing the ttcbc buffer prior to the if available, which you are not). It doesn't accomplish anything.
Why do you think it is required?

Sorry I didn't remove the IF AVAILAVLE ttcbc and try it, it was added by different user before my time. I'm not very confident.....

Why did you add the qualification of the table name with a database name? This code won't work as you expect if you run it against a database with a different logical name. On the other hand, if the belief that the correct database name is always "darwin" is strong enough to hard-code it, then why specify the database name? Will this session be connected to multiple databases simultaneously, where more than one database has a table named "cupbackconv", and you need the qualifier to make the reference unambiguous? Why do you think the qualifier is required?

The database name was added because we have multiple databases connected with the same table and fields.

It is not clear what you are referring to with this statement.

I can't be 100% on this but it was inside another loop and without the colon it would go right to the bottom, as soon as I added the colon and end statement it worked (Contained it).

Thanks for you help much appreciated @Patrice Perrot @Stefan and @WinningJr and everyone else.
 
Last edited:
Top