Skip to Content

abap code explanation related to ds enhancement.

Hi all ,

This blog explain the DS Enhancement. In this blog , i just concentrated on ABAP code with a simple example. and i don’t explain how to append the field for the ds and navigation step because there are many articles present in the scn forums related to ds enhancement.

Let me explain the scenario , i have a ds with the fields  rno , name , address . and a table with fields rno and branch.

Now i have to append that ds by adding the field branch .

Datasource ( person_ds)                          Table ( Person )

Rno                                                          Rno

Name                                                       Branch



The below is the code

types : begin of ty_person,

            rno type n ,                                //here rno is the common field .

            branch type c ,                          // and branch is the field which we want to append.

          end of ty_person.

data it_per type table of ty_person.

data is_per type ty_person.                                                   //  step no : 1

data c_t_data2  type table of <extractstructure>.

field-symbol  <wa> type <extractstructure>.

c_t_data2[] = c_t_data[].                                                    // step no : 2

select * from person into table it_per

                                                      for all entries in c_t_data2

                                                      with key rno = c_t_data2-rno    // step no : 3

loop at c_t_data2 assigning <wa>.           //step no : 4

read table it_per into is_per with key rno = <wa>-rno.

<wa>-branch = is_per-branch. 


c_t_data[] = c_t_data2[].             // step no : 5



Explanation for the above program :


1) First we have to create the structure , and in that structure we have to include the common field and the field that needs to be appended( here in this case the appending field is branch and the common field is rno ).

then create the internal table and work area.

2) We have to copy the data from c_t_data into c_t_data2 , because we can’t perform any operation directly on the c_t_data standard parameters.

3)  select * from person into table it_per

                                                      for all entries in c_t_data2

                                                      with key rno = c_t_data2-rno.

The above statement  fills the table it_per with the condition for all entries in c_t_data2.

for all entries :-   Enables you to create a join between an internal table and a database table based on the condition ( here in the above case the condition is rno ) .

4) loop at c_t_data2 assigning <wa>.

         read table it_per into is_per with key rno = <wa>-rno.

          <wa>-branch = is_per-branch.   // this is the statement where the appended field will be populated.  


The above is the most important statement which we see in every enhancement code.

now the statement

loop at c_t_data2 assigning <wa> .          

whenever the above statement is executed, then it will place the one record present in the c_t_data2 into the wa.

So here for the first time loop execution, the following record is placed in the work area.

rno        name      address        branch


1       Ravi             Hyd             


read table it_per into is_per with key rno = <wa>-rno.

Since the value of <wa>-rno is 1 , the read statement will fetch the data  1   IT from the it_per internal table and places this record in the work area is_per. since the branch record is present in the work area is_per , we have to append the data by using the below statement.

<wa>-branch = is_per-branch.

<wa>-branch refers to the work area of the c_t_data2.

and is_per-branch refers to the work area of the it_per internal table.

so after the execution of this statement the first record will be appended as

Rno    Name       Address       Branch

1        Ravi          Hyd                IT             

2        Sunil        Wgl                    

and again the loop will be executed and the 2nd record will be appened and now all the records will be appended. and the output will be as shown below.

Rno     Name     Address          Branch

1          Ravi       Hyd       IT

2          Sunil      Wgl       IT          

and finally it will come out of the loop and now the appended field is enhanced with the data but this data is present in the c_t_data2 table . now we need to assign this data to the c_t_data table.

5) Now we are the assigning the data the data present in the c_t_data2 to the c_t_data table.

Please feel free to ask question, if you are facing troubles in the above coding part…….

Hope you got it,

Thanx & Regards,


You must be Logged on to comment or reply to a post.
  • Hi ravi,

    Good work.Till  now i did not find any blog explaining the abap code related to ds enhancement. Every article i refered just explain about how to append the field and and where to write the code but i think this is the first blog explaining about the abap code.

    thanx for sharing your valuable knowledge.

      • @Anand:

        You can use work area instead of field symbol also , but if you use the work area then there is disadvantage of loading performance, because the data from the internal table has to come to work area and then we have to perform the required operation and then we have to modify the records in the internal table , so if there exists some millions of records then it will degrade the loading performance as it has to bring each and every records and then apply the logic as per the requirement and then modify the records in the internal table . but if you use the field-symbol then data won’t come to the work area instead the data will be modified directly.

        Hope you got it,



  • Thanks for your efforts on this.

    Dont you think we need to sort the Table IT_PER with the keys used in reading the above. Although the Tables has been defined based out of the structure ty_person which has fields in that sequence but i think it would be better to sort it first .



    • Hi kamal,

      We can sort the itab and use the binary search operation to improve the performance. In this blog i concentrated on the basic rule for the ds enhancement.

  • Nice blog. Very useful for beginners. However I have a small doubt. Don’t we need to reassign the values from the <wa>-branch to c_t_data2. I understand <wa>-branch refers to the work area of the c_t_data2, but where is it moving to c_t_data2. Is it assumed ?

    I believe we still need to move/append the data in <wa>-branch to c_t_data2. Am I right ? Please advise.