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

Convert structure to string and viceversa

oliver_am
Active Participant
0 Likes
7,300

Hello, I need to convert a structure with some amount fields to a char like field, and then do the opposite.

I can convert the structure to a cfield with this:

DATA: lv_content  TYPE asafbtabcontent,
      lo_record TYPE REF TO data.


GET REFERENCE OF ls_my_str INTO lo_record.

PERFORM record_to_cfield IN PROGRAM saplas_afb USING lo_record  CHANGING lv_content.

But, how to do the opposite?

Abap 731.

Trying something like this, but values are wrong.

  FIELD-SYMBOLS:
    <ls_my_str> TYPE zz_my_str.

 ASSIGN lv_content TO <ls_my_str> CASTING. "HANDLE lo_TYPEDESCR.
  IF sy-subrc EQ 0.
      ls_my_str = <ls_my_str>.
  ENDIF.

I seem to remember that there was a FM or METHOD * CONTAINER * to do this conversions, but don't remember the name.

Any clue?

Thanks

Hello, I need to convert a structure with some amount fields to a char like field, and then do the opposite.

I can convert the structure to a cfield with this:

DATA: lv_content  TYPE asafbtabcontent,
      lo_record TYPE REF TO data.


GET REFERENCE OF ls_my_str INTO lo_record.

PERFORM record_to_cfield IN PROGRAM saplas_afb USING lo_record  CHANGING lv_content.

But, how to do the opposite?

Abap 731.

Trying something like this, but values are wrong.

  FIELD-SYMBOLS:
    <ls_my_str> TYPE zz_my_str.

 ASSIGN lv_content TO <ls_my_str> CASTING. "HANDLE lo_TYPEDESCR.
  IF sy-subrc EQ 0.
      ls_my_str = <ls_my_str>.
  ENDIF.

I seem to remember that there was a FM or METHOD * CONTAINER * to do this conversions, but don't remember the name.

Any clue?

Thanks

7 REPLIES 7
Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
6,322

Is this class what you are looking for?

CL_ABAP_CONTAINER_UTILITIES
-- Tomas --
Read only

0 Likes
6,322

Thanks ! this is what I was looking for

Read only

former_member1716
Active Contributor
6,322

Hello Oliver AM,

It should be CL_ABAP_CONTAINER_UTILITIES. To know more about on how to use it, please follow the below Blog.

BLOG

Regards!

Read only

matt
Active Contributor
0 Likes
6,322

Just to comment that using external performs is bad practice (as is using PERFORMs since they're considered obsolete now).

Read only

oliver_am
Active Participant
0 Likes
6,322

I have a problem with the class CL_ABAP_CONTAINER_UTILITIES.

I've created a report to save the data from a table into a txt file.
If I read the downloaded file in the same system I can read and convert the data to the structure type correctly.

But I'm trying to read this file in other system, and in this other system the method READ_CONTAINER_C is not working fine. Returns wrong data and strange characters.

Do you know what can be the problem?
Version of first system; 731 and second system; 75D S4/HANA.

Code of the method READ_CONTAINER_C in both systems is the same.
Any clue?

Read only

6,322

CL_ABAP_CONTAINER_UTILITIES is only a temporary solution when you convert a system from Non-Unicode to Unicode. In non-unicode programs, structures with packed fields could be transferred to character fields. It's considered incorrect practice since Unicode (it's not really connected to Unicode, it's just that it was a good occasion to clean ABAP code). If you want to transfer data in a standardized way, please use JSON or XML (it could be done via data clusters too, with the classes CL_ABAP_EXPIMP* (which support internal formats of several kernel versions), but I don't like it because it's a SAP proprietary method).

Read only

oliver_am
Active Participant
0 Likes
6,322

Thanks Matthew, It's was only a try.
I'll try to use OO in the future and not use PERFORMs any more.