You are on page 1of 9

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

* Program: ZAM02004
Creation Date: 2006/12/22 *
* Title : Fixed Assets Retirements
*
* Author : Marisol Alarcon V.
*
* Type : Report ALV
Script ID: ITGETBEHAA20-EX108 *
*&------------------------------------------------------------------**
* Description: Delete fixed Asset
*
*&------------------------------------------------------------------**
* Modification History
*
* YYYY/MM/DD
Author
Description
Transport# *
*&---------- -------------- ----------------------------------------**
* 2006/12/22
Marisol Alarcon V. Developed program DV5K927424 *
*--------------------------------------------------------------------*
PROGRAM zam02004
NO STANDARD PAGE HEADING
LINE-SIZE 1023 MESSAGE-ID 00.
INCLUDE <icon>.
*&---------------------------------------------------------------------*& Tables Definition
*&---------------------------------------------------------------------*
TABLES: zf02014. "Maestro de activos fijos tablas ANLA, ANLB,ANLC, ANLZ
*&---------------------------------------------------------------------*
*& Definicin de Parmetros y Select-Options
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bloq1 WITH FRAME TITLE text-t01.
PARAMETERS: p_bukrs LIKE zf02014-bukrs OBLIGATORY
DEFAULT '2158'. "" Company Code
SELECT-OPTIONS: s_anln1 FOR zf02014-anln1. "Main asset number
PARAMETERS: p_anln2 LIKE zf02014-anln2 OBLIGATORY
DEFAULT '0000'."Asset sub-number
SELECT-OPTIONS: "s_anln2 FOR zf02014-anln2,"Asset sub-numbe
s_werks FOR zf02014-werks,"Plant
s_kostl FOR zf02014-kostl,"Cost Center
s_ord44 FOR zf02014-ord44, "Operating Plant
s_stort FOR zf02014-stort, "Asset location
s_ktansw FOR zf02014-ktansw, ". contable account
s_ktogr FOR zf02014-ktogr, "Account determination
s_anlkl FOR zf02014-anlkl, "Asset class
s_ord43 FOR zf02014-ord43, "Category Codes
s_aktiv FOR zf02014-aktiv. "Asset capitalization date
SELECTION-SCREEN END OF BLOCK bloq1.
*----------------------------------------------------------------------*
* Types Definition
*----------------------------------------------------------------------*
TYPES: ty_zf02014 TYPE zf02014.
*----------------------------------------------------------------------*
* internal tables
*----------------------------------------------------------------------*
DATA: it_zf02014 TYPE STANDARD TABLE OF ty_zf02014.
DATA: wa_zf02014 TYPE ty_zf02014.
* Predefine a local class for event handling to allow the
* declaration of a reference variable before the class is defined.
CLASS lcl_event_receiver DEFINITION DEFERRED.

DATA: ok_code LIKE sy-ucomm,


gt_sflight TYPE TABLE OF sflight,
gt_sbook TYPE TABLE OF sbook,
g_repid LIKE sy-repid,
g_max TYPE i VALUE 100,
gs_fieldcat TYPE lvc_s_fcat,
gt_fieldcat TYPE lvc_t_fcat,
gt_sort
TYPE lvc_t_sort,
gs_sort
TYPE lvc_s_sort,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
"for parameter IS_VARIANT
g_alv
TYPE REF TO cl_gui_alv_grid,
cont_on_main TYPE scrfname VALUE 'BCALVC_TOOLBAR_D100_C1',
cont_on_dialog TYPE scrfname VALUE 'BCALVC_TOOLBAR_D101_C1',
grid1 TYPE REF TO cl_gui_alv_grid,
custom_container1 TYPE REF TO cl_gui_custom_container,
event_receiver TYPE REF TO lcl_event_receiver.
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
*===============================================================
* class lcl_event_receiver: local class to
*
define and handle own functions.
*
* Definition:
* ~~~~~~~~~~~
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive,
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
ENDCLASS.
*
* lcl_event_receiver (Definition)
*===============================================================
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
*===============================================================
* class lcl_event_receiver (Implementation)
*
*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
* 2.In event handler method for event TOOLBAR: Append own functions
* by using event parameter E_OBJECT.
DATA: ls_toolbar TYPE stb_button.
*....................................................................

*
*
*
*

E_OBJECT of event TOOLBAR is of type REF TO CL_ALV_EVENT_TOOLBAR_SET.


This class has got one attribute, namly MT_TOOLBAR, which
is a table of type TTB_BUTTON. One line of this table is
defined by the Structure STB_BUTTON (see data deklaration above).

* A remark to the flag E_INTERACTIVE:


* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
'e_interactive' is set, if this event is raised due to
*
the call of 'set_toolbar_interactive' by the user.
*
You can distinguish this way if the event was raised
*
by yourself or by ALV
*
(e.g. in method 'refresh_table_display').
*
An application of this feature is still unknown... :-)
* append a separator to normal toolbar
CLEAR ls_toolbar.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
* append an icon to show booking table
CLEAR ls_toolbar.
MOVE 'BORRAR' TO ls_toolbar-function.
MOVE icon_delete TO ls_toolbar-icon.
MOVE 'Delete Fixed Assets'(111) TO ls_toolbar-quickinfo.
MOVE 'Borrar Activos'(010) TO ls_toolbar-text.
MOVE ' ' TO ls_toolbar-disabled.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
*------------------------------------------------------------------METHOD handle_user_command.
* 3.In event handler method for event USER_COMMAND: Query your
* function codes defined in step 2 and react accordingly.
DATA: lt_rows TYPE lvc_t_row.
CASE e_ucomm.
WHEN 'BORRAR'.
CALL METHOD grid1->get_selected_rows
IMPORTING et_index_rows = lt_rows.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ELSE.
PERFORM delete_fixed_assets TABLES lt_rows.
LEAVE PROGRAM.
ENDIF.
ENDCASE.
ENDMETHOD.
*----------------------------------------------------------------ENDCLASS.
*
* lcl_event_receiver (Implementation)

*===================================================================
*---------------------------------------------------------------------*
*
INITIALIZATION.
*---------------------------------------------------------------------*
INITIALIZATION.
*---------------------------------------------------------------------*
*
START-OF-SELECTION.
*---------------------------------------------------------------------*
START-OF-SELECTION.
IF ( cl_gui_object=>www_active = 'X' ).
MESSAGE i000(0k) WITH text-003.
ENDIF.
IF ( cl_gui_control=>www_active = ' ' ).
PERFORM select_table_zf02014 CHANGING it_zf02014.
IF sy-subrc NE 0.
MESSAGE e368 WITH text-t02.
LEAVE PROGRAM.
ENDIF.
ENDIF.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Sociedad'.
gs_fieldcat-fieldname = 'BUKRS'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '8'.
gs_fieldcat-key = 'X'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'No. Activo Fijo'.
gs_fieldcat-fieldname = 'ANLN1'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '16'.
gs_fieldcat-key = 'X'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Ejercicio'.
gs_fieldcat-fieldname = 'GJAHR'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '10'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Centro'.
gs_fieldcat-fieldname = 'WERKS'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '6'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Centro de coste'.
gs_fieldcat-fieldname = 'KOSTL'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '15'.
gs_fieldcat-auto_value = 'X'.

APPEND gs_fieldcat TO gt_fieldcat.


CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Planta Operativa'.
gs_fieldcat-fieldname = 'ORD44'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '15'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l
gs_fieldcat-outputlen
gs_fieldcat-fieldname
gs_fieldcat-ref_table
APPEND gs_fieldcat TO

= 'Emplazamiento del activo fijo'.


= '23'.
= 'STORT'.
= 'ZF02014'.
gt_fieldcat.

CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l
gs_fieldcat-fieldname
gs_fieldcat-ref_table
gs_fieldcat-outputlen
APPEND gs_fieldcat TO

= 'Subclase de Activo'.
= 'ORD43'.
= 'ZF02014'.
= '15'.
gt_fieldcat.

CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Cuenta de mayor'.
gs_fieldcat-fieldname = 'KTANSW'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '15'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l
gs_fieldcat-fieldname
gs_fieldcat-ref_table
gs_fieldcat-outputlen
APPEND gs_fieldcat TO

= 'Fecha Capitalizacin Activo fijo'.


= 'AKTIV'.
= 'ZF02014'.
= '23'.
gt_fieldcat.

CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Clase de activos fijos'.
gs_fieldcat-fieldname = 'ANLKL'.
gs_fieldcat-ref_table = 'ZF02012'.
gs_fieldcat-outputlen = '23'.
gs_fieldcat-auto_value = 'X'.
APPEND gs_fieldcat TO gt_fieldcat.
CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l
gs_fieldcat-fieldname
gs_fieldcat-ref_table
gs_fieldcat-outputlen
APPEND gs_fieldcat TO

= 'Denominacin del activo fijo'.


= 'TXT50'.
= 'ZF02014'.
= '23'.
gt_fieldcat.

CLEAR gs_fieldcat.
gs_fieldcat-scrtext_l = 'Subnmero Activo Fijo'.
gs_fieldcat-fieldname = 'ANLN2'.
gs_fieldcat-ref_table = 'ZF02014'.
gs_fieldcat-outputlen = '16'.
gs_fieldcat-auto_value = 'X'.

APPEND gs_fieldcat TO gt_fieldcat.

*
*
*
*

gs_sort-fieldname = 'ANLN1'.
CLEAR gs_variant .
'gs_layout' must at least contain the report-id to allow
saving a layout.
g_repid = sy-repid.
2.At least field REPORT of this structure has to be filled!
gs_variant-report = g_repid.
Set initial dynpro
CALL SCREEN 100.

*---------------------------------------------------------------------*
*
FORM EXIT_PROGRAM
*
*---------------------------------------------------------------------*
FORM exit_program.
* The instance grid1 is freed
CALL METHOD custom_container1->free.
CALL METHOD cl_gui_cfw=>flush.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
ENDIF.
LEAVE PROGRAM.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Module PBO_100 OUTPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE pbo_100 OUTPUT.
SET PF-STATUS 'MAIN100'.
IF custom_container1 IS INITIAL.
* create a custom container control for our ALV Control
CREATE OBJECT custom_container1
EXPORTING
container_name = cont_on_main
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
IF sy-subrc NE 0.
* add your handling, for example
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = g_repid
txt2 = sy-subrc
txt1 = 'El control no puede ser creado'(510).
ENDIF.
* create an instance of alv control
CREATE OBJECT grid1

EXPORTING i_parent = custom_container1.


* Set a titlebar for the grid control
gs_layout-grid_title = 'Baja Activos Fijos'(100).
* allow to select multiple lines
gs_layout-sel_mode = 'A'.
CALL METHOD grid1->set_table_for_first_display
EXPORTING
i_save
= 'A'
is_variant = gs_variant "&see below
is_layout
= gs_layout
i_default
= 'X'
CHANGING
it_fieldcatalog = gt_fieldcat
it_sort
= gt_sort
it_outtab
= it_zf02014.
*******
* ->Create Object to receive events and link them to handler methods.
* When the ALV Control raises the event for the specified instance
* the corresponding method is automatically called.
*
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_user_command FOR grid1.
SET HANDLER event_receiver->handle_toolbar FOR grid1.
*
********
* 4.Call method 'set_toolbar_interactive' to raise event TOOLBAR.
CALL METHOD grid1->set_toolbar_interactive.
ENDIF.
"IF grid1 IS INITIAL
CALL METHOD cl_gui_control=>set_focus EXPORTING control = grid1.
ENDMODULE.
" PBO_100 OUTPUT
*&---------------------------------------------------------------------*
*&
Module PAI_100 INPUT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
MODULE pai_100 INPUT.
CASE ok_code.
WHEN 'EXIT'.
PERFORM exit_program.
ENDCASE.
CLEAR ok_code.
ENDMODULE.
" PAI_100 INPUT
*&---------------------------------------------------------------------*
*&
Form SELECT_TABLE_SFLIGHT
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
*
<--P_GT_SFLIGHT text
*----------------------------------------------------------------------*
FORM select_table_zf02014 CHANGING p_it_zf02014 LIKE it_zf02014[].
REFRESH it_zf02014[].
CLEAR it_zf02014[].

*** Select fixed assets


SELECT * INTO TABLE it_zf02014
FROM zf02014
WHERE anln1 IN s_anln1 AND
werks IN s_werks AND
kostl IN s_kostl AND
ord44 IN s_ord44 AND
stort IN s_stort AND
ktansw IN s_ktansw AND
ktogr IN s_ktogr AND
anlkl IN s_anlkl AND
ord43 IN s_ord43 AND
aktiv IN s_aktiv .
ENDFORM.

" SELECT_TABLE_SFLIGHT

*&---------------------------------------------------------------------*
*&
Form delete_fixed_assets
*&---------------------------------------------------------------------*
FORM delete_fixed_assets TABLES p_et_index_rows
STRUCTURE lvc_s_row.
DATA: ls_selected_line LIKE lvc_s_row,
lf_row_index TYPE lvc_index,
ls_sflight LIKE LINE OF gt_sflight.
DATA: v_answer(01).
**

confirm if the fixed asset will be deleted


CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
diagnosetext1 = text-m01
textline1
= text-m02
titel
= text-m03
cancel_display = ' '
IMPORTING
answer
= v_answer.
IF v_answer = 'J'.
LOOP AT p_et_index_rows INTO ls_selected_line.
lf_row_index = ls_selected_line-index.

READ TABLE it_zf02014 INDEX lf_row_index INTO wa_zf02014.


IF sy-subrc EQ 0.
** Delete Fixed Assets
DELETE FROM zf02014
WHERE bukrs EQ wa_zf02014-bukrs
AND anln1 EQ wa_zf02014-anln1
AND anln2 EQ wa_zf02014-anln2
AND werks EQ wa_zf02014-werks
AND kostl EQ wa_zf02014-kostl
AND ord44 EQ wa_zf02014-ord44
AND stort EQ wa_zf02014-stort
AND ktansw EQ wa_zf02014-ktansw
AND ktogr EQ wa_zf02014-ktogr
AND anlkl EQ wa_zf02014-anlkl
AND ord43 EQ wa_zf02014-ord43
AND aktiv EQ wa_zf02014-aktiv.
"AND statu eq 'V'.
IF sy-subrc = 0.

DELETE FROM zf02016


WHERE anln1 EQ wa_zf02014-anln1
AND anln2 EQ wa_zf02014-anln2
AND bukrs EQ wa_zf02014-bukrs.
COMMIT WORK.
ELSE.
MESSAGE s398 WITH text-011 wa_zf02014-anln1
wa_zf02014-anln2 wa_zf02014-bukrs.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.
" delete_fixed_assets