Skip to Content

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

internal table

Hi,

My internal table having 4 fileds.

ITAB

F1 f2 f3 f4

a1 b1 c1 d1

a1 b12 c13 d1

a1 b22 c23 d1

b1 b3 c3 d3

b1 b32 c33 d3

b1 b32 c34 d3

I need internal table as

F1 f2 f3 f4

a1 b1 c1

a1 b12 c13

a1 b22 c23 d1

b1 b3 c3

b1 b32 c33

b1 b32 c34 d3

Here I want to change column

Tags:
Former Member
Former Member replied

Hi Asha SAP,

Try this.

TYPES : BEGIN OF TYP_itab,
          F1(3),
          F2(3),
          F3(3),
          F4(3),
        END   OF TYP_itab.

DATA : GT_itab TYPE STANDARD TABLE OF TYP_itab,
       GW_itab TYPE TYP_itab,
       V_F4   TYPE TYP_itab-F4,
       V_INDEX TYPE I.

START-OF-SELECTION.
  GW_itab-F1 = 'a1'.
  GW_itab-F2 = 'b1'.
  GW_itab-F3 = 'c1'.
  GW_itab-F4 = 'd1'.
  APPEND GW_itab TO GT_itab.

  GW_itab-F1 = 'a1'.
  GW_itab-F2 = 'b12'.
  GW_itab-F3 = 'c13'.
  GW_itab-F4 = 'd1'.
  APPEND GW_itab TO GT_itab.

  GW_itab-F1 = 'a1'.
  GW_itab-F2 = 'b22'.
  GW_itab-F3 = 'c23'.
  GW_itab-F4 = 'd1'.
  APPEND GW_itab TO GT_itab.

  GW_itab-F1 = 'b1'.
  GW_itab-F2 = 'b3'.
  GW_itab-F3 = 'c3'.
  GW_itab-F4 = 'd3'.
  APPEND GW_itab TO GT_itab.

  GW_itab-F1 = 'b1'.
  GW_itab-F2 = 'b32'.
  GW_itab-F3 = 'c33'.
  GW_itab-F4 = 'd3'.
  APPEND GW_itab TO GT_itab.

  GW_itab-F1 = 'b1'.
  GW_itab-F2 = 'b32'.
  GW_itab-F3 = 'c34'.
  GW_itab-F4 = 'd3'.
  APPEND GW_itab TO GT_itab.

  WRITE : /5 'Before processing :'.
  SKIP 1.
  LOOP AT GT_itab INTO GW_itab.
    WRITE : /10 SY-TABIX,
                GW_itab-F1,
                GW_itab-F2,
                GW_itab-F3,
                GW_itab-F4.
  ENDLOOP.


  LOOP AT GT_itab INTO GW_itab.
    IF SY-TABIX = 1.
      V_F4 = GW_itab-F4.
      CONTINUE.
    ENDIF.
    IF V_F4 = GW_itab-F4.
      V_INDEX = SY-TABIX - 1.
      CLEAR GW_itab-F4.
      MODIFY GT_itab FROM GW_itab INDEX V_INDEX TRANSPORTING F4.
    ELSE.
      V_F4 = GW_itab-F4.
    ENDIF.
  ENDLOOP.

  SKIP 10.

  WRITE : /5 'After processing :'.
  SKIP 1.
  LOOP AT GT_itab INTO GW_itab.
    WRITE : /10 SY-TABIX,
                GW_itab-F1,
                GW_itab-F2,
                GW_itab-F3,
                GW_itab-F4.
  ENDLOOP.

Regards,

R.Nagarajan.

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