Author: Not specified Language: abap
Description: Not specified Timestamp: 2018-06-21 11:49:13 +0000
View raw paste Reply
  1. *&---------------------------------------------------------------------*
  2. *& Report z_pj_tests
  3. *&---------------------------------------------------------------------*
  4. *&
  5. *&---------------------------------------------------------------------*
  6. REPORT z_pj_tests.
  7.  
  8. *DATA:
  9. *  lt_test1 TYPE TABLE OF REF TO object, "TABLE OF REF TO object,
  10. *  lt_test2 TYPE TABLE OF REF TO /gicom/cl_negotiation.
  11. *
  12. *FIELD-SYMBOLS:
  13. *    <lt_test3> TYPE STANDARD TABLE.
  14. *
  15. *
  16. *APPEND NEW /gicom/cl_negotiation( ) TO <lt_test3>.
  17. *
  18. *lt_test2 = <lt_test3>.
  19.  
  20. INTERFACE if_where_element.
  21.     expand
  22.       RETURNING
  23.         VALUE(rv_result) TYPE string.
  24.  
  25. TYPES tty_where_element TYPE TABLE OF REF TO if_where_element WITH DEFAULT KEY.
  26.  
  27. CLASS cl_where_symbol DEFINITION.
  28.   PUBLIC SECTION.
  29.     INTERFACES:
  30.       if_where_element.
  31.     METHODS:
  32.       constructor
  33.         IMPORTING
  34.           iv_left_operand  TYPE string
  35.           iv_operator      TYPE string
  36.           iv_right_operand TYPE string.
  37.   PRIVATE SECTION.
  38.     DATA:
  39.       gv_left_operand  TYPE string,
  40.       gv_operator      TYPE string,
  41.       gv_right_operand TYPE string.
  42.  
  43. CLASS cl_where_symbol IMPLEMENTATION.
  44.   METHOD if_where_element~expand.
  45.     IF me->gv_right_operand IS NOT INITIAL.
  46.       rv_result = me->gv_left_operand && ` ` && me->gv_operator && ` ` && me->gv_right_operand.
  47.     ENDIF.
  48.  
  49.   METHOD constructor.
  50.     me->gv_left_operand = iv_left_operand.
  51.     me->gv_operator = iv_operator.
  52.     me->gv_right_operand = iv_right_operand.
  53.  
  54. CLASS cl_where_part DEFINITION.
  55.   PUBLIC SECTION.
  56.     INTERFACES:
  57.       if_where_element.
  58.     METHODS:
  59.       constructor
  60.         IMPORTING
  61.           it_operands TYPE tty_where_element
  62.           iv_operator TYPE string OPTIONAL.
  63.   PRIVATE SECTION.
  64.     DATA:
  65.       gt_operands TYPE tty_where_element,
  66.       gv_operator TYPE string.
  67.  
  68. CLASS cl_where_part IMPLEMENTATION.
  69.   METHOD if_where_element~expand.
  70.     DATA lv_at_first TYPE abap_bool VALUE abap_true.
  71.  
  72.     rv_result = rv_result && '(' && ` `.
  73.  
  74.     LOOP AT me->gt_operands INTO DATA(lo_operand).
  75.       DATA(ls_part) = lo_operand->expand( ).
  76.       IF ls_part IS NOT INITIAL.
  77.         IF lv_at_first = abap_true.
  78.           lv_at_first = abap_false.
  79.         ELSE.
  80.           rv_result = rv_result && ` ` && me->gv_operator && ` `.
  81.         ENDIF.
  82.  
  83.         rv_result = rv_result && ls_part.
  84.       ENDIF.
  85.     ENDLOOP.
  86.  
  87.     rv_result = rv_result && ` ` && ')'.
  88.  
  89.   METHOD constructor.
  90.     me->gt_operands = it_operands.
  91.     me->gv_operator = iv_operator.
  92.  
  93. CLASS cl_query_builder DEFINITION.
  94.   PUBLIC SECTION.
  95.       build_where_clause
  96.         IMPORTING
  97.           io_where_root          TYPE REF TO if_where_element
  98.         RETURNING
  99.           VALUE(rv_where_clause) TYPE string.
  100.  
  101. CLASS cl_query_builder IMPLEMENTATION.
  102.   METHOD build_where_clause.
  103.     rv_where_clause = io_where_root->expand( ).
  104.     IF rv_where_clause IS INITIAL.
  105.       rv_where_clause = '1 = 1'.
  106.     ENDIF.
  107.  
  108.  
  109.   DATA(lo_where) = NEW cl_where_part(
  110.       it_operands = VALUE #(
  111.           ( NEW cl_where_symbol( iv_left_operand = 'field1' iv_operator = '=' iv_right_operand = 'field2' ) )
  112.           ( NEW cl_where_symbol( iv_left_operand = 'field2' iv_operator = '=' iv_right_operand = 'field2' ) )
  113.           ( NEW cl_where_part(
  114.             it_operands = VALUE #(
  115.                 ( NEW cl_where_symbol( iv_left_operand = 'field3' iv_operator = '=' iv_right_operand = 'field4' ) )
  116.                 ( NEW cl_where_symbol( iv_left_operand = 'field5' iv_operator = '=' iv_right_operand = 'field6' ) )
  117.             )
  118.             iv_operator = 'AND'
  119.           ) )
  120.       )
  121.       iv_operator = 'OR'
  122.   ).
  123.  
  124.   WRITE cl_query_builder=>build_where_clause( lo_where ).
View raw paste Reply