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

how to convert a structure to string?

Former Member
0 Likes
19,089

Hi all,

I want to convert a structure to a string variable. we have a structure with length 1020 we want to convert it into string.

Thanks in advance

hari

Hi all,

I want to convert a structure to a string variable. we have a structure with length 1020 we want to convert it into string.

Thanks in advance

hari

11 REPLIES 11
Read only

Former Member
0 Likes
7,131

Hello,

DO like this:


DATA: LV_STRING TYPE STRING.
LV_STRING = WA_STR " (Your structure Name)
write: LV_STRING.

If useful reward.

Vasanth

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
7,131

Hi,

It's nothing great to do that.

Just declare ur a vaiable of type string.

Assign ur structure to string.

Data : st1 type mara,

s type string.

string = st1.

Cheers,

Simha.

Reward all the helpful asnwers..

Read only

Former Member
0 Likes
7,131

Hi,

If you know the structure that the table needs to be moved to then it is possible with assign..

pls check the code below...

REPORT yytest88 LINE-COUNT 20 NO STANDARD PAGE HEADING.

TYPES: BEGIN OF ty_test,

f1(10),

f2(10),

END OF ty_test.

DATA : wa_type(10) VALUE 'TY_TEST'.

DATA : BEGIN OF itab OCCURS 0,

f(20),

END OF itab.

DATA : BEGIN OF itab1 OCCURS 0,

f(35),

END OF itab1.

FIELD-SYMBOLS : <fs1> TYPE any.

FIELD-SYMBOLS : <fs2> TYPE any.

FIELD-SYMBOLS : <fs3> TYPE any.

itab-f = '12345678901234567890'.

APPEND itab.

itab-f = '09876543210987654321'.

APPEND itab.

LOOP AT itab.

ASSIGN itab-f TO <fs1> CASTING TYPE (wa_type).

IF sy-subrc = 0.

do.

assign component sy-index of structure <fs1> to <fs2>.

if sy-subrc = 0.

if itab1-f is initial.

concatenate itab1-f <fs2> into itab1-f.

else.

concatenate itab1-f <fs2> into itab1-f separated by 'BREAK'.

endif.

else.

exit.

endif.

enddo.

APPEND itab1.

clear : sy-subrc, itab1-f.

ENDIF.

ENDLOOP.

LOOP AT itab1.

WRITE 😕 itab1-f.

ENDLOOP.

Regards

Read only

Former Member
0 Likes
7,131

DATA:

rec1 (2500),

it_p0002 TYPE TABLE OF pa0002,

wa_p0002 LIKE LINE OF it_p0002,

table(15),

leng TYPE i.

table = 'P0002'.

FIELD-SYMBOLS <fs> TYPE ANY.

ASSIGN (table) TO <fs>.

SELECT SINGLE * FROM pa0002 INTO wa_p0002 WHERE pernr = '1'.

MOVE-CORRESPONDING wa_p0002 TO <fs>.

Move <fs> to rec1.(this is working but still not getting the entire record its only moving 255 characters)

please chek it out and tell a solution according to this

Read only

0 Likes
7,131

Hi Hari ,

Here is the code for the same

DATA:

rec1(2500),

it_p0002 TYPE TABLE OF pa0002,

wa_p0002 LIKE LINE OF it_p0002,

table(15),

leng TYPE i.

table = 'P0002'.

FIELD-SYMBOLS <fs> TYPE ANY.

ASSIGN (table) TO <fs>.

SELECT SINGLE * FROM pa0002 INTO wa_p0002 WHERE pernr = '1'.

MOVE wa_p0002 TO rec1.

write:/ rec1+0(200) ,

/ rec1+200(200) ,

/ rec1+400(200).

If you try to print rec1 then it will display only 255 char , so you need to use offset to get the entire stuff.

Regards

Arun

Read only

0 Likes
7,131

Hi Arun,

it didnt work the code you have send had errors

MOVE wa_p0002 TO rec1. here wa_p0002 is a structure and rec1 is a string

it is showing the following error

The data object cannot be converted to a character-type object.

Read only

0 Likes
7,131

Hi Hari ,

It might be some version conflicts , as the program worked fine in my system , any why replace the write statement with the one below

write:/ wa_p0002+0(200) ,

/ wa_p0002+200(200) ,

/ wa_p0002+400(200).

and do tell the result.

Assign points if helpful.

Regards

Arun

Read only

uwe_schieferstein
Active Contributor
7,131

Hello Hari

Every solution thus far provided will run you into trouble as soon as you convert to <b>Unicode </b>system. Therefore if you are already working on SAP release <b>>= 6.20</b> (4.70) then you should use the methods of class <b>CL_ABAP_CONTAINER_UTILITIES</b>, in your case use method <b>FILL_CONTAINER_C</b>.

Regards

Uwe

Read only

0 Likes
7,131

Yes, this would be the correct method.

But, Can you please tell me, how to use the above method in situations such as :

Select * from PA0002

into table li_infotype_records

for all entries in...............

where pernr=......................

PA0002 - is a structure having both type 'c' fields and type 'p' fields.

li_infotype_records is a String.

Please respond.

Thanks

Vijay

Read only

former_member188827
Active Contributor
0 Likes
7,131

TRY SUMTHING LIKE DIS:

DATA: BEGIN OF IT,

FIELD1(4) TYPE C,

FIELD2 TYPE I,

END OF IT.

IT-FIELD1 = 'A1'.

IT-FIELD2 = 1.

DATA ZSTR(20) TYPE C.

DATA A TYPE I.

DATA B TYPE I.

DATA ZSTR1 TYPE C.

MOVE IT-FIELD1 TO ZSTR.

A = STRLEN( ZSTR ).

MOVE IT-FIELD2 TO ZSTR1.

B = STRLEN( ZSTR1 ).

MOVE IT-FIELD2 TO ZSTR+A(ZSTR1).

WRITE ZSTR.

RGDS.

REWARD POINTS IF IT HELPS.

Read only

Former Member
0 Likes
7,131

Hi,

Use the following FM.

Data : v_string type string length 1020.

CALL FUNCTION 'SO_STRUCT_TO_CHAR'

EXPORTING

ip_struct = structure name

IMPORTING

EP_STRING = v_String.

Hope this helps.

Reward Points if useful....

Thanks

Jitendra