10-26-2007 9:31 AM
Hi Experts,
The below loop is appending blank in table aufnr_tab. What is wrong in it ?
Loop at lts_objnr.
SELECT SINGLE aufnr plnbez INTO CORRESPONDING FIELDS OF aufnr_tab
FROM caufv
where aufpl = lts_objnr-aufpl
AND AUTYP = '10'
AND LOEKZ <> 'X'
AND aufnr = '000001011267'.
aufnr_tab-aufnr = caufv-aufnr.
aufnr_tab-plnbez = caufv-plnbez.
Append aufnr_tab.
Endloop.
YAB
10-29-2007 2:05 PM
Yusuf,
You seem to be looking for just one specific record in table view CAUFV (where the order number AUFNR = 000001011267). Are you sure this is what you are looking to do? I believe that you might want to get rid of the clause '<b>AND aufnr = '000001011267'.</b>' If indeed you are just looking for one record I don't see why you need to retrieve it so many times (within a loop). For table view CAUFV, field AUFNR is the primary key. You are likely to get just one record with AUFNR = 000001011267.
I think your logic should be something like this.
TYPES: BEGIN OF ty_caufv,
aufpl TYPE caufv-aufpl,
aufnr TYPE caufv-aufnr,
plnbez TYPE caufv-plnbez,
END OF ty_caufv.
DATA: w_caufv TYPE ty_caufv,
lts_caufv TYPE SORTED TABLE OF ty_caufv
WITH NON-UNIQUE KEY aufpl,
lts_objnr_tmp LIKE TABLE OF lts_objnr.
IF NOT lts_objnr[] IS INITIAL.
lts_objnr_tmp[] = lts_objnr[].
SORT lts_objnr_tmp BY aufpl.
DELETE ADJACENT DUPLICATES FROM lts_objnr_tmp COMPARING aufpl.
SELECT aufpl
aufnr
plnbez
FROM caufv
INTO TABLE t_caufv
FOR ALL ENTRIES IN lts_objnr_tmp
WHERE autyp EQ '10'
AND loekz NE 'X'
AND aufpl EQ lts_objnr_tmp-aufpl.
ENDIF.
REFRESH aufnr_tab.
LOOP AT lts_objnr.
READ TABLE lts_caufv INTO w_caufv
WITH KEY aufpl = lts_objnr-aufpl.
IF sy-subrc EQ 0.
aufnr_tab-aufnr = w_caufv-aufnr.
aufnr_tab-plnbez = w_caufv-plnbez.
APPEND aufnr_tab.
ENDIF.
ENDLOOP.
10-26-2007 9:35 AM
Hi Yusuf,
Try This:
Loop at lts_objnr into wa_objnr.
SELECT SINGLE aufnr plnbez INTO CORRESPONDING FIELDS OF aufnr_tab
FROM caufv
where aufpl = wa_objnr-aufpl
AND AUTYP = '10'
AND LOEKZ <> 'X'
AND aufnr = '000001011267'.
if sy-subrc eq 0.
aufnr_tab-aufnr = caufv-aufnr.
aufnr_tab-plnbez = caufv-plnbez.
Append aufnr_tab.
endif.
Endloop.
Reward If Useful.
Regards,
Chitra
10-26-2007 9:36 AM
Try following Code...
SELECT aufnr plnbez INTO CORRESPONDING FIELDS OF aufnr_tab
FROM caufv
<b>for all entries in lts_objnr</b>
where aufpl = lts_objnr-aufpl
AND AUTYP = '10'
AND LOEKZ <> 'X'
AND aufnr = '000001011267'.
aufnr_tab-aufnr = caufv-aufnr.
aufnr_tab-plnbez = caufv-plnbez.
Append aufnr_tab.
ENDSELECT.
10-26-2007 9:44 AM
First of all using select within a loop is a vaery bad practice...
so remove dat by using FOR ALL Entries..
and remove the following lines from ur code..
aufnr_tab-aufnr = caufv-aufnr.
aufnr_tab-plnbez = caufv-plnbez.
put an END SELECT instead of dat after using FOR ALL ENTRIES..
This will solve ur query..
Reward all helpful answers
10-26-2007 10:25 AM
Yusuf,
The wrong thing is you should check sy-subrc and then do the appned.
Much better approach is declare an internal table & then use select for all entries with lts_objnr as the driver table.
-ashim
10-27-2007 6:57 AM
Hi YAB,
When you use CORRESPONDING FIELDS OF, you load the table directly. So what you are doing is loading a SINGLE record into aufnr_tab. I think caufv-aufnr and caufv-plnbez is an invalid reference because you retrieved your data into the table and not into caufv. So it is empty. then you append your header into your table which is a blank record. I think the way you coded it, your single record select will overwrite the previous record so you should end up with one record and one blank in your table.
To correct this it is better to use For All Entries rather than loop ITS_OBJNR because your SELECT single only brings back one record at a time. This is inefficient.
Here is the corrected code.
SELECT aufnr plnbez into table aufnr_tab
FROM caufv FOR ALL ENTRIES IN Its_objnr
where aufpl = Its_objnr-aufpl
and autyp = '10'
and loekz = space "use positive rather than negative condition
and aufnr = '000001011267'.
Your table aufnr_tab should have aufnr and plnbez as the first and second fields of the table. If this is not possible, you can use
SELECT aufnr plnbez INTO CORRESPONDING FIELDS OF aufnr_tab.
This is slightly less efficient than INTO TABLE aufnr_tab but ok.
Hope this helps.
Filler
10-27-2007 7:01 AM
Hi
if sy-subrc = 0.
Append aufnr_tab.
endif.
Regards
Navneet
10-29-2007 2:05 PM
Yusuf,
You seem to be looking for just one specific record in table view CAUFV (where the order number AUFNR = 000001011267). Are you sure this is what you are looking to do? I believe that you might want to get rid of the clause '<b>AND aufnr = '000001011267'.</b>' If indeed you are just looking for one record I don't see why you need to retrieve it so many times (within a loop). For table view CAUFV, field AUFNR is the primary key. You are likely to get just one record with AUFNR = 000001011267.
I think your logic should be something like this.
TYPES: BEGIN OF ty_caufv,
aufpl TYPE caufv-aufpl,
aufnr TYPE caufv-aufnr,
plnbez TYPE caufv-plnbez,
END OF ty_caufv.
DATA: w_caufv TYPE ty_caufv,
lts_caufv TYPE SORTED TABLE OF ty_caufv
WITH NON-UNIQUE KEY aufpl,
lts_objnr_tmp LIKE TABLE OF lts_objnr.
IF NOT lts_objnr[] IS INITIAL.
lts_objnr_tmp[] = lts_objnr[].
SORT lts_objnr_tmp BY aufpl.
DELETE ADJACENT DUPLICATES FROM lts_objnr_tmp COMPARING aufpl.
SELECT aufpl
aufnr
plnbez
FROM caufv
INTO TABLE t_caufv
FOR ALL ENTRIES IN lts_objnr_tmp
WHERE autyp EQ '10'
AND loekz NE 'X'
AND aufpl EQ lts_objnr_tmp-aufpl.
ENDIF.
REFRESH aufnr_tab.
LOOP AT lts_objnr.
READ TABLE lts_caufv INTO w_caufv
WITH KEY aufpl = lts_objnr-aufpl.
IF sy-subrc EQ 0.
aufnr_tab-aufnr = w_caufv-aufnr.
aufnr_tab-plnbez = w_caufv-plnbez.
APPEND aufnr_tab.
ENDIF.
ENDLOOP.