*&---------------------------------------------------------------------*
*& Report ZTAS_ITAB_OPERATIONS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTAS_ITAB_OPERATIONS.
* Data Type Declaration
TABLES: T001.
TYPES:BEGIN OF T_TY_ITAB,
BUKRS TYPE BUKRS, "Company Code
BUTXT TYPE BUTXT, "Company name
ORT01 TYPE ORT01, "City
LAND1 TYPE LAND1, "Country Key
END OF T_TY_ITAB.
DATA: ITAB TYPE TABLE OF T_TY_ITAB,
WA_ITAB TYPE T_TY_ITAB.
*Fetch data from the table T001 to Internal table
SELECT BUKRS BUTXT ORT01 LAND1 INTO TABLE ITAB FROM T001 WHERE LAND1 = 'DE'.
SORT ITAB DESCENDING BY BUKRS.
* Display Data
CLEAR:SY-INDEX.
LOOP AT ITAB INTO WA_ITAB .
* CLEAR:SY-INDEX.
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1),
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
* WRITE:SY-INDEX.
ENDLOOP.
WRITE:/ SY-ULINE(84).
*ADDING MORE RECORDS
CLEAR : WA_ITAB. "CLEAR CONTENTS OF WORK AREA
WA_ITAB-BUKRS = 'A100'.
WA_ITAB-BUTXT = 'INVINCIBLER'.
WA_ITAB-ORT01 = 'MUMBAI'.
WA_ITAB-LAND1 = 'IN'.
APPEND WA_ITAB TO ITAB.
*Display Data AFTER ADDING RECORD
WRITE : / 'AFTER APPENDING DATA TO INTERNAL TABLE' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1),
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
CLEAR : WA_ITAB. "CLEAR CONTENTS OF WORK AREA
WA_ITAB-BUKRS = 'B100'.
WA_ITAB-BUTXT = 'LITTLEMASTER'.
WA_ITAB-ORT01 = 'DELHI'.
WA_ITAB-LAND1 = 'IN'.
INSERT WA_ITAB INTO ITAB INDEX 10. " INDEX 10 MEANS THE RECORD IS INSERTED AT 10 TH POSITION IN THE TABLE
* Display Data AFTER ADDING RECORD
WRITE : / 'AFTER INSERTING DATA TO INTERNAL TABLE' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
* DELETING DATA FROM INTERNAL TABLE
DELETE ITAB FROM 6 TO 9.
* SKIP 1. " specifies No of blank line
* DISPLAY DATA AFTER DELETING
WRITE : / 'AFTER DELETING DATA FROM INTERNAL TABLE' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
* MODIFICATION
CLEAR :WA_ITAB.
WA_ITAB-LAND1 = 'US'.
MODIFY ITAB FROM WA_ITAB TRANSPORTING LAND1 WHERE BUKRS = 'A100' OR BUKRS = 'B100'.
WRITE : / 'AFTER MODIFICATION DATA FROM INTERNAL TABLE' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
* READ INTERNAL TABLE
SORT ITAB DESCENDING BY BUKRS.
CLEAR :WA_ITAB.
READ TABLE ITAB INTO WA_ITAB WITH KEY LAND1 = 'US' BINARY SEARCH.
WRITE : / 'DATA AFTER READ' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
* DELETE ADJACENT DUPLICATES
CLEAR:WA_ITAB.
WA_ITAB-BUKRS = 'C100'.
WA_ITAB-BUTXT = 'MASTERBLASTER'.
WA_ITAB-ORT01 = 'CHENNAI'.
WA_ITAB-LAND1 = 'IN'.
DO 3 TIMES.
APPEND WA_ITAB TO ITAB.
ENDDO.
WRITE : / 'DATA AFTER ADDING DUPLICATES' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).
SORT ITAB BY BUKRS. " SORT IS MANDATORY TO PERFORM ADJCENT DUPLICATES
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING BUKRS.
WRITE : / 'DATA AFTER ADJACENT DUPLICATES' COLOR 5.
LOOP AT ITAB INTO WA_ITAB .
WRITE :/ SY-ULINE(84). " ULINE DRAWS THE HORIZANTAL LINE , VLINE DRAWS VERTICAL LINE
WRITE: / SY-VLINE(1),SY-TABIX,SY-VLINE(1), " SY-TABIX FINDS THE CURRENT LINE IN THE INTERNAL TABLE
WA_ITAB-BUKRS,SY-VLINE(1),
WA_ITAB-BUTXT,SY-VLINE(1),
WA_ITAB-ORT01,SY-VLINE(1),
WA_ITAB-LAND1,SY-VLINE(1).
ENDLOOP.
WRITE:/ SY-ULINE(84).