Skip to Content
0
Oct 13, 2008 at 03:20 AM

Newbie question on "refresh itab"

14 Views

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.