DATA: gt_final1 TYPE TABLE OF ty_final,
go_tree TYPE REF TO cl_salv_tree.
* Create ALV tree
TRY.
cl_salv_tree=>factory(
IMPORTING
r_salv_tree = go_tree
CHANGING
t_table = gt_final1 ).
CATCH cx_salv_error.
LEAVE LIST-PROCESSING.
ENDTRY.
* Set GUI STATUS
go_tree->set_screen_status( pfstatus = 'ZSTATUS'
report = sy-repid
set_functions = go_tree->c_functions_all ).
DATA: lo_events TYPE REF TO cl_salv_events_tree.
lo_events = go_tree->get_event( ).
SET HANDLER go_create->on_link_click FOR lo_events.
SET HANDLER go_create->on_user_command FOR lo_events.
SET HANDLER go_create->reshape_tree FOR lo_events.
METHOD on_user_command.
*---------------------------------------------------------
* Select/ Deselect all checkboxes
*---------------------------------------------------------
DATA: lo_nodes TYPE REF TO cl_salv_nodes,
lt_nodes TYPE salv_t_nodes,
lo_item TYPE REF TO cl_salv_item,
lv_set TYPE xfeld,
lv_value TYPE salv_de_constant.
FIELD-SYMBOLS: <ls_nodes> TYPE salv_s_nodes.
* Get reference of the nodes of the tree
lo_nodes = go_tree->get_nodes( ).
* Get all the nodes of the tree
TRY.
lt_nodes = lo_nodes->get_all_nodes( ).
CATCH cx_salv_msg.
EXIT.
ENDTRY.
CASE sy-ucomm.
WHEN '&ALL'.
lv_set = abap_true. "check
WHEN '&NONE'.
lv_set = abap_false. "uncheck
ENDCASE.
* Loop at the nodes where the type is a checkbox (3)
LOOP AT lt_nodes ASSIGNING <ls_nodes>.
lo_item = <ls_nodes>-node->get_hierarchy_item( ).
lv_value = lo_item->get_type( ).
IF lo_item->is_enabled( ) = abap_true AND lv_value = 3. "Checkbox
lo_item->set_checked( lv_set ).
ENDIF.
ENDLOOP.
ENDMETHOD. "on_user_command
METHOD reshape_tree.
*---------------------------------------------------------
* Expand/ Collapse all nodes
*---------------------------------------------------------
DATA: lo_nodes TYPE REF TO cl_salv_nodes,
lo_columns TYPE REF TO cl_salv_columns.
* Get reference of the nodes of the tree
lo_nodes = go_tree->get_nodes( ).
CASE sy-ucomm.
WHEN '&EXPAND'.
lo_nodes->expand_all( ).
WHEN '&COLLAPSE'.
lo_nodes->collapse_all( ).
ENDCASE.
ENDMETHOD. "reshape_tree
METHOD if_dlv_create_extout~additional_output.
DATA: lt_callstack TYPE abap_callstack.
FIELD-SYMBOLS: <ls_extension_out> TYPE bapiparex,
<ls_messages> TYPE vbfs.
* Read the stack
CALL FUNCTION 'SYSTEM_CALLSTACK'
IMPORTING
callstack = lt_callstack.
SORT lt_callstack BY mainprogram.
* Continue if it is Order Combination report
READ TABLE lt_callstack TRANSPORTING NO FIELDS
WITH KEY mainprogram = 'ZORDER_COMBINATION' "our report name
BINARY SEARCH.
IF sy-subrc EQ 0.
* Fill the Extension Out with VBFS table
LOOP AT it_messages ASSIGNING <ls_messages>.
APPEND INITIAL LINE TO ct_extension_out ASSIGNING <ls_extension_out>.
<ls_extension_out>-structure = 'VBFS'.
<ls_extension_out>-valuepart1 = <ls_messages>.
<ls_extension_out>-valuepart2 = <ls_messages>+240(20).
ENDLOOP.
ENDIF.
ENDMETHOD.
METHOD create_delivery.
*---------------------------------------------------------
* Create the delivery from the selected Orders
*---------------------------------------------------------
DATA: lt_nodes TYPE salv_t_nodes,
lo_item TYPE REF TO cl_salv_item,
lo_data TYPE REF TO data,
lv_delivery TYPE vbeln_vl,
lv_number TYPE vbnum,
lt_sales_orders TYPE STANDARD TABLE OF bapidlvreftosalesorder,
lt_created_items TYPE STANDARD TABLE OF bapidlvitemcreated,
lt_return TYPE STANDARD TABLE OF bapiret2,
lt_extension_out TYPE STANDARD TABLE OF bapiparex,
lo_item_delivery TYPE REF TO cl_salv_item,
lt_vbfs TYPE STANDARD TABLE OF vbfs.
FIELD-SYMBOLS: <ls_nodes> TYPE salv_s_nodes,
<ls_data> TYPE ty_final,
<ls_orders> TYPE bapidlvreftosalesorder,
<ls_items> TYPE bapidlvitemcreated,
<ls_vbfs> TYPE vbfs,
<ls_ext_out> TYPE bapiparex.
* Get the entire subtree
TRY.
lt_nodes = io_node->get_subtree( ).
CATCH cx_salv_msg.
EXIT.
ENDTRY.
* Here we will loop at all the nodes, find the ones that are selected
* and pass those orders to BAPI for Delivery Creation
LOOP AT lt_nodes ASSIGNING <ls_nodes>.
* Get the item details
lo_item = <ls_nodes>-node->get_hierarchy_item( ).
* Get the node data if it is checked
IF lo_item->is_enabled( ) = abap_true
AND lo_item->is_checked( ) = abap_true.
lo_data = <ls_nodes>-node->get_data_row( ).
ASSIGN lo_data->* TO <ls_data>.
IF sy-subrc EQ 0.
* Get the sales order and item
APPEND INITIAL LINE TO lt_sales_orders ASSIGNING <ls_orders>.
<ls_orders>-ref_doc = <ls_data>-vbeln.
<ls_orders>-ref_item = <ls_data>-posnr.
ENDIF.
ENDIF.
ENDLOOP.
*Call the BAPI for delivery creation
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
IMPORTING
delivery = lv_delivery
num_deliveries = lv_number
TABLES
sales_order_items = lt_sales_orders
created_items = lt_created_items
extension_out = lt_extension_out
return = lt_return.
* FIll VBFS from Extension out table
LOOP AT lt_extension_out ASSIGNING <ls_ext_out>.
APPEND INITIAL LINE TO lt_vbfs ASSIGNING <ls_vbfs>.
<ls_vbfs>+0(240) = <ls_ext_out>-valuepart1.
<ls_vbfs>+240(20) = <ls_ext_out>-valuepart2.
ENDLOOP.
SORT lt_vbfs BY vbeln.
SORT lt_created_items BY ref_doc ref_item.
IF lv_delivery IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
* Next, we loop at the nodes and display the delivery
LOOP AT lt_nodes ASSIGNING <ls_nodes>.
lo_item = <ls_nodes>-node->get_hierarchy_item( ).
TRY.
lo_item_delivery = <ls_nodes>-node->get_item( 'DELIVERY' ).
CATCH cx_salv_msg.
EXIT.
ENDTRY.
IF lo_item->is_checked( ) = abap_true.
lo_item->set_checked( abap_false ).
lo_data = <ls_nodes>-node->get_data_row( ).
ASSIGN lo_data->* TO <ls_data>.
IF sy-subrc EQ 0.
* Set the delivery
READ TABLE lt_created_items ASSIGNING <ls_items>
WITH KEY ref_doc = <ls_data>-vbeln
ref_item = <ls_data>-posnr
BINARY SEARCH.
IF sy-subrc EQ 0.
<ls_data>-delivery = <ls_items>-deliv_numb.
<ls_nodes>-node->set_data_row( <ls_data> ).
ELSE.
READ TABLE lt_vbfs ASSIGNING <ls_vbfs>
WITH KEY vbeln = <ls_data>-vbeln
BINARY SEARCH.
IF sy-subrc EQ 0.
MESSAGE ID <ls_vbfs>-msgid TYPE <ls_vbfs>-msgty
NUMBER <ls_vbfs>-msgno
WITH <ls_vbfs>-msgv1 <ls_vbfs>-msgv2
<ls_vbfs>-msgv3 <ls_vbfs>-msgv4
INTO <ls_data>-logs.
ENDIF.
ENDIF.
ENDIF.
* Disable the checkbox if the delivery is created,
IF <ls_data>-delivery IS NOT INITIAL.
lo_item->set_enabled( abap_false ).
lo_item->set_icon( '@0V\QOK@' ). "OK
* Set link-click for the delivery > Now you can navigate to delivery
lo_item_delivery->set_type( if_salv_c_item_type=>link ).
* Set the node to green color
<ls_nodes>-node->set_row_style( if_salv_c_tree_style=>emphasized_positive ).
ELSE.
* Set button for error log
lo_item_delivery->set_type( if_salv_c_item_type=>button ).
lo_item_delivery->set_value( 'Display Error Log' ).
* Set the node to red color
<ls_nodes>-node->set_row_style( if_salv_c_tree_style=>emphasized_negative ).
ENDIF.
ENDIF.
ENDLOOP.
ENDMETHOD. "create_delivery
METHOD on_link_click.
*---------------------------------------------------------
* Method when the user clicks on Link or button
*---------------------------------------------------------
DATA: lo_nodes TYPE REF TO cl_salv_nodes,
lo_node TYPE REF TO cl_salv_node,
lo_data TYPE REF TO data.
FIELD-SYMBOLS: <ls_data> TYPE ty_final.
lo_nodes = go_tree->get_nodes( ).
* Get the parent node
TRY.
lo_node = lo_nodes->get_node( node_key ).
CATCH cx_salv_msg.
EXIT.
ENDTRY.
lo_data = lo_node->get_data_row( ).
ASSIGN lo_data->* TO <ls_data>.
IF sy-subrc EQ 0.
* Check what the user has clicked
CASE <ls_data>-delivery.
WHEN 'Delivery Creation'.
go_create->create_delivery( lo_node ).
WHEN 'Display Error Log'.
MESSAGE <ls_data>-logs TYPE 'I'.
WHEN OTHERS.
* Open the delivery in VL03N
SET PARAMETER ID 'VL' FIELD <ls_data>-delivery.
CALL FUNCTION 'ABAP4_CALL_TRANSACTION'
EXPORTING
tcode = 'VL03N'
skip_screen = abap_true
EXCEPTIONS
call_transaction_denied = 1
tcode_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
EXIT.
ENDCASE.
ENDIF.
ENDMETHOD. "on_link_click
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |