Here, for updating long text at line item level, we have 2 approaches.
1st Approach without using Implicit Enhancement
- Post FI Document using BAPI_ACC_DOCUMENT_POST.Then collect all successfully posted documents into one internal table.
- Then select data from BSEG table for each posted document.so that we will get line items of each posted document.
- Then update long text for each line item using Function Module ‘CREATE_TEXT’.
2nd Approach using Implicit Enhancement
- While posting using BAPI_ACC_DOCUMENT_POST,append line item no and its long text into EXTENSION1 Table.
- In BAPI_ACC_DOCUMENT_POST write an implicit enhancement which will read EXTENSION1 table for all line items and store line
item number and long text into other internal table. - In perform bapi_post, when document number gets created , loop on internal table of long text and update long text using
CREATE_TEXT Function Module.
What is Implicit Enhancement?
The implicit enhancement is a new technology to enhance SAP’s standard objects such as includes, function modules, forms,global classes and all source code units.
The enhancement option makes it possible to add your own functionality to standard SAP objects without changing the original object. The additional functionality you added to the system by enhancement does not create any problems while the system upgrades and can be available without making any adjustment.
Enhancement options are positions where we can add our code, SAP has provides with these positions where we can put our code as per the requirement, we can add an implementation element without modifying the original code of SAP.
Enhancement implantation elements are stored in the package with own transport objects thus avoiding any conflict in modification in later stages.
Explicit and Implicit Enhancement Options
Implicit Enhancement options are for free, provided by the framework, while the explicit ones need to be inserted explicitly, as the name indicates.
Sometimes you have requirements to set a default value for a standard field, or you have to add an extra column in the standard SAP List Viewer (ALV). Or you might have to include a custom include in standard code. All such requirements can be fulfilled by using implicit enhancements. Without using implicit enhancements, you have to modify the standard code, which can cause problems when upgrading your system.
Updating Long text using implicit enhancements
In bapi ‘BAPI_ACC_DOCUMENT_POST’, there is table called EXTENSION1.This table can be used to pass fields to edit the accounting document before it is transferred to the accounting components for the update.
Pass item number and its long text to EXTENSION1 table with fields
Extension1-field1 = ‘LONG_TEXT’
Extension1-field2 = long text
Extension1-field3 = Item no.
Declare global internal table by creating implicit enhancement in Global Data of BAPI_ACC_DOCUMENT _POST.
Write Implicit Enhancement in form call_customer_function, to get line item number and its long text in
one global internal table from EXTENSION1 table.
Write Implicit Enhancement in
FORM document_post
USING r_compo LIKE bapiache09-compo_acc.
To update Long Text at line item level.
Here we will get Document number generated for posting in field gs_aw-awkey+0(10).
In Function Module write a code to update Long Text
FUNCTION zde_fm_update_long_text.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_ITEM) TYPE CHAR3
*" VALUE(IM_LONG_TEXT) TYPE ZDE_DE_LONG_TEXT
*" VALUE(IM_BUKRS) TYPE BUKRS
*" VALUE(IM_BELNR) TYPE BELNR_D
*" VALUE(IM_GJAHR) TYPE GJAHR
*" EXPORTING
*" REFERENCE(EX_RETURN) TYPE BAPIRET2
*"----------------------------------------------------------------------
"Type Declartions
TYPES: BEGIN OF lt_type_temp,
line(132) TYPE c,
END OF lt_type_temp.
"Data Declarations
DATA : lt_temp TYPE STANDARD TABLE OF lt_type_temp,
lt_flines TYPE STANDARD TABLE OF tline,
l_fname TYPE thead-tdname,
l_length TYPE i,
ls_flines TYPE tline,
ls_temp TYPE lt_type_temp,
l_long_text(500) TYPE c.
"Constants
CONSTANTS : c_fid TYPE thead-tdid VALUE '0001',
c_fobject TYPE thead-tdobject VALUE 'DOC_ITEM'.
CONCATENATE im_bukrs
im_belnr
im_gjahr
im_item INTO l_fname.
l_length = strlen( im_long_text ).
l_long_text = im_long_text.
IF l_length > 132.
CALL FUNCTION 'SPLIT_LINE'
EXPORTING
text = l_long_text
len = l_length
maxlen = '132'
TABLES
result_tab = lt_temp.
IF lt_temp[] IS NOT INITIAL.
LOOP AT lt_temp INTO ls_temp.
ls_flines-tdformat = '*'.
ls_flines-tdline = ls_temp-line.
APPEND ls_flines TO lt_flines.
CLEAR ls_flines.
ENDLOOP.
ENDIF.
ELSE.
ls_flines-tdformat = '*'.
ls_flines-tdline = im_long_text.
APPEND ls_flines TO lt_flines.
CLEAR ls_flines.
ENDIF.
*long Text udated line item level
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid = c_fid
flanguage = sy-langu
fname = l_fname
fobject = c_fobject
save_direct = 'X'
TABLES
flines = lt_flines
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
IF sy-subrc = 0.
CLEAR: l_fname, lt_flines[].
ELSE.
IF sy-subrc <> 0.
"Message Long Text Not Updated for Doc No &1
MESSAGE e054(zde_mc_message) INTO g_msg1 WITH im_belnr.
CALL FUNCTION 'BALW_BAPIRETURN_GET2' "#EC FB_RC
EXPORTING
type = sy-msgty
cl = sy-msgid
number = sy-msgno
par1 = sy-msgv1
par2 = sy-msgv2
par3 = sy-msgv3
par4 = sy-msgv4
IMPORTING
return = ex_return.
ENDIF.
ENDIF.
ENDFUNCTION.