SAP Help create bobx enhancement action









create enhancement action






see @@create-enhancement-determination


Using a
Step 1 - first create a business object enhancement or use existing

find the business object you want to enhance
create enhancement action step 1



Create enhancement
create enhancement action step 2



enter name and business object and press ok to create
create enhancement action step 3






Step 2 - Find business object Elements

first find the relevant business object enhancement created above or one you have created before. It is good practice to keep the number of enhanacements
low. Infact there no reason why you would need more than one per BO, unless you need to develop/transfer then separately or have some specifc reason to do so.
create enhancement action step 5



Double click on business object z enhancement
create enhancement action step 6



Expand the Node Elements
create enhancement action step 7





select change mode
create enhancement action step 8



and find the node you want to create an enhancement Action for (i.e. ROOT). You can expand the actions
node to see all the existing actions available(standard + other enhancements). Useful to see how these work and be able
to find code that you might want to use in your new action.

Right click on the Action node and select Create Action
create enhancement action step 9







ABAP CODE



DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.
FIELD-SYMBOLS: TYPE /scmtms/s_tor_item_tr_k.
DATA: lt_mod TYPE /bobf/t_frw_modification,
ls_mod TYPE /bobf/s_frw_modification,
lo_chg TYPE REF TO /bobf/if_tra_change,
lo_message TYPE REF TO /bobf/if_frw_message,
lv_rejected TYPE abap_bool,
lt_rej_bo_key TYPE /bobf/t_frw_key2.


CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key " Business Object
* iv_create_sync_notifications = ABAP_FALSE " Switch on/off sync notifications
* iv_create_assoc_notifications = ABAP_FALSE " Switch on/off association change notifications
* iv_create_prop_notifications = ABAP_FALSE " Switch on/off property change notifications
RECEIVING
eo_service_manager = lo_svc_mngr. " Interface for (Proxy) Service Manager


CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
RECEIVING
eo_transaction_manager = lo_txn_mngr. " Standalone Transaction Manager Instance

DATA: it_key TYPE /bobf/t_frw_key,
lv_key TYPE /bobf/s_frw_key.

DATA: wa_upd_status LIKE LINE OF it_upd_status.

data: ld_text type string.


****trigger action to set update all stages to unloaded(i.e. arrived and unloaded)
LOOP AT it_stages INTO ls_stages.
REFRESH it_key.
lv_key-key = ls_stages-source_stop_key. "stage stop key
APPEND lv_key TO it_key.

DATA: lr_action_param TYPE REF TO /scmtms/s_tor_a_set_handl_exec.
CREATE DATA lr_action_param.
lr_action_param->handling_exec_stop = '12'. "unloaded (i.e. arrived and unloaded)

"20 departed
"06 arrived
"04 not arrived
"18 loaded
"12 unloaded

lo_svc_mngr->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-stop-set_handling_execution" item_tr-update_quantities " Action executioninformation-process_exec_info "
it_key = it_key " Key Table
is_parameters = lr_action_param " Action
* IMPORTING
* eo_change = " Interface of Change Object
* eo_message = " Interface of Message Object
* et_failed_key = " Key Table
* et_failed_action_key = " Key Table
* et_data =
).


** Call the SAVE method of the transaction manager
lo_txn_mngr->save(
IMPORTING
ev_rejected = lv_rejected
eo_change = lo_chg
eo_message = lo_message
et_rejecting_bo_key = lt_rej_bo_key
).

write/ 'Execution status updated to', wa_upd_status-exec_status.

ENDLOOP.




ABAP Full program
*****************
*&---------------------------------------------------------------------*
*& Report ZUPDATE_EXEC_STATUS
*&---------------------------------------------------------------------*
REPORT ZUPDATE_EXEC_STATUS.

TABLES: /scmtms/s_tor_root_k.

TYPES: BEGIN OF t_exec_status_upd,
execorder TYPE /scmtms/integer_value,
stop_key TYPE /bobf/conf_key,
exec_status TYPE /scmtms/tor_s_hdl_exec_status,
END OF t_exec_status_upd.
DATA: gs_upd_status TYPE t_exec_status_upd,
gt_messages TYPE /scmtms/t_string.
DATA: ld_timestamp TYPE timestamp.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-f03.
PARAMETERS: p_tor_id TYPE /scmtms/tor_to_rail_id. " /scmtms/s_tor_root_k-tor_id .
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-f04.
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-f02.
PARAMETERS: p_lay TYPE disvariant-variant. "ALV Variant
SELECTION-SCREEN END OF BLOCK b3.

TYPES: tt_item_tr TYPE TABLE OF /scmtms/s_tor_item_tr_k WITH NON-UNIQUE KEY item_parent_key item_id .

DATA: lt_item TYPE /scmtms/t_tor_item_tr_k,
wa_item TYPE /scmtms/s_tor_item_tr_k,
lt_wagon TYPE /scmtms/t_tor_item_tr_k,
ls_head TYPE /scmtms/s_tor_item_tr_k.

DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.

DATA: lt_root TYPE /scmtms/t_tor_root_k,
lt_party TYPE /scmtms/t_tor_party_k,
lt_stages TYPE /scmtms/t_pln_stage,
lt_stops TYPE /scmtms/t_tor_stop_k,
ls_stop TYPE /scmtms/s_tor_stop_k.

DATA: lt_key TYPE /bobf/t_frw_key,
ls_key TYPE /bobf/s_frw_key,
lt_sel TYPE /bobf/t_frw_query_selparam.


TYPES: BEGIN OF t_rows,
row TYPE /scmtms/res_seq_drv,
END OF t_rows.
DATA: it_rows TYPE STANDARD TABLE OF t_rows,
wa_rows LIKE LINE OF it_rows,
ld_count TYPE /scmtms/res_seq_drv,
lv_answer TYPE c.
FIELD-SYMBOLS: TYPE /scmtms/s_tor_root_k.


*Data Declaration
*---------------------------------------------------------------------------------*
TYPES: BEGIN OF t_report,
sel TYPE xfeld,
stage(10) TYPE c,
tor_id TYPE /scmtms/tor_to_rail_id,
voyage_id TYPE /scmtms/voyage_id,
date TYPE datum,
time TYPE uzeit,
fromid TYPE /sapapo/locno,
toid TYPE /sapapo/locno,
desc TYPE string,
handling_exec TYPE /scmtms/tor_s_hdl_exec_status,
handling_text TYPE string,
new_exec TYPE /scmtms/tor_s_hdl_exec_status,
stop_key TYPE /bobf/conf_key,
line_color TYPE lvc_t_scol,
field_style TYPE lvc_t_styl, "FOR DISABLE
celltype TYPE salv_t_int4_column,
END OF t_report.
DATA: lt_s_color TYPE lvc_t_scol.
DATA: ls_s_color TYPE lvc_s_scol.

DATA: it_report TYPE STANDARD TABLE OF t_report,
wa_report LIKE LINE OF it_report.
DATA alv_table TYPE REF TO cl_salv_table.
DATA alv_columns TYPE REF TO cl_salv_columns_table.
DATA single_column TYPE REF TO cl_salv_column.
DATA: g_xstring TYPE xstring.

DATA: gd_save_chk TYPE c.
DATA:
lt_item_tr TYPE /scmtms/t_tor_item_tr_k,
ls_stages TYPE /scmtms/s_pln_stage,
lv_domval TYPE dd07l-domvalue_l,
ls_dd07v TYPE dd07v.

DATA: gd_sid TYPE /scmtms/voyage_id,
gd_sdate TYPE datum.
DATA: gd_nodatames TYPE string.

"screen ALV definitions
*---------------------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------------------*
* Local Class definition
*---------------------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION FINAL.
PUBLIC SECTION.
METHODS:
on_f4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display.
METHODS:
catch_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id "#EC NEEDED
e_column_id
es_row_no.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed
e_onf4 e_onf4_before e_onf4_after.

ENDCLASS. "lcl_event_receiver DEFINITION


*---------------------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------------------*
* Implement Local Event
*---------------------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD on_f4.
ENDMETHOD.

METHOD catch_hotspot_click.
CONSTANTS: lc_screen_9000 TYPE sydynnr VALUE '9000'.
DATA: ls_stable TYPE lvc_s_stbl,

lv_retcode TYPE sysubrc.
DATA: seltab TYPE TABLE OF rsparams,
seltab_wa LIKE LINE OF seltab.

FIELD-SYMBOLS: LIKE LINE OF it_report, LIKE LINE OF it_report.

CASE e_column_id-fieldname.
WHEN 'SEL'. "Checkbox selected/deselected READ TABLE it_report ASSIGNING INDEX es_row_no-row_id. IF -sel IS INITIAL.
LOOP AT it_report ASSIGNING . CLEAR: -sel.
ENDLOOP. -sel = 'X'.
ELSE. CLEAR: -sel.
ENDIF.

PERFORM refresh_the_screen.
WHEN OTHERS.
ENDCASE.
ENDMETHOD. "catch_hotspot_click


METHOD handle_data_changed.
* See class CL_ALV_CHANGED_DATA_PROTOCOL for all methods and attributes
* of er_data_changed including their type

DATA: ls_good_cells TYPE lvc_s_modi,
ls_row TYPE REF TO data.
DATA: l_price TYPE sflight-price,
ld_fieldname(100) TYPE c.
FIELD-SYMBOLS: TYPE t_report, "t_tms_item, TYPE any.

* loop at all fiels that have changed
LOOP AT er_data_changed->mt_good_cells INTO ls_good_cells.

* Read table row that has changed READ TABLE it_report ASSIGNING INDEX ls_good_cells-row_id.

* Build name of table field that changed within field symbol CONCATENATE '-' ls_good_cells-fieldname INTO ld_fieldname.

* Assign a fs to field that has changed ASSIGN (ld_fieldname) TO .

* Get new value straight into table field
CALL METHOD er_data_changed->get_cell_value
EXPORTING
i_row_id = ls_good_cells-row_id
i_fieldname = ls_good_cells-fieldname
IMPORTING e_value = . "-res_seq.

* Set flag that data has changed
gd_save_chk = 'X'.
ENDLOOP.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_event_receiver IMPLEMENTATION

DATA:
gt_fcat TYPE lvc_t_fcat,
gt_sort TYPE lvc_t_sort,
gs_sort TYPE lvc_s_sort,
gs_container TYPE scrfname VALUE 'CONT1',
gs_grid TYPE REF TO cl_gui_alv_grid,
go_docking TYPE REF TO cl_gui_docking_container, "Needed for header
go_splitter TYPE REF TO cl_gui_easy_splitter_container, "Needed for header
go_top_cont TYPE REF TO cl_gui_container, "Needed for header
go_bot_cont TYPE REF TO cl_gui_container, "Needed for header
go_document TYPE REF TO cl_dd_document, "Needed for header
gs_custom_container TYPE REF TO cl_gui_custom_container,
gs_event_receiver TYPE REF TO lcl_event_receiver,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant.
***** ALV screen definition end


*---------------------------------------------------------------------------------*
* AT SELECTION-SCREEN ON VALUE-REQUEST *
*---------------------------------------------------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_lay.
PERFORM f4_layouts
USING if_salv_c_layout=>restrict_none
CHANGING p_lay.


*---------------------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------------------*
INITIALIZATION.
* Get default report layout.
PERFORM get_default_layout
USING if_salv_c_layout=>restrict_none
CHANGING p_lay.


************************************************************************
* START-OF-SELECTION
START-OF-SELECTION.
gd_nodatames = 'No data found'.
IF p_tor_id IS INITIAL.
MESSAGE i000(/SCMTMS/GENERAL) WITH 'Please enter TOR_ID'.
EXIT.
ELSE.
* Get dg data.
PERFORM data_retrieval.
ENDIF.

************************************************************************
* END-OF-SELECTION
END-OF-SELECTION.
IF NOT it_report[] IS INITIAL.
CALL SCREEN 9000.
ELSE.
MESSAGE i000(/SCMTMS/GENERAL) WITH gd_nodatames.
ENDIF.

*---------------------------------------------------------------------------------*
FORM get_default_layout USING i_restrict TYPE salv_de_layout_restriction
CHANGING c_layout TYPE disvariant-variant.

DATA: ls_layout TYPE salv_s_layout_info,
ls_key TYPE salv_s_layout_key.

ls_key-report = sy-repid.

ls_layout = cl_salv_layout_service=>get_default_layout(
s_key = ls_key
restrict = i_restrict ).

c_layout = ls_layout-layout.
ENDFORM. " get_default_layout


*&---------------------------------------------------------------------*

*& FORM data retrieval.


* Retirve data related to the freight order selection criteria
*&---------------------------------------------------------------------*
FORM data_retrieval.
DATA: lt_torexe TYPE STANDARD TABLE OF /scmtms/d_torexe,
ls_torexe LIKE LINE OF lt_torexe.

DATA: lt_keys TYPE /bobf/t_frw_key.
DATA: wa_keys LIKE LINE OF lt_keys.

DATA: lt_torstp TYPE STANDARD TABLE OF /scmtms/d_torstp,
ls_torstp LIKE LINE OF lt_torstp.

TYPES: BEGIN OF t_tor,
db_key TYPE /scmtms/d_torrot-db_key,
tor_id TYPE /scmtms/d_torrot-tor_id,
plan_trans_time TYPE /scmtms/d_torstp-plan_trans_time,
END OF t_tor.
DATA: lt_tor TYPE STANDARD TABLE OF t_tor.

DATA ls_stylerow TYPE lvc_s_styl .
DATA lt_styletab TYPE lvc_t_styl .
DATA: lt_selparam TYPE /bobf/t_frw_query_selparam.
DATA: lt_data TYPE /scmtms/t_tor_root_k,
ls_data TYPE /scmtms/s_tor_root_k.

DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.
wa_report-tor_id = p_tor_id. "-tor_id.

REFRESH: lt_item, lt_wagon, lt_stops, lt_root.

CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key " Business Object
* iv_create_sync_notifications = ABAP_FALSE " Switch on/off sync notifications
* iv_create_assoc_notifications = ABAP_FALSE " Switch on/off association change notifications
* iv_create_prop_notifications = ABAP_FALSE " Switch on/off property change notifications
RECEIVING
eo_service_manager = lo_svc_mngr. " Interface for (Proxy) Service Manager

*Auto complete is ctrl+space, select, tab, ctrl+space, select, tab
CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
RECEIVING
eo_transaction_manager = lo_txn_mngr. " Standalone Transaction Manager Instance APPEND INITIAL LINE TO lt_selparam ASSIGNING FIELD-SYMBOL(). -attribute_name = 'TOR_ID'. -sign = 'I'. -option = 'EQ'. -low = p_tor_id. "'6100000011'. "-HIGH
lo_svc_mngr->query(
EXPORTING
iv_query_key = /scmtms/if_tor_c=>sc_query-root-tor_key_by_pln_attr " fo_data_by_attr " fu_data_by_attr "if_resource_c=>sc_query-root-qu_by_attributes " QU_BY_ATTRIBUTES_ALL " Query
* IT_FILTER_KEY = " Key Table
it_selection_parameters = lt_selparam " Query Selection Parameters
* IS_QUERY_OPTIONS = " Query Options
iv_fill_data = abap_true " Data element for domain BOOLE: TRUE (='X') and FALSE (=' ')
* IT_REQUESTED_ATTRIBUTES = " List of Names (e.g. Fieldnames)
IMPORTING
* EO_MESSAGE = " Message Object
* ES_QUERY_INFO = " Query Information
et_data = lt_data
et_key = lt_key
).

CALL METHOD /scmtms/cl_print_helper=>get_tor_nodes
EXPORTING
it_key = lt_key
IMPORTING
et_root = lt_root
et_item_tr = lt_item
et_party = lt_party
et_stages = lt_stages
et_stop = lt_stops.

lt_item_tr[] = lt_item[].

DATA: ld_stage TYPE n,
ld_val TYPE dd07v-domvalue_l,
wa_dd07v TYPE dd07v.
LOOP AT lt_stages ASSIGNING FIELD-SYMBOL(). " MOVE-CORRESPONDING TO wa_report. wa_report-stop_key = -source_stop_key.
ld_stage = sy-tabix.
ld_val = wa_report-handling_exec.

CONCATENATE 'Stage' ld_stage INTO wa_report-stage.

CALL FUNCTION 'DDUT_DOMVALUE_TEXT_GET'
EXPORTING
name = '/SCMTMS/TOR_S_HDL_EXEC_STATUS'
value = ld_val
* LANGU = SY-LANGU
* TEXTS_ONLY = ' '
IMPORTING
dd07v_wa = wa_dd07v
EXCEPTIONS
not_found = 1
illegal_input = 2
OTHERS = 3.

wa_report-handling_text = wa_dd07v-ddtext.

READ TABLE lt_stops INTO ls_stop WITH KEY stop_id = '0000000010'.

CONVERT TIME STAMP ls_stop-plan_trans_time TIME ZONE sy-zonlo INTO DATE wa_report-date TIME wa_report-time. "ls_torstp

wa_report-voyage_id = ls_head-voyage_id.

CLEAR: wa_report-fromid.
wa_report-fromid = -source_stop-log_locid.

CLEAR: wa_report-toid.
wa_report-toid = -dest_stop-log_locid.

ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled." mc_style_disabled.

ls_stylerow-fieldname = 'NEW_EXEC' .
INSERT ls_stylerow INTO TABLE wa_report-field_style.
ls_stylerow-style = cl_gui_alv_grid=>mc_style_enabled." mc_style_disabled.

APPEND wa_report TO it_report.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL


*&---------------------------------------------------------------------*

*& FORM build layout.


*&---------------------------------------------------------------------*
FORM build_layout.
DATA: layout TYPE REF TO cl_salv_layout.
DATA: layout_key TYPE salv_s_layout_key.
layout = alv_table->get_layout( ).
layout_key-report = sy-repid.
layout->set_key( layout_key ).
layout->set_save_restriction( if_salv_c_layout=>restrict_none ).
" layout->set_initial_layout( pa_lay ).
" layout->set_default( 'X' ).
ENDFORM. "BUILD_LAYOUT


*&---------------------------------------------------------------------*

*& Form f4 layouts


*&---------------------------------------------------------------------*
FORM f4_layouts USING i_restrict TYPE salv_de_layout_restriction
CHANGING c_layout TYPE disvariant-variant.

DATA: ls_layout TYPE salv_s_layout_info,
ls_key TYPE salv_s_layout_key.

ls_key-report = sy-repid.

ls_layout = cl_salv_layout_service=>f4_layouts(
s_key = ls_key
restrict = i_restrict ).

c_layout = ls_layout-layout.
ENDFORM.


*&---------------------------------------------------------------------*

*& Form REPORT HEADER


*&---------------------------------------------------------------------*
* Report Header
*---------------------------------------------------------------------------------*
FORM report_header USING p_type TYPE c.
DATA: header TYPE REF TO cl_salv_form_layout_grid,
label TYPE REF TO cl_salv_form_label,
flow TYPE REF TO cl_salv_form_layout_flow,
picture TYPE REF TO cl_salv_form_picture,
logo TYPE REF TO cl_salv_form_layout_logo.
DATA: ld_txt(100) TYPE c.
DATA tz TYPE ttzz-tzone.

TYPES:
BEGIN OF ty_s_slv_header_add,
label TYPE string,
tip TYPE string,
text TYPE string,
END OF ty_s_slv_header_add .

DATA: l_text TYPE sdydo_text_element.

CALL METHOD go_document->add_text_as_heading
EXPORTING
text = 'Update Execution Status'.

CALL METHOD go_document->add_text
EXPORTING
text = 'Date/Time:'.

CALL METHOD go_document->add_gap
EXPORTING
width = 17.

WRITE sy-datum TO l_text DD/MM/YYYY.
CALL METHOD go_document->add_text
EXPORTING
text = l_text.
CALL METHOD go_document->new_line.

CALL METHOD go_document->display_document
EXPORTING
parent = go_top_cont.

* Calling top of page pf ALV
CALL METHOD gs_grid->list_processing_events
EXPORTING
i_event_name = 'TOP_OF_PAGE'.

ENDFORM.


*&---------------------------------------------------------------------*

*& Form FILL FIELD CATALOG


*&---------------------------------------------------------------------*
FORM fill_field_catalog . FIELD-SYMBOLS: LIKE LINE OF gt_fcat.
DATA: wa_fcat LIKE LINE OF gt_fcat.
CLEAR: gt_fcat.

wa_fcat-fieldname = 'SEL' .
wa_fcat-checkbox = abap_true.
wa_fcat-edit = abap_true.
wa_fcat-hotspot = abap_true.
wa_fcat-key = abap_true.
wa_fcat-col_pos = 1.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'STAGE' .
wa_fcat-scrtext_s = 'Stage' .
wa_fcat-scrtext_m = 'Stage' .
wa_fcat-scrtext_l = 'Stage' .
wa_fcat-col_pos = 2.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'TOR_ID' .
wa_fcat-scrtext_s = 'Order' .
wa_fcat-scrtext_m = 'Order' .
wa_fcat-scrtext_l = 'Order' .
wa_fcat-datatype = 'NUMC'. " remove leading zeroes for display only
wa_fcat-col_pos = 3.
wa_fcat-key = abap_true.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'VOYAGE_ID' .
wa_fcat-scrtext_s = 'Voyage' .
wa_fcat-scrtext_m = 'Voyage ID' .
wa_fcat-scrtext_l = 'Voyage ID' .
wa_fcat-key = abap_true.
wa_fcat-col_pos = 4.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'FROMID' .
wa_fcat-scrtext_s = 'From ID' .
wa_fcat-scrtext_m = 'From ID' .
wa_fcat-scrtext_l = 'From ID' .
wa_fcat-key = abap_true.
wa_fcat-col_pos = 5.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.


wa_fcat-fieldname = 'TOID' .
wa_fcat-scrtext_s = 'To ID' .
wa_fcat-scrtext_m = 'To ID' .
wa_fcat-scrtext_l = 'To ID' .
wa_fcat-key = abap_true.
wa_fcat-col_pos = 7.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.


wa_fcat-fieldname = 'HANDLING_EXEC' .
wa_fcat-scrtext_s = 'Current Status' .
wa_fcat-scrtext_m = 'Current Status' .
wa_fcat-scrtext_l = 'Current Status' .
wa_fcat-col_pos = 9.
wa_fcat-outputlen = 8.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'HANDLING_TEXT' .
wa_fcat-scrtext_s = 'Current Status' .
wa_fcat-scrtext_m = 'Current Status' .
wa_fcat-scrtext_l = 'Current Status' .
wa_fcat-col_pos = 9.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.

wa_fcat-fieldname = 'NEW_EXEC' .
wa_fcat-scrtext_s = 'New Status' .
wa_fcat-scrtext_m = 'New Status' .
wa_fcat-scrtext_l = 'New Status' .
wa_fcat-col_pos = 9.
wa_fcat-ref_field = 'HANDLING_EXEC'.
wa_fcat-ref_table = '/SCMTMS/D_TORSTP'.
wa_fcat-edit = 'X'.
wa_fcat-f4availabl = 'X'.
wa_fcat-outputlen = 8.
APPEND wa_fcat TO gt_fcat.
CLEAR: wa_fcat.
ENDFORM.


*&---------------------------------------------------------------------*

*& Form CHECK BEFORE EXIT


*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
FORM check_before_exit .


IF gd_save_chk = 'X'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Loss of data'
text_question = 'Changes will be lost. Do you want to continue?'
text_button_1 = 'Yes'
text_button_2 = 'No'
default_button = '2'
display_cancel_button = ' '
IMPORTING
answer = lv_answer.
IF lv_answer = 1. "yes
LEAVE TO SCREEN 0.
ENDIF.
ELSE.
LEAVE TO SCREEN 0.
ENDIF.
ENDFORM.


*&---------------------------------------------------------------------*

*& Form REFRESH THE SCREEN


*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
FORM refresh_the_screen .
* Refresh the screen.
* This all needs to happen in the PBO so just leave to screen and let
* PBO of screen handle it
LEAVE TO SCREEN 9000.
ENDFORM.


*&---------------------------------------------------------------------*

*& Form SET DRDN TABLE


*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
FORM set_drdn_table .
*ยง1.Define a dropdown table and pass it to ALV.
* One listbox is referenced by a handle, e.g., '1'.
* For each entry that shall appear in this listbox
* you have to append a line to the dropdown table
* with handle '1'.
* This handle can be assigned to several columns
* of the output table using the field catalog.
*
DATA: lt_dropdown TYPE lvc_t_drop,
ls_dropdown TYPE lvc_s_drop.

DATA: lt_dral TYPE lvc_t_dral, "#EC NEEDED
ls_dral TYPE lvc_s_dral. "#EC NEEDED

* First listbox (handle '1').


*Use lvc_t_drop if value is same as display text
* ls_dropdown-handle = '1'.
* ls_dropdown-value = 'G'.
* append ls_dropdown to lt_dropdown.
* gs_grid->set_drop_down_table(
* it_drop_down = lt_dropdown ).

*else use lvc_t_dral if value is different to diaplsy text
* ls_dral-handle = '1'.
* ls_dral-int_value = 'KG'.
* ls_dral-value = 'Kilogramm'.
* append ls_dral to lt_dral.

" LOOP AT it_tb INTO wa_tab.
ls_dral-handle = '1'.
" ls_dral-int_value = wa_tab-field1.
" ls_dral-value = wa_tab-field2.

APPEND ls_dral TO lt_dral.
" ENDLOOP.

gs_grid->set_drop_down_table(
it_drop_down_alias = lt_dral ).
ENDFORM.

*PBO
*---------------------------------------------------------------------------------*
***INCLUDE Z..._O01.
*---------------------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'STANDARD1'.
SET TITLEBAR '001'.

DATA: lt_toolbar_excl_tab TYPE ui_functions.

IF gs_grid IS INITIAL.

*Added for Header
* Create object docking container
CREATE OBJECT go_docking
EXPORTING
ratio = '95'.

CREATE OBJECT go_splitter
EXPORTING
parent = go_docking
orientation = 0
sash_position = 20
with_border = 1.

* Split docking container
go_top_cont = go_splitter->top_left_container.
go_bot_cont = go_splitter->bottom_right_container.

gs_variant-report = sy-repid.
gs_variant-variant = p_lay.

* Modified for Header
CREATE OBJECT gs_grid
EXPORTING
i_parent = go_bot_cont. ""gs_custom_container.

* Added for Header
* Create document object
CREATE OBJECT go_document
EXPORTING
style = 'ALV_GRID'.
* Header for screen ALV
PERFORM report_header USING ' '.

* Build screen alv field catalog
PERFORM fill_field_catalog.

* Define a drop down table.
PERFORM set_drdn_table.

* ALV Grid Layout settings
gs_layout-cwidth_opt = abap_true. "ALV control: Optimise column width
gs_layout-no_rowmark = abap_true. "ALV control: Disable row selections

* style functionality
gs_layout-stylefname = 'FIELD_STYLE'.

* COLOR functionality
"gs_layout-info_fname = 'LINE_COLOR'. "Denotes which field will nominate the colour for a row on the report.
"gs_layout-ctab_fname = 'COLOR_CELL'. "Denotes which field will nominate the colour for an individual cell on the report.

** ALV Toolbar Functions to be excluded (not shown)
APPEND cl_gui_alv_grid=>mc_fc_loc_insert_row TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_loc_append_row TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_loc_delete_row TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_loc_copy_row TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_check TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_refresh TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_loc_paste_new_row TO lt_toolbar_excl_tab.
* APPEND cl_gui_alv_grid=>mc_fc_loc_copy TO lt_toolbar_excl_tab.
* APPEND cl_gui_alv_grid=>mc_fc_loc_cut TO lt_toolbar_excl_tab.
APPEND cl_gui_alv_grid=>mc_fc_loc_paste TO lt_toolbar_excl_tab.

DATA: gs_print TYPE lvc_s_prnt.

CALL METHOD gs_grid->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = 'A'
is_layout = gs_layout
it_toolbar_excluding = lt_toolbar_excl_tab
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = it_report[] "gt_inv_items[]
it_sort = gt_sort.


CREATE OBJECT gs_event_receiver.
SET HANDLER: gs_event_receiver->on_f4 FOR gs_grid,
gs_event_receiver->catch_hotspot_click FOR gs_grid.
" gs_event_receiver->handle_top_of_page FOR gs_grid,
" gs_event_receiver->handle_top_of_list FOR gs_grid.

* CREATE OBJECT gs_event_receiver.
SET HANDLER gs_event_receiver->handle_data_changed FOR gs_grid.

* Set editable cells to ready for input initially
CALL METHOD gs_grid->set_ready_for_input
EXPORTING
i_ready_for_input = 1.

* Registering the EDIT Event
CALL METHOD gs_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified
EXCEPTIONS
error = 1
OTHERS = 2. IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSE.
* refresh_table_display must be called from the screen PBO for it to work 100% of the time
CALL METHOD gs_grid->refresh_table_display
EXPORTING
" is_stable = ls_stable
i_soft_refresh = ' '
EXCEPTIONS
finished = 1
OTHERS = 2. IF sy-subrc <> 0 ##needed.
ENDIF.
ENDIF.

ENDMODULE.


*---------------------------------------------------------------------------------*
FORM event_top_of_page USING dg_dyndoc_id TYPE REF TO cl_dd_document.

DATA:w_length(255) TYPE c,
w_leng TYPE i.

ENDFORM.

*PAI

*---------------------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
DATA: eo_message TYPE REF TO /bobf/if_frw_message.

TYPES: BEGIN OF t_mess,
message(250) TYPE c,
END OF t_mess.
DATA: it_messages TYPE STANDARD TABLE OF t_mess,
wa_messages LIKE LINE OF it_messages.
DATA: ld_lines TYPE i.




DATA: it_message TYPE /bobf/t_frw_message_k.
DATA: ld_etxt TYPE string.
DATA: ld_line TYPE sy-tabix.

DATA: lt_upd_status TYPE STANDARD TABLE OF t_exec_status_upd,
wa_upd_status TYPE t_exec_status_upd.

FIELD-SYMBOLS: TYPE /bobf/s_frw_message_k. FIELD-SYMBOLS: TYPE t_report. "t_tms_item.

* Action the User Command.
CASE sy-ucomm.
WHEN 'BACK'. "back
LEAVE TO SCREEN 0.
" PERFORM check_before_exit.
WHEN 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0.
" PERFORM check_before_exit.
WHEN 'STATUS'.
LOOP AT it_report ASSIGNING WHERE sel = 'X'.
ENDLOOP.
IF sy-subrc EQ 0. MOVE-CORRESPONDING TO wa_report.

wa_upd_status-execorder = 1. wa_upd_status-exec_status = -new_exec. wa_upd_status-stop_key = -stop_key.
APPEND wa_upd_status TO lt_upd_status.

PERFORM execute_update TABLES lt_upd_status.

SUBMIT (sy-repid) WITH p_tor_id = p_tor_id.
ELSE.
MESSAGE i000(/SCMTMS/GENERAL) WITH 'Please select a row to Update'.
ENDIF.
ENDCASE.
ENDMODULE.


*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9001 INPUT
*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
MODULE user_command_9001 INPUT.
gd_save_chk = 'X'.
CASE sy-ucomm.
WHEN 'BACK' OR 'SAVE'. "back LOOP AT it_report ASSIGNING WHERE sel = 'X'. MOVE-CORRESPONDING wa_report TO .
EXIT.
ENDLOOP.
PERFORM check_before_exit.
WHEN 'EXIT' OR 'CANC'.
PERFORM check_before_exit.
WHEN OTHERS.

ENDCASE.
ENDMODULE.

*&---------------------------------------------------------------------*

*& Form EXECUTE UPDATE2


*&---------------------------------------------------------------------*
* text
*---------------------------------------------------------------------------------*
* -->P_LT_UPD_STATUS text
*---------------------------------------------------------------------------------*
FORM execute_update TABLES it_upd_status STRUCTURE gs_upd_status.


DATA lo_svc_mngr TYPE REF TO /bobf/if_tra_service_manager.
DATA lo_txn_mngr TYPE REF TO /bobf/if_tra_transaction_mgr.
FIELD-SYMBOLS: TYPE /scmtms/s_tor_item_tr_k.
DATA: lt_mod TYPE /bobf/t_frw_modification,
ls_mod TYPE /bobf/s_frw_modification,
lo_chg TYPE REF TO /bobf/if_tra_change,
lo_message TYPE REF TO /bobf/if_frw_message,
lv_rejected TYPE abap_bool,
lt_rej_bo_key TYPE /bobf/t_frw_key2.


CALL METHOD /bobf/cl_tra_serv_mgr_factory=>get_service_manager
EXPORTING
iv_bo_key = /scmtms/if_tor_c=>sc_bo_key " Business Object
* iv_create_sync_notifications = ABAP_FALSE " Switch on/off sync notifications
* iv_create_assoc_notifications = ABAP_FALSE " Switch on/off association change notifications
* iv_create_prop_notifications = ABAP_FALSE " Switch on/off property change notifications
RECEIVING
eo_service_manager = lo_svc_mngr. " Interface for (Proxy) Service Manager


*Auto complete is ctrl+space, select, tab, ctrl+space, select, tab
CALL METHOD /bobf/cl_tra_trans_mgr_factory=>get_transaction_manager
RECEIVING
eo_transaction_manager = lo_txn_mngr. " Standalone Transaction Manager Instance


DATA: it_key TYPE /bobf/t_frw_key,
lv_key TYPE /bobf/s_frw_key.


DATA: it_dd07v TYPE TABLE OF dd07v,
wa_dd07v TYPE dd07v.
DATA: wa_upd_status LIKE LINE OF it_upd_status.

DATA: ld_text TYPE string.

LOOP AT it_upd_status INTO wa_upd_status.
REFRESH it_key.
lv_key-key = wa_upd_status-stop_key. "
APPEND lv_key TO it_key.

DATA: lr_action_param TYPE REF TO /scmtms/s_tor_a_set_handl_exec.
CREATE DATA lr_action_param.
lr_action_param->handling_exec_stop = wa_upd_status-exec_status.
" gd_curr_status = ls_stages-handling_exec.
" gd_next_status
" gd_curr_item


"test 610000...16
"20 departed
"06 arrived
"04 not arrived

lo_svc_mngr->do_action(
EXPORTING
iv_act_key = /scmtms/if_tor_c=>sc_action-stop-set_handling_execution" item_tr-update_quantities " Action executioninformation-process_exec_info "
it_key = it_key " Key Table
is_parameters = lr_action_param " Action
* IMPORTING
* eo_change = " Interface of Change Object
* eo_message = " Interface of Message Object
* et_failed_key = " Key Table
* et_failed_action_key = " Key Table
* et_data =
).


** Call the SAVE method of the transaction manager
lo_txn_mngr->save(
IMPORTING
ev_rejected = lv_rejected
eo_change = lo_chg
eo_message = lo_message
et_rejecting_bo_key = lt_rej_bo_key
).


DATA:

ld_val TYPE dd07v-domvalue_l.


ld_val = wa_upd_status-exec_status.
CALL FUNCTION 'DDUT_DOMVALUE_TEXT_GET'
EXPORTING
name = '/SCMTMS/TOR_S_HDL_EXEC_STATUS'
value = ld_val
* LANGU = SY-LANGU
* TEXTS_ONLY = ' '
IMPORTING
dd07v_wa = wa_dd07v
EXCEPTIONS
not_found = 1
illegal_input = 2
OTHERS = 3. IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


CONCATENATE 'Execution status updated to' wa_dd07v-ddtext INTO ld_text SEPARATED BY space.
APPEND ld_text TO gt_messages.


ENDLOOP.
IF sy-subrc NE 0.
ld_text = 'Loco has already been departed'.
APPEND ld_text TO gt_messages.
ENDIF.
ENDFORM.