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: 

Long text for materials

Former Member
0 Kudos
2,019

Hi Experts,

I have to create a ALV report in which i have to select plant and material no. and it will display short text, long text1, long text2, longtext3. In column long text1, i need to display only 72 char, if more than 72 then in next column long text2 and so on.

While downloading (save in excel) long text should save as maximum 256 characters per cell, if more than 256 char text then in next cell

I dnt no which table and field i have to use for long text.for short text its maktx

Also please tel me how to proceed in this issue, if any code for reference it will be helpful !!!

Regards

Nikhil

6 REPLIES 6

Former Member
0 Kudos
279

Hi

Long Texts are not stored completely in any table but their parameters like OBJECT,OBJECTNAME,ID and LANG are stored in STXH table

We have to fetch them using the READ_TEXT fun module into an internal tables and to display the data into some fixed length strings and to display

see the doc on Read_text and do accordingly

READ_TEXT

READ_TEXT provides a text for the application program in the specified work areas.

The function module reads the desired text from the text file, the text memory, or the archive. You must fully specify the text using OBJECT, NAME, ID, and LANGUAGE. An internal work area can hold only one text; therefore, generic specifications are not allowed with these options.

After successful reading, the system places header information and text lines into the work areas specified with HEADER and LINES.

If a reference text is used, SAPscript automatically processes the reference chain and provides the text lines found in the text at the end of the chain. If an error occurs, the system leaves the function module and triggers the exception REFERENCE_CHECK.

Function call:

CALL FUNCTION 'READ_TEXT'

EXPORTING CLIENT = SY-MANDT

OBJECT = ?...

NAME = ?...

ID = ?...

LANGUAGE = ?...

ARCHIVE_HANDLE = 0

IMPORTING HEADER =

TABLES LINES = ?...

EXCEPTIONS ID =

LANGUAGE =

NAME =

NOT_FOUND =

OBJECT =

REFERENCE_CHECK =

WRONG_ACCESS_TO_ARCHIVE =

Export parameters:

CLIENT

Specify the client under which the text is stored. If you omit this parameter, the system uses the current client as default.

Reference field: SY-MANDT

Default value: SY-MANDT

OBJECT

Enter the name of the text object to which the text is allocated. Table TTXOB contains the valid objects.

Reference field: THEAD-TDOBJECT

NAME

Enter the name of the text module. The name may be up to 70 characters long. Its internal structure depends on the text object used.

Reference field: THEAD-TDNAME

ID

Enter the text ID of the text module. Table TTXID contains the valid text IDs, depending on the text object.

Reference field: THEAD-TDID

LANGUAGE

Enter the language key of the text module. The system accepts only languages that are defined in table T002.

Reference field: THEAD-TDSPRAS

ARCHIVE_HANDLE

If you want to read the text from the archive, you must enter a handle here. The system uses it to access the archive. You can create the handle using the function module ACHIVE_OPEN_FOR_READ.

The value '0' indicates that you do not want to read the text from the archive.

Reference field: SY-TABIX

Default value: 0

Import parameters:

HEADER

If the system finds the desired text, it returns the text header in this parameter.

Structure: THEAD

Table parameters:

LINES

The table contains all text lines that belong to the text read.

Structure: TLINE

Exceptions:

ID

The text ID specified in the parameter ID does not exist in table TTXID. It must be defined there together with the object of the text module.

LANGUAGE

The parameter LANGUAGE contains a language key that does not exist in table T002.

NAME

The parameter NAME contains the name of a text module that does not correspond to the SAPscript conventions.

Possible errors:

The field contains only blanks.

The field contains the invalid characters ‘*’ or ‘,’.

OBJECT

The parameter OBJECT contains the name of a text object that does not exist in table TTXOB.

NOT_FOUND

The system did not find the specified text module.

REFERENCE_CHECK

The text module to be read has no text lines of its own but refers to the lines of another text module. This reference chain can include several levels. For the current text, the chain is interrupted, that is, one of the text modules referred to in the chain no longer exists.

WRONG_ACCESS_ TO_ARCHIVE

The exception WRONG_ACCESS_TO_ARCHIVE is triggered if an archive is accessed using an incorrect or non-existing archive handle or an incorrect mode (that is, read if the archive is open for writing or vice versa).

<b>Reward points for useful Answers</b>

Regards

Anji

0 Kudos
279

Hi Anji,

The issue they upload the material no, plant and long text in MM03 transaction using LSMW. the format of excel is Material No, Plant, Text1(max 72 char), Text2 (max 72 char), Text3(max 72 char). 72 char in Text cells Because the text area om MM03 only takes 72 char in a line.

So i want to display in ALV as 72 char in each long text fields

After that report, when i have to save it in excel it should save long text as 256 char per cell if more than 256 char then save it on other cell and so on. 256 char per cell because in the current system if they save it, it shows error that more that 256 char not allowed in a cell

Please tel me how to solve these 2 issues

Regards

Nikhil

Former Member
0 Kudos
279

Hi

You have to use function module 'READ_TEXT'

Previously i got the same situation so i develeoped a report i'll give it to you hope it may helpyou

*&---------------------------------------------------------------------*
*& Report  ZREADTEXTTEST                                               *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZMATERAILDESCRIPTION                           .


tables: ekpo,MAKT.
TYPE-POOLS: slis.
 DATA: thread LIKE thead.
 DATA: l_index LIKE sy-tabix.


DATA: BEGIN OF INT_OUT OCCURS 0,
        MATNR LIKE  EKPO-MATNR,
        MAKTX LIKE MAKT-MAKTX,
        TDLINE LIKE TLINE-TDLINE,
        WERKS LIKE EKPO-WERKS,
      END OF INT_OUT.
DATA: BEGIN OF INT_OUT_new OCCURS 0,
        MATNR LIKE  MAKT-MATNR,
        MAKTX LIKE MAKT-MAKTX,
        TDLINE LIKE TLINE-TDLINE,
        tline like tline occurs 0,
        WERKS LIKE EKPO-WERKS,
      END OF INT_OUT_new.




DATA: it_tlines  LIKE tline OCCURS 10 WITH HEADER LINE.

**************************
****ALV list definintion
*************************
DATA: ws_cat TYPE slis_fieldcat_alv ,
      int_cat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
      g_custom_container TYPE REF TO cl_gui_custom_container.




*****************
*selection-screen
*****************




SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 25(20) text-001.
**PARAMETERS:  S_MATNR LIKE MAKT-MATNR obligatory.
*
SELECT-OPTIONS: S_MATNR FOR MAKT-MATNR  .
SELECTION-SCREEN END OF LINE.




*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 25(20) text-002.
**PARAMETERS:p_ebeln LIKE ekko-ebeln obligatory.
*SELECT-OPTIONS: S_WERKS  FOR EKPO-WERKS OBLIGATORY.
*SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK b1.


START-OF-SELECTION.
  PERFORM get_data.
*  PERFORM field_catalog.
*  PERFORM display_data.

END-OF-SELECTION.
*FORM GET_DATA.


form get_data.




 DATA: l_index LIKE sy-tabix.

*SELECT
*      a~matnr
*      a~werks
*      b~maktx FROM ekpo AS a
*              INNER JOIN makt AS b
*              ON b~matnr = a~matnr
*              INTO CORRESPONDING FIELDS OF TABLE int_out
*              WHERE
**              a~matnr = s_matnr and
*              a~werks IN s_werks.



*To Fetch Data From Makt.

SELECT MATNR MAKTX FROM MAKT INTO CORRESPONDING FIELDS OF TABLE
int_out WHERE MAKT~MATNR IN S_MATNR.



LOOP AT int_out.



l_index = sy-tabix.

* read table int_out_new with key matnr = int_out-matnr.

    int_out_new-matnr = int_out-matnr.
    int_out_new-maktx = int_out-maktx.

*
    thread-tdname = int_out-matnr.

CALL FUNCTION 'READ_TEXT'
        EXPORTING
              client = sy-mandt
              id = 'BEST'
              language = sy-langu
              name = thread-tdname
              object = 'MATERIAL'
              TABLES
              lines = it_tlines
        EXCEPTIONS
              id = 1
              language = 2
              name = 3
              not_found = 4
              object = 5
              reference_check = 6
              wrong_access_to_archive = 7
              OTHERS = 8.

*Loop on it_tlines where long text is coming .

loop at it_tlines.


    IF sy-subrc = 0.

        int_out_new-tdline = it_tlines-tdline.
        append int_out_new.
        clear int_out_new.
        clear int_out_new-tdline.

    ENDIF.

endloop.

delete  adjacent  duplicates  from INT_OUT .
append int_out_new.
ENDLOOP.

* Field Catalog

***MATERIAL NO no
  int_cat-tabname       = 'INT_OUT_NEW'.
  int_cat-fieldname     = 'MATNR'.
  int_cat-reptext_ddic  = 'MATERIAL NO'.
  APPEND int_cat .

*material Short Description
  int_cat-tabname       = 'INT_OUT_NEW'.
  int_cat-fieldname     = 'MAKTX'.
  int_cat-reptext_ddic  = 'MATERIAL SHORT DESCRIPTION'.
  int_cat-datatype = 'CHAR'.
  int_cat-outputlen = '45'.

  APPEND int_cat .

** Material Long Description
  int_cat-tabname       = 'INT_OUT_NEW'.
  int_cat-fieldname     = 'TDLINE'.
  int_cat-reptext_ddic  = 'MATERIAL LONG DESCRIPTION'.
  int_cat-datatype = 'CHAR'.
  int_cat-outputlen = '200'.

    APPEND int_cat .


  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      it_fieldcat        = int_cat[]

    TABLES
      t_outtab           = int_out_NEW
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.



ENDFORM.                    "display_data

Reward all helpfull answers

Regards

Pavan

0 Kudos
279

Hi Pavan

I also created the a report in ALV same as u have given, the problem with my report and ur report is it puts the text in second line if it the text exceeds more than 200 char (in my report 72 char), i need to break the text in 72 - 72 chars and i have to put it in next column insted of next row.

how to saparate (break it in 72 char) and then put it in next column insted of next line

0 Kudos
279

Hi

As i had already executed this report. My report will not break at 72 characters i had defined a max length just copy and paste the same code and execute it and check it out

Regards

Pavan

Former Member
0 Kudos
279

Hi,

tabel stxl - use fm READ_TEXT.

Use the function module READ_TEXT for fetching the long text..

I came across similar situation in my project where i need to fetch the long text for Notification no.I have used the following code for fetching the Notificatin long text,you can just compare this logic and change accordingly.

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT

ID = 'LTXT'

LANGUAGE = WA_STRUCT12-KZMLA

NAME = QMNUM

OBJECT = 'QMEL'

TABLES

LINES = INT_TAB13.

Specify LANGUAGE if you wanna fetch the long text regardless of the log on lang.The resulting long text will be stored in the itab INT_TAB13 which can be defined with reference to the structure TLINE.

Regards