yaramohamed78

select option test -v4

Jan 18th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 3.66 KB | None | 0 0
  1. FUNCTION Z_ASG_FN_SEARCH_TEST.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     REFERENCE(WA_EMP) TYPE  ZASG_EMP
  6. *"  TABLES
  7. *"      Z_EMPID STRUCTURE  SELOPT
  8. *"----------------------------------------------------------------------
  9. DATA : emp_name LIKE ZASG_EMP-name,
  10.        emp_amount LIKE ZASG_SAL-amount,
  11.        emp_currency LIKE ZASG_SAL-currency,
  12.        where_statement TYPE STRING,
  13.        STR2 TYPE STRING, STR3 TYPE STRING,
  14.        counter TYPE INT1 VALUE 0,
  15.        errors TYPE INT1 VALUE 0.
  16.  
  17.  
  18. IF NOT Z_EMPID IS INITIAL.
  19. LOOP AT Z_EMPID.
  20. *  WRITE : / 'welcome'.
  21. *  WRITE : / Z_EMPID-low.
  22.   counter = counter + 1.
  23.  IF Z_EMPID-OPTION = 'EQ'.
  24.    where_statement = 'e~id = Z_EMPID-LOW'.
  25.    CONCATENATE where_statement STR2 INTO where_statement.
  26.  ELSEIF Z_EMPID-OPTION = 'NE'.
  27.    STR2 = 'e~id <> Z_EMPID-LOW'.
  28.     CONCATENATE where_statement STR2 INTO where_statement.
  29.  ELSEIF Z_EMPID-OPTION = 'GT'.
  30.    STR2 = 'e~id > Z_EMPID-LOW'.
  31.     CONCATENATE where_statement STR2 INTO where_statement.
  32.   ELSEIF Z_EMPID-OPTION = 'LT'.
  33.     STR2 = 'e~id < Z_EMPID-LOW'.
  34.     CONCATENATE where_statement STR2 INTO where_statement.
  35.     ELSEIF Z_EMPID-OPTION = 'GE'.
  36.     STR2 = 'e~id >= Z_EMPID-LOW'.
  37.     CONCATENATE where_statement STR2 INTO where_statement.
  38.     ELSEIF Z_EMPID-OPTION = 'LE'.
  39.     STR2 = 'e~id <= Z_EMPID-LOW'.
  40.     CONCATENATE where_statement STR2 INTO where_statement.
  41.     ELSEIF Z_EMPID-OPTION = 'BT'.
  42.       STR2 = 'e~id BETWEEN Z_EMPID-LOW AND Z_EMPID-HIGH'.
  43.    CONCATENATE where_statement STR2  INTO where_statement.
  44.   ENDIF.
  45.  
  46.   IF NOT wa_emp-name is INITIAL.
  47.   IF where_statement is INITIAL.
  48.     STR2 = 'e~name = wa_emp-name'.
  49.   CONCATENATE where_statement STR2  INTO where_statement.
  50.    ELSE.
  51.     STR2 = 'AND e~name = wa_emp-name'.
  52.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  53.    ENDIF.
  54.   ENDIF.
  55.  
  56.   IF NOT wa_emp-empposition is INITIAL.
  57.   IF where_statement is INITIAL.
  58.     STR2 = 'e~empposition = wa_emp-empposition'.
  59.   CONCATENATE where_statement STR2  INTO where_statement.
  60.    ELSE.
  61.     STR2 = 'AND e~empposition = wa_emp-empposition'.
  62.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  63.    ENDIF.
  64.   ENDIF.
  65. WRITE : / where_statement.
  66.   SELECT e~name s~amount s~currency
  67.     INTO (emp_name,emp_amount,emp_currency)
  68.   FROM (
  69.     ZASG_EMP AS e
  70.     INNER JOIN ZASG_SAL AS s ON e~id = s~empid
  71.     )
  72.     WHERE (where_statement).
  73.     WRITE : / emp_name , emp_amount , emp_currency.
  74.     ENDSELECT.
  75. *    If no id is found.
  76.    IF  SY-SUBRC <> 0.
  77.      errors = errors + 1.
  78.  ENDIF.
  79. ENDLOOP.
  80.  
  81. ELSE.
  82.     IF NOT wa_emp-name is INITIAL.
  83.   IF where_statement is INITIAL.
  84.     STR2 = 'e~name = wa_emp-name'.
  85.   CONCATENATE where_statement STR2  INTO where_statement.
  86.    ELSE.
  87.     STR2 = 'AND e~name = wa_emp-name'.
  88.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  89.    ENDIF.
  90.   ENDIF.
  91.  
  92.   IF NOT wa_emp-empposition is INITIAL.
  93.   IF where_statement is INITIAL.
  94.     STR2 = 'e~empposition = wa_emp-empposition'.
  95.   CONCATENATE where_statement STR2  INTO where_statement.
  96.    ELSE.
  97.     STR2 = 'AND e~empposition = wa_emp-empposition'.
  98.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  99.    ENDIF.
  100.   ENDIF.
  101.  
  102.   SELECT e~name s~amount s~currency
  103.     INTO (emp_name,emp_amount,emp_currency)
  104.   FROM (
  105.     ZASG_EMP AS e
  106.     INNER JOIN ZASG_SAL AS s ON e~id = s~empid
  107.     )
  108.     WHERE (where_statement).
  109.     WRITE : / emp_name , emp_amount , emp_currency.
  110.     ENDSELECT.
  111.     ENDIF.
  112. *
  113. *
  114. *
  115. *
  116. **if errors = counter.
  117. **MESSAGE ID 'ZINSERTION_ERRORS' TYPE 'I' NUMBER '007'.
  118. **ENDIF.
  119.  
  120.  
  121. ENDFUNCTION.
Add Comment
Please, Sign In to add comment