Skip to Content
Technical Articles
Author's profile photo Jigang Zhang 张吉刚

Long text from Excel cell to SAP document to Adobe form cell

One Chinese proverb said: The faintest ink is more powerful than the strongest memory. Absolutely, sometimes I’m rush to google something and figure out one Issue without any kind of archive; then it turns out to be one fresh issue totally when it happens again.

In this article, I’ll wrap up the basic method from upload long text from a single cell of excel file to save as long text at SAP, then how to display this long text at one cell at the output in form of Adobe form.

1. From Excel Cell to SAP

First, need to upload long text from a single cell of excel file to SAP. (Forgive me I still haven’t started to use ABAP2XLSX in the production environment cause of some restrictions~.) I’m referring to this approach to achieve this by copy&modify based on Function Module: ALSM_EXCEL_TO_INTERNAL_TABLE which limitation is field ALSMEX_TABLINE-VALUE can only contain text from the cell up to 50 characters.

After extending this length with pure FM copy&modify is not working for me as it’ll missing some routine, so I copy& create a new function group ZALSMEX based on ALSMEX. And update the type definition as well at the top include program like LZALSMEXTOP to skip syntax error.

With updated FM we can accept long text from cells with more than 50 characters now. Then to deal with the inputted text at the cell as a large block of text in one paragraph, above mentioned article uses the method to get the length of the whole text first and then truncate it into several lines with a fixed length per line (here it uses 53).

DATA: LV_LEN TYPE I.
DATA: LV_OFF TYPE I.

LV_LEN = STRLEN( p_text ).  "total length
LV_LEN = LV_LEN / 53  + 1.  "Finding Number of Row’s taken by Long Text
    DO lv_LEN TIMES.
      MOVE '*' TO IT_LINES-TDFORMAT.
      MOVE  P_TEXT+LV_OFF(53) TO IT_LINES-TDLINE.
      SHIFT IT_LINES-TDLINE LEFT DELETING LEADING ‘ ‘.
      LV_OFF = LV_OFF + 53.
      APPEND IT_LINES.
      CLEAR IT_LINES.
    ENDDO.

This approach will force to switch new lines per 53 characters but it didn’t consider original word wrap& line breaks. Still not perfect~

Using split into a table at separator like cl_abap_char_utilities=>newline will not generate table TLINE perfectly as well, cause can’t make sure contents will contain that kind of separators. Another FM VB_CP_CONVERT_STRING_2_ITF will deal with this perfectly! Just convert the text get from cell to string type as its input then you will get TLINE table lines like below alignment. Save the long text using the TLINE table by FM: ‘READ_TEXT’.

2. From SAP long text to the cell of Adobe form

When want to display the long text get from SAP text editor at single-cell of the line in adobe form, we have to convert TLINE contents back to a string with alignment as well.

After getting TLINE with FM: ‘READ_TEXT’ just use FM: IDMX_DI_TLINE_INTO_STRING to convert TLINE back to a string will do. Besides, few things need to check:

  • Tick the checkbox the “allowed Multiple lines” for the cell

  • Tick the checkbox ‘Expand to fit’ for all the fields that share the same line with this specific cell
  • Then no matter what’s the column length of the cell, you will get aligned long text at single-cell of the main item.

Assigned Tags

      6 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jigang Zhang 张吉刚
      Jigang Zhang 张吉刚
      Blog Post Author
      To download long text as the cell of excel is the same approach:
      1, using READ_TEXT get contents of long text;
      2, using FUNCTION 'IDMX_DI_TLINE_INTO_STRING' to generate string contains all texts with the format;
      The only issue: needs to click the content of a single cell of excel once, the format like linefeed will show; otherwise it will show as a long string inside the cell.

      Author's profile photo Raul Daimiel
      Raul Daimiel

      Dear Jigang Zhang 张吉刚

      Thank you very much for you post!. It was really helpful.

      I think it might help me with an issue I am facing with an SO10 text in ADOBE. Let me briefly explain to you:

      We have a long SO10 Text and we would like to adjust the text to the widht of the form.

      Have found the following link FM for Splitting Paragraph into Fixed length | SAP Blogs but I have not

      been totaly able to make it work.

      Is there any way to "kind-of-easily" adjust the content of the text?.

      It'd be just nice to have a sample code of it.

      Kind Regards

      Author's profile photo Jigang Zhang 张吉刚
      Jigang Zhang 张吉刚
      Blog Post Author

      Raul Daimiel

      Maybe you can try like below to get the formatted long text by using attributes of the SO10 object. Then bind this long text as I mentioned at this blog.

      *&---------------------------------------------------------------------*
      *&      Form  FRM_GET_LONG_TEXT
      *&---------------------------------------------------------------------*
      *       text
      *----------------------------------------------------------------------*
      *      -->P_LD_ID  text
      *      -->P_LD_NAME  text
      *      -->P_LD_OBJECT  text
      *      <--P_LS_INTERFACE_ZSHIP_INSTRU  text
      *----------------------------------------------------------------------*
      FORM frm_get_long_text USING pd_id TYPE thead-tdid
                                   pd_name TYPE thead-tdname
                                   pd_object TYPE thead-tdobject
                          CHANGING pd_longtext.
        DATA: lt_tline TYPE TABLE OF tline,
              ls_tline TYPE tline,
              ld_string TYPE string.
      
        CALL FUNCTION 'READ_TEXT'
           EXPORTING
             client                  = sy-mandt
             id                      = pd_id
             language                = sy-langu
             name                    = pd_name
             object                  = pd_object
      *     ARCHIVE_HANDLE          = 0
      *     LOCAL_CAT               = ' '
      *  IMPORTING
      *     HEADER                  =
      *     OLD_LINE_COUNTER        =
           TABLES
             lines                   = lt_tline
           EXCEPTIONS
             id                      = 1
             language                = 2
             name                    = 3
             not_found               = 4
             object                  = 5
             reference_check         = 6
             wrong_access_to_archive = 7
             OTHERS                  = 8.
        IF sy-subrc = 0.
          CALL FUNCTION 'IDMX_DI_TLINE_INTO_STRING'
                EXPORTING
                    it_tline             = lt_tline
                IMPORTING
                    ev_text_string       = ld_string.
      
          pd_longtext = ld_string.
        ENDIF.
      ENDFORM.                    " FRM_GET_LONG_TEXT
      Author's profile photo Raul Daimiel
      Raul Daimiel

      Dear Jigang Zhang,

      Thank you very much for your sample!!!. :).

      I tested your suggestion and It worked 90 % perfectly fine for me.

      The content  was stored in a string variable... 🙁

      But, by checking the IDMX_xxxx available FM's, I found the FM that would help me. 🙂

      CALL FUNCTION 'IDMX_DI_SPLIT_TEXT'
      EXPORTING
      iv_character_chain       ld_string
      IV_LENGTH                95
      IMPORTING
      ET_STRING_TABLE          it_lines_adjusted
      EXCEPTIONS
      ERROR                    1
      OTHERS                   2

      The result is EXACTLY the one I expected!!!

      Thank you very much!!!!!!!!.

      Author's profile photo Jayvardhan Sharma
      Jayvardhan Sharma

      Hi Jigang,

      Thank you for the wonderful blog,I tried to use this functionality but formatting of text is gone once converted to string and downloaded in excel.

      Any suggestions for that?

      Author's profile photo Jigang Zhang 张吉刚
      Jigang Zhang 张吉刚
      Blog Post Author

      Jayvardhan Sharma

      what kind of formatting? This blog is more about alignment, for text format like font, bold, or color which is rich text, it may not work.