Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member202517
Participant

This blog explain you about writing the routine in transformation. There are many documents available on where to write the code, but this document explains about how to write the code.

Note: The data which is green color is the explanation. The final code will be at the bottom

Prerequisite information that are required are.

  1. Source. ( Here YDSO_9 is the source DSO)
  2. Key fields and the data field which is to be populated

Here YMAT_2 is the key field in the source DSO and the field that we need to populate to the target is YMAT_D5 (Data field)


Types: begin of ty_dso1,

/bic/YMAT_2 type /BIC/OIYMAT_2,

/bic/YMAT_D5 type /BIC/OIYMAT_D5,

end of ty_dso1.

In the above we took /bic/YMAT_2 as type of /BIC/OIYMAT_2. To know the Data element of an infoobject, open the object and we can find the data element as show below


Now we are declaring Internal Table and Work Area. Here I have considered IT_Tab1 for defining Internal Table.

Note: Many people use different naming conventions. So please don’t get confused while reading the Internal table or Work Areas.

data: it_tab1 type standard table of ty_dso1,

       wa_tab1 type ty_dso1.

if result_package[] is not initial.


At the below we need to select the required fields from the Active table of source DSO(Source DSO here is YDSO_9).

If you are not sure about the Active table of your DSO. Please refer the below steps.

Go to manage of DSO Contents Tab. Once you Click on Active data you will be able to see the table as shown in the below screenshots.


select /bic/YMAT_2 /bic/YMAT_D5 from /bic/AYDSO_900 into corresponding fields of table it_tab1 for all entries in result_package where

/bic/YMAT_2 = result_package-/bic/YMAT_2.

Here we are populating the data to Internal Table IT_Tab1 from the source DSO YDSO_900 based on where condition.

If we are not sure about the field names to select from the Source DSO. Go to Se11 enter the name of

/BIC/ AYDSO_900 and we will get information about the fields

The active table name of a dso will be like this /BIC/ADSOName00.

Eg: /BIC/AYDSO_900. Replace YDSO_9 with your DSO Name


Here the condition is /bic/YMAT_2 = result_package-/bic/YMAT_2. Which will check the values of YMAT_2 of source DSO with YMAT_2 of Target DSO(Maximum here we will specify the Key fields.)

In some cases we may not have same objects in the lookup DSO and target infoproivder.

In this case we need to consider the similar object related to Key fields.

Example:

We have 0Doc_num in DSO and ZDOCNUM in the target infoprovider. Then we can use these 2 objects in the where conditions like as per below

select 0doc_num /bic/YMAT_D5 from /bic/AYDSO_900 into corresponding fields of table it_tab1 for all entries in result_package where

doc_num = result_package-/bic/ZDOCNUM.

if sy-subrc = 0.

sort it_tab1 by /bic/YMAT_2.

  1. endif.
  2. endif.

loop at result_package assigning <result_fields>.

Now we need to populate the data to Workarea from Internal table. The below Read statement read data from Internal table and will populate the data to WA based on the Key fields.

  read table it_tab1 into wa_tab1 with key

  /bic/YMAT_2 = <result_fields>-/bic/YMAT_2 binary search.

Now WA holds the data which has to be populated to result fields of YMAT_D5. The below statement populate the data to result fields

  if sy-subrc = 0.

    <result_fields>-/bic/YMAT_D5 = wa_tab1-/bic/YMAT_D5.

    endif.

    Endloop.

The final code will be


Types : begin of ty_dso1,

/bic/YMAT_2 type /BIC/OIYMAT_2,

/bic/YMAT_D5 type /BIC/OIYMAT_D5,

end of ty_dso1.

data: it_tab1 type standard table of ty_dso1,

wa_tab1 type ty_dso1.

if result_package[] is not initial.

select /bic/YMAT_2 /bic/YMAT_D5 from /bic/AYDSO_900 into corresponding fields of table it_tab1 for all entries in result_package where

/bic/YMAT_2 = result_package-/bic/YMAT_2.

if sy-subrc = 0.

sort it_tab1 by /bic/YMAT_2.

endif.

endif.

loop at result_package assigning <result_fields>.

  read table it_tab1 into wa_tab1 with key

  /bic/YMAT_2 = <result_fields>-/bic/YMAT_2 binary search.

  if sy-subrc = 0.

<result_fields>-/bic/YMAT_D5 = wa_tab1-/bic/YMAT_D5.

endif.

endif.

endloop.

3 Comments
Labels in this area