Employee Search with Dynamic Where Clause

I have implemented this function for a custom fiori application employee value help.

It is simply used as an employee value help backend function.

There are 3 fields at value help structure from but000

PARTNER

NAME_FIRST

NAME_LAST

 

FUNCTION z_crm_ui5_oneri_partner_vhelp.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IS_PARTNER_VHELP) TYPE  ZCRM_UI5_S063 OPTIONAL
*"  EXPORTING
*"     VALUE(ET_PARTNER_VHELP) TYPE  ZCRM_UI5_S063_T
*"----------------------------------------------------------------------

  DATA: lv_value           TYPE string,
        lv_where_statement TYPE string,
        lt_where_statement TYPE TABLE OF string.

  CHECK is_partner_vhelp IS NOT INITIAL.

  IF is_partner_vhelp-partner_no IS NOT INITIAL.
    CLEAR: lv_where_statement, lv_value.
    IF lines( lt_where_statement ) NE 0.
      lv_where_statement = 'AND'.
    ENDIF.
    CONCATENATE '''' is_partner_vhelp-partner_no '''' INTO lv_value.
    CONCATENATE lv_where_statement 'a~partner EQ' lv_value INTO lv_where_statement SEPARATED BY space.
    APPEND lv_where_statement TO lt_where_statement.
  ENDIF.

  IF is_partner_vhelp-name_first IS NOT INITIAL.
    CLEAR: lv_where_statement, lv_value.
    IF lines( lt_where_statement ) NE 0.
      lv_where_statement = 'AND'.
    ENDIF.

    CONCATENATE '''' is_partner_vhelp-name_first '''' INTO lv_value.
    CONCATENATE lv_where_statement 'a~name_first EQ' lv_value INTO lv_where_statement SEPARATED BY space.
    APPEND lv_where_statement TO lt_where_statement.
  ENDIF.

  IF is_partner_vhelp-name_last IS NOT INITIAL.
    CLEAR: lv_where_statement, lv_value.
    IF lines( lt_where_statement ) NE 0.
      lv_where_statement = 'AND'.
    ENDIF.

    CONCATENATE '''' is_partner_vhelp-name_last '''' INTO lv_value.
    CONCATENATE lv_where_statement 'a~name_last EQ' lv_value INTO lv_where_statement SEPARATED BY space.
    APPEND lv_where_statement TO lt_where_statement.
  ENDIF.

  CLEAR: lv_where_statement, lv_value.

  CHECK lt_where_statement IS NOT INITIAL.

  CONCATENATE '''' 'BUP003' '''' INTO lv_value.
  CONCATENATE 'AND B~RLTYP EQ' lv_value INTO lv_where_statement SEPARATED BY space.
  APPEND lv_where_statement TO lt_where_statement.

  SELECT a~partner
         a~name_first
         a~name_last
    INTO TABLE et_partner_vhelp
    FROM but000 AS a
   INNER JOIN but100 AS b
      ON a~partner EQ b~partner
   WHERE (lt_where_statement).


ENDFUNCTION.

 

Input:

 

Debugger:

 

Output:

 

 

ABOUT Uğur Kaya

http://linkedin.com/in/kayau

RELATED POSTS

COMMENTS

comments powered by Disqus