Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

amitkumar24
Explorer
0 Kudos

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

14 REPLIES 14

Former Member
0 Kudos

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!

0 Kudos

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

0 Kudos

Dear Always Learner,

I thought BAPI_TRANSACTION_COMMIT will work for a BAPI, anyway, I will have a try, thanks a lot

0 Kudos

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

0 Kudos

Hello Hook,

Call BAPI_TRANSACTION_COMMIT after BAPI_ACC_DOCUMENT_POST.


Thanks

0 Kudos

Thanks for your input, I will try what you mentioned

0 Kudos

Hi Always Learner,

Actually I tried but still failed...Thank you all the same for you input

0 Kudos

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...

0 Kudos

Hi

But why do you want to do a selection of document items you're posting?

Max

0 Kudos

Dear Max,

It's Because this is for Item level, it's Item description...

0 Kudos

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

amitkumar24
Explorer
0 Kudos

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

0 Kudos

Hi , thanks a lot, now it works after I changed the code as that you mentioned

0 Kudos

I still believe it's not usefull (for your process) to do a selection of BSEG

Max