Application Development and Automation 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: 
Read only

Saving and Reading Text

Former Member
0 Likes
2,898

I am trying to save text to text tables, and then read the same text. It appears as though the save is working (it returns sy-subrc of 0), but I'm not sure, because I can't see the text in the tables (STXH and STXL). When I try to retrieve the text, it is saying it is not found.

Here is my code for saving the text:

* Convert a String to TDLINE Table
  CALL FUNCTION 'SOTR_SERV_STRING_TO_TABLE'
    EXPORTING
      TEXT                = qtcomm
      FLAG_NO_LINE_BREAKS = 'X'
      LINE_LENGTH         = 132
      LANGU               = SY-LANGU
    TABLES
      TEXT_TAB            = t_tdline.

* Convert TDLINE to ITAB_LINES and adding the format
  loop at t_tdline into lw_tdline.

    clear wtab_lines.

    if sy-tabix = 1.
      wtab_lines-tdformat = '*'.
    else.
      wtab_lines-tdformat = '/'.
    endif.

    wtab_lines-tdline = lw_tdline.
    append wtab_lines to itab_lines.

  endloop.

* Save Text
  CALL FUNCTION 'INIT_TEXT'
    EXPORTING
      ID       = 'ST'
      LANGUAGE = sy-langu
      NAME     = lv_name
      OBJECT   = 'TEXT'
    IMPORTING
      header   = lv_texthead
    TABLES
      LINES    = itab_lines
    EXCEPTIONS
      OTHERS   = 5.

  if sy-subrc is initial.
  CALL FUNCTION 'SAVE_TEXT'
    EXPORTING
      client          = sy-mandt
      HEADER          = lv_texthead
      SAVEMODE_DIRECT = 'X'
    TABLES
      LINES           = itab_lines
    EXCEPTIONS
      OTHERS          = 5.
  endif.

Here is my code for retrieving the text:

    CALL FUNCTION 'READ_TEXT'
      EXPORTING
        ID                      = 'ST'
        LANGUAGE                = sy-langu
        NAME                    = lv_tdname
        OBJECT                  = 'TEXT'
      TABLES
        LINES                   = t_tdline
      EXCEPTIONS
        id                      = 1
        language                = 2
        name                    = 3
        not_found               = 4
        object                  = 5
        reference_check         = 6
        wrong_access_to_archive = 7
        others                  = 8.

The read_text is returning a sy-subrc value of 4 (not found). The tdname value in both the save and the read is "Q0000000161 1".

Does anybody see any problems with my code?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,722

Hi,

you need to call the FM COMMIT_TEXT after your SAVE_TEXT FM call.

then only your text will be saved.

Regards

vijay

Hi,

you need to call the FM COMMIT_TEXT after your SAVE_TEXT FM call.

then only your text will be saved.

Regards

vijay

10 REPLIES 10
Read only

Former Member
0 Likes
1,722

Hi,

Try to call the function COMMIT_TEXT after save_text and before read_text.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

0 Likes
1,722

Which parameters in the COMMIT_TEXT do I need to use? They are all optional. Which ones are required?

        CALL FUNCTION 'COMMIT_TEXT'
*         EXPORTING
*           OBJECT                = '*'
*           NAME                  = '*'
*           ID                    = '*'
*           LANGUAGE              = '*'
*           SAVEMODE_DIRECT       = ' '
*           KEEP                  = ' '
*           LOCAL_CAT             = ' '
*         IMPORTING
*           COMMIT_COUNT          =
*         TABLES
*           T_OBJECT              =
*           T_NAME                =
*           T_ID                  =
*           T_LANGUAGE            =

Read only

0 Likes
1,722

Are you able to Display the Text using SO10?

Regards,

Suresh Datti

Read only

0 Likes
1,722

No, it is not appearing in SO10.

Read only

Former Member
0 Likes
1,722

Hi Denise,

Please try to code something like this.

CALL FUNCTION 'SAVE_TEXT'    
  EXPORTING      
    CLIENT          = sy-mandt      
    HEADER          = lv_texthead      
    INSERT          = 'X'    
  TABLES      
    LINES           = itab_lines    
  EXCEPTIONS      
    OTHERS          = 5.

CALL FUNCTION 'COMMIT_TEXT'.

Hope this will help.

Regarsd,

Ferry Lianto

Please reward points if helpful.

Read only

0 Likes
1,722

I have added the call to COMMIT_TEXT, but it still isn't saving it.

Read only

Former Member
0 Likes
1,723

Hi,

you need to call the FM COMMIT_TEXT after your SAVE_TEXT FM call.

then only your text will be saved.

Regards

vijay

Read only

0 Likes
1,722

Hi,

The fact that you are unable to see the data in SO10 could be because its not getting committed, which has a lesser probability of happening or the parameters you are passing need to looked at again.

Can you go in debig mode, make a note of the exact value being passed to SAVE_TEXT and use those exact values in SO10?

Regards,

Ravi

Read only

0 Likes
1,722

Yes, I just did this. Copied the name value, then using that in SO10, and it isn't there.

Read only

0 Likes
1,722

I thought INIT_TEXT deletes the line items and only populated the header with some defaults?

I usually build the lines after INIT_TEXT.

Also, can you show is the value of LV_TEXTHEAD just before SAVE_TEXT?