Skip to Content
author's profile photo
Former Member

Sql statement, internal table

<i>This is a simplified example of the problem:</i>

types: begin of t_MaterialStruct,

X_MARC_MATNR type MARC-MATNR,

X_MARC_WERKS type MARC-WERKS,

X_MBEW_VERPR type MBEW-VERPR,

end of t_MaterialStruct.

data: i_MaterialTab type table of t_MaterialStruct with header line.

The above table is partly filled with data.

It's missing the X_MBEW_VERPR.

Is it possible to update my internal table in a new select statement or ?

Something like this:

select VERPR from MBEW into i_MaterialTab where BWKEY = 3100

//Martin

Message was edited by: Martin Andersson

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    author's profile photo
    Former Member
    Posted on Jan 20, 2005 at 03:37 PM

    Hello Martin,

    When you say that the above table is <i>partially</i> filled with data, are you referring to the partiality of the rows or of the columns?

    Case 1 : If the internal table already has, let us say, some 10 records, you can certainly add new records to the internal table using the syntax :

    SELECT VERPR
      FROM MBEW
      APPENDING CORRESPONDING FIELDS OF i_MaterialTab
     WHERE BWKEY = 3100. 
    

    Case 2 : If the internal table has, for example 10 rows, but none of these rows has the X_MBEW_VERPR fields populated, then neither is it possible , nor does it technically make sense to populate this field in the 10 rows using another SELECT statement. That is beacuse, the SELECT statement might return more than 10 rows as the result. Also, the data fetched by the SELECT statement might not be consistent with the rest of the fields' data in those 10 rows.

    Hope the explanation has been clear enough. If not please get back. If yes, then please mark the question as answered.

    Regards,

    Anand Mandalika.

    Add comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 20, 2005 at 03:30 PM

    Nop..... the statement will overwrite the previous data. You going to have to loop thru your internal table and get the data with single selects. This also could be achieved with one select statement with some creative joining.

    Good luck.

    Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Jan 20, 2005 at 03:33 PM

    Hi Martin,

    The method you want is NOT possible.

    However, why don't you use a join-statement to collect the data?

    It would look like this

    SELECT amatnr awerks b~verpr

    INTO TABLE i_materialtab

    FROM marc AS a

    INNER JOIN mbew AS b

    ON bmatnr = amatnr

    WHERE b~bwkey = '3100'.

    This fills the internal table in one pass with all the data.

    Hope this helps you,

    Regards,

    Rob.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Posted on Jan 20, 2005 at 03:34 PM

    Hi Martin,

    It's always better to use the same field names inside your internal tables so that you can execute these selects with a faster and easier responses.

    Try this:

    TYPES: BEGIN OF t_materialstruct,

    matnr TYPE marc-matnr,

    werks TYPE marc-werks,

    verpr TYPE mbew-verpr,

    END OF t_materialstruct.

    DATA: i_materialtab TYPE TABLE OF t_materialstruct WITH HEADER LINE.

    SELECT verpr

    APPENDING CORRESPONDING FIELDS OF TABLE i_materialtab

    FROM mbew

    WHERE bwkey = '3100'.

    Hope this is what you need...

    Regards.

    Message was edited by: Jorge Balart

    Add comment
    10|10000 characters needed characters exceeded