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
Address
================================================================================================
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.
endloop.
c_t_data[] = c_t_data2[]. // step no : 5
endif.
===============================================================
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.
endloop.
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,
RaviChandra