Skip to Content
0
Sep 11, 2007 at 08:50 PM

Quick help with a select statement...

56 Views

Hello all,

I will try to lay this out as simply as possible. I have the following table in my code:

TYPES: BEGIN OF ty_table,
    vbeln TYPE likp-vbeln,
    lfdat TYPE likp-lfdat,
    lfart TYPE likp-lfart,
    wadat_ist TYPE likp-wadat_ist,
    vstel TYPE likp-vstel,
    route TYPE likp-route,
    vsbed TYPE likp-vsbed,
    inco1 TYPE likp-inco1,
    inco2 TYPE likp-inco2,
    kunnr TYPE likp-kunnr,
    kunag TYPE likp-kunag,
    brgew TYPE lips-brgew,
    matnr TYPE lips-matnr,
    arktx TYPE lips-arktx,
    meins TYPE lips-meins,
    lgmng TYPE lips-lgmng,
    vgbel TYPE lips-vgbel,
    name2 TYPE adrc-name2,
    street TYPE adrc-street,
    city1 TYPE adrc-city1,
    region TYPE adrc-region,
    post_code1 TYPE adrc-post_code1,
    lifnr  TYPE lfa1-lifnr,
    name1 TYPE adrc-name1,
    so_vbeln TYPE vbak-vbeln,
    erdat TYPE vbak-erdat,
  END OF ty_table.

DATA: it_table TYPE TABLE OF ty_table.

I then run through a select statement as follows:

* Get data from LIKP and LIPS.
  SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
           b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
           FROM likp AS a
            INNER JOIN lips AS b ON b~vbeln = a~vbeln
            WHERE a~vstel IN so_vstel
            AND a~wadat_ist IN so_wadat
            AND b~mtart IN so_mtart.

That works fine. The next statement, in the report, is the following select. When this next select runs it clears all of the fields except for vbeln and erdat. I want c~vbeln to go into it_table-so_vbeln. Now it is going into it_table-vbeln.

* Get Sales order info from VBAK
  SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
      FROM lips AS a
        INNER JOIN vbap AS b ON b~vbeln = a~vgbel
        AND b~posnr = a~vgpos
          INNER JOIN vbak AS c ON c~vbeln = b~vbeln
          FOR ALL ENTRIES IN it_table
            WHERE a~vgbel = it_table-vgbel.

I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).

* Get Sales order info from VBAK
  SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
    FROM lips AS a
      INNER JOIN vbap AS b ON b~vbeln = a~vgbel
      AND b~posnr = a~vgpos
        INNER JOIN vbak AS c ON c~vbeln = b~vbeln
        FOR ALL ENTRIES IN it_table
          WHERE a~vgbel = it_table-vgbel.

Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table? Also, is there a way to combine the two selects into one join?

Regards,

Davis