2008 Jul 17 10:48 AM
HI Experts ,
i have an internal table which conatin some fields .one of the field itself a internal table ..
how can i access that compnent ....?
Thanks and Regards
Priyank Dixit
2008 Jul 17 11:12 AM
Hi,
here a short example:
TABLES: MARA, MAKT.
*
TYPES: BEGIN OF TY_ITAB1,
WERKS LIKE MARC-WERKS,
END OF TY_ITAB1.
*
DATA: WA_ITAB1 TYPE TY_ITAB1.
*
DATA: BEGIN OF ITAB0 OCCURS 0,
MATNR LIKE MARA-MATNR,
IT_ITAB1 TYPE TABLE OF TY_ITAB1,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB0.
*
SELECT * FROM MARA UP TO 10 ROWS.
ITAB0-MATNR = MARA-MATNR.
ITAB0-MAKTX = 'Test'.
CLEAR: ITAB0-IT_ITAB1[].
WA_ITAB1-WERKS = '1000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
WA_ITAB1-WERKS = '2000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
WA_ITAB1-WERKS = '3000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
APPEND ITAB0.
ENDSELECT.
*
LOOP AT ITAB0.
WRITE: / ITAB0-MATNR.
LOOP AT ITAB0-IT_ITAB1 INTO WA_ITAB1.
WRITE: WA_ITAB1-WERKS.
ENDLOOP.
WRITE: / ITAB0-MAKTX.
ENDLOOP.
Regards, Dieter
2008 Jul 17 10:49 AM
Hi,
Check this link:(Nested Internal Tables)
http://help.sap.com/saphelp_nw70/helpdata/en/9f/db9eaa35c111d1829f0000e829fbfe/content.htm
Regards
Adil
2008 Jul 17 10:56 AM
Hi Priyank,
Check this following sample code:
Formatting Data Using Nested Internal Tables
REPORT DEMO.
DATA: SUM TYPE I, CNT TYPE I.
NODES: SPFLI, SFLIGHT, SBOOK.
DATA: BEGIN OF WA_SBOOK,
BOOKID TYPE SBOOK-BOOKID,
SMOKER TYPE SBOOK-SMOKER,
CLASS TYPE SBOOK-CLASS,
LUGGWEIGHT TYPE SBOOK-LUGGWEIGHT,
WUNIT TYPE SBOOK-WUNIT,
END OF WA_SBOOK.
DATA: BEGIN OF WA_SFLIGHT,
FLDATE TYPE SFLIGHT-FLDATE,
SBOOK LIKE TABLE OF WA_SBOOK ,
END OF WA_SFLIGHT.
DATA: BEGIN OF WA_SPFLI,
CARRID TYPE SPFLI-CARRID,
CONNID TYPE SPFLI-CONNID,
CITYFROM TYPE SPFLI-CITYFROM,
CITYTO TYPE SPFLI-CITYTO,
SFLIGHT LIKE TABLE OF WA_SFLIGHT ,
END OF WA_SPFLI.
DATA TAB_SPFLI LIKE TABLE OF WA_SPFLI .
START-OF-SELECTION.
GET SPFLI.
REFRESH WA_SPFLI-SFLIGHT.
GET SFLIGHT.
REFRESH WA_SFLIGHT-SBOOK.
GET SBOOK.
MOVE-CORRESPONDING SBOOK TO WA_SBOOK.
APPEND WA_SBOOK TO WA_SFLIGHT-SBOOK.
GET SFLIGHT LATE.
MOVE-CORRESPONDING SFLIGHT TO WA_SFLIGHT.
APPEND WA_SFLIGHT TO WA_SPFLI-SFLIGHT.
GET SPFLI LATE.
MOVE-CORRESPONDING SPFLI TO WA_SPFLI.
APPEND WA_SPFLI TO TAB_SPFLI.
END-OF-SELECTION.
SORT TAB_SPFLI BY CITYFROM CITYTO CONNID.
LOOP AT TAB_SPFLI INTO WA_SPFLI.
SKIP.
WRITE: / WA_SPFLI-CARRID,
WA_SPFLI-CONNID,
'from', (15) WA_SPFLI-CITYFROM,
'to', (15) WA_SPFLI-CITYTO.
ULINE.
SORT WA_SPFLI-SFLIGHT BY FLDATE.
LOOP AT WA_SPFLI-SFLIGHT INTO WA_SFLIGHT.
SKIP.
WRITE: / 'Date:', WA_SFLIGHT-FLDATE.
WRITE: 20 'Book-ID', 40 'Smoker', 50 'Class'.
ULINE.
SORT WA_SFLIGHT-SBOOK BY CLASS SMOKER BOOKID.
SUM = 0.
CNT = 0.
LOOP AT WA_SFLIGHT-SBOOK INTO WA_SBOOK.
WRITE: / WA_SBOOK-BOOKID UNDER 'Book-ID',
WA_SBOOK-SMOKER UNDER 'Smoker',
WA_SBOOK-CLASS UNDER 'Class'.
SUM = SUM + WA_SBOOK-LUGGWEIGHT.
CNT = CNT + 1.
ENDLOOP.
ULINE.
WRITE: 'Number of bookings: ', (3) CNT,
/ 'Total luggage weight:',
(3) SUM, WA_SBOOK-WUNIT.
ENDLOOP.
ENDLOOP.
This program creates the same list as in the Example of Formatted Data.
During the GET events, the system reads the data into the three-level internal table SORT_SPFLI which contains the substructure SFLIGHT and its substructure SBOOK. The sorting process takes place on the individual nesting levels.
This way of programming does not require key relations between the internal tables (no WHERE conditions), but it is more complex than using flat internal tables. And the increased internal administration effort has a negative effect on the storage space required as well as on the runtime.
Hope this helps you.
Regards,
Chandra Sekhar
2008 Jul 17 11:02 AM
2008 Jul 17 11:03 AM
2008 Jul 17 11:12 AM
Hi,
here a short example:
TABLES: MARA, MAKT.
*
TYPES: BEGIN OF TY_ITAB1,
WERKS LIKE MARC-WERKS,
END OF TY_ITAB1.
*
DATA: WA_ITAB1 TYPE TY_ITAB1.
*
DATA: BEGIN OF ITAB0 OCCURS 0,
MATNR LIKE MARA-MATNR,
IT_ITAB1 TYPE TABLE OF TY_ITAB1,
MAKTX LIKE MAKT-MAKTX,
END OF ITAB0.
*
SELECT * FROM MARA UP TO 10 ROWS.
ITAB0-MATNR = MARA-MATNR.
ITAB0-MAKTX = 'Test'.
CLEAR: ITAB0-IT_ITAB1[].
WA_ITAB1-WERKS = '1000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
WA_ITAB1-WERKS = '2000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
WA_ITAB1-WERKS = '3000'. APPEND WA_ITAB1 TO ITAB0-IT_ITAB1.
APPEND ITAB0.
ENDSELECT.
*
LOOP AT ITAB0.
WRITE: / ITAB0-MATNR.
LOOP AT ITAB0-IT_ITAB1 INTO WA_ITAB1.
WRITE: WA_ITAB1-WERKS.
ENDLOOP.
WRITE: / ITAB0-MAKTX.
ENDLOOP.
Regards, Dieter
2008 Jul 17 11:13 AM