09-10-2014 4:00 AM
Dear Experts,
I met an issue for updating FI Document Long text, the requirement now is uploading one .txt file to Application Server and then the program can read this file and generate a FI Document and then if the bank description is longer than 50 characters, the long text should be updated with other remained character(except 50 previous characters).
Technical issue is when the FI Document was generated by COMMIT WORK, I use CREATE_TEXT to create a new long text for the FI Document, but failed, kindly refer to below code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = v_head
TABLES
accountgl = v_item[]
accountreceivable = v_ar_item[]
accounttax = v_tax[]
currencyamount = v_currency[]
extension2 = v_extension[]
return = v_return[].
READ TABLE v_return INDEX 1.
IF v_return-type = 'S'.
MESSAGE ID v_return-id TYPE v_return-type NUMBER v_return-number INTO v_message WITH v_return-message_v1 v_return-message_v2 v_return-message_v3 v_return-message_v4.
WRITE : / v_message.
COMMIT WORK.
LOOP AT it_l_text INTO wa_l_text.
SELECT SINGLE *
FROM bseg
INTO wa_bseg
WHERE bukrs = wa_l_text-bukrs
AND belnr = v_return-message_v2+0(10)
AND gjahr = wa_l_text-budat+0(4)
AND buzei = wa_l_text-posnr.
* AND hkont = wa_l_text-hkont.
IF sy-subrc EQ 0.
REFRESH v_flines.
CLEAR: v_tdname,
v_n,
v_m,
v_i,
v_t_length,
v_l_length.
CONCATENATE wa_l_text-bukrs v_return-message_v2+0(10)
wa_l_text-budat+0(4) wa_l_text-posnr INTO v_tdname.
CLEAR v_length.
v_length = strlen( wa_l_text-lntxt ).
v_m = v_length MOD 72.
v_n = v_length / 72.
v_l_length = v_length - v_n * 72. "0 or not 0
WHILE v_i LE v_n.
IF v_i EQ v_n.
APPEND wa_l_text-lntxt+v_t_length(v_l_length) TO v_flines.
ELSE.
APPEND wa_l_text-lntxt+v_t_length(72) TO v_flines.
v_i = v_i + 1.
v_t_length = v_i * 72.
ENDIF.
ENDWHILE.
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid = '0001'
flanguage = sy-langu
fname = v_tdname
fobject = 'DOC_ITEM'
save_direct = 'X'
fformat = '*'
TABLES
flines = v_flines
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
IF sy-subrc EQ 0.
COMMIT WORK.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDLOOP.
09-11-2014 9:58 AM
Hello Hook,
I think while debugging, system gets more time to save the
changes. Hence you select query for item is successful and logic to create long
text gives desired result. But when you run this without breakpoint, the FI
document might not be in database yet.
As Raymond had suggested earlier, please try
putting the select into DO.. ENDO loop. Exit the loop when query is successful and
then the logic to add long text should get triggered.
-Regards,
Amit
09-10-2014 4:03 AM
There is a strange thing that when I debug this, it could generate the Long text and can be displayed in FB03,but run it directly or in background mode,it could not generate the long text for the new FI Document....Could anyone who has any idea and help me with this? Thanks a lot!
09-10-2014 5:28 AM
Hi Hook Hu,
Try with 'BAPI_TRANSACTION_COMMIT' instead of commit work and check.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = it_ret.
Thanks
09-10-2014 6:41 AM
Dear Always Learner,
I thought BAPI_TRANSACTION_COMMIT will work for a BAPI, anyway, I will have a try, thanks a lot
09-10-2014 6:42 AM
Try to add the AND WAIT option to COMMIT WORK, so the update task get more time to update database and/or put the SELECT statement in a DO/ENDDO until successful.
Regards,
Raymond
09-10-2014 6:52 AM
Hello Hook,
Call BAPI_TRANSACTION_COMMIT after BAPI_ACC_DOCUMENT_POST.
Thanks
09-10-2014 11:03 AM
09-10-2014 5:29 PM
Hi Always Learner,
Actually I tried but still failed...Thank you all the same for you input
09-10-2014 5:31 PM
I have tried this before but failed and I even try to make it to wait 2 Seconds, but failed, and there is an strange thing that when I am debugging the program , it could generate the long text...
09-10-2014 5:40 PM
Hi
But why do you want to do a selection of document items you're posting?
Max
09-11-2014 9:11 AM
Dear Max,
It's Because this is for Item level, it's Item description...
09-11-2014 9:27 AM
Yes of course
but you're creating a standard text and this object is independent from item, I mean you can create the text while the item is not stored yet.
if you know the item key (so company code, fyscal year, document and item number) I believe it can create the text without worrying the item is really stored on database.
So the if the BAPI doesn't return some error, you can save your text, perhaps you can insert the updating of text in a process in update task, in this way it'll be called after saving process of BAPI.
Max
09-11-2014 9:58 AM
Hello Hook,
I think while debugging, system gets more time to save the
changes. Hence you select query for item is successful and logic to create long
text gives desired result. But when you run this without breakpoint, the FI
document might not be in database yet.
As Raymond had suggested earlier, please try
putting the select into DO.. ENDO loop. Exit the loop when query is successful and
then the logic to add long text should get triggered.
-Regards,
Amit
09-11-2014 2:28 PM
Hi , thanks a lot, now it works after I changed the code as that you mentioned
09-11-2014 2:34 PM
I still believe it's not usefull (for your process) to do a selection of BSEG
Max