Skip to Content

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

Newbie question on "refresh itab"

Dear forumers,

What does the sequence of these codes mean? More specifically, what does REFRESH do to lt_tmp_mchb and why is it needed here?

REFRESH lt_tmp_mchb.
lt_tmp_mchb[] = tt_mchb[].
DELETE ADJACENT DUPLICATES FROM lt_tmp_mchb COMPARING matnr werks.

Fuller code snippet:-

DATA: 
lt_tmp_mchb TYPE STANDARD TABLE OF ty_mchb WITH HEADER LINE,
lt_tmp_msku TYPE STANDARD TABLE OF ty_msku WITH HEADER LINE.

  IF r_n_spe = 'X'.
    SELECT matnr werks charg vfdat
        INTO TABLE tt_mcha
        FROM mcha
        WHERE werks IN s_werks
        AND vfdat BETWEEN sy-datum AND expire_within.
    SORT tt_mcha BY matnr werks charg.

    IF tt_mcha[] IS NOT INITIAL.
      SELECT matnr werks lgort charg clabs
          INTO TABLE tt_mchb
          FROM mchb
          FOR ALL ENTRIES IN tt_mcha
          WHERE matnr = tt_mcha-matnr
          AND   werks = tt_mcha-werks
          AND   lgort IN s_lgort
          AND   charg = tt_mcha-charg
          AND   lvorm <> 'X'.
      SORT tt_mchb BY matnr werks lgort charg.
    ENDIF.

    lt_tmp_mchb[] = tt_mchb[].
    DELETE ADJACENT DUPLICATES FROM lt_tmp_mchb COMPARING matnr.

    IF lt_tmp_mchb[] IS NOT INITIAL.
      SELECT matnr bismt mhdrz meins matkl
          INTO TABLE ts_mara
          FROM mara
          FOR ALL ENTRIES IN lt_tmp_mchb
          WHERE matnr = lt_tmp_mchb-matnr
          AND matkl IN s_matkl.

      SELECT matnr maktx
          INTO TABLE ts_makt
          FROM makt
          FOR ALL ENTRIES IN ts_mara
          WHERE matnr = ts_mara-matnr
          AND spras = sy-langu.
    ENDIF.

    REFRESH lt_tmp_mchb.
    lt_tmp_mchb[] = tt_mchb[].
    DELETE ADJACENT DUPLICATES FROM lt_tmp_mchb COMPARING matnr werks.

    IF lt_tmp_mchb[] IS NOT INITIAL.
      SELECT matnr bwkey bwtar lbkum salk3
          INTO TABLE tt_mbew
          FROM mbew
          FOR ALL ENTRIES IN lt_tmp_mchb
          WHERE matnr = lt_tmp_mchb-matnr
          AND bwkey = lt_tmp_mchb-werks.
      SORT tt_mbew BY matnr bwkey bwtar.
    ENDIF.

    REFRESH lt_tmp_mchb.
    lt_tmp_mchb[] = tt_mchb[].
    DELETE ADJACENT DUPLICATES FROM lt_tmp_mchb
                                      COMPARING matnr werks lgort.

Tags:
Former Member
Former Member replied

Hi...

REFRESH ITAB or CLEAR ITAB[].

Both these statements to clear the contents of internal table body. As we know where CLEAR ITAB clears the contents of its header line.

In your case...

REFRESH lt_tmp_mchb.  <----- *lt_tmp_mchb* table body contents are deleted. So now its empty
lt_tmp_mchb[] = tt_mchb[]. <------- *lt_tmp_mchb* filled with the contents of *tt_mchb*. For this both itabs should have same structure
DELETE ADJACENT DUPLICATES FROM lt_tmp_mchb COMPARING matnr werks.<------ You are deleting the repeated entries in *lt_tmp_mchb* by comparing with those two fields.

Thanks,

Naveen.I

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question