Copying Sales Order attachments to the invoice using BADI SD_CIN_LV60AU02

By Jayshree Santosh Mahajan, Cognizant

Copying Sales Order attachments to the invoice

Recently, I got a requirement to copy sales order attachment to the invoice.  I searched a lot on this; however I could not get one.

Here is the solution I have used.

Scenario in brief:

1.     Go to the transaction code VA02/VA03. You will see below button.

2.     Create an attachment to the sales order as shown below.

Note: Attachment list is disabled here.

3.     See attachment.

Note: Attachment list is enabled now.  

4.     Attachment is created.

Now, when an invoice with this sales order is created, all the attachments should be copied to the corresponding invoice.  

Let’s see how this can be achieved.

Solution :

1.     Create a function module with below parameters and code. Make it as remote enabled (as we cannot use commit work in BADI, we will call this FM in separate task).

Function Module Name

ZSO_COPY_ATTACHMENTS

RFC/Normal/Update

RFC

Import Parameters

Parameter Name

Reference

Mandatory

Description

I_SO_INSTID

VBELN_VA

Yes

Source document number

I_TG_INSTID

VBELN_VA

Yes

Target document number

 Source code:

  DATA: lt_services TYPE tgos_sels.    " Services table type

  DATA: ls_service  TYPE sgos_sels.    " Services structure type

  DATA: ls_source   TYPE sibflporb,      " Source

        ls_target   TYPE sibflporb.      " Target  

  CONSTANTS : lc_service TYPE sgs_srvnam VALUE 'PCATTA_CREA',

              lc_i       TYPE char1 VALUE 'I',

              lc_eq      TYPE char2 VALUE 'EQ',

              lc_catid   TYPE sibflporb-catid VALUE 'BO'.  

* Service needs to be performed

  ls_service-sign   = lc_i.

  ls_service-option = lc_eq.

  ls_service-low    = lc_service.

  APPEND ls_service TO lt_services.  

* Source

  ls_source-instid = i_source_instid.

  ls_source-typeid = 'BUS2032'.         " Sales order BOR

  ls_source-catid  = lc_catid.  

* Target

  ls_target-instid = i_target_instid.

  ls_target-typeid =  'VBRK'.           " Invocie BOR

  ls_target-catid  = lc_catid.  

* Copy the objects between Source and Target

  cl_gos_service_tools=>copy_linked_objects(

      is_source            = ls_source

      is_target            = ls_target

      it_service_selection = lt_services

         ).  

COMMIT WORK.  

Note:  BOR can be determined using FM “SD_OBJECT_TYPE_DETERMINE”.  

2.     We can call this FM in the BADI SD_CIN_LV60AU02.

Create an implementation of BADI and call FM in this implementation.

Code:

  DATA : ls_vbrp     TYPE vbrp,         " Work area for billing item

         ls_vbrk     TYPE vbrk,         " Work area for billing header

         l_trtyp     TYPE t180-trtyp.   " Transaction type  

  CONSTANTS : lc_trtyp_h TYPE t180-trtyp VALUE 'H',         " Add

              lc_trtyp_v TYPE t180-trtyp VALUE 'V'.         " Change  

* Get transaction type for current transaction

  SELECT SINGLE trtyp

    FROM t180

    INTO l_trtyp

    WHERE tcode = sy-tcode.  

* If transaction type is Add or change, copy the sales order attachment to the invoice

  IF l_trtyp = lc_trtyp_h OR l_trtyp = lc_trtyp_v .

    READ TABLE xvbrk INTO ls_vbrk INDEX 1.

    IF sy-subrc = 0.

      READ TABLE xvbrp INTO ls_vbrp INDEX 1.

      IF sy-subrc = 0.

          CALL FUNCTION 'ZSO_COPY_ATTACHMENTS' STARTING NEW TASK 'T'

            EXPORTING

              i_so_instid = ls_vbrp-vgbel

              i_tg_instid = ls_vbrk-vbeln.

        ENDIF.

      ENDIF.

    ENDIF. 

Output:

Create an invoice transaction code VF01.

In this way, we can copy the sales order attachments to the invoice. This will work for the transactions VF01 and VF02.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image