We have a situation where we wanted to copy the header texts from Contract to Invoice , but the standard CRM system does not support copying header texts from Contract to Invoice. As there are no standard BADIs available to enhance this functionality we came up with a resolution creating action types to create one or more action which will call a method to save the header text in the invoice.
Define action profile and action in IMG.
IMG -> Customer relationship management -> Basic Functions -> actions -> Actions in Billing -> Define Action profiles and actions.
We have several action profiles defined then select the appropriate action profile in our case it is for Contracts hence select ZF2CACT.
(a) Double click on ZF2CACT Action Profile – Custom action created for
(b) Click on Action Definition and create new action definition,
(c) Select Schedule Automatically radio button and deselect everything
d) In the processing types select Method call
(e) In the settings method call select ZBILLINGL_TXT
Go to Se18 for the BADI EXEC_METHODCALL_PPF, a new implementation will be created name and write the code to get Contract text and save it in invoice.
data: lr_action_execute type ref to cl_action_execute,
lo_bea type ref to cl_bea_ppf,
lv_appl type bef_appl,
lw_guid_ref type crmt_object_guid.
types : begin of ty_bri_guid,
bdh_guid type /1bea/crmb_bdh-bdh_guid,
bill_type type /1bea/crmb_bdh-bill_type,
bill_org type /1bea/crmb_bdh-bill_org,
payer type /1bea/crmb_bdh-payer,
src_guid type /1bea/crmb_bdi-src_guid,
src_headno type /1bea/crmb_bdi-src_headno,
src_process_type type /1bea/crmb_bdi-src_process_type,
end of ty_bri_guid.
data: lit_header_guid type crmt_object_guid_tab,
lit_text type crmt_text_wrkt,
lit_bri_guid type standard table of ty_bri_guid,
lit_lines type standard table of tline,
lit_temp type standard table of tline,
lw_temp type tline,
ls_line type tline,
ls_text type crmt_text_wrk
data : lw_guid type crmt_object_guid,
lw_object type ty_bri_guid,
lw_kind type crmt_object_kind value ‘A’,
lw_boolean type crmt_boolean value ‘X’,
lw_thead type thead,
lw_process_type(4) type c.
create object lr_action_execute.
(a) Get the GuidID of the billing document
LO_BEA ?= IO_APPL_OBJECT.
LV_APPL = LO_BEA->GET_BEA_NAME( ).
LW_GUID_REF = LO_BEA->GET_HEADGUID( ).
(b) Get previous document (Contract) for the billing document
(LW_GUID_REF in our case is the guid for the Billing Document)
SELECT H~BDH_GUID H~BILL_TYPE H~BILL_ORG H~PAYER
I~SRC_GUID I~SRC_HEADNO I~SRC_PROCESS_TYPE
INTO TABLE LIT_BRI_GUID FROM /1BEA/CRMB_BDH AS H
JOIN /1BEA/CRMB_BDI AS I
ON H~BDH_GUID = I~BDH_GUID
WHERE H~BDH_GUID = LW_GUID_REF.
(c) Get previous document (Contract) text If multiple previous documents
exist, get the text from all previous documents and copy to invoice.
This is to get the guid of the Contract in our case.
LOOP AT LIT_BRI_GUID INTO LW_OBJECT.
SELECT SINGLE GUID INTO LW_GUID
WHERE OBJECT_ID = LW_OBJECT-SRC_HEADNO.
clear: LIT_HEADER_GUID, lit_text.
APPEND LW_GUID TO LIT_HEADER_GUID.
To get the header text by passing the Contract guid and lw_kind = ‘A’.
CALL FUNCTION ‘CRM_TEXT_READ_API’
IT_GUID = LIT_HEADER_GUID
IV_OBJECT_KIND = LW_KIND
IV_BUILD_INT_TABLES = LW_BOOLEAN
ET_TEXT = LIT_TEXT.
LOOP AT LIT_TEXT INTO LS_TEXT
LIT_LINES = LS_TEXT-LINES.
In our case we are getting only for Internal notes from several Contracts and then accumulating into the internal table LIT_LINES.
IF LS_TEXT-STXH-TDID = ‘ZT3′.
APPEND LINES OF LIT_LINES TO LIT_LINES.
APPEND INITIAL LINE TO LIT_LINES.
LW_THEAD-TDSPRAS = SY-LANGU.
LW_THEAD-TDNAME = LW_GUID_REF.
LW_THEAD-TDOBJECT = ‘BEA_BDH’.
Saving the text for Internal Notes
IF NOT LIT_LINES IS INITIAL.
LW_THEAD-TDID = ‘ZI01’.
CALL FUNCTION ‘SAVE_TEXT’
CLIENT = SY-MANDT
HEADER = LW_THEAD
INSERT = ‘I’
SAVEMODE_DIRECT = ‘X’
LINES = LIT_LINES_ZBSV_ZT3
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5.