Skip to content

Instantly share code, notes, and snippets.

@js1972
Last active December 20, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save js1972/8d3c195e622d71443cbf to your computer and use it in GitHub Desktop.
Save js1972/8d3c195e622d71443cbf to your computer and use it in GitHub Desktop.
#ABAP #FPM Search GUIBB feeder class for finding Purchase Orders. Contains a good example of a multi-line selectable Search GUIBB as well as usage of the helper class cl_fpm_guibb_search_conversion which enables conversion between search criteria types (FPM, Select-options, WHERE clause). Note: This class uses the NEEDS_CONFIRMATION method of if…
*----------------------------------------------------------------------*
* CLASS zcl_po_serch_feeder DEFINITION
*----------------------------------------------------------------------*
* Feeder class for SEARCH GUIBB that enables searching for
* Purchase Orders.
* Users of this app require authorisation for t-code: SXMB_MONI.
*----------------------------------------------------------------------*
class zcl_po_search_feeder definition
public
final
create public .
public section.
interfaces if_fpm_guibb.
interfaces if_fpm_guibb_search_ext.
interfaces if_fpm_guibb_search.
protected section.
private section.
data purchaseorders type standard table of zspo_search_guibb_def.
data fpm_factory type ref to if_fpm.
data selected_lines_of_result type if_fpm_guibb_search=>t_result.
methods execute_search importing !it_fpm_search_criteria type fpmgb_t_search_criteria
!iv_max_num_results type i
changing !et_messages type fpmgb_search_t_t100_message
!ev_result type fpm_event_result.
methods send_po_outbound returning value(error_messages) type fpmgb_search_t_t100_message.
endclass. "zcl_po_search_feeder DEFINITION
*----------------------------------------------------------------------*
* CLASS ZCL_PO_SEARCH_FEEDER IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class zcl_po_search_feeder implementation.
method execute_search.
data error_message like line of et_messages.
data where_clause_tab type rsds_where_tab.
data abap_struct_ref type ref to cl_abap_structdescr.
abap_struct_ref ?= cl_abap_structdescr=>describe_by_name( 'ZSPO_SEARCH_GUIBB_DEF' ).
try.
cl_fpm_guibb_search_conversion=>to_abap_select_where_tab(
exporting
it_fpm_search_criteria = it_fpm_search_criteria
iv_table_name = 'ZSPO_SEARCH_GUIBB_DEF'
io_field_catalog = abap_struct_ref
importing
et_abap_select_table = where_clause_tab
).
catch cx_fpmgb.
ev_result = if_fpm_constants=>gc_event_result-failed.
error_message-severity = 'E'.
error_message-plaintext = 'Error searching for purchase orders: unable to structure where clause!'.
append error_message to et_messages.
return.
endtry.
"Struct ZSPO_SEARCH_GUIBB_DEF has same fieldnames as EKKO, so we can use
"the WHERE clause without conversion.
"We need to ensure only PO's are selected by adding to the WHERE clause.
if lines( where_clause_tab ) = 0.
append '( BSTYP = ''F'' )' to where_clause_tab.
else.
append 'AND ( BSTYP = ''F'' )' to where_clause_tab.
endif.
clear purchaseorders.
select ebeln lifnr bukrs ekorg ekgrp bedat konnr into table purchaseorders
from ekko up to iv_max_num_results rows
where (where_clause_tab).
if sy-subrc = 0.
ev_result = if_fpm_constants=>gc_event_result-ok.
else.
ev_result = if_fpm_constants=>gc_event_result-failed.
endif.
endmethod. "execute_search
method if_fpm_guibb_search_ext~after_failed_event.
endmethod. "if_fpm_guibb_search_ext~after_failed_event
method if_fpm_guibb_search_ext~before_dispatch_event.
endmethod. "if_fpm_guibb_search_ext~before_dispatch_event
method if_fpm_guibb_search_ext~get_own_persistence_util.
endmethod. "if_fpm_guibb_search_ext~get_own_persistence_util
method if_fpm_guibb_search_ext~needs_confirmation.
data conf_request_obj type ref to cl_fpm_confirmation_request.
data conf_text type string_table.
data msg type string.
case io_event->mv_event_id.
when 'EVENT_ID_SEND'.
check lines( selected_lines_of_result ) > 0.
msg = |Are you sure you wish to send { lines( selected_lines_of_result ) } Purchase Order|.
if lines( selected_lines_of_result ) > 1.
msg = msg && `'s?`.
else.
msg = msg && `?`.
endif.
append msg to conf_text.
create object conf_request_obj
exporting
it_confirmation_text = conf_text.
eo_confirmation_request = conf_request_obj.
endcase.
endmethod. "if_fpm_guibb_search_ext~needs_confirmation
method if_fpm_guibb_search~check_config.
endmethod. "if_fpm_guibb_search~check_config
method if_fpm_guibb_search~flush.
me->selected_lines_of_result = it_selected_lines_of_result.
endmethod. "if_fpm_guibb_search~flush
method if_fpm_guibb_search~get_data.
case io_event->mv_event_id.
when if_fpm_guibb_search=>fpm_execute_search.
check iv_raised_by_own_ui = abap_true.
et_result_list = purchaseorders.
endcase.
endmethod. "if_fpm_guibb_search~get_data
method if_fpm_guibb_search~get_default_config.
endmethod. "if_fpm_guibb_search~get_default_config
method if_fpm_guibb_search~get_definition.
data ls_field like line of et_field_description_attr.
"setup search fields
eo_field_catalog_attr ?= cl_abap_structdescr=>describe_by_name( 'ZSPO_SEARCH_GUIBB_DEF' ).
ev_result_table_selection_mode = '04'. "multiNoLead old: '06' "none
"es_options-raise_event_on_result_lead_sel = abap_true.
ls_field-name = 'EBELN'.
ls_field-default_op = '01'. "is - this is the default anyway
append ls_field to et_field_description_attr.
"setup default result list
eo_field_catalog_result ?= cl_abap_tabledescr=>describe_by_data( purchaseorders ).
endmethod. "if_fpm_guibb_search~get_definition
method if_fpm_guibb_search~process_event.
data lo_event type ref to cl_fpm_event.
data lv_selected_row type i.
data error_message like line of et_messages.
field-symbols <order> like line of purchaseorders.
case io_event->mv_event_id.
when if_fpm_guibb_search=>fpm_execute_search.
"handle when the search button is clicked
check iv_raised_by_own_ui = abap_true.
execute_search( exporting it_fpm_search_criteria = it_fpm_search_criteria
iv_max_num_results = iv_max_num_results
changing ev_result = ev_result
et_messages = et_messages ).
when 'FPM_RESET_SEARCH'.
"handle the event when RESET is selected on the search screen
clear purchaseorders.
when 'FPM_RESULT_SEL'.
"handle the event when a user selects a Purchase Order in the result list
io_event->mo_event_data->get_value( exporting iv_key = 'RESULT_ROW' importing ev_value = lv_selected_row ).
read table purchaseorders assigning <order> index lv_selected_row.
if sy-subrc = 0.
create object lo_event
exporting
iv_event_id = if_fpm_constants=>gc_event-leave_initial_screen.
lo_event->mo_event_data->set_value( iv_key = 'EBELN' iv_value = <order>-ebeln ).
fpm_factory->raise_event( io_event = lo_event ).
endif.
when 'EVENT_ID_SEND'.
if lines( me->selected_lines_of_result ) = 0.
error_message-severity = 'E'.
error_message-plaintext = 'Search and select Purchase Orders first...'.
append error_message to et_messages.
else.
et_messages = send_po_outbound( ).
endif.
endcase.
endmethod. "if_fpm_guibb_search~process_event
method if_fpm_guibb~get_parameter_list.
endmethod. "if_fpm_guibb~get_parameter_list
method if_fpm_guibb~initialize.
data system_message type symsg.
fpm_factory = cl_fpm_factory=>get_instance( ).
"Only allow access if user has t-code SXMB_MONI (i.e. PI support/admin)
authority-check object 'S_TCODE' id 'TCD' field 'SXMB_MONI'.
if sy-subrc <> 0.
system_message-msgty = 'E'.
system_message-msgid = 'ZM'.
system_message-msgno = '014'.
fpm_factory->display_error_page( cl_fpm_error_factory=>create_from_t100( is_t100 = system_message ) ).
endif.
endmethod. "if_fpm_guibb~initialize
method send_po_outbound.
"Loop through the chosen purchase orders and send each one by one
"using the service interface:
"SAP APPL 6.06
"http://sap.com/xi/APPL/Global2
"PurchaseOrderERPReplenishmentOrderCollaborationNotification_Out.
data: po_interface type ref to cl_se_pur_poerprocollabnotif,
bapiret_tab type bapirettab,
error_message like line of error_messages.
field-symbols: <order> like line of purchaseorders,
<selection> like line of me->selected_lines_of_result.
try.
po_interface = cl_se_pur_poerprocollabnotif=>get_instance( ).
loop at me->selected_lines_of_result assigning <selection>.
read table me->purchaseorders index <selection>-index assigning <order>.
if sy-subrc <> 0.
error_message-severity = 'E'.
error_message-plaintext = 'Processing Terminated'.
append error_message to error_messages.
error_message-severity = 'E'.
error_message-plaintext = 'Invalid selection index on search result'.
append error_message to error_messages.
return.
endif.
po_interface->process_out( exporting iv_po_no = <order>-ebeln
importing et_return = bapiret_tab ).
endloop.
commit work.
error_message-severity = 'S'.
error_message-plaintext = 'Selected Purchase Order - Sent!'.
append error_message to error_messages.
catch cx_ai_system_fault. " Application Integration: Technical Error
error_message-severity = 'E'.
error_message-plaintext = 'Processing Terminated'.
append error_message to error_messages.
error_message-severity = 'E'.
error_message-plaintext = 'Proxy System Fault'.
append error_message to error_messages.
catch cx_ops_se. " Error in OPS Service
error_message-severity = 'E'.
error_message-plaintext = 'Processing Terminated'.
append error_message to error_messages.
error_message-severity = 'E'.
error_message-plaintext = 'OPS Service Error (cl_se_pur_poerprocollabnotif)'.
append error_message to error_messages.
catch cx_appl_proxy_badi_processing. " Error in BAdI Processing in Proxy
error_message-severity = 'E'.
error_message-plaintext = 'Processing Terminated'.
append error_message to error_messages.
error_message-severity = 'E'.
error_message-plaintext = 'BAdI Processing error'.
append error_message to error_messages.
endtry.
endmethod. "send_po_outbound
endclass. "ZCL_PO_SEARCH_FEEDER IMPLEMENTATION
@js1972
Copy link
Author

js1972 commented Jul 31, 2013

Code nugget: https://www.dropbox.com/s/n62xgup3neqrnsn/NUGG_ZCL_PO_SEARCH_FEEDER.nugg
(This nugget includes the source of the feeder class as well as the FPM app config files: WebDynpro Application; WebDynpro Application config; OVP config, Component config for the Search GUIBB and Table Structure used for defining the search fields. All up this enables the full running FPM application.)
Image of app: https://www.dropbox.com/s/i75lhiwahfmtfc8/Z_PO_OUTBOUND_SEND_TOOL.PNG

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment