Application Development 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: 

REGARDING SELECT

Former Member
0 Kudos

Hi experts,

is it feasible to use 4-5 select statements in a nested select statement.if no then what would be the alternative..i could not use join as well bcz i am using BSEG TABLE which is a cluster table..i am sending you the code.

when i try to execute it,it gives a short dump with error 'time limit exceeds'..plz solve it by giving right code

SELECT BUDAT BELNR FROM BKPF INTO (WBUDAT, WBELNR) WHERE BUDAT IN P_DATE.

SELECT BUKRS VBELN FROM VBRK INTO (WBUKRS, WVBELN) WHERE BUKRS = CMP_CD.

SELECT BUKRS BELNR KOART SHKZG DMBTR FROM BSEG INTO CORRESPONDING FIELDS OF ITAB

WHERE BUKRS = WBUKRS

AND BELNR = WBELNR

AND LIFNR IN VENDOR.

SELECT NAME1 ORT01 PSTLZ STRAS FROM LFA1 INTO (ITAB-NAME1,ITAB-ORT01,ITAB-PSTLZ,ITAB-STRAS) WHERE LIFNR = ITAB-LIFNR.

SELECT VBELN FROM VBRK INTO ITAB-VBELN WHERE BUKRS = ITAB-BUKRS.

APPEND ITAB.

ENDSELECT.

ENDSELECT.

ENDSELECT.

ENDSELECT.

ENDSELECT.

LOOP AT ITAB.

WRITE:/ ITAB-NAME1,ITAB-ORT01,ITAB-VBELN,ITAB-BELNR.

ENDLOOP.

regards,

raman.

5 REPLIES 5

Former Member
0 Kudos

Hi Joshi,

Can you please tell me..what is the exactly data do you want to fetch.Why are you using BSEG table.

Regards

Azad.

0 Kudos

hi Azad,

i need to fetch BUKRS BELNR KOART SHKZG DMBTR from bseg

Former Member
0 Kudos

please it is not suggestable for 4-5 level of nested select in that case do like this

you can use for all entries in this case ....

" SELECT command  

The select command is the most fundamental function of writing ABAP programs allowing the retrieval ofdata from SAP database tables. Below are a few examples of the various ways of selecting data.


*Code to demonstrate select command
*Code to demonstrate select into internal table command
TYPES: BEGIN OF t_bkpf,
*  include structure bkpf.
  bukrs LIKE bkpf-bukrs,
  belnr LIKE bkpf-belnr,
  gjahr LIKE bkpf-gjahr,
  bldat LIKE bkpf-bldat,
  monat LIKE bkpf-monat,
  budat LIKE bkpf-budat,
  xblnr LIKE bkpf-xblnr,
  awtyp LIKE bkpf-awtyp,
  awkey LIKE bkpf-awkey,
 END OF t_bkpf.
DATA: it_bkpf TYPE STANDARD TABLE OF t_bkpf INITIAL SIZE 0,
      wa_bkpf TYPE t_bkpf.

TYPES: BEGIN OF t_bseg,
*include structure bseg.
  bukrs     LIKE bseg-bukrs,
  belnr     LIKE bseg-belnr,
  gjahr     LIKE bseg-gjahr,
  buzei     LIKE bseg-buzei,
  mwskz     LIKE bseg-mwskz,         "Tax code
  umsks     LIKE bseg-umsks,         "Special G/L transaction type
  prctr     LIKE bseg-prctr,         "Profit Centre
  hkont     LIKE bseg-hkont,         "G/L account
  xauto     LIKE bseg-xauto,
  koart     LIKE bseg-koart,
  dmbtr     LIKE bseg-dmbtr,
  mwart     LIKE bseg-mwart,
  hwbas     LIKE bseg-hwbas,
  aufnr     LIKE bseg-aufnr,
  projk     LIKE bseg-projk,
  shkzg     LIKE bseg-shkzg,
  kokrs     LIKE bseg-kokrs,
 END OF t_bseg.
DATA: it_bseg TYPE STANDARD TABLE OF t_bseg INITIAL SIZE 0,
      wa_bseg TYPE t_bseg.


*Select directly into an internal table
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
       dmbtr mwart hwbas aufnr projk shkzg kokrs
  FROM bseg
  INTO TABLE it_bseg.


* Select directly into an internal table where fields are in a
* different order or not all fields are specified 
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
       dmbtr mwart hwbas aufnr projk shkzg kokrs
  FROM bseg
  INTO CORRESPONDING FIELDS OF TABLE it_bseg.


*Select... endselect command
SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
       dmbtr mwart hwbas aufnr projk shkzg kokrs
  FROM bseg
  INTO wa_bseg.

  APPEND wa_bseg TO it_bseg.
ENDSELECT.


*Select FOR ALL ENTRIES command
SELECT bukrs belnr gjahr bldat monat budat xblnr awtyp awkey
  UP TO 100 ROWS
  FROM bkpf
  INTO TABLE it_bkpf.

IF sy-subrc EQ 0.
* The FOR ALL ENTRIES comand only retrieves data which matches
* entries within a particular internal table.
  SELECT bukrs belnr gjahr buzei mwskz umsks prctr hkont xauto koart
         dmbtr mwart hwbas aufnr projk shkzg kokrs
    FROM bseg
    INTO TABLE it_bseg
    FOR ALL ENTRIES IN it_bkpf
    WHERE bukrs EQ it_bkpf-bukrs AND
          belnr EQ it_bkpf-belnr AND
          gjahr EQ it_bkpf-gjahr.
ENDIF.

reward points if it is usefull.......

Girish

Former Member
0 Kudos

Hi,

when we r using cluster table like bseg then we can join by using for all entries option instead of nested select.

Thanks

Sudha

Former Member
0 Kudos

hi Prakash

u can make use of read statement instead of several select statements

regards

gaurav

plz reward if helpful