To delete bp attachments like invoice or payment advice in BP T-code.

                      I want to delete invoice/payment advice based on date or business partner.

----------------------------------------Steps to find filename----------------------------------------------

Step 1: Goto T-code - BP.

Step 2: Give business partner and press enter. 

Step 3: Goto attachments in top left (Services for object) and click on attachment list.

Step 4: Note the title.



Step 5: I picked Payment Advice title.

----------------------------------------Create AMDP Class---------------------------------------------------

Step 1: Right click on project click on new select abap class.

Step 2: Give package name, Class name and description.

Step 3: Click on finish after giving all the details.

Step 4: Write code.

METHOD get_gos_objects_amdp BY DATABASE PROCEDURE FOR HDB LANGUAGE SQLSCRIPT
                              OPTIONS READ-ONLY
                              USING sood srgbtbrel but000.
    DECLARE l_c_f_reltype_url  CONSTANT NVARCHAR(10) := 'URL';
    DECLARE l_c_f_icon_url     CONSTANT NVARCHAR(4) := '@8S@';
    DECLARE l_c_stat_o         CONSTANT NVARCHAR(1) := 'O';
    DECLARE l_c_stat_desc_open CONSTANT NVARCHAR(30) := 'Open';
    DECLARE l_c_instid_b_prt1  CONSTANT nvarchar(17) := 'FOL41000000000004';

/--*  Apply Select option for Run Date */
    l_t_sood_1 = APPLY_FILTER ( sood, :i_f_crdt_where );

/--*  Fetch the IDs based on application and Run Date */
    l_t_sood_2 = SELECT concat( l_c_instid_b_prt1 , concat( concat( objtp, objyr )  , objno ) )
                     AS instid_b, ownnam
                   FROM :l_t_sood_1
                  WHERE mandt = session_context('CLIENT')
                    AND objdes = :i_f_objdes;

/--*  Apply Select option for BPs */
    l_t_srgbtbrel = APPLY_FILTER ( srgbtbrel, :i_f_bp_where );

/--*  Fetch all the URL objects with details */
    e_t_gos_obj SELECT a.brelguid,
                          a.reltype,
                          a.instid_a,
                          a.typeid_a,
                          a.catid_a,
                          a.instid_b,
                          a.typeid_b,
                          a.catid_b,
                          c.partner,
                          c.name_org1,
                          b.ownnam,
                          CASE reltype
                            WHEN l_c_f_reltype_url THEN l_c_f_icon_url
                          END AS rel_type,
                          :i_f_objdes as objdes,
                          left(utctolocal(cast(a.utctime as char( 17 ) ) ) , 19) as utctime,
                          l_c_stat_o AS status_cd,
                          l_c_stat_desc_open AS status_desc
                     FROM :l_t_srgbtbrel as a
                    INNER JOIN :l_t_sood_2 as b ON a.instid_b = b.instid_b
                    INNER JOIN but000 AS c ON c.partner = a.instid_a and c.client = session_context( 'CLIENT' )
                    WHERE a.client = session_context('CLIENT')
                    ORDER BY instid_a;

  ENDMETHOD.

----------------------------------------Create Report---------------------------------------------------------

Step 1: Goto T-code - SE38.

Step 2: Give Program and click on create.

Step 3: Write Code.

REPORT zr_ca_bp_url_delete.
*---------------------------------------------------------------------*
* Includes                                                            *
*---------------------------------------------------------------------*

INCLUDE zn_ca_bp_url_delete_top.
INCLUDE zn_ca_bp_url_delete_sel_scr.
INCLUDE zn_ca_bp_url_delete_evts.
INCLUDE zn_ca_bp_url_delete_status_o01.
INCLUDE zn_ca_bp_url_delete_cl_impl.
INCLUDE zn_ca_bp_url_delete_user_coi01.

---------------------------------Structure-------------------------------- 



--------------------------------------------End structure--------------------------------

*&---------------------------------------------------------------------*
*& Include          ZR_CA_BP_URL_DELETE_TOP
*&---------------------------------------------------------------------*

TYPES: g_ty_t_output TYPE STANDARD TABLE OF zsr_ca_bp_url_del.

CONSTANTS:g_c_save_a     TYPE char1 VALUE 'A',
            g_c_sel_mode_a TYPE char1 VALUE 'A'.

CLASS lcl_bp_url DEFINITION FINAL.
  PUBLIC SECTION.
    CONSTANTS:
      pb_c_stat_d TYPE char1 VALUE 'D',
      pb_c_stat_e TYPE char1 VALUE 'E'.
    CLASS-METHODS:
      fetch_data EXPORTING e_t_output TYPE g_ty_t_output,
      delete_urls IMPORTING i_t_items TYPE lvc_t_row.

ENDCLASS.

CLASS lcl_alv DEFINITION FINAL.
  PUBLIC SECTION.
    CONSTANTS:
      pb_c_but_typ_3  TYPE tb_btype VALUE 3,
      pb_c_but_typ_0  TYPE tb_btype VALUE 0,
      pb_c_icon_del   TYPE iconname VALUE '@18@',
      pb_c_fun_delurl TYPE ui_func  VALUE 'DEL_URL'.
    CLASS-METHODS:
      display_alv ,
      display_alv_pr.
  PRIVATE SECTION.
    CLASS-METHODS:
      build_fieldcat.
ENDCLASS.

CLASS lcl_alv_evt_hndlr DEFINITION FINAL.
  PUBLIC SECTION.
    METHODS:
      handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm,
      handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object.
ENDCLASS.

CLASS lcl_global DEFINITION FINAL.
  PUBLIC SECTION.
    CLASS-DATA:
      pbs_f_okcode TYPE syucomm,
      pbs_o_bp_url   TYPE REF TO lcl_bp_url,
      pbs_o_alv      TYPE REF TO lcl_alv,
      pbs_t_output   TYPE g_ty_t_output,
      pbs_o_alv1     TYPE REF TO cl_gui_alv_grid,
      pbs_r_layout   TYPE lvc_s_layo,
      pbs_r_variant  TYPE disvariant,
      pbs_f_partner  TYPE but000-partner,
      pbs_t_fieldcat TYPE lvc_t_fcat.
ENDCLASS.

CLASS lcl_validations DEFINITION FINAL.
  PUBLIC SECTION.
    CLASS-METHODS:
      validate_bp.
ENDCLASS.

 

*&---------------------------------------------------------------------*
*& Include          ZL_CA_BP_URL_DELETE_SEL_SCR
*&---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
  so_rundt FOR sy-datum,
  so_partn FOR lcl_global=>pbs_f_partner.
SELECTION-SCREEN END OF BLOCK b1.


SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-004.
PARAMETERS:
  p_pymadv TYPE char1 RADIOBUTTON GROUP r1 DEFAULT 'X',
  p_mntinv TYPE char1 RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK b2.

*&---------------------------------------------------------------------*
*& Include          ZN_CA_BP_URL_DELETE_EVTS
*&---------------------------------------------------------------------*

*---------------------------------------------------------------------*
* Selection Screen Validations                                        *
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON so_partn.

  lcl_validations=>validate_bp( ).

*--Start of Selection  

START-OF-SELECTION.
*--- Fetch Data
  CREATE OBJECT lcl_global=>pbs_o_bp_url.
  CALL METHOD lcl_global=>pbs_o_bp_url->fetch_data
    IMPORTING
      e_t_output = lcl_global=>pbs_t_output.


*-- End of Selection                                                 
END-OF-SELECTION.
  CREATE OBJECT lcl_global=>pbs_o_alv.
  IF lcl_global=>pbs_t_output IS NOT INITIAL.
    lcl_global=>pbs_o_alv->display_alv( ).
  ELSE.
    MESSAGE i091(z_ca_msgs).
  ENDIF.

*----------------------------------------------------------------------*
***INCLUDE ZR_CA_BP_URL_DELETE_STATUS_O01.
*----------------------------------------------------------------------*

MODULE status_0100 OUTPUT.
  lcl_alv=>display_alv_pr( ).
ENDMODULE.

*&---------------------------------------------------------------------*
*& Include          ZR_CA_BP_URL_DELETE_CL_DEF
*&---------------------------------------------------------------------*

CLASS lcl_bp_url IMPLEMENTATION.
  METHOD fetch_data.
    CONSTANTS:
      l_c_msgty_i TYPE symsgty VALUE 'I'.
    DATA:
      l_f_objdes TYPE so_obj_des,
      l_o_gos    TYPE REF TO zcl_ca_gen_obj_services.
    CLEAR e_t_output.
    IF p_pymadv IS NOT INITIAL.
      l_f_objdes = 'Payment Advice'(002).
    ELSEIF p_mntinv IS NOT INITIAL.
      l_f_objdes = 'Invoice(Monthly)'(003).
    ENDIF.
*---   Prepare ere clause for BPs entered on Selection  Screen
    TRY.
        CALL METHOD cl_shdb_seltab=>combine_seltabs
          EXPORTING
            it_named_seltabs = VALUE #( ( name = 'INSTID_A' dref = REF #( so_partn[] ) ) )
          RECEIVING
            rv_where         = DATA(l_f_where_bp).
      CATCH cx_shdb_exception INTO DATA(l_o_shdb_exc).
        DATA(l_f_message) = l_o_shdb_exc->if_message~get_text( ).
        MESSAGE l_f_message TYPE l_c_msgty_i.
        RETURN.
    ENDTRY.

*---   Prepare where Clause for Creation Date entered on Selection Screen
    TRY.
        CALL METHOD cl_shdb_seltab=>combine_seltabs
          EXPORTING
            it_named_seltabs = VALUE #( ( name = 'CRDAT' dref = REF #( so_rundt[] ) ) )
          RECEIVING
            rv_where         = DATA(l_f_where_crdt).
      CATCH cx_shdb_exception INTO l_o_shdb_exc.
        l_f_message = l_o_shdb_exc->if_message~get_text( ).
        MESSAGE l_f_message TYPE l_c_msgty_i.
        RETURN.
    ENDTRY.
*---   Call AMDP to get the data
    CREATE OBJECT l_o_gos.
    TRY.
        CALL METHOD l_o_gos->get_gos_objects_amdp
          EXPORTING
            i_f_objdes     = l_f_objdes
            i_f_bp_where   = l_f_where_bp
            i_f_crdt_where = l_f_where_crdt
          IMPORTING
            e_t_gos_obj    = e_t_output.
      CATCH cx_amdp_error INTO DATA(l_o_amdp_amdp_error).
        l_f_message = l_o_amdp_amdp_error->if_message~get_text( ).
        MESSAGE l_f_message TYPE l_c_msgty_i.
    ENDTRY.
  ENDMETHOD.

  METHOD delete_urls.
    DATA:
      l_f_reltype TYPE binreltyp,
      l_r_rolea   TYPE borident,
      l_r_roleb   TYPE borident.

*--   Delete the URLs
    LOOP AT i_t_items ASSIGNING FIELD-SYMBOL(<l_r_sel_rows>).
      READ TABLE lcl_global=>pbs_t_output ASSIGNING FIELD-SYMBOL(<l_r_output>)
      INDEX <l_r_sel_rows>-index.
      IF sy-subrc EQ 0.
        IF <l_r_output>-status_cd NE lcl_bp_url=>pb_c_stat_d.
*---          Delete the URL
          CLEAR: l_r_rolea, l_r_roleb.
          l_r_rolea-objkey = <l_r_output>-instid_a.
          l_r_rolea-objtype = <l_r_output>-typeid_a.
          l_r_roleb-objkey = <l_r_output>-instid_b.
          l_r_roleb-objtype = <l_r_output>-typeid_b.
          l_f_reltype = <l_r_output>-reltype.

          CALL FUNCTION 'BINARY_RELATION_DELETE_COMMIT'
            EXPORTING
              obj_rolea          = l_r_rolea
              obj_roleb          = l_r_roleb
              relationtype       = l_f_reltype
            EXCEPTIONS
              entry_not_existing = 1
              internal_error     = 2
              no_relation        = 3
              no_role            = 4
              OTHERS             = 5.
          IF sy-subrc <> 0.
            <l_r_output>-status_cd = lcl_bp_url=>pb_c_stat_e.          " Error
            <l_r_output>-status_desc = 'Error'(010).
          ELSE.
            <l_r_output>-status_cd = lcl_bp_url=>pb_c_stat_d.          " Deleted
            <l_r_output>-status_desc = 'Deleted'(011).
          ENDIF.
        ELSE.
          <l_r_output>-status_desc = 'Already Deleted'(005).
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

CLASS lcl_alv IMPLEMENTATION.

  METHOD display_alv.
    CALL SCREEN '0100'.
  ENDMETHOD.

  METHOD display_alv_pr.
    SET PF-STATUS '0100'.
    SET TITLEBAR 'TITLE_100'.
    IF lcl_global=>pbs_t_output IS NOT INITIAL.
*--   Creating object of alv
      CREATE OBJECT lcl_global=>pbs_o_alv1
        EXPORTING
          i_parent          = cl_gui_container=>default_screen
        EXCEPTIONS
          error_cntl_create = 1
          error_cntl_init   = 2
          error_cntl_link   = 3
          error_dp_create   = 4
          OTHERS            = 5.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
*--     Alv layout
      lcl_global=>pbs_r_layout-cwidth_opt = abap_true.
      lcl_global=>pbs_r_layout-sel_mode = g_c_sel_mode_a.
      lcl_global=>pbs_r_variant-report = sy-repid.
*--     Alv field catalogue
      CALL METHOD build_fieldcat.
      DATA(l_o_hndlr) = NEW lcl_alv_evt_hndlr( ).
      SET HANDLER l_o_hndlr->handle_toolbar FOR lcl_global=>pbs_o_alv1 ACTIVATION abap_true.
      SET HANDLER l_o_hndlr->handle_user_command FOR lcl_global=>pbs_o_alv1 ACTIVATION abap_true.

*--     Displaying the ALV grid
      CALL METHOD lcl_global=>pbs_o_alv1->set_table_for_first_display
        EXPORTING
          is_layout                     = lcl_global=>pbs_r_layout
          is_variant                    = lcl_global=>pbs_r_variant
          i_save                        = g_c_save_a
        CHANGING
          it_outtab                     = lcl_global=>pbs_t_output
          it_fieldcatalog               = lcl_global=>pbs_t_fieldcat
        EXCEPTIONS
          invalid_parameter_combination = 1
          program_error                 = 2
          too_many_lines                = 3
          OTHERS                        = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDIF.
  ENDMETHOD.

  METHOD build_fieldcat.
    CONSTANTS:
      l_c_strnam TYPE tabname VALUE 'ZSR_CA_BP_URL_DEL'.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_bypassing_buffer     = abap_true
        i_structure_name       = l_c_strnam
      CHANGING
        ct_fieldcat            = lcl_global=>pbs_t_fieldcat
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        OTHERS                 = 3.
    IF sy-subrc EQ 0.
      LOOP AT lcl_global=>pbs_t_fieldcat ASSIGNING FIELD-SYMBOL(<l_r_fieldcat>).
        <l_r_fieldcat>-selddictxt = 'M'.
        CASE <l_r_fieldcat>-fieldname.
          WHEN 'STATUS_CD'.
            <l_r_fieldcat>-scrtext_m = 'Status Code'(007).
          WHEN 'STATUS_DESC'.
            <l_r_fieldcat>-scrtext_m = 'Status Description'(012).
          WHEN 'REL_TYPE'.
            <l_r_fieldcat>-scrtext_m = 'Relation Type'(014).
          WHEN 'BRELGUID' OR 'RELTYPE' OR 'TYPEID_A' OR 'CATID_A' OR 'INSTID_B'
               OR 'TYPEID_B' OR 'CATID_B' OR 'INSTID_A'.
            <l_r_fieldcat>-tech = abap_true.
          WHEN 'UTCTIME'.
            <l_r_fieldcat>-scrtext_m = 'Date & Time'(006).
        ENDCASE.
      ENDLOOP.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

CLASS lcl_alv_evt_hndlr IMPLEMENTATION.

  METHOD handle_toolbar.

    APPEND INITIAL LINE TO e_object->mt_toolbar ASSIGNING FIELD-SYMBOL(<l_r_toolbar>).
    <l_r_toolbar>-butn_type = lcl_alv=>pb_c_but_typ_3.           " Seperator

    APPEND INITIAL LINE TO e_object->mt_toolbar ASSIGNING <l_r_toolbar>.
    <l_r_toolbar>-butn_type = lcl_alv=>pb_c_but_typ_0.           " Normal Button
    <l_r_toolbar>-function = lcl_alv=>pb_c_fun_delurl.           " function code
    <l_r_toolbar>-icon = lcl_alv=>pb_c_icon_del.                 " Icon
    <l_r_toolbar>-text = 'Delete URL'(009).

  ENDMETHOD.                    "TOOLBAR

  METHOD handle_user_command.

    DATA:
      l_t_sel_rows TYPE lvc_t_row.

    IF e_ucomm = lcl_alv=>pb_c_fun_delurl.
*---     Get the Selected Rows
      CALL METHOD lcl_global=>pbs_o_alv1->get_selected_rows
        IMPORTING
          et_index_rows = l_t_sel_rows.
      IF l_t_sel_rows IS NOT INITIAL.

*---       Delete the URLs
        lcl_global=>pbs_o_bp_url->delete_urls( i_t_items = l_t_sel_rows ).

*--       Refresh ALV Display
        CALL METHOD lcl_global=>pbs_o_alv1->refresh_table_display
          EXPORTING
            i_soft_refresh = abap_true
          EXCEPTIONS
            finished       = 1
            OTHERS         = 2.
        IF sy-subrc <> 0.
          MESSAGE i090(z_ca_msgs).
        ENDIF.
      ELSE.
        MESSAGE i089(z_ca_msgs).
      ENDIF.
    ENDIF.
  ENDMETHOD.                    "USER_COMMAND
ENDCLASS.

CLASS lcl_validations IMPLEMENTATION.
  METHOD validate_bp.
    IF so_partn[] IS NOT INITIAL.
      SELECT partner
       UP TO 1 ROWS
        FROM but000
        INTO @DATA(l_f_partner)
       WHERE partner IN @so_partn.
      ENDSELECT.
      IF sy-subrc NE 0.
        MESSAGE e092(z_ca_msgs).
      ENDIF.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

*----------------------------------------------------------------------*
***INCLUDE ZN_CA_BP_URL_DELETE_USER_COI01.
*----------------------------------------------------------------------*

MODULE user_command_0100 INPUT.
  CASE lcl_global=>pbs_f_okcode.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      SET SCREEN 0.
      LEAVE SCREEN.
  ENDCASE.
ENDMODULE.

Step 4: Create Screen 0100 and give element list and create an empty layout and create pf status and title bar.

Step 5: Check and activate.

------------------------------------------------------Test-------------------------------------------------------------

Step 1: Execute the report.

Step 2: based on requirement you can give selection screen values.


Step 3: Select the rows you want to delete and click on delete icon.



********************************Thank You*****************************


Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).