Skip to Content

BAdi are Business Add-Ins which allows us to define the user requirement using ABAP. Creation of partitions on SPO based on BAdi helps us to define dynamic partitions. Standard BAdi RSLPO_BADI_PARTITIONING is used to create partitions for SPO. Using this standard BAdi an enhancement implementation can be created and multiple logics can be added in the same implementation. 

Scenario

Master data 0REGION is maintained by business. Semantic partitioned object is created with partitions based on 0REGION. If the total no. of regions are more, each partition has to be manually defined which is tedious. Also every time if a new region is introduced, a new partition has to be created manually in the SPO or if any region is removed, the partition has to be manually deleted.

If partitions of SPO are created using BAdi, then creation of numerous partitions can be automated and addition/deletion/updating partition also becomes easier. Once the partitions are created using BAdi and if there is any change in master data then, the only task to be performed is activation of SPO based on BAdi using transaction RSLPO_MASS_ACT. Activation process can be performed on regular intervals in production system if required.

Steps to create partition

Create a New BAdi to generate partition criteria using trasaction code SE19.

Give the name of enhancement spot as RSLPO_BADI_PARTITIONING

create_impl.JPG

Give the name of the enhancement implementation and short text

create_enh_impl.JPG

Click continue and save

Now give the name of the BAdi implementation, implementation class and specify the standard BAdi definition as RSLPO_BADI_PARTITIONING and click continue and save

create_impl.JPG

After saving the below screen appears:

create_impl.JPG

Double click the implementation class in the left pane

create_impl.JPG

The 5 methods of the class ZCL_DEMO_BADI_PARTITION which can be used to define the partitions are displayed in right pane.

Each method have a specific role to play.

Double click the method IF_RSLPO_BADI_PARTITIONING~GET_T_SPO

create_impl.JPG

To create implementation click on Yes and then following screen will be displayed.

create_impl.JPG

Specify the code to assign the name of the SPO in the method GET_T_SPO.

method IF_RSLPO_BADI_PARTITIONING~GET_T_SPO.
 
DATA:
        l_spo
TYPE rslponame.
  l_spo
= ‘Z_DEMO’.
 
APPEND l_spo TO r_t_spo.

endmethod.

create_impl.JPG

Save and activate the method and the class.

Similarly specify the code in other methods

IF_RSLPO_BADI_PARTITIONING~GET_T_PART specifies the partition id and position of the partition for the SPO.

method IF_RSLPO_BADI_PARTITIONING~GET_T_PART.
 
DATA:
        l_cnt
TYPE i,
        l_posit
TYPE i VALUE 1,
        l_id
TYPE c LENGTH 2,
        l_s_part      
TYPE rslpo_badi_s_part.
 
 
IF i_spo = ‘Z_DEMO’.

    SELECT COUNT(*) FROM /BI0/TREGION INTO l_cnt WHERE REGION NE .

    IF l_cnt NE 0.
     
WHILE l_posit LE l_cnt.

        UNPACK l_posit to l_id.
        l_s_part
idpart = l_id.

        l_s_partposit  = l_posit.

        APPEND l_s_part TO r_t_part.
        l_posit
= l_posit + 1 .

      ENDWHILE.

    ENDIF.

IF_RSLPO_BADI_PARTITIONING~GET_T_PART_TEXT specifies the text that should be assigned to each partition against the corresponding partition id.

Below code will automatically create partition based on the text table of the master data.

In this eg partitions are based on 0REGION info-object. Hence the Master data maintenance for 0REGION should be done beforehand.

method IF_RSLPO_BADI_PARTITIONING~GET_T_PART_TEXT.
   
DATA:
          l_posit
TYPE i VALUE 1,
          l_cnt
TYPE i,
          l_id
TYPE c LENGTH 2,
          l_it_region
TYPE TABLE OF /BI0/TREGION,
          l_wa_region
TYPE /BI0/TREGION,
          l_s_part_text 
TYPE rslpo_badi_s_part_text.

    IF i_spo = ‘Z_DEMO’.

    SELECT COUNT(*) FROM /BI0/TREGION INTO l_cnt WHERE REGION NE .

    IF l_cnt NE 0.
     
SELECT * FROM /BI0/TREGION INTO CORRESPONDING FIELDS OF TABLE l_it_region.

      LOOP AT l_it_region INTO l_wa_region.

        UNPACK l_posit to l_id.
        l_s_part_text
idpart = l_id.

        l_s_part_textlangu = ‘E’.

        MOVE l_wa_regiontxtsh TO l_s_part_texttxtlg .

        APPEND l_s_part_text TO r_t_part_text.
        l_posit
= l_posit + 1 .

      ENDLOOP.

    ENDIF.

  ENDIF.endmethod.

IF_RSLPO_BADI_PARTITIONING~GET_T_PART_CRIT specifies the criteria of partition.

Below code will automatically create partition based on the text table of the master data. Object name iobjnm is used to get the field on which the partition has to be applied.

method IF_RSLPO_BADI_PARTITIONING~GET_T_PART_CRIT.

  DATA:
        l_posit
TYPE i VALUE 1,
        l_id
TYPE c length 2,
        l_cnt
TYPE i,
        l_it_region
TYPE TABLE OF /BI0/TREGION,
        l_wa_region
TYPE /BI0/TREGION,
        l_s_part_crit 
TYPE rslpo_badi_s_part_crit.

  IF i_spo = ‘Z_DEMO’.

    l_s_part_critiobjnm = ‘0REGION’.
    l_s_part_crit
opt    = ‘EQ’.

    SELECT COUNT(*) FROM /BI0/TREGION INTO l_cnt WHERE REGION NE .

    IF l_cnt NE 0.
     
SELECT * FROM /BI0/TREGION INTO CORRESPONDING FIELDS OF TABLE l_it_region.

      LOOP AT l_it_region INTO l_wa_region.

        UNPACK l_posit to l_id.
        l_s_part_crit
idpart = l_id.

        MOVE l_wa_regionregion TO l_s_part_critlow .

        l_s_part_critposit = l_posit .

        APPEND l_s_part_crit TO r_t_part_crit.
        l_posit
= l_posit + 1 .

      ENDLOOP.

    ENDIF.

  ENDIF.endmethod.

IF_RSLPO_BADI_PARTITIONING~GET_T_PART_DTP specifies the filter to be used in DTP.

Input specifications like the name of the DTP template, Object name objnm is used to to specify the source of the SPO. If it is a datasource, then source system also needs to be assigned. Tlogo refers to the type of source used in SPO.

method IF_RSLPO_BADI_PARTITIONING~GET_T_PART_DTP.

  DATA:
        l_posit
TYPE i VALUE 1,
        l_cnt
TYPE i,
        l_id
TYPE c LENGTH 2,
        l_s_part_dtp
type rslpo_badi_s_part_dtp.

  IF i_spo = ‘Z_DEMO’.

    SELECT COUNT(*) FROM /BI0/TREGION INTO l_cnt WHERE REGION NE .

      IF l_cnt NE 0.
        l_s_part_dtp
dtptemplate = ‘Demo Template’.
        l_s_part_dtp
objnm = ‘ZDS_DEMO’.
        l_s_part_dtp
logsys = ‘PC_FILE’.
        l_s_part_dtp
tlogo = ‘RSDS’.

        WHILE l_posit LE l_cnt.

          UNPACK l_posit to l_id.
          l_s_part_dtp
idpart = l_id.

          APPEND l_s_part_dtp TO r_t_part_dtp.
          l_posit
= l_posit + 1 .

        ENDWHILE.

      ENDIF.
 
ENDIF.endmethod.

Once all the method definitions are given, activate the Enhancement Implementation.

The SPO can be created now

On clicking Maintain partition, check Get chars from BAdi. The partition field will automatically get assigned

create_impl.JPG

create_impl.JPG

create_impl.JPG

Once partitions are activated and DTP is to be created.In the DTP generation screen, select the appropriate DTP template from right pane and all the partitioned object as shown below and finally click BAdi version.create_impl.JPG

Once the DTP gets created, click on Generate. The filter of the DTP will be directly assigned as per the partitions based on BAdi.

Once the new region is generated and Master data maintenance is done, goto RSA1 and click Mass Activation of BAdi SPOs or directly use program/transaction RSLPO_MASS_ACT.

create_impl.JPG

create_impl.JPG

On executing the activation of SPO, new partition and the corresponding part provider will automatically be created. However the DTP has to be created.

create_impl.JPG

If a region is deleted from the master data and SPO is activated, the corresponding part provider and its data flow will be removed from the SPO automatically. However, if the process chain exists with that DTP, then the inactive DTP should be removed from process chain.

create_impl.JPG

create_impl.JPG

If a partition is changed, then the partition and also the DTP will automatically get updated. Once the DTP with the changed filter value is executed, then requests from the previous filter criteria will be deleted automatically and the new request with the new filter criteria will be added in the SPO.

If there is a requirement to manage the code such that the partitions already created are not getting re-created simply because of the change in the partition id when a new partition is added in between the list or if it has to be deleted from somewhere in between.

Create a include program which will send the partition details to a transparent table and access the partition details in all 5 methods from the custom table instead of text table of master data. The custom table should have id, region, text, flag as fields. This inclued can be called only once in the first method GET_T_SPO.

The code for the include program will be:

   DATA:
        l_posit TYPE i VALUE 1,
        l_id TYPE c LENGTH 2,
        l_cnt TYPE i,
        l_zcnt TYPE i,
        l_it_zregion TYPE TABLE OF ztregion,
        l_wa_zregion TYPE ztregion,
        l_it_region TYPE TABLE OF /bi0/tregion,
        l_wa_region TYPE /bi0/tregion.

SELECT COUNT(*) FROM /bi0/tregion INTO l_cnt WHERE region NE .
SELECT COUNT(*) FROM ztregion INTO l_zcnt .

IF l_cnt NE 0 AND l_zcnt EQ 0 .
  SELECT * FROM /bi0/tregion INTO CORRESPONDING FIELDS OF TABLE l_it_region.

  LOOP AT l_it_region INTO l_wa_region.

    MOVE l_wa_regionregion TO l_wa_zregionregion .
    MOVE l_wa_regiontxtsh TO l_wa_zregiontxtsh .
    l_wa_zregionid = l_posit .
    APPEND l_wa_zregion TO l_it_zregion.
    l_posit = l_posit + 1 .

  ENDLOOP.

  LOOP AT l_it_zregion INTO l_wa_zregion.
    INSERT INTO ztregion VALUES l_wa_zregion.
  ENDLOOP.

ENDIF.

IF l_cnt NE 0 AND l_zcnt NE 0 .
  SELECT * FROM /bi0/tregion INTO CORRESPONDING FIELDS OF TABLE l_it_region.
  SELECT * FROM ztregion INTO CORRESPONDING FIELDS OF TABLE l_it_zregion.

  READ TABLE l_it_zregion INTO l_wa_zregion INDEX l_zcnt.
  l_posit = l_wa_zregionid .
  CLEAR l_wa_zregion.
  FIELD-SYMBOLS : <l_wa_zregion> TYPE ztregion.
  LOOP AT l_it_region INTO l_wa_region.

    READ TABLE l_it_zregion ASSIGNING <l_wa_zregion> WITH KEY region = l_wa_regionregion.
    IF sysubrc EQ 0.
      IF <l_wa_zregion> IS ASSIGNED.
        <l_wa_zregion>txtsh = l_wa_regiontxtsh.
        <l_wa_zregion>flag = ‘X’.
      ENDIF.
    ELSE.
      MOVE l_wa_regionregion TO l_wa_zregionregion .
      MOVE l_wa_regiontxtsh TO l_wa_zregiontxtsh .
      l_posit = l_posit + 1 .
      l_wa_zregionid = l_posit.
      l_wa_zregionflag = ‘X’.
      APPEND l_wa_zregion TO l_it_zregion .
    ENDIF.

  ENDLOOP.

  MODIFY ztregion FROM TABLE l_it_zregion .
  DELETE FROM ztregion WHERE flag = .
  UPDATE ztregion SET flag = .

ENDIF.

This code will enhance the partition creation process.

For more details refer:

http://scn.sap.com/people/juergen.haupt/blog/2010/12/07/sap-netweaver-bw-730-semantically-partitioned-objects-spos-built-from-badi-consistent-rule-based-modeling-of-logical-partitions

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Suman K

    Hi Jaiswal,

    While using BADI & when a new partition is added I am not getting DTP’s activated automatically. Instead I have manually click at BADI in Create DTp step.
    Any solution for this?

    Thanks,
    Suman

    (0) 

Leave a Reply