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

converting all data types to CHAR type

Former Member
0 Likes
4,026

Hi Experts,

-


I have a requirement where i have to convert all(packed,raw,etc..) data types in CHAR type

-


Populate the data , in a table where all associated type are CHAR type and display it.

Regards

samuel

Hi Experts,

-


I have a requirement where i have to convert all(packed,raw,etc..) data types in CHAR type

-


Populate the data , in a table where all associated type are CHAR type and display it.

Regards

samuel

11 REPLIES 11
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,545

You should look at the method CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C( ) .

Read only

Former Member
0 Likes
2,545

Hi,

thanks for quick response

could you please elaborate with some sample code

my values in the variables are 1.999(RAW) 33.666(DEC) 30.08.2011(DATS) respectively.

i am expecting these values to associate with 1.999(CHAR) 33.666(CHAR) 30.08.2011(CHAR) data type in an internal table .....

Thanks in advance.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,545

Hello Sam,

Using this method is pretty straight forward

could you please elaborate with some sample code

Spoon feeding is not encouraged in the forums. Please try the solution & get back to the forum in case you face any specific errors.

Cheers,

Suhas

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,545

To be sure to understand you, you want to create an internal table with same field list (same field names) than an original one (internal table or ddic structrure) but in external format "character" (with or without conversion, comma ? conversion exit ?), map the data field by field converting to characters (kind of write-corresponding) and display,

Where are you blocked, getting structure definition, creating the dynamic internal table, mapping the data or displaying the table ?

There are many threads at sdn on each of these topics in sdn, did you use the search tool ?

Regards,

Raymond

Read only

koolspy_ultimate
Active Contributor
0 Likes
2,545

hi,

You can get this by searching the sdn,[R|;

any ways please find the following code to be usefull.


tables mara.
data : wa_ymara type mara. 
loop at i_ymara into wa_ymara.
  call method cl_abap_container_utilities=>fill_container_c
    exporting
      im_value               = wa_ymara
    importing
      ex_container           = i_yindx-vdata
    exceptions
      illegal_parameter_type = 1
      others                 = 2.
  append i_yindx.
endloop.

regards,

kool.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,545

Method cl_abap_container_utilities=>fill_container_c map the whole structure into a string field (container) that can be then converted back with method cl_abap_container_utilities=>read_container_c, in no case will this method convert data from internal format to external format.

Can you confirm your requirement ?

Regards,

Raymond

Read only

0 Likes
2,545

HI Raymond Giuseppi

THANK YOU

I have the table data in a field symbol ,now i want to convert the table data into CHAR type and put it in a static internal table and display it.

ACTUAL DATA at runtime in the field symbol : 01(raw) 29.647(dec) 17.08.2011(dats) 38.446(dec) 17.08.2011(dats)

Now i want to display the data in : 01(char) 29.647(char) 17.08.2011(char) 38.446(char) 17.08.2011(char)

Read only

0 Likes
2,545

- In the LOOP AT <itab> assigning <record> you can loop ASSIGNing [COMPONENT integer OF STRUCTURE record|http://help.sap.com/abapdocu_70/en/ABAPASSIGN_MEM_AREA.htm#&ABAP_ALTERNATIVE_7@7@] thru the fields of the record

- You could use method of CL_ABAP_STRUCTDESCR and/or CL_ABAP_DATADESCR (*) to get description of each field (once at first record) -> get length of external format (CHAR type) - perform this only once at first record (store result somewhere in an itab for performance)

- You will also be able to find a conversion exit name and then convert from internal to external format, or use WRITE (**), you may have to manage some types the "hard coded" way, eg. TIMS, DATS, etc.

Regards,

Raymond

(*) Read first [RTTS - Run Time Type Services|http://help.sap.com/abapdocu_70/en/ABENRTTI.htm]

(**) Problem with WRITE is it will pad some fields to the length available in the target field, which may be undesirable depending the definition of target field, so use length retrieved via abap utilities class.

Read only

0 Likes
2,545

hi

thanks for your reply

i am unable to interpret the line

- You will also be able to find a conversion exit name and
 then convert from internal to external format

since i am new...it seems to be complex to me

could you please explain with some sample code

Regards

samuel

Edited by: sam_samuel on Sep 2, 2011 2:10 PM

Read only

0 Likes
2,545

thanks for your valuable suggestions

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
2,545

This message was moderated.