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

ITAB data to Xstring

Former Member
0 Likes
3,018

Hi all,

in the below code i am converting the ITAB data to Xstring by using Fm : SCMS_TEXT_TO_XSTRING.

here in ITAB i am taking 2 records, but in the generted Xstring is the same for both the records.

how do i get different Xstring for different rows of ITAB.?

where i am doing wrong in the code ?

types: BEGIN OF t_mara,

matnr type mara-matnr,

END OF t_mara.

data: itab TYPE TABLE OF t_mara,

wa TYPE t_mara.

select matnr FROM mara INTO TABLE itab UP TO 3 ROWS.

DATA: i_xstr TYPE XSTRING.

delete itab WHERE matnr is INITIAL.

LOOP AT itab INTO wa .

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = wa-matnr

IMPORTING

OUTPUT = wa-matnr

.

WRITE:/ wa-matnr.

at new matnr.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

  • EXPORTING

  • FIRST_LINE = 0

  • LAST_LINE = 0

  • MIMETYPE = ' '

IMPORTING

BUFFER = i_xstr

TABLES

text_tab = itab

EXCEPTIONS

FAILED = 1

OTHERS = 2

.

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:/ i_xstr.

endat.

clear i_xstr.

thanks

KR.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,427

hi,

Write the FM call outside the Loop.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'


EXPORTING 
FIRST_LINE = 0 
LAST_LINE = 0 
MIMETYPE = ' ' 
IMPORTING
BUFFER = i_xstr
TABLES
text_tab = itab
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF.

5 REPLIES 5
Read only

Former Member
0 Likes
2,428

hi,

Write the FM call outside the Loop.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'


EXPORTING 
FIRST_LINE = 0 
LAST_LINE = 0 
MIMETYPE = ' ' 
IMPORTING
BUFFER = i_xstr
TABLES
text_tab = itab
EXCEPTIONS
FAILED = 1
OTHERS = 2
.
IF sy-subrc 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF.

Read only

Former Member
0 Likes
2,427

HI,

I am getting different string values if I code like this....

DATA: itab LIKE tstc OCCURS 0 WITH HEADER LINE.

DATA: buffer TYPE xstring.

SELECT * FROM tstc INTO TABLE itab UP TO 2 ROWS.

LOOP AT itab.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

EXPORTING

first_line = sy-tabix

last_line = sy-tabix

  • MIMETYPE = ' '

IMPORTING

buffer = buffer

TABLES

text_tab = itab

EXCEPTIONS

failed = 1

OTHERS = 2

.

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:/ buffer.

ENDLOOP.

I never used this FM, but i am trying to use this FM.

Regards,

Venkatesh

Read only

0 Likes
2,427

Hi venkatesh,

thanks for reply.

replace the TSTC with MARA and check the output. i am getting same XSTRING output for all records.

why ia m getting like that ?

any idea ..?

Thanks

Kr

Read only

Former Member
0 Likes
2,427

You have looped itab into wa and passed itab to the FM.

either pass wa and try to move the generated Xstrings to anothertable or handle it outside of teh loop.

Read only

Former Member
0 Likes
2,427

Hi,

Try this

data: begin of itab occurs 0,

matnr type mara-matnr,

ersda type mara-ersda,

end of itab.

DATA: buffer TYPE xstring.

SELECT matnr ersda FROM mara INTO TABLE itab UP TO 2 ROWS.

LOOP AT itab.

CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'

EXPORTING

first_line = sy-tabix

last_line = sy-tabix

MIMETYPE = ' '

IMPORTING

buffer = buffer

TABLES

text_tab = itab

EXCEPTIONS

failed = 1

OTHERS = 2

.

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:/ buffer.

ENDLOOP.

Output

3030303030303030303030303030303034330D0A

3030303030303030303030303030303035380D0A

Here when i have declared my itab like mara then the output it similar,

but when i declared like above fashion , the output differs.

Regards,

Venkatesh