*&---------------------------------------------------------------------*
*& Report ZBC400_22_ITAB
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBC400_22_ITAB.
"BEST PRACTICE TO DECLARE TYPE FIRST
"THEN ONLY ASSIGN THE TYPE TO EITHER STRUCTURE OR TABLE
"TYPE TABLE OF <<<< KEY WORD TO CREATE AN INTERNAL TABLE
"THEN FOLLOWED BY
"LIKE LINE OF <<<< KEY WORD TO CREATE A WORK AREA / STRUCTURE FOR THE TABLE
*defination of internal table
*TYPES : TY_FLIGHT TYPE SFLIGHT.
TYPES :
BEGIN OF TY_FLIGHT. "this is to include a table structure
INCLUDE STRUCTURE SFLIGHT. "this is to include a table structure
TYPES : "this extra type is due to the table being inserted
F1 TYPE C LENGTH 4,
F2 TYPE C LENGTH 4,
F3 TYPE SFLIGHT-FLDATE,
END OF TY_FLIGHT.
DATA: IT_FLIGHT TYPE TABLE OF TY_FLIGHT, "[[[ THIS IS THE INTERNAL TABLE BEING CREATED ]]]
WA_FLIGHT LIKE LINE OF IT_FLIGHT. " WA_FLIGHT TYPE TY_FLIGHT
"< DONT FOLLOW THE COMMENT THOUGH SAME
START-OF-SELECTION.
SELECT * INTO TABLE IT_FLIGHT FROM SFLIGHT. "MODIFY
LOOP AT IT_FLIGHT INTO WA_FLIGHT. "MODIFY
WA_FLIGHT-PRICE = '88.88'. "CHANGING TO STRUCTURE ONLY "MODIFY
MODIFY IT_FLIGHT INDEX SY-TABIX FROM WA_FLIGHT. "MODIFY
"MODIFY
ENDLOOP.
DELETE IT_FLIGHT WHERE CARRID = 'LH'. "DELETE
"APPEND WORKS ONLY FOR STANDARD DATA
CLEAR WA_FLIGHT. "APPEND
WA_FLIGHT-CARRID = 'LH'. "APPEND
WA_FLIGHT-CONNID = '8888'. "APPEND
WA_FLIGHT-FLDATE = '20111231'. "APPEND
APPEND WA_FLIGHT TO IT_FLIGHT. "APPEND
CLEAR WA_FLIGHT. "CLEAR TO ENSURE THE WA IS CLEAN
READ TABLE IT_FLIGHT INTO WA_FLIGHT WITH KEY CARRID = 'JL'. "READ AND ASSIGN TO WA_FLIGHT
IF SY-SUBRC = 0 . "DISPLAYED ASSIGNED WA_FLIGHT
WRITE: / 'ROW NUMBER=', SY-TABIX, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-CARRID, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-CONNID, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-FLDATE. "DISPLAYED ASSIGNED WA_FLIGHT
ENDIF. "DISPLAYED ASSIGNED WA_FLIGHT
CLEAR WA_FLIGHT. "CLEAR TO ENSURE THE WA IS CLEAN
SORT IT_FLIGHT BY CARRID. "SORT IT_FLIGHT BY CARRID
LOOP AT IT_FLIGHT INTO WA_FLIGHT FROM SY-TABIX. "LOOP AND ASSIGN TO WA_FLIGHT BY INDEX
IF WA_FLIGHT-CARRID = 'LH'. "CONDITIONAL WHERE EQUAL TO LH
WRITE: / 'ROW NUMBER=', SY-TABIX, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-CARRID, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-CONNID, "DISPLAYED ASSIGNED WA_FLIGHT
WA_FLIGHT-FLDATE. "DISPLAYED ASSIGNED WA_FLIGHT
ENDIF.
ENDLOOP.
CHECK 1 = 1.
No comments:
Post a Comment