Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

creating table in side a internal table by using identifier

Former Member
0 Likes
416

hi friends..

i need to create a table which consistes of more 3 sub tables as IDENTIFIERS..

so please try to help me by giving procedure with suitable examples..

its too urgent for me

i need to submit by monday morning..

thanks in advance

kranthi

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
387

Hello

I assume you need to understand how complex itabs are handled. I try to give an example using the following standard tables:

KNB1 (customer) -> has n records in KNVV (sales areas per customer)


TYPES: BEGIN OF ty_s_data.
TYPES: kunnr            TYPE kunnr.
TYPES  salesarea      TYPE STANDARD TABLE OF knvv.
TYPES: END OF ty_s_data.
TYPES: ty_t_data       TYPE STANDARD TABLE ty_s_data
                                 WITH DEFAULT KEY.

DATA:
  gt_list           TYPE ty_s_data,
  gs_list           TYPE ty_s_list.


  SELECT * FROM knb1 INTO TABLE gt_knb1.
  SELECT * FROM knvv INTO TABLE gt_knvv
    FOR ALL ENTRIES IN gt_knb1
    WHERE kunnr = gt_knb1-kunnr.

  LOOP AT gt_knb1 INTO gs_knb1.
    CLEAR: gs_list.
    gs_list-kunnr = gs_knb1-kunnr.

    LOOP AT gt_knvv INTO gs_knvv
              WHERE ( kunnr = gs_knb1-kunnr ).
      APPEND gs_knvv TO gs_list-salesarea.
    ENDLOOP.

  ENDLOOP.

Regards

Uwe

Read only

ian_maxwell2
Active Participant
0 Likes
387

There are many ways to do it, they key thing is just keeping your code well organized otherwise you'll get lost. Here is an example from one of my programs where I've got a table as part of another table and also inside that it has a data type that is a reference to another field.

Basically this peice of code is keeping a list of unique postal codes and a reference to the fields in the structure of another internal table that contain those values so that in a later part of the program I can do a mass update via this one to many relationship for each postal code (example, change all records with postal code X to now be postal code Y.

~Ian

Example type decleration:

Types:

begin of t_PostalCodeRef,

ref type ref to Z1CED_INB_CONFIG-ATWRT,

end of t_PostalCodeRef,

t_table_PostalCodeRef type table of t_PostalCodeRef with non-unique default key,

begin of t_PostalCode,

PostalCode type Z1CED_INB_CONFIG-ATWRT,

Refs type t_Table_PostalCodeRef,

end of t_PostalCode,

t_table_PostalCode type table of t_PostalCode with non-unique default key.

Example usage to populate:

field-symbols:

<PostalCode> type t_PostalCode.

data:

l_Tabix type sy-Tabix,

l_PostalCode type t_PostalCode,

l_PostalCodeRef type t_PostalCodeRef.

if ( ( l_Z1CED_INB_CONFIG-ATINN = 'OP' ) or

( l_Z1CED_INB_CONFIG-ATINN = 'OC ) ).

read table l_PostalCodes

assigning <PostalCode>

with key PostalCode = l_INB_CONFIG-ATWRT

binary search.

l_Tabix = sy-Tabix.

if ( sy-Subrc = 0 ).

clear l_PostalCodeRef.

get reference of l_INB_CONFIG-ATWRT into l_PostalCodeRef-Ref.

append l_PostalCodeRef to <PostalCode>-Refs.

else.

clear l_PostalCode.

l_PostalCode-PostalCode = l_INB_CONFIG-ATWRT.

clear l_PostalCodeRef.

get reference of l_INB_CONFIG-ATWRT into l_PostalCodeRef-Ref.

append l_PostalCodeRef to l_PostalCode-Refs.

insert l_PostalCode into l_PostalCodes index l_Tabix.

endif.

endif.

Example of usage to process:

loop at l_PostalCodes assigning <PostalCode>.

s_Tabix = s_Tabix + 1.

if ( s_Tabix > s_Count ).

s_Tabix = 1.

endif.

read table s_ADRPSTCODE

assigning <NewPostalCode>

index s_Tabix.

loop at <PostalCode>-Refs assigning <PostalCodeRef>.

assign <PostalCodeRef>-Ref->* to <PostalCodeValue>.

<PostalCodeValue> = <NewPostalCode>-PostalCode.

endloop.

endloop.