Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8944

Buffering concept in OO ABAP .

$
0
0

Hi Experts,

         I got a requirement that if there are 3 fields say vbeln, matnr and posnr. and a Display button in my screen .

I have created abstract class and one method in it .and implemented it in another subclass.

 

               The requirement is first time if I Click on Display button it should Fetch the data from DATABASE and the programme should be running and 

and second time if we click on Display button it should fetch the data from BUFFER.

 

I am new to OO ABAP .Please provide me your valuable solutions? Below is the code which is written in the method implementation :

 

method READ_METHOD.

     FIELD-SYMBOLS:

                 <fs_wa1>           TYPE any,

                 <fs_wa2>           TYPE any,

                 <fs_wa3>           TYPE any,

                 <fs_wa4>           TYPE any,

                 <fs_wa5>           TYPE any,

                 <fs_itab1>         TYPE ANY TABLE,

                 <fs_itab2>         TYPE ANY TABLE,

                 <fs_itab3>         TYPE ANY TABLE,

                 <fs_itab4>         TYPE ANY TABLE.

 

   DATA :  mv_ritab TYPE REF TO DATA,

         IM_RDATA TYPE ZVBAP11,

                d_ref_d           TYPE REF TO    data,

                  d_ref_w           TYPE REF TO    data,

                  d_ref_t           TYPE REF TO    data,

                  lv_count          TYPE           n,              "counter variable

                  lv_num_r          TYPE           i,              "counter variable

                  lv_str            TYPE           string,

                  lv_field          TYPE           string,

                  lv_val            TYPE           string,

                  lv_si             TYPE           c VALUE `'`,    " constant, help building where condition(used in concatenation).

                  lv_strg           TYPE           string,

                  lv_guid_st       type           string,

**** data variables for the type descriptor

                  lr_structdescr    TYPE REF TO    cl_abap_structdescr,

                  lt_components     TYPE           abap_component_tab,

                  ls_wa             TYPE LINE OF   abap_component_tab,

                  ls_components     TYPE LINE OF   abap_component_tab,

                  lr_ref            TYPE REF TO    data,

                  lr_oref           TYPE REF TO    cx_root.

 

   CREATE DATA d_ref_d      TYPE TABLE OF zvbap.

   CREATE DATA d_ref_t      TYPE TABLE OF zvbap.

   CREATE DATA d_ref_w      TYPE          zvbap.

   ASSIGN d_ref_d->*        TO            <fs_itab1>.               "pointing field symbol to table

   ASSIGN d_ref_d->* TO            <fs_itab3>.

   ASSIGN d_ref_w->* TO            <fs_wa1>.

   ASSIGN d_ref_w->* TO            <fs_wa2>.

   ASSIGN d_ref_w->* TO            <fs_wa3>.

   ASSIGN d_ref_w->* TO            <fs_wa5>.

 

   IF mv_ritab IS NOT BOUND.

     CREATE DATA mv_ritab  TYPE TABLE OF zvbap.           "READ buffer.

   ENDIF.

   ASSIGN mv_ritab->* TO <fs_itab2>.

   <fs_itab1> =  IM_RDATA.

   lv_count = 0.

 

****Extracting field names and their respective values and building where condition.

   LOOP AT <fs_itab1> ASSIGNING <fs_wa1>.

     DO.

       ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa1> TO <fs_wa4>.

       lr_structdescr ?= cl_abap_structdescr=>describe_by_data( <fs_wa1> ).

       lt_components = lr_structdescr->get_components( ).

        DESCRIBE TABLE lt_components LINES lv_num_r.

       IF <fs_wa4> IS ASSIGNED AND <fs_wa4> IS NOT INITIAL.

         lr_structdescr ?= cl_abap_structdescr=>describe_by_data( <fs_wa1> ).

         lt_components = lr_structdescr->get_components( ).

         READ TABLE lt_components INTO ls_wa INDEX sy-index.

         lv_field = ls_wa-name.

         lv_guid_st = <fs_wa4>.

         READ TABLE <fs_itab2> INTO <fs_wa3> WITH KEY (lv_field) = <fs_wa4>.

         CONCATENATE lv_si lv_guid_st lv_si INTO lv_val.

*        DESCRIBE TABLE lt_components LINES lv_num_r.                                     "Getting the count for number of fields in table.

         lv_count = lv_count + 1.

         IF lv_count > 1.

           CONCATENATE lv_str 'and' lv_field '=' lv_val INTO lv_str SEPARATED BY space.   "if two fields in where condition.

         ELSE.

           CONCATENATE lv_str lv_field '=' lv_val INTO lv_str SEPARATED BY space.         "if single field in where condition.

         ENDIF.

         endif.

         IF sy-index = lv_num_r.                                                          " loop termination condition.

           EXIT.

         ENDIF.

*      ENDIF.

     ENDDO.

   ENDLOOP.

**** checking for the entries present in the READ buffer.

   LOOP AT <fs_itab2> ASSIGNING <fs_wa5> WHERE (lv_str)."reading from buffer.

     INSERT <fs_wa5> INTO TABLE <fs_itab3>.

   ENDLOOP.

**** fetching entries from the database.

   IF sy-subrc = 4 AND VBELN IS NOT INITIAL.

     SELECT * FROM zvbap INTO TABLE <fs_itab3> WHERE vbeln = vbeln."reading from database.

 

 

     IF sy-subrc = 0.

       LOOP AT <fs_itab3> ASSIGNING <fs_wa1> .

         INSERT <fs_wa1> INTO TABLE <fs_itab2>.

       ENDLOOP.

     ENDIF.

   ENDIF.

   ex_rdata = <fs_itab2>.

 

 

   endmethod.


Viewing all articles
Browse latest Browse all 8944

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>