Skip to Content

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Oct 13, 2008 at 03:30 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 13, 2008 at 03:31 AM

    REFRESH lt_tmp_mchb.

    lt_tmp_mchb[] = tt_mchb[].

    Prior to moving the contents of tt_mchb[] to it_tmp_mchp[].Refresh clears the contents of it_tmp_mchp[] if it contains any data such as initial values or temporary data.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 13, 2008 at 03:26 AM

    Hi,

    Welcome to SDN,

    Refresh Statement Refreshes the Internal table data ( content of hte internal Table).

    DELETE ADJACENT DUPLICATES deletes the duplicate entries from the internal table on the basis of matnr werks

    Thanks,

    Chidanand

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 13, 2008 at 03:46 AM

    Hi,

    RERFRESH clears the internal table body contents,

    In your code

    First lt_tmp_mchb is used to fill internal tables ts_mara, ts_makt.

    Then the contents of the internal table lt_tmp_mchb is cleared with REFRESH statement.

    And then again same internal table is fill with the contents of tt_mchb.

    Regards

    Bala Krishna

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 13, 2008 at 08:40 AM

    Thanks for all the explanations, everyone. Appreciate it.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.