cancel
Showing results for 
Search instead for 
Did you mean: 

'INTO' is invalid (due to grammar) error while SQL in BAPI

igma
Explorer
0 Kudos

Hi guys!

The error occurs in the first INTO of the first SELECT. I have 'INTO' is invalid (due to grammar)
I need to return several tables that will become arrays in an application that will call this BAPI remotely (RFC). However, when I add this code to the SAP that will run the RFC, it gives a problem with the INTO clause.
INTO is invalid here (due to grammar), but I don't know what I'm doing wrong, because I've already run this function in other SAPs and it worked normally.
The logic of this RFC is to return the data from the MARD, MARC, MAKT and MBEW tables based on the MARA table. Then I perform a select with where in the MARA table that will return a series of items, and based on the code of these items I perform a FOR ALL ENTRIES to search for these same materials in other tables and return them separately. I can't use joins. And then I come across the INTO clause error when I use anything between the word MARA (FROM MARA) and INTO. (In this case it's the order by)
I need the up to to be able to limit the lines of this return.
Can anyone help me?

Code (also attached): 

 

FUNCTION Z_GET_MATERIAL_FULL_CUSTOM.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(MARA_MAX_ROWS) TYPE INT4
*" REFERENCE(MARA_SKIP_ROWS) TYPE INT4
*" TABLES
*" MARA_TABLE STRUCTURE MARA
*" MARD_TABLE STRUCTURE MARD
*" MARC_TABLE STRUCTURE MARC
*" MAKT_TABLE STRUCTURE MAKT
*" MBEW_TABLE STRUCTURE MBEW
*"----------------------------------------------------------------------
SELECT MATNR, MEINS, MTPOS_MARA 
FROM MARA WHERE 
              MTPOS_MARA = 'ZMAP' OR MTPOS_MARA = 'ZMAN' 
ORDER BY MATNR INTO CORRESPONDING FIELDS OF TABLE _TABLE 
UP TO _MAX_ROWS ROWS OFFSET _SKIP_ROWS .

SELECT MATNR, LABST, LGPBE 
FROM MARD FOR ALL ENTRIES IN _TABLE WHERE 
                                       MATNR = _TABLE-MATNR 
INTO CORRESPONDING FIELDS OF TABLE @MARD_TABLE.


SELECT MATNR, MINBE, MABST, PLIFZ, DISMM, STEUC 
FROM MARC FOR ALL ENTRIES IN _TABLE WHERE 
                                        MATNR = _TABLE-MATNR 
INTO CORRESPONDING FIELDS OF TABLE _TABLE.


SELECT MATNR, MAKTX FROM MAKT 
FOR ALL ENTRIES IN _TABLE WHERE 
                              MATNR = _TABLE-MATNR AND SPRAS = 'P' 
INTO CORRESPONDING FIELDS OF TABLE _TABLE.


SELECT MATNR, VERPR FROM 
MBEW FOR ALL ENTRIES IN _TABLE WHERE 
                                   MATNR = _TABLE-MATNR 
INTO CORRESPONDING FIELDS OF TABLE @MBEW_TABLE.


ENDFUNCTION.

 

Sandra_Rossi
Active Contributor
0 Kudos

Please use the buttons "..." and "</>" to make the code easy to read.

Also use the ABAP Cleaner (I hope you use Eclipse ADT):

DATA mara_max_rows TYPE int4.
DATA mara_skip_rows TYPE int4.
DATA mara_table TYPE STANDARD TABLE OF mara.
DATA mard_table TYPE STANDARD TABLE OF mard.

SELECT matnr, meins, mtpos_mara
    FROM mara
    WHERE    mtpos_mara = 'ZMAP'
          OR mtpos_mara = 'ZMAN'
    ORDER BY matnr
    INTO CORRESPONDING FIELDS OF TABLE @Mara_table
    UP TO @Mara_max_rows ROWS
    OFFSET @Mara_skip_rows.

SELECT matnr, labst, lgpbe
    FROM mard
    FOR ALL ENTRIES IN @Mara_table
    WHERE matnr = @Mara_table-matnr
    INTO CORRESPONDING FIELDS OF TABLE @mard_table.

 

Sandra_Rossi
Active Contributor
0 Kudos
There is no syntax error in ABAP 7.52. You must be using an old ABAP version which doesn't support this syntax.

Accepted Solutions (0)

Answers (1)

Answers (1)

Sandra_Rossi
Active Contributor

There is no syntax error in ABAP 7.58.

Also, without OFFSET, it's also valid in ABAP 7.40.

You must be using an old ABAP version which doesn't support this syntax. Which one?

Please use the buttons "..." and "</>" to make the code easy to read. Also use the ABAP Cleaner (I hope you use Eclipse ADT). Here is better formatting:

DATA mara_max_rows TYPE int4.
DATA mara_skip_rows TYPE int4.
DATA mara_table TYPE STANDARD TABLE OF mara.
DATA mard_table TYPE STANDARD TABLE OF mard.

SELECT matnr, meins, mtpos_mara
    FROM mara
    WHERE    mtpos_mara = 'ZMAP'
          OR mtpos_mara = 'ZMAN'
    ORDER BY matnr
    INTO CORRESPONDING FIELDS OF TABLE @Mara_table
    UP TO @Mara_max_rows ROWS
    OFFSET @Mara_skip_rows.

SELECT matnr, labst, lgpbe
    FROM mard
    FOR ALL ENTRIES IN @Mara_table
    WHERE matnr = @Mara_table-matnr
    INTO CORRESPONDING FIELDS OF TABLE @mard_table.