clear: new_bplan, new_bopti, new_bcovr.
select * from z_plan_map up to 1 rows
  where barea eq pa0171-barea
    and bengr eq pa0171-bengr
    and bstat eq pa0171-bstat
    and old_bplan eq t_health-ben_plan
    and old_bopti eq t_health_ben_option
    and old_bcovr eq t_health_dep_cover
    and endda ge sel_date
    and begda le sel_date.
endselect.
If sy-subrc eq 0.
* make sure the proposed plan is allowed
  read table t_health with key
    ben_plan eq z_plan_map-new_bplan
    ben_option eq z_plan_map-new_bopti
    dep_cover eq z_plan_map-new_bcovr
    not_elig eq space.
  If sy-subrc eq 0.
* this is the new election
    new_bplan = z_plan_map-new_bplan.
    new_bopti = z_plan_map-new_bopti.
    new_bcovr = z_plan_map-new_bcovr.
  endif.
endif.
* z_plan_map did not provide a new plan
* so use the default plans table
If new_bplan is initial.
  Select * from t5ub6
    Where barea = pa0171-barea
      And bengr = pa0171-bengr
      And bstat = pa0171-bstat
      And pltyp = t_health-plan_type.
* this is the new election
    new_bplan = t5ub6-bplan.
    new_bopti = t58b6-bopti.
    new_bcovr = t5ub6-depcv.
  endselect.
  If sy-subrc ne 0.
*   error message goes here
  endif
endif.