‎2007 Aug 22 9:25 PM
Hi Guys,
I have a strange requirement as stated below :
Kindly replace the following select statement by select single. I doubt if it is possible.
SELECT matnr
dgcl
INTO TABLE pt_dgtmd[]
FROM dgtmd
FOR ALL ENTRIES IN pt_matd[]
WHERE matnr = pt_matd-matnr.
IF sy-subrc = 0. ENDIF.
Appreciate with max points if any body could help at the earliest.
Regards,
Shankar
‎2007 Aug 22 9:28 PM
You have internal table
loop at pt_matd.
SELECT single matnr dgcl
INTO pt_dgtmd -> this is work area
FROM dgtmd
WHERE matnr = pt_matd-matnr.
if sy-subrc eq 0.
endif.
endloop.
Thanks
Seshu
‎2007 Aug 22 9:57 PM
You're selecting a group of records (into table pt_dgtmd) which join with another group of records (in pt_matd).
If you intend to select a single record, your source should also be a single record. If you must select the first one, you could do this:
CLEAR wa_dgtmd.
LOOP AT pt_matd.
SELECT SINGLE matnr dgcl
INTO wa_dgtmd
FROM dgtmd
WHERE matnr = pt_matd-matnr.
IF sy-subrc = 0.
EXIT.
ENDIF.
ENDLOOP.
IF NOT wa_dgtmd IS INITIAL.
" You've found your single record
ELSE.
" You didn't
ENDIF.
Regards.
One more thing, is matnr the primary key of dgtmd table? Because if not, you shouldn't be trying to use SELECT SINGLE, you could try SELECT...UP TO 1 ROWS instead.
Message was edited by:
Alejandro Bindi
‎2007 Aug 22 10:12 PM
Guys,
Thanks for your immediate replies. Since the table PT_MATD does not have an header line it is not possible to loop this table. Moreover this table is declared as types.
Please help.
Regards,
Shankar
‎2007 Aug 22 10:15 PM
Add commented code:
DATA: wa_matd LIKE LINE OF pt_matd. "<<< Added code
CLEAR wa_dgtmd.
LOOP AT pt_matd INTO wa_matd. "<<< Modified code
SELECT SINGLE matnr dgcl
INTO wa_dgtmd
FROM dgtmd
WHERE matnr = wa_matd-matnr. "<<< Modified code
IF sy-subrc = 0.
EXIT.
ENDIF.
ENDLOOP.
IF NOT wa_dgtmd IS INITIAL.
" You've found your single record
ELSE.
" You didn't
ENDIF.
Regards
‎2007 Aug 22 10:17 PM
you have internal table without header
then declare work area
data wt_matd like line of pt_matd.
data wt_dgtmd like line of pt_dgtmd.
loop at pt_matd into wa_matd.
SELECT single matnr dgcl
INTO TABLE wt_dgtmd
FROM dgtmd
WHERE matnr = wt_matd-matnr.
IF sy-subrc = 0.
ENDIF.
endloop.
Thanks
Seshu
‎2007 Aug 22 10:22 PM
Thanks buddy, I am not getting any syntax error.
Once the user comes back, let me give u more points.
Regards,
Shankar
‎2007 Aug 23 8:45 AM
I hope that you are aware that the original select would be the better choice than the loop select single.
‎2007 Aug 23 10:01 PM
Hi Boes,
The original select statement gives me the ABAP Run time dump.
Regards,
Shankar
‎2007 Aug 24 5:59 AM
Hi
Select Single is mainly used for validation perpouse , even it will get all the data from the database table
SELECT <b>single</b> matnr dgcl
INTO TABLE pt_dgtmd[]
FROM dgtmd
FOR ALL ENTRIES IN pt_matd
WHERE matnr = pt_matd-matnr.
IF sy-subrc = 0. ENDIF.
reward if usefull