Skip to Content
0
Apr 24, 2007 at 06:46 PM

Help with a select

109 Views

I am getting a syntax error in the following code. The error is in second to last line (WHERE sa_num = adrc-addrnumber). The error I get is "Field SA_NUM is unknown"

*&---------------------------------------------------------------------*
*& Report  ZPARTNER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zpartner.

TABLES: vbak,
        vbpa,
        adrc.


TYPES: BEGIN OF ty_detail,
         vbeln TYPE vbak-vbeln,
         erdat TYPE vbak-erdat,
         vdatu TYPE vbak-vdatu,
         sa_num TYPE vbpa-adrnr,
         sa_name TYPE adrc-name1,
         sa_city TYPE adrc-city1,
         sa_state TYPE adrc-region,
         sa_zip TYPE adrc-post_code1,
         sa_tel TYPE adrc-tel_number,
         ag_num TYPE vbpa-kunnr,
         ag_name TYPE kna1-name1,
         ag_street TYPE kna1-stras,
         ag_city TYPE kna1-ort01,
         ag_state TYPE kna1-regio,
         ag_zip TYPE kna1-pstlz,
         ag_tel TYPE kna1-telf1,
         ag_sales TYPE vbak-vkbur,
         we_num TYPE likp-kunnr,
         we_name TYPE kna1-name1,
         we_name2 TYPE kna1-name2,
         we_street TYPE kna1-stras,
         we_city TYPE kna1-ort01,
         we_state TYPE kna1-regio,
         we_zip TYPE kna1-pstlz,
         we_tel TYPE kna1-telf1,
       END OF ty_detail.

DATA: it_detail TYPE SORTED TABLE OF ty_detail WITH UNIQUE KEY vbeln sa_num ag_num we_num,
      wa_detail LIKE LINE OF it_detail.

DATA addressnum TYPE vbpa-adrnr.






**----------------------------------------------------------------------
* S E L E C T I O N - S C R E E N
**----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK required WITH FRAME TITLE text-002.
SELECT-OPTIONS:  s_vdatu FOR vbak-vdatu OBLIGATORY.    "Req delivery date
SELECTION-SCREEN END OF BLOCK required.

SELECTION-SCREEN BEGIN OF BLOCK temp WITH FRAME TITLE text-001.
SELECT-OPTIONS:  s_auart FOR vbak-auart OBLIGATORY.
PARAMETER:  p_parfun TYPE vbpa-parvw DEFAULT 'Z5' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK temp.

INITIALIZATION.
  REFRESH s_auart.
  CLEAR s_auart.
  s_auart-sign = 'I'.
  s_auart-option = 'EQ'.
  s_auart-low = 'OR'.
  APPEND s_auart.
  s_auart-low = 'ZDT'.
  APPEND s_auart.
**----------------------------------------------------------------------
* END OF SELECTION SCREEN
**----------------------------------------------------------------------

**----------------------------------------------------------------------
* M A I N - B O D Y
**----------------------------------------------------------------------
*Main select statement.
  SELECT a~vbeln a~erdat a~vdatu c~adrnr c~kunnr
      INTO TABLE it_detail
      FROM vbak AS a
        INNER JOIN vbap AS b
            ON b~vbeln = a~vbeln
        INNER JOIN vbpa AS c
            ON c~vbeln = b~vbeln
            AND c~posnr = b~posnr
                 WHERE a~auart IN s_auart
                 AND a~vdatu IN s_vdatu
                 AND c~parvw = p_parfun.


  LOOP AT it_detail INTO wa_detail.
    SELECT name1 street city1 region post_code1 tel_number
        FROM adrc INTO CORRESPONDING FIELDS OF wa_detail
        WHERE sa_num = adrc-addrnumber.
    ENDLOOP.

Regards,

Davis