Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Record appending Blank in internal table....

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

Former Member
Former Member replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question