SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Помогите с Native SQL



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP
View previous topic :: View next topic  
Author Message
extreme
Участник
Участник



Joined: 05 Sep 2008
Posts: 1

PostPosted: Fri Sep 05, 2008 9:30 am    Post subject: Помогите с Native SQL Reply with quote

Не работает данный SQL. В чем может быть проблема???
-------------------------------------
Code:
EXEC SQL.
  OPEN CURSOR C FOR
  select a1~NOM_CH_F, a1~summa
  from ( select NOM_CH_F,sum(SUM_BUY) summa
  from T_BUF
  group by NOM_CH_F) a1
  where a1~summa =0 .
ENDEXEC.
DO.
  EXEC SQL.
    FETCH NEXT CURSOR C INTO WA.
  ENDEXEC.
  IF sy-subrc <> 0.
    EXEC SQL.
      CLOSE C
    ENDEXEC.
    EXIT.
  ENDIF.
ENDDO.

-------------------------------------
ошибка: ORA-00900

Сделал вот так.. как написано в доке.... тоже не работает, но уже другая ошибка...ORA-00933
-------------------------------------------------
Code:
DATA: d1 LIKE zzz_book_buy_h-nom_ch_f,
      d2 LIKE zzz_book_buy_h-sum_buy.
******------------------------------------------------------*********
EXEC SQL.
  OPEN C FOR
  SELECT A1-NOM_CH_F, A1-SUMMA
  FROM ( SELECT NOM_CH_F,SUM(SUM_BUY) AS SUMMA
  from ZZZ_BOOK
  GROUP BY NOM_CH_F) AS A1
  WHERE A1-SUMMA =0
ENDEXEC.
DO.
  EXEC SQL.
    FETCH NEXT C INTO 1, 2
    IF SY-SUBRC <> 0.
    CLOSE C
    EXIT.
    ENDIF.
  ENDEXEC.
ENDDO.
******------------------------------------------------------*********
Back to top
View user's profile Send private message
vga
Мастер
Мастер


Age: 170
Joined: 04 Oct 2007
Posts: 1218
Location: Санкт-Петербург

PostPosted: Fri Sep 05, 2008 12:51 pm    Post subject: Reply with quote

Селект c суммой кривой. Зачем так сложно, что Вы на выходе получить хотите?

По моему
Code:
  OPEN C FOR
  SELECT A1.NOM_CH_F, A1.SUMMA
  FROM ( SELECT NOM_CH_F,SUM(SUM_BUY) SUMMA
  FROM Z_BOOK
  GROUP BY NOM_CH_F) A1
  WHERE A1.SUMMA = 0


можно заменить, как в коде ниже или DISTINCT.

Code:
* MSSQL syntax
EXEC SQL.
  IF EXISTS(SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE
            TABLE_NAME = 'Z_BOOK') DROP TABLE Z_BOOK;
ENDEXEC.

EXEC SQL.
  CREATE TABLE Z_BOOK (
         CLIENT   CHAR(3)  NOT NULL,
         ID       INTEGER  NOT NULL,
         NOM_CH_F CHAR(20)  NOT NULL,
         SUM_BUY    INTEGER,
         PRIMARY KEY (CLIENT, ID)
                        )
ENDEXEC.

IF NOT sy-subrc IS INITIAL.
  WRITE: / 'Table Z_BOOK creation error'.
  EXIT.
ENDIF.

EXEC SQL.
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 1, 'Book0', 0)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 2, 'Book1', 10)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 3, 'Book1', 15)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 4, 'Book2', 20)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 5, 'Book2', 25)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 6, 'Book3', 30)
  INSERT INTO Z_BOOK (CLIENT, ID, NOM_CH_F, SUM_BUY)
         VALUES ('100', 7, 'Book3', 35)

ENDEXEC.

WRITE: / 'Select One record'.
EXEC SQL.
  SELECT CLIENT, NOM_CH_F, SUM_BUY INTO :CLIENT, :NOM_CH_F, :SUM_BUY
  FROM Z_BOOK
ENDEXEC.

WRITE: / CLIENT, NOM_CH_F, SUM_BUY.

WRITE: / 'Select All records'.
EXEC SQL.
  OPEN C FOR
    SELECT CLIENT, NOM_CH_F, SUM_BUY FROM Z_BOOK
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT C INTO :CLIENT, :NOM_CH_F, :SUM_BUY
  ENDEXEC.
  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.
  WRITE: / CLIENT, NOM_CH_F, SUM_BUY.
ENDDO.
EXEC SQL.
  CLOSE C
ENDEXEC.

WRITE: / 'Select records with null sum'.
EXEC SQL.
  OPEN C FOR
    SELECT NOM_CH_F, SUM(SUM_BUY)
    FROM Z_BOOK
    WHERE SUM_BUY = 0
    GROUP BY NOM_CH_F
ENDEXEC.

DO.
  EXEC SQL.
    FETCH NEXT C INTO :NOM_CH_F, :SUM_BUY
  ENDEXEC.
  IF SY-SUBRC <> 0.
    EXIT.
  ENDIF.
  WRITE: / NOM_CH_F, SUM_BUY.
ENDDO.
EXEC SQL.
  CLOSE C
ENDEXEC.

EXEC SQL.
  DROP TABLE Z_BOOK
ENDEXEC.
Back to top
View user's profile Send private message Blog Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ABAP All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.