Advertisement
yaramohamed78

select option test -v5

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