Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using buffering option in select query

Former Member
0 Kudos

Hi All,

Can anybody give me a brief idea on , where we will use the buffering and how we will write it in coding part.Similarly please tell me what will happen if we use by passing buffering addition in select query. Please explain it with steps of sample code if possible.

Thanks in advance.

Regards,

Rakesh.

5 REPLIES 5

former_member156446
Active Contributor
0 Kudos

You need to understand this concepts:

[Statements Bypassing the Buffer|http://help.sap.com/saphelp_nwce10/helpdata/en/a7/6e9fff3a08c64f960a29966ecdb9ec/content.htm]

[SAP buffering |http://help.sap.com/abapdocu/en/ABENSAP_BUFFERING_GLOSRY.htm]

Former Member
0 Kudos

Hi Sharma,

Buffer is used to hold large amount of data.

if internla table is unable to hold data.. Buffer is used..this is mainly used in copy data from PRD to Quality as a part testung.

see the sample code how the buffer is used..


FUNCTION zzrfc_get_zcpeg_fg_related.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(PL_VERSION) LIKE  ZCPEG_FG_RELATED-PL_VERSION OPTIONAL
*"     VALUE(BYPASS_BUFFER) LIKE  SY-FTYPE DEFAULT SPACE
*"     VALUE(FROM_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"     VALUE(GEN_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"     VALUE(MAX_ENTRIES) LIKE  SY-TABIX DEFAULT 0
*"     VALUE(TABLE_NAME) LIKE  X030L-TABNAME
*"     VALUE(TO_KEY) LIKE  SY-ENTRY DEFAULT SPACE
*"  EXPORTING
*"     VALUE(NUMBER_OF_ENTRIES) LIKE  SY-INDEX
*"  TABLES
*"      ENTRIES STRUCTURE  ZCPEG_FG_RELATED
*"  EXCEPTIONS
*"      INTERNAL_ERROR
*"      TABLE_EMPTY
*"      TABLE_NOT_FOUND
*"----------------------------------------------------------------------
  TABLES dd02l.

  DATA: BEGIN OF buf OCCURS 100,
            line(4100),
        END OF buf.

  DATA keyln TYPE i.

  DATA: l_tabname LIKE dd25v-viewname.
  DATA: l_len     TYPE i.

  DATA : w_plversion TYPE /sapapo/vrsioex.   "PJONNALA
  w_plversion =  pl_version.                 "PJONNALA

  l_tabname = table_name.
  CALL FUNCTION 'VIEW_AUTHORITY_CHECK'
    EXPORTING
      view_action                = 'S'
      view_name                  = l_tabname
      no_warning_for_clientindep = 'X'
    EXCEPTIONS
      OTHERS                     = 6.
  IF sy-subrc <> 0.
    RAISE internal_error.
  ENDIF.

  IF bypass_buffer NE ' ' AND bypass_buffer NE 'N'.
    bypass_buffer = 'Y'.
  ENDIF.

  IF gen_key CA ' '. ENDIF.
  keyln = sy-fdpos.

* read client dependant tables always with client
  SELECT SINGLE * FROM dd02l WHERE tabname = table_name
                              AND as4local =  'A'.
  IF dd02l-clidep = 'X'.
*l_len = strlen( sy-mandt ) * cl_abap_char_utilities=>charsize.
*  " ecwg. unicode
*    move gen_key to gen_key+l_len.
*    move sy-mandt to gen_key(l_len).
*    add l_len to keyln.
    CONCATENATE sy-mandt gen_key INTO gen_key.
    keyln = STRLEN( gen_key ) * cl_abap_char_utilities=>charsize.
  ENDIF.
*  endselect.

  IF keyln NE 0 OR from_key = space.
    CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                       ID 'INTTAB'    FIELD buf-*sys*
                       ID 'GENKEY'    FIELD gen_key
                       ID 'GENKEY_LN' FIELD keyln
                       ID 'DBCNT'     FIELD number_of_entries
                       ID 'BYPASS'    FIELD bypass_buffer.
  ELSE.
    CALL 'C_GET_TABLE' ID 'TABLNAME'  FIELD table_name
                       ID 'INTTAB'    FIELD buf-*sys*
                       ID 'FROM_KEY'  FIELD from_key
                       ID 'TO_KEY'    FIELD to_key
                       ID 'DBCNT'     FIELD number_of_entries
                       ID 'BYPASS'    FIELD bypass_buffer.
  ENDIF.

  CASE sy-subrc.
    WHEN 4.  RAISE table_empty.
    WHEN 8.  RAISE table_not_found.
    WHEN 12. RAISE internal_error.
  ENDCASE.

  DESCRIBE TABLE buf LINES number_of_entries.

ENDFUNCTION.

Regards,

Prabhudas

former_member181962
Active Contributor
0 Kudos

Hi rakesh,

SAo uses a technique called SAp Buffering when it tries to read data from Database.

As you know SAP has three layers viz. Database, Application, Presentation.

When you write a select statement, SAP buffers the data in the applicating server temporarily.

If you use

BYPASSING BUFFER , then the data is read directly from DATABASE.

IN your abap editor, wtite the statement BUFFERING and press f1 to know more.

sample code:

SELECT * 
       FROM spfli AS s 
       INTO wa 
     BYPASSING BUFFER
       where carrid in s_carrid.
  WRITE: / wa-carrid, wa-connid. 
ENDSELECT.

Regards,

Ravi Kanth Talagana

Former Member
0 Kudos

Hi Rakesh,

In the select query if do not specify BYPASSING BUFFER and the table is buffered and previously in the same sever somebody select from the same table (means records are in the buffer ) then the latest select query fetches from the buffer.

In the select query if you specify BYPASSING BUFFER , that will select from the database irrespective of the table buffering.

If the table SPFLI is FULLY BUFFERED and the records in the buffer then the followed

code will select from the buffer other wise it will select from the database.

DATA : t_spfli LIKE TABLE OF spfli.
SELECT * FROM spfli INTO TABLE t_spfli.

Irrespective of the table buffering and buffer status , the followed code will select from the database.

DATA : t_spfli LIKE TABLE OF spfli.
SELECT * FROM spfli INTO TABLE t_spfli BYPASSING BUFFER.

some times buffered records might have some inconsistencies.

Regards

Pinaki

Former Member