Skip to Content
avatar image
Former Member

How to update long text for FI Document and can be displayed in FB03

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 11, 2014 at 08: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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 10, 2014 at 03: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!

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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