/SAPAPO/CL_GEN_DB_READ2 - General table reader

ABAP Short Reference   General Material Data  
This documentation is copyright by SAP AG.

Functionality

Typical usage:

1. Step: Create object /SAPAPO/CL_GEN_DB_READ

2. Step: Add range(s) with ADD_RANGE method

You have 2 possibilities:

  • You can set the range with the IV_CONSTANT and IV_OPTION (it has default value EQ) parameters if the range has only one value
  • You can set the RANGE with the IT_RANGE parameter if the range is more complex or you have already a range table

If both possibilities are given then IV_CONSTANT will be used

3. Step:Read DB table with READ_TABLE method

If the IT_FORALL parameter is given then you have 2 possibilities:

  • Without IT_FIELD_MAPPING parameter the SELECT will use those fields of the IT_FORALL table which have the same name like the DB fields with EQ parameter.
  • With IT_FIELD_MAPPING parameter you can do mapping between DB table fields and the IT_FORALL tablefields and you can set EQ (default) or NE parameter. This case only those fields will be used which are in the IT_FIELD_MAPPING.

Restrictions:

Read method:

There is a size limitation (see SAP Note 649157 and 635318) in the SQL for the WHERE parameter. We maximized the cumulated number of lines of used ranges (currently 600) instead of to calculate the size of those in Kb.

Because of this:

- If the cumulated number of lines of the used ranges is less than the maximum then we use all of them for the SELECT

- If the cumulated number of lines of the used ranges is more than the maximum then we sort the rangesby line number in ascending order and add to the WHERE while the cumulated number of lines is less thanthe maximum. If the For All table is not given then we use the biggest range table from the remainingones as a For All table. For this, the biggest range table has to contain only discrete values (it meansthe SIGN field always I and the OPTION field always EQ), but they usually do. After the SELECT we filter the result with the remaining range tables.

Recommendation:

To find easier a DB read for the given table we suggest to create dedicated reader class for each DBtable and use the /SAPAPO/CL_GEN_DB_READ class as a superclass and call the superclass constructor with table name as constant. In the example you can see local class, but we suggest to create global class.

Relationships

Example

REPORT ZDB_TEST.

*----------------------------------------------------------------------*

*       CLASS CL_LOC_TABLE_READ_TMP  DEFINITIO

*----------------------------------------------------------------------*

CLASS cl_loc_table_read_tmp DEFINITION

  INHERITING FROM /sapapo/cl_gen_db_read

  FINAL

  CREATE PUBLIC.

  PUBLIC SECTION.

    METHODS constructor .

ENDCLASS.                    "CL_LOC_TABLE_READ_TMP  DEFINITIO

*----------------------------------------------------------------------*

*       CLASS CL_LOC_TABLE_READ_TMP IMPLEMENTATION

*----------------------------------------------------------------------*

CLASS cl_loc_table_read_tmp IMPLEMENTATION.

  METHOD constructor.

    CALL METHOD super->constructor

      EXPORTING

        iv_db_table_name = '/SAPAPO/LOC'.

  ENDMETHOD.                    "CONSTRUCTOR

ENDCLASS.                    "CL_LOC_TABLE_READ_TMP IMPLEMENTATION

TABLES:

  /sapapo/loc.

TYPES:

  BEGIN OF forall_line_type,

    loctype  TYPE /sapapo/c_loctype,

  END OF forall_line_type,

  BEGIN OF result_line_type,

    locid    TYPE /sapapo/locid,

    locno    TYPE /sapapo/locno,

    loctype  TYPE /sapapo/c_loctype,

  END OF result_line_type.

DATA:

  gc_table   TYPE REF TO cl_loc_table_read_tmp,

  gt_loc     TYPE STANDARD TABLE OF /sapapo/loc,

  gt_forall  TYPE STANDARD TABLE OF forall_line_type,

  gs_forall  LIKE LINE OF gt_forall,

  gt_result  TYPE STANDARD TABLE OF result_line_type,

  gs_result  LIKE LINE OF gt_result.

* Selection screen -----------------------------------------------------

SELECT-OPTIONS:

  s_locno    FOR /sapapo/loc-locno.

* Reading --------------------------------------------------------------

START-OF-SELECTION.

  CREATE OBJECT gc_table.

  CALL METHOD gc_table->add_range

    EXPORTING

      iv_field_name              = 'LOCNO'

      it_range                   = s_locno[].

  gs_forall-loctype = '1001'.

  APPEND gs_forall TO gt_forall.

  CALL METHOD gc_table->read_table

    EXPORTING

      it_forall = gt_forall[]

    IMPORTING

      et_result = gt_result[].

* Write ouptut ---------------------------------------------------------

END-OF-SELECTION.

  LOOP AT gt_result INTO gs_result.

    WRITE:/ gs_result.

  ENDLOOP.

Notes

Further information



BAL_S_LOG - Application Log: Log header data   BAL Application Log Documentation  
This documentation is copyright by SAP AG.


Length: 8830 Date: 20120526 Time: 071053     triton ( 246 ms )