This website is not affiliated with, sponsored by, or approved by SAP AG.

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

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

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

Postby handsome1234 » Wed Nov 15, 2017 12:12 am

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 .
handsome1234
 
Posts: 1
Joined: Tue Nov 14, 2017 10:15 pm

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

Postby Gothmog » Thu Nov 16, 2017 8:15 am

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 )
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1945
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

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

Postby VLozano » Wed Jan 17, 2018 9:09 am

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).
Tuly Idiots
Because we know we are part of the problem
VLozano
 
Posts: 5142
Joined: Mon Sep 13, 2004 8:17 am
Location: Idiocity


Return to ABAP

Who is online

Users browsing this forum: No registered users and 15 guests





This website is not affiliated with, sponsored by, or approved by SAP AG.