Page 1 of 1

simple code with error: If the new Open SQL syntax is used,

PostPosted: Wed Nov 15, 2017 12:12 am
by handsome1234
If the new Open SQL syntax is used, it must be used throughout. This includes using @ to escape host variables.
code:
TABLES SBOOK.
DATA: AACOUNT TYPE I,AASUM TYPE P DECIMALS 2,AAAVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID, COUNT(*), SUM(LUGGWEIGHT), AVG(LUGGWEIGHT) INTO (CONNID,AACOUNT,AASUM,AAAVG)
FROM SBOOK
WHERE
CARRID = 'LH' AND FLDATE = '19590228'
GROUP BY CONNID.
WRITE: / CONNID,AACOUNT,AASUM,AAAVG.
CHECK AASUM > 10.
WRITE: / ' THE SUM WEITHT>10'.
ENDSELECT .

Re: simple code with error: If the new Open SQL syntax is used,

PostPosted: Thu Nov 16, 2017 8:15 am
by Gothmog
The culprits are the commas added in the list of selected fields.
To keep the old syntax, it should be:
Code: Select all
SELECT CONNID COUNT(*) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )

Re: simple code with error: If the new Open SQL syntax is used,

PostPosted: Wed Jan 17, 2018 9:09 am
by VLozano
Just be aware of the velociraptors. I suppose it's how you call what in the 20th century we used to call "bugs".

I was about to close the browser after I've read the answer of Gothmog (hi), but could not resist me anymore.

TABLES??? REALLY???

Not even in my deepest nightmares (those what involve the massive sheep extinction) I thought I would be as scared as to see someone using "TABLES" in a code sample.

Yes, it's a two months old thread, but hey, it's a TABLES sentence on my screen, I must react somehow.

Code: Select all
TABLES SBOOK.
DATA: AACOUNT TYPE I,AASUM TYPE P DECIMALS 2,AAAVG TYPE F.
DATA: CONNID LIKE SBOOK-CONNID.
SELECT CONNID, COUNT(*), SUM(LUGGWEIGHT), AVG(LUGGWEIGHT) INTO (CONNID,AACOUNT,AASUM,AAAVG)
FROM SBOOK
WHERE
CARRID = 'LH' AND FLDATE = '19590228'
GROUP BY CONNID.
WRITE: / CONNID,AACOUNT,AASUM,AAAVG.
CHECK AASUM > 10.
WRITE: / ' THE SUM WEITHT>10'.
ENDSELECT .


This also works, and it's a bit cleaner (IMO)
Code: Select all
SELECT CONNID, COUNT(*), SUM(LUGGWEIGHT), AVG(LUGGWEIGHT)
  FROM SBOOK
  INTO ( @DATA(id), @DATA(counter), @DATA(summatory), @DATA(average) )
  WHERE CARRID = 'LH'
    AND FLDATE = '19590228'
  GROUP BY CONNID.
  WRITE: / id, counter, summatory, average.
  IF summatory > 10.
    WRITE: / ' THE SUM WEITHT>10'.
  ENDIF.
ENDSELECT .
Basically, I removed the data declarations (TABLES included) because you are using it just in this piece of code, I renamed the variables just for my personal taste and changed the CHECK because I want to remove my bad habit of use it (it will lead to errors if you change your code in the far future and don't notice it).