Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Syntax error

0 Likes
7,530

Hi Experts,

I'm getting below syntax error while saving the program. Kindly share your inputs.

Error : "if the new open SQL syntax is used, it must be used throughout. This includes @ to escape host variables.

Getting error in line "INTO TABLE IT_mseg".

tables : bkpf , acdoca , mseg.

types : begin of ty_mseg,
          bukrs type bkpf-bukrs,
          belnr type bkpf-belnr,
          mblnr type mseg-mblnr,
          blart type bkpf-blart,
          hsl   type  acdoca-hsl,
        end of ty_mseg.

data : it_mseg type table of ty_mseg,
       wa_mseg type ty_mseg.

select-options :  s_bukrs for bkpf-bukrs,
                  s_gjahr for bkpf-gjahr,
                 s_blart for bkpf-blart.

start-of-selection.

  select  bkpf~bukrs , acdoca~belnr , mseg~mblnr , bkpf~blart , acdoca~hsl
          from bkpf inner join acdoca
          on bkpf~belnr = acdoca~belnr
          inner join mseg
          on bkpf~xblnr = mseg~mblnr
          INTO TABLE IT_mseg
          where bkpf-bukrs in s_bukrs
          and  bkpf-gjahr in s_gjahr
          and  bkpf-blart in s_blart.

  loop at : it_mseg into wa_mseg.

    write : / wa_mseg-bukrs , wa_mseg-belnr , wa_mseg-mblnr , wa_mseg-blart , wa_mseg-hsl.
  endloop.

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
6,700

I say like Subhajit and concerning Error : "if the new open SQL syntax is used, it must be used throughout. This includes @ to escape host variables. Getting error in line "INTO TABLE IT_mseg".

This is due to using commas between column names.

Solution (NB: INTO must be at the end):

where bkpf~bukrs in @s_bukrs
  and bkpf~gjahr in @s_gjahr
  and bkpf~blart in @s_blart
INTO TABLE @IT_mseg
8 REPLIES 8
Read only

subhajit
Active Participant
6,700


Can you correct it to

where bkpf~bukrs in s_bukrs

and bkpf~gjahr in s_gjahr

and bkpf~blart in s_blart.

Thanks.

Read only

Sandra_Rossi
Active Contributor
6,701

I say like Subhajit and concerning Error : "if the new open SQL syntax is used, it must be used throughout. This includes @ to escape host variables. Getting error in line "INTO TABLE IT_mseg".

This is due to using commas between column names.

Solution (NB: INTO must be at the end):

where bkpf~bukrs in @s_bukrs
  and bkpf~gjahr in @s_gjahr
  and bkpf~blart in @s_blart
INTO TABLE @IT_mseg
Read only

0 Likes
6,700

Just to escape the variables will fix the error. The INTO position has no effect here (I always put my INTO after the SELECT because I'm used to it).

Read only

0 Likes
6,700

vicen.lozano Oh, you're right for the INTO. Sometimes the syntax checker requires to place it at the end, not here (I should learn what the exact positioning rules are :-p).

Read only

6,700

Yup... I remembered it because sometimes the checker asks me to do that, and then I become upset XD

Read only

0 Likes
6,700

It worked. Thanks.

Read only

0 Likes
6,700

Thanks for the feedback. Please use the COMMENT button for comments, questions, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

Read only

VXLozano
Active Contributor
0 Likes
6,700

You're lucky Sandra came here fast. The next time, just read the error message, it's clear enough.