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

SQ02- READ_TEXT multiple rows

Former Member
0 Likes
2,109

Greetings SAP-Gurus,

I (an SAP newb) am trying to retrieve the Basicdatatext from MM02. I am using an extra field with additional code that uses the FM READ_DATA. The problem with my code however is that it only returns the first line from the text field. I have tried searching but haven't found the solution to my problem.

Here is the code I have been using (for the extra field):

TABLES:

    STXH.

DATA:

    TDNAME LIKE STXH-TDNAME,

    MYLINE LIKE TLINE-TDLINE,

    ZE13_LINE(200) TYPE C.

DATA: BEGIN OF LINES OCCURS 0.

        INCLUDE STRUCTURE TLINE.

DATA:END OF LINES.

DATA:BEGIN OF MYHEADER.

        INCLUDE STRUCTURE THEAD.

DATA:END OF MYHEADER.

CLEAR V_EXTRATEKST.

CLEAR TDNAME.

MOVE MARA-MATNR

TO TDNAME.

CALL FUNCTION 'READ_TEXT'

    EXPORTING

        ID                       = 'GRUN'

        LANGUAGE                 = sy-langu

        NAME                     = TDNAME

        OBJECT                   = 'MATERIAL'

     IMPORTING

        HEADER                   = MYHEADER

     TABLES

        LINES                    = LINES

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.

   LOOP AT LINES.

    MOVE LINES-TDLINE(132) TO V_EXTRATEKST.

    EXIT.

  ENDLOOP.

ENDIF.

I tried replacing:

    MOVE LINES-TDLINE(132) TO V_EXTRATEKST.

With:

     WRITE:/ LINES-TDLINE.

This gives me the total text, however it is putting it into the header.

Hopefully you can provide me with the correct code.

Roeland

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,047

Hi,

Declare a variable with type STRING. Then concatenate the LINES-TDLINE into the new variable.

Data: v_text type string.

Loop at lines.

if sy-tabix = 1.

move lines-tdline to v_text.

else.

concatenate v_text line-tdline into v_text separated by space.

endif.

endloop.

You will get the text in the variable v_text.

Cheers

~Niranjan

3 REPLIES 3
Read only

Former Member
0 Likes
1,047

Hi Roeland,

If you do need all the rows then why are you using EXIT in the LOOP. Comment that and check.

Go in Debug mode and check the LINES internal table to see how many lines it holds.

Thanks,

Shambu

Read only

Former Member
0 Likes
1,048

Hi,

Declare a variable with type STRING. Then concatenate the LINES-TDLINE into the new variable.

Data: v_text type string.

Loop at lines.

if sy-tabix = 1.

move lines-tdline to v_text.

else.

concatenate v_text line-tdline into v_text separated by space.

endif.

endloop.

You will get the text in the variable v_text.

Cheers

~Niranjan

Read only

0 Likes
1,047

Thank you for your quick response. It worked! I have rewarded you with points.