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: 

Conversion of char to internal representation

Former Member
0 Kudos

I am extracting a field of char40 and creating a file out of it. The problem I have is

A99\260 Z1 50000700 SPECIFIC GRAVITY @ 15.6 C 1.0600

A99\260 Z1 50000751 BLOT (PASS) Clean

A99\260 Z1 50000757 CLARITY (CLEAR) Slight Haze Pass

A99\260 Z1 50000761 COLOR 3.0 typical L 0.5

A99\260 Z1 50000731 VISCOSITY @ 40 C, CST 69.00

A99\260 Z1 50000725 VISCOSITY @ 100 C, CST 8.300

As you can see the field values after the char field are been placed based on the actual length of the char field. I need to convert it to 40 chars so I can write the rest of the fields following it as a tabbed distance away. My file format gets whacked if one of the values is blank. How to fill them? Thanks

Message was edited by:

Megan Flores

1 ACCEPTED SOLUTION

Former Member
0 Kudos

How do I display the entire length of the field. This is my code.

TYPES: BEGIN OF t_qualitydata,
         matnr      TYPE char18,
         charg      TYPE char10,
         verwmerkm  TYPE char8,
         char_descr TYPE char40,
         kurztext   TYPE char40,
         mean_value TYPE char22,
       END OF t_qualitydata.

LOOP AT i_qualitydata INTO wa_qualitydata.
  CONCATENATE wa_qualitydata-matnr
              wa_qualitydata-charg
              wa_qualitydata-verwmerkm
              wa_qualitydata-char_descr
              wa_qualitydata-kurztext
              wa_qualitydata-mean_value INTO gv_row SEPARATED BY space.
  TRANSFER gv_row TO c_file.
ENDLOOP.

5 REPLIES 5

Former Member
0 Kudos

Try to display the full length of the field.

Thanks,

SKJ

Former Member
0 Kudos

How do I display the entire length of the field. This is my code.

TYPES: BEGIN OF t_qualitydata,
         matnr      TYPE char18,
         charg      TYPE char10,
         verwmerkm  TYPE char8,
         char_descr TYPE char40,
         kurztext   TYPE char40,
         mean_value TYPE char22,
       END OF t_qualitydata.

LOOP AT i_qualitydata INTO wa_qualitydata.
  CONCATENATE wa_qualitydata-matnr
              wa_qualitydata-charg
              wa_qualitydata-verwmerkm
              wa_qualitydata-char_descr
              wa_qualitydata-kurztext
              wa_qualitydata-mean_value INTO gv_row SEPARATED BY space.
  TRANSFER gv_row TO c_file.
ENDLOOP.

0 Kudos

In this case you may have to take fixed lenght of the field i guess.

i.e. for example:

wa_qualitydata-char_descr+1(30)

This would give you a fixed length description and the data will not be skiewed.

Thanks,

SKJ

0 Kudos

Check the below program :

parameters: d1 type localfile default

'/usr/sap/TST/SYS/Test.txt'.

data: begin of itab occurs 0,

field1(20) type c,

field2(20) type c,

field3(20) type c,

end of itab.

data: str type string.

constants: con_tab type x value '09'.

  • if you have a newer version, then you can use this

instead.

*constants:

  • con_tab type c value

cl_abap_char_utilities=>HORIZONTAL_TAB.

start-of-selection.

itab-field1 = 'ABC'.

itab-field2 = 'DEF'.

itab-field3 = 'GHI'.

append itab.

itab-field1 = '123'.

itab-field2 = '456'.

itab-field3 = '789'.

append itab.

open dataset d1 for output in text mode.

loop at itab.

translate itab using ' # '.

concatenate itab-field1 itab-field2 itab-field2

into str

separated by con_tab.

translate str using ' # '.

transfer str to d1.

endloop.

close dataset d1.

Thanks

Seshu

0 Kudos

Hi Megan,

The tab is represented as CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB in Unicode system.

Changed your code as follows.

LOOP AT i_qualitydata INTO wa_qualitydata.

CONCATENATE wa_qualitydata-matnr

wa_qualitydata-charg

wa_qualitydata-verwmerkm

wa_qualitydata-char_descr

wa_qualitydata-kurztext

wa_qualitydata-mean_value INTO gv_row SEPARATED BY <b>CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.</b>

TRANSFER gv_row TO c_file.

ENDLOOP.

Thanks,

Vinay