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: 

FM 'save_text'

Former Member
0 Kudos

hi all,

my requirement is

create a new program where input for the selection screen is a text file.

when we execute the program, the content in the file should be copied to the area in 'long texts' tab in 'bp' transaction.

i came to know gui_upload & save_text are the FM'S which help to achieve the above requirement.

i am confused with input and output parameters of FM save_text.

my question is

what parameters we have to pass to achieve the requirement.

can any one explain in detail about fields like todoobject, tdid ..etc

16 REPLIES 16

raymond_giuseppi
Active Contributor
0 Kudos

Call the transaction that display or maintain the long text, open one text, then go to menu : goto, header. A popup screen will display the key value needed to call [SAVE_TEXT|https://www.sdn.sap.com/irj/sdn/advancedsearch?cat=sdn_all&query=SAVE_TEXT+&adv=false&sortby=cm_rnd_rankvalue].

  • Text id

  • Text object

  • Text name (key)

Regards

0 Kudos

hi double click on the place where u want to add text,

in the menu bar

GOTO -> Header

there u can find all values that u have to pass for SAVE_TEXT

Regards,

Ajay

0 Kudos

data : lt_header like standard table of THEAD,

lt_lines like standard table of tline.

data : wa_header like line of lt_header,

wa_lines like line of lt_lines.

wa_header-TDNAME = '0010017195'.

wa_header-TDOSPRAS = 'E'.

wa_header-TDID = '0001'.

wa_header-TDOBJECT = 'BUT000'.

append wa_header to lt_header.

clear wa_header.

wa_lines-TDFORMAT = ' '.

wa_lines-TDLINE = 'it is working'.

append wa_lines to lt_lines.

what is the error in it?

CALL FUNCTION 'SAVE_TEXT'

EXPORTING

CLIENT = SY-MANDT

header = lt_header

tables

lines = lt_lines

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

OBJECT = 4

OTHERS = 5

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

it is giving dump.

In the function module interface, you can specify only

fields of a specific type and length under "HEADER".

Although the currently specified field

"LT_HEADER" is the correct type, its length is incorrect.

what is the error in it?

Edited by: srinivasa reddy mallidi on Oct 21, 2008 12:03 PM

Edited by: srinivasa reddy mallidi on Oct 21, 2008 12:04 PM

0 Kudos

Hi,

Check this

Pass wa_header for HEADER parameter

data : lt_header like standard table of THEAD,
lt_lines like standard table of tline.

data : wa_header like line of lt_header,
wa_lines like line of lt_lines.

wa_header-TDNAME = '0010017195'.
wa_header-TDOSPRAS = 'E'.
wa_header-TDID = '0001'.
wa_header-TDOBJECT = 'BUT000'.

append wa_header to lt_header.
clear wa_header.

wa_lines-TDFORMAT = ' '.
wa_lines-TDLINE = 'it is working'.

append wa_lines to lt_lines.


CALL FUNCTION 'SAVE_TEXT'
EXPORTING
CLIENT = SY-MANDT
header = wa_header " Pass wa here
tables
lines = lt_lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5
.
IF sy-subrc NE 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Edited by: Rajvansh Ravi on Oct 21, 2008 12:23 PM

Edited by: Rajvansh Ravi on Oct 21, 2008 12:24 PM

0 Kudos

Hi,

The import parameter HEADER of type THEAD isn´t a table. It´s a structure.

Regards,

Charles Oliveira

0 Kudos

hi,

CALL FUNCTION 'SAVE_TEXT'

EXPORTING

CLIENT = SY-MANDT

HEADER = ITAB_HEADER

SAVEMODE_DIRECT = LC_X

  • INSERT = ''

INSERT = 'X'

IMPORTING

FUNCTION = FUNCTION

NEWHEADER = NEWHEADER

TABLES

LINES = LINES

EXCEPTIONS

ID = 1

LANGUAGE = 2

NAME = 3

OBJECT = 4.

this code is replacing the text in the tab of bp. Actually it should not replace,it should add text to the text which is already present in that tab.

wat code changes i need to make?

0 Kudos

Hi,

Then use READ_TEXT to get the text already present there .

Then append extra data to internal table.

Then use SAVE_TEXT.

Regards

0 Kudos

TYPES: BEGIN OF itab_data,

lv_sonumber TYPE but000-partner,

lv_comment TYPE string,

END OF itab_data.

DATA :lt_data TYPE STANDARD TABLE OF itab_data,

wa_data LIKE LINE OF lt_data.

DATA :file TYPE string.

DATA : lv_sonumber1 TYPE but000-partner.

DATA : itab_header LIKE thead.

DATA : function TYPE c,

newheader LIKE thead,

lines TYPE STANDARD TABLE OF tline WITH HEADER LINE.

DATA : wa_lines LIKE LINE OF lines.

DATA : lc_x TYPE c.

lc_x = 'X'.

DATA : i_tline TYPE STANDARD TABLE OF tline.

DATA : wa_tline LIKE LINE OF i_tline.

DATA : lv_name TYPE thead-tdname.

data : lt_output like TLINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(50) text-001 FOR FIELD p_file.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF LINE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

static = 'X'

CHANGING

file_name = p_file.

file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file

has_field_separator = '#'

TABLES

data_tab = lt_data

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT lt_data INTO wa_data.

free : lines.

lv_name = wa_data-lv_sonumber.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = 'ZSPI'

language = 'E'

name = lv_name

object = 'BUT000'

TABLES

lines = i_tline

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

IF i_tline IS NOT INITIAL.

LOOP AT i_tline INTO wa_tline.

lines-tdformat = '*'.

lines-tdline = wa_tline-tdline.

APPEND lines.

CLEAR wa_tline.

ENDLOOP.

ENDIF.

FREE : i_tline.

free : itab_header.

itab_header-tdobject = 'BUT000'.

itab_header-tdname = wa_data-lv_sonumber.

itab_header-tdid = 'ZSPI'.

itab_header-tdspras = 'E'.

itab_header-tdtxtlines = '00009'.

itab_header-tdmacode1 = 'BP SAPLBUPA'.

itab_header-mandt = SY-MANDT.

lines-tdformat = '*'.

lines-tdline = wa_data-lv_sonumber.

APPEND lines.

lines-tdformat = '*'.

lines-tdline = 'success'.

APPEND lines.

CALL FUNCTION 'SAVE_TEXT'

EXPORTING

client = SY-MANDT

header = ITAB_HEADER

savemode_direct = 'X'

insert = 'X'

IMPORTING

function = FUNCTION

newheader = NEWHEADER

TABLES

lines = LINES

EXCEPTIONS

id = 1

language = 2

name = 3

object = 4.

CLEAR wa_data.

ENDLOOP.

write : / 'hello'.

it is giving run time error (input output error) at save_text FM.

is it necessary to use 'commit_text' or 'save_text' is sufficient to save the data.

0 Kudos

Hi Reddy,

Can you give the full details of the error so that it will be helpful to pinpoint the problem

Regards

0 Kudos

hi,

CALL FUNCTION 'SAVE_TEXT'

EXPORTING

client = sy-mandt

header = itab_header

savemode_direct = 'X'

insert = ''

IMPORTING

function = function

newheader = newheader

TABLES

lines = lines

EXCEPTIONS

id = 1

language = 2

name = 3

object = 4.

In the above function module, I am passing single bp to itab_header-tdname

Is there any other way to pass multiple values at a time for saving.

now I am looping at internal table which consist of bp's and i m calling this FM in that loop.As it becomes a performance issue,can you suggest me any other way in this regard.

0 Kudos

Hi,

I don't think that is possible as you can pass only single value to this HEADER.

May be you can schedule it as a background job..

But is your dump issue resolved??

Regards

0 Kudos

ya it is resolved.

0 Kudos

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file

has_field_separator = '#'

TABLES

data_tab = lt_data

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17

I am using the above FM to read data from a text file. now i want to read data from an excel sheet.

is it possible using this same FM? i tried but it is not working .

If it is possible what changes i need to make in passing the parameters.

otherwise is there any FM which reads data from excel sheet?

0 Kudos

Hi,

Put your SCARR table in Excel file and try this code. This works

Your ITAB definition is very important . Replicate the same format for your table

DATA : IT_SCARR TYPE TABLE OF SCARR.

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = 'C:\Documents and Settings\sap\Desktop\SCARR.xls'
*   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
*   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
  TABLES
    DATA_TAB                      = IT_SCARR
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   NO_AUTHORITY                  = 6
*   UNKNOWN_ERROR                 = 7
*   BAD_DATA_FORMAT               = 8
*   HEADER_NOT_ALLOWED            = 9
*   SEPARATOR_NOT_ALLOWED         = 10
*   HEADER_TOO_LONG               = 11
*   UNKNOWN_DP_ERROR              = 12
*   ACCESS_DENIED                 = 13
*   DP_OUT_OF_MEMORY              = 14
*   DISK_FULL                     = 15
*   DP_TIMEOUT                    = 16
*   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

WRITE 'HAI'.

Edited by: Rajvansh Ravi on Oct 24, 2008 8:51 AM

Former Member
0 Kudos

TYPES: BEGIN OF itab_data,

lv_sonumber TYPE but000-partner,

lv_comment(100) TYPE c,

END OF itab_data.

data : lt_data type table of itab_data.

DATA :file TYPE string.

constants: lc_x TYPE c VALUE 'X'.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  • F4 help for the input file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

static = lc_x

CHANGING

file_name = p_file.

start-of-selection.

file = p_file.

  • This Function module helps to get data into an an internal table from the input file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = file

filetype = 'ASC'

has_field_separator = lc_x

TABLES

data_tab = lt_data

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

end-of-selection.

write : / 'hai'.

it is not working.

what is the file type for excel file?

i tried by commenting that also.

0 Kudos

Hi,

Are you getting dump or is the internal table getting populated with junk?

If it is junk may be you missed out HAS_FIELD_SEPARATOR = 'X'

Have you tried if my code is working? File type is ASC..

Also check the columns in Excel matches properly with the columns in the internal table

Regards

Edited by: Rajvansh Ravi on Oct 24, 2008 12:46 PM

Edited by: Rajvansh Ravi on Oct 24, 2008 12:49 PM