Saturday, 15 March 2014

LUW : DB Luw & SAP Luw

----------------------------------------------------------------------------------------------------------------------------
Scenario: Suppose a transaction involves multiple screens. We can say that the  Transaction is successful if all the data involved in multiple screens are properly updated in the data base tables else the Transaction is unsuccessful.

For this case the Developer Can proceed with two ways:
Meth-1. While navigating from one screen(Source Screen) to another screen(Target Screen), just before navigation, Update the data base tables(DB Commit) for that particular source screen.
So this method involves Database Updates for each individual screen.

Meth-2. While navigating from one screen(Source Screen) to another screen(Target Screen), collect the required data in some internal tables for each individual screen and at the end of the last screen of the transaction, update the database with all the relevant data from multiple screens of the transaction .

In method-1, The Transaction is successful if each  DB commit of Individual screen is successful.
But many times this is not the case. What if the DB commit is successful for the first screen of the transaction but DB commit fails for the subsequent screens of the Transaction. In total  the Transaction is failed but some of the database update is committed leads to data inconsistencies.

To over come this problem, the method 2 approach is adapted. Which ensures that  all the data is either fully committed or else everything is rolled back.

DB Luw: The DB Luw happens for each individual screen.
SAP Luw: The SAP Luw combines all DB Luw's of the  Transaction into a Single LUW.

To implement Method-2 (SAP LUW), either we have to use Update Function  Module or Subroutine : Perform XXXXXX on Commit technique.











_________________________________________________________________________________




Sunday, 9 March 2014

Changing the Value of the Private Attribute of a class Out Side of the Class

Scenario: This Post describes changing the Value of the Private attribute of the class Outside of the class by Using Reference Technique.
_________________________________________________________________________________
Step1. Create a Report in SE38 and execute it.

REPORT  ztest_private_attr_val_change.

*----------------------------------------------------------------------*
*       CLASS lcl_private_attr_change_tech DEFINITION
*----------------------------------------------------------------------*


CLASS lcl_private_attr_change_tech DEFINITION.
  PUBLIC SECTION.
    METHODS : get_private_attribute_value,
                         get_refrence_of_priv_attr EXPORTING e_fp_salary TYPE REF TO data.

  PRIVATE SECTION.
    DATA : lv_salary TYPE p  DECIMALS 2 VALUE '50000.00'.
ENDCLASS.                    "lcl_private_attr_change_tech DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_private_attr_change_tech IMPLEMENTATION
*----------------------------------------------------------------------*


CLASS lcl_private_attr_change_tech IMPLEMENTATION.

  METHOD get_private_attribute_value.
    WRITE :/ 'Value of Private Attribute Salary is :', lv_salary.
  ENDMETHOD.                    "get_private_attribute_value


  METHOD get_refrence_of_priv_attr.
    GET REFERENCE OF lv_salary INTO e_fp_salary.
  ENDMETHOD.                    "get_refrence_of_pri_attr


ENDCLASS.                    "lcl_private_attr_change_tech IMPLEMENTATION

START-OF-SELECTION.

  DATA : lv_oref TYPE REF TO lcl_private_attr_change_tech.
  DATA : lv_ref_salary TYPE REF TO data.
  FIELD-SYMBOLS : <fs_salary> TYPE any.
  CREATE OBJECT lv_oref.
  CALL METHOD lv_oref->get_private_attribute_value.
******get the reference of the private attribute of the class*********
  CALL METHOD lv_oref->get_refrence_of_priv_attr
    IMPORTING
      e_fp_salary = lv_ref_salary.

*******Assign the data reference to the Field Symbol*******
  ASSIGN lv_ref_salary->* TO <fs_salary>.

*******Change the value of the Private attribute by the reference using the Field Symbol******


  <fs_salary> = '80000.00' .

  CALL METHOD lv_oref->get_private_attribute_value.



_________________________________________________________________________________
Step2. Execute it and see the Output.










_________________________________________________________________________________

Thursday, 6 March 2014

Nested Loop Vs Parallel Cursor Technique

Scenario: Many times In development scenario we come across situations where we need to have a nested loop to find our the matching records in the Header and the Item table. In that case we follow Nested loop which takes a longer processing time. To Improve the program performance the Nested Loop Condition can be optimized in a certain way called Parallel Cursor technique to improve the performance.

The below post demonstrates the same by considering the two table : BKPF & BSEG.

_________________________________________________________________________________

REPORT  zparallel_cursor_test.

DATA : lt_bkpf TYPE TABLE OF bkpf,
              lt_bseg TYPE TABLE OF bseg,
              ls_bkpf TYPE bkpf,
              ls_bseg TYPE bseg.
DATA : lv_time1 TYPE i,
              lv_time2 TYPE i,
              lv_time3 TYPE i,
              lv_time4 TYPE i,
              lv_res_time_gn_process TYPE i,
              lv_res_time_pa_process TYPE i,
              indx TYPE i.
DATA : lv_bkpf_recs TYPE i.
DATA : lv_bseg_recs TYPE i.

START-OF-SELECTION.

  SELECT * FROM bkpf INTO TABLE lt_bkpf.
  SELECT * FROM bseg INTO TABLE lt_bseg.


  DESCRIBE TABLE lt_bkpf LINES lv_bkpf_recs.
  DESCRIBE TABLE lt_bseg LINES lv_bseg_recs.

  GET RUN TIME FIELD lv_time1.
  LOOP AT lt_bkpf INTO ls_bkpf.
    LOOP AT lt_bseg INTO ls_bseg WHERE vbeln = ls_bkpf-belnr.

* BUSINESS LOGIC GOES HERE.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD lv_time2.

  lv_res_time_gn_process = lv_time2 - lv_time1.


  * Applying Parallel Cursor Technique

 SORT lt_bkpf BY belnr.
  SORT lt_bseg BY belnr.


  GET RUN TIME FIELD lv_time3.
  LOOP AT lt_bkpf INTO ls_bkpf.
    READ TABLE lt_bseg INTO ls_bseg WITH  KEY belnr = ls_bkpf-belnr BINARY SEARCH.
    IF sy-subrc = 0.
      indx = sy-tabix.
      LOOP AT lt_bseg INTO ls_bseg FROM indx.
        IF ls_bseg-belnr <> ls_bkpf-belnr.
          EXIT.
        ENDIF.
* BUSINESS LOGIC GOES HERE.
      ENDLOOP.
    ENDIF.
  ENDLOOP.

  GET RUN TIME FIELD lv_time4.


  lv_res_time_pa_process = lv_time4 - lv_time3.

  WRITE :/ 'Comparision Between Nested Loop And Parallel Cursor Technique'.
  WRITE:/ 'No Of records in BKPF(Header) Table = ', lv_bkpf_recs.
  WRITE:/ 'No Of records in BSEG(Item) Table = ', lv_bseg_recs.

  Write :/ 'Time Taken in Normal Nested loop Processing', lv_res_time_gn_process  ,'Vs.' ,
           ' Time Taken In Parallel Cursor Technique', lv_res_time_pa_process.

_________________________________________________________________________________

Output:
_________________________________________________________________________________


_________________________________________________________________________________

Comments system

Disqus Shortname