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: 

READ_TEXT is not working with in a Loop... Endloop properly.

Former Member
0 Kudos

if there are three records in a loop, it's always fetching long text for last 2 records.

below is the model code:

PARAMETERS: p_ordid TYPE afru-aufnr.
SELECT * FROM afru INTO TABLE it_afru
         WHERE aufnr = p_ordid AND
               ltxa1 <> '0'.
LOOP AT it_afru INTO ws_afru.
  CONCATENATE ws_afru-mandt ws_afru-rueck ws_afru-rmzhl INTO var_name.

  CALL FUNCTION 'READ_TEXT'
    EXPORTING
*     client                  = sy-mandt
      id                       = 'RMEL'
      language             sy-langu
      name                  = var_name
      object                 'AUFK'
    TABLES
      lines                   = tbl_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 EQ 0.

       LOOP AT tbl_lines.

       CONCATENATE tbl_lines-tdline tbl_com-tdline  INTO tbl_com-tdline.

       APPEND tbl_comm.

  ENDIF.

ENDLOOP.

Here in the loop. first time tbl_lines being fetched 3rd line long text of it_afru and then 2nd line long text and when it come for 3 record again it's fetchin last one.

please suggest me on this, i'm missing anything in exporting.

thanks.

ram

14 REPLIES 14

Former Member
0 Kudos

hi ram,

ENDLOOP is missing after append tbl_comm.

0 Kudos

Thanks to correcting syntactically. The main problem is with FM.

Former Member
0 Kudos

Hi Ram,

How about refresh tbl_lines itab before read_text?

Or the long text of 2nd just same as the 3rd one`s ?

regards,

Archer

0 Kudos

Hi Zhang,

thanks for the reply, clearing variable is taken care.

it's like, 1st text: aaaaaaaaaaaaaaaaaaaaaaaa1111111111111111111111

             2nd text : bbbbbbbbbbbbbbbbbbbbbbbbbbbbb222222222222222222222222222

            3rd text : ccccccccccccccccccccccccccccccc333333333333333333333333333

by using FM, the output we are getting :

ccccccccccccccccccccccccccccccc333333333333333333333333333

bbbbbbbbbbbbbbbbbbbbbbbbbbbbb222222222222222222222222222

ccccccccccccccccccccccccccccccc333333333333333333333333333

atlimately the 1st text is missing.

0 Kudos

HI Ram,

I guess it is not missing but it is being over written. Can u tell me the screen shot of the data that is there.

In the debug try to check after the first loop what is the result and then try doing it.

First try to store the single lines in the Comments and then try debugging. Later as a second step if you are able to c the correct results for one line then try adding another line and debug to further analyse the issue.

Thanks and Regards,

Chanakya

chanakya1
Explorer
0 Kudos

Hey HI Ram,

That FM will never fetch wrong results. It's the standard. SO we need to make it used correctly.

Since that is in a loop, below are the things that should be concentrated,

1) we need to refresh the TBL_LINES after the endloop of the main loop.

2) the declaration for the variable should be similar to that of the parameters that are being used in the FM

3) If the value is existing then definitely it would be captured into the internal table.

Kindly check and update.  Kindly reply if your still facing any issues.

Thanks and Regards,

Chanakya

Former Member
0 Kudos

Hi Chanakya,

Thanks for the response.

please see the below code and suggest me if mistakes:

   DATA: it_afru TYPE TABLE OF afru,
      ws_afru TYPE afru,
      var_name     LIKE thead-tdname,
      tbl_lines    LIKE tline   OCCURS 0 WITH HEADER LINE,
      tbl_comm     LIKE tline   OCCURS 0 WITH HEADER LINE.

PARAMETERS: p_ordid TYPE afru-aufnr.

SELECT * FROM afru INTO TABLE it_afru
         WHERE aufnr = p_ordid AND
               ltxa1 <> '0'.
CLEAR ws_afru.
LOOP AT it_afru INTO ws_afru.
  CLEAR var_name.
  CONCATENATE ws_afru-mandt ws_afru-rueck ws_afru-rmzhl INTO var_name.
  CLEAR tbl_lines.
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
*     client                  = sy-mandt
      id                      = 'RMEL'
      language                = 'F'"sy-langu
      name                    = var_name
      object                  = 'AUFK'
    TABLES
      lines                   = tbl_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 EQ 0.
    CLEAR: tbl_lines.
    LOOP AT tbl_lines.
      CLEAR tbl_comm.
      CONCATENATE tbl_lines-tdline tbl_comm-tdline  INTO tbl_comm-tdline.
      APPEND tbl_comm.
    ENDLOOP.
  ENDIF.
ENDLOOP.

   CLEAR tbl_comm.
LOOP AT tbl_comm.
  WRITE :/ tbl_comm.
ENDLOOP.

Result:

*/*/*/*/*/**/-/-*/*/*//*-/*-/*-///*-/*-/*-/*-/*/-/-*//*-/-*/

143284972357852379062769237592739572590723757213572309572359

*/*/*/*/*/**/-/-*/*/*//*-/*-/*-///*-/*-/*-/*-/*/-/-*//*-/-*/

0 Kudos

Hi Ram,

Thanks for your detailed code.

The clear statement is used usually for clearing the Work Area and not for the internal table.

Here in the above logic use Refresh TBL_lines. Instead of clear TBL_COMM use even Refresh TBL_COMM also. Please use this statement before Endloop. and after the APPEND TBL_COMM.

Because the values from the READ_TEXT is returned into TBL_LINES and after storing the data to the internal table TBL_COMM before the second loop the TBL_LINES should be refreshed.

So that next loop will not get the fresh values of the resultant and that would be again stored in the TBL_COMM.

As an alternative if your still unsuccessful. Could you please let me know the field in the transaction for which you are trying to fetch the data.

So that even I would try from my end. Thanks.

Regards,

Chanakya

Former Member
0 Kudos

Hi Chanakya,

still same problem, please find the below details with screen-shot. Thanks for your support.

T.CODE : IW43

FIELD Name: LTXA1(structure-AFRUD)

DB Table - AFRU

Former Member
0 Kudos

I have tried another way without calling the FM directly, of course the logic may same for both but i wrote a small program to check out. i'm posting the code here, which is also giving the same result.

please suggest me if i miss something logically.

   TYPES: BEGIN OF ty_stxl,
          tdname TYPE stxl-tdname,
          clustr TYPE stxl-clustr,
          clustd TYPE stxl-clustd,
        END OF ty_stxl.
DATAt_stxl TYPE STANDARD TABLE OF ty_stxl.
FIELD-SYMBOLS: <stxl> TYPE ty_stxl.
*Compressed text data without text name
TYPES: BEGIN OF ty_stxl_raw,
          clustr TYPE stxl-clustr,
          clustd TYPE stxl-clustd,
        END OF ty_stxl_raw.
DATAt_stxl_raw TYPE STANDARD TABLE OF ty_stxl_raw.
DATAw_stxl_raw TYPE ty_stxl_raw.
*Decompressed text
DATAt_tline TYPE STANDARD TABLE OF tline.
FIELD-SYMBOLS: <tline> TYPE tline.
DATA: t_stxh TYPE STANDARD TABLE OF stxh,
       w_stxh TYPE stxh.

SELECT * FROM afru INTO TABLE it_afru
         WHERE aufnr = p_ordid AND
               ltxa1 <> '0'.
REFRESH : t_stxh, t_stxl, t_tline.
LOOP AT it_afru INTO ws_afru.
  CONCATENATE ws_afru-mandt ws_afru-rueck ws_afru-rmzhl INTO var_name.

  SELECT tdname tdobject tdid
     FROM stxh
       INTO CORRESPONDING FIELDS OF TABLE t_stxh
            WHERE tdobject = 'AUFK' AND
                    tdname = var_name AND
                      tdid = 'RMEL'.
*and then select compressed text lines in blocks of 3000 (adjustable)
  SELECT tdname clustr clustd
          INTO TABLE t_stxl
          FROM stxl
          PACKAGE SIZE 3000
          FOR ALL ENTRIES IN t_stxh
          WHERE relid    = 'TX'   
            AND tdobject = t_stxh-tdobject
            AND tdname   = t_stxh-tdname
            AND tdid     = t_stxh-tdid
            AND tdspras  = sy-langu.

    LOOP AT t_stxl ASSIGNING <stxl>.
*Decompress text
      CLEAR: t_stxl_raw[], t_tline[].
      w_stxl_raw-clustr = <stxl>-clustr.
      w_stxl_raw-clustd = <stxl>-clustd.
      APPEND w_stxl_raw TO t_stxl_raw.

      IMPORT tline = t_tline FROM INTERNAL TABLE t_stxl_raw.

*Access text lines for further processing
      LOOP AT t_tline ASSIGNING <tline>.
        WRITE: / <tline>-tdline.
      ENDLOOP.
    ENDLOOP.
    FREE t_stxl.

  ENDSELECT.
ENDLOOP.

-Regards,

Ram

Former Member
0 Kudos

Hi,

Can anybody suggest me on this READ_TEXT FM or is there any alternate solution.

regards,

Ram

0 Kudos

Hi Ram ,

The confirmation text is stored in LTXA1 field for AFRU table. Please check this filed and let me know if you are looking for this text additional with long text.

Thanks

-Learner

0 Kudos

Yes, exactly trying to extract the long text of that field.

0 Kudos

Hi Ram,

Can you paste the screenshot of the long text from the system..

And screenshot of internal table tbl_lines data in debug..

Regards,

Raju