Advertisement
yaramohamed78

select option test -v5

Jan 22nd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 4.56 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. IF Z_EMPID[] IS NOT INITIAL.
  18. LOOP AT Z_EMPID.
  19. counter = counter + 1.
  20.  
  21. IF Z_EMPID-SIGN = 'I'.
  22.  
  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. ELSEIF Z_EMPID-SIGN = 'E'.
  47. IF Z_EMPID-OPTION = 'EQ'.
  48.    STR2 = 'e~id <> Z_EMPID-LOW'.
  49.     CONCATENATE where_statement STR2 INTO where_statement.
  50. ELSEIF Z_EMPID-OPTION = 'NE'.
  51.    STR2 = 'e~id = Z_EMPID-LOW'.
  52.     CONCATENATE where_statement STR2 INTO where_statement.
  53.  
  54. ELSEIF Z_EMPID-OPTION = 'GT'.
  55.    STR2 = 'e~id <= Z_EMPID-LOW'.
  56.     CONCATENATE where_statement STR2 INTO where_statement.
  57.  
  58. ELSEIF Z_EMPID-OPTION = 'LT'.
  59.     STR2 = 'e~id >= Z_EMPID-LOW'.
  60.     CONCATENATE where_statement STR2 INTO where_statement.
  61.  
  62. ELSEIF Z_EMPID-OPTION = 'GE'.
  63.     STR2 = 'e~id < Z_EMPID-LOW'.
  64.     CONCATENATE where_statement STR2 INTO where_statement.
  65.  
  66. ELSEIF Z_EMPID-OPTION = 'LE'.
  67.     STR2 = 'e~id > Z_EMPID-LOW'.
  68.     CONCATENATE where_statement STR2 INTO where_statement.
  69.  
  70. ELSEIF Z_EMPID-OPTION = 'BT'.
  71.       STR2 = 'e~id NOT BETWEEN Z_EMPID-LOW AND Z_EMPID-HIGH'.
  72.    CONCATENATE where_statement STR2  INTO where_statement.
  73.  
  74. ENDIF.
  75. ENDIF.
  76. IF NOT wa_emp-NAME IS INITIAL.
  77.   IF where_statement IS INITIAL.
  78.     STR2 = 'e~name = wa_emp-name'.
  79.   CONCATENATE where_statement STR2  INTO where_statement.
  80.    ELSE.
  81.     STR2 = 'AND e~name = wa_emp-name'.
  82.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  83.    ENDIF.
  84.   ENDIF.
  85.  
  86.   IF NOT wa_emp-empposition IS INITIAL.
  87.   IF where_statement IS INITIAL.
  88.     STR2 = 'e~empposition = wa_emp-empposition'.
  89.   CONCATENATE where_statement STR2  INTO where_statement.
  90.    ELSE.
  91.     STR2 = 'AND e~empposition = wa_emp-empposition'.
  92.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  93.    ENDIF.
  94.   ENDIF.
  95.  
  96.    SELECT e~NAME s~amount s~CURRENCY
  97.     INTO (emp_name,emp_amount,emp_currency)
  98.   FROM (
  99.     ZASG_EMP AS e
  100.     INNER JOIN ZASG_SAL AS s ON e~ID = s~empid
  101.     )
  102.     WHERE (where_statement).
  103.     WRITE : / emp_name , emp_amount , emp_currency.
  104.     ENDSELECT.
  105. *    If no id is found.
  106.    IF  SY-SUBRC <> 0.
  107.      errors = errors + 1.
  108.  ENDIF.
  109. ENDLOOP.
  110.  
  111. ELSE.
  112.  
  113. IF NOT wa_emp-NAME IS INITIAL.
  114.   IF where_statement IS INITIAL.
  115.     STR2 = 'e~name = wa_emp-name'.
  116.   CONCATENATE where_statement STR2  INTO where_statement.
  117.    ELSE.
  118.     STR2 = 'AND e~name = wa_emp-name'.
  119.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  120.    ENDIF.
  121.   ENDIF.
  122.  
  123.  
  124.   IF NOT wa_emp-empposition IS INITIAL.
  125.   IF where_statement IS INITIAL.
  126.     STR2 = 'e~empposition = wa_emp-empposition'.
  127.   CONCATENATE where_statement STR2  INTO where_statement.
  128.    ELSE.
  129.     STR2 = 'AND e~empposition = wa_emp-empposition'.
  130.   CONCATENATE where_statement STR2  INTO where_statement SEPARATED BY ' '.
  131.    ENDIF.
  132.   ENDIF.
  133.  
  134.   SELECT e~NAME s~amount s~CURRENCY
  135.     INTO (emp_name,emp_amount,emp_currency)
  136.   FROM (
  137.     ZASG_EMP AS e
  138.     INNER JOIN ZASG_SAL AS s ON e~ID = s~empid
  139.     )
  140.     WHERE (where_statement).
  141.     WRITE : / emp_name , emp_amount , emp_currency.
  142.     ENDSELECT.
  143.     ENDIF.
  144.  
  145. IF errors = counter AND where_statement IS NOT INITIAL.
  146. MESSAGE ID 'ZINSERTION_ERRORS' TYPE 'I' NUMBER '012'.
  147. ENDIF.
  148.  
  149. ENDFUNCTION.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement