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

Datatype convertion

MarkusKlein
Active Contributor
0 Likes
940

Hello

i have a structure A with 3 fields.

- Field A is of type DATS length 8.

- FIELD B is of type DEC length 5.

- FIELD C is of type CHAR length 7.

The problem is with datatypes of DATS the internal value is '0000000' when the value is initial.

Now i need to move the entries of the structure A to a structure B with 3 fields as well

- FIELD A is of type CHAR length 8.

- FIELD B is of type CHAR length 5.

- FIELD C is of type CHAR length 7.

I do have 2 problems now:

1.) when the value field A of structure A is emtpy, 0000000 gets move to field A of structure B. This shouldnt happen, or at least i need to clear it afterwards.

2.) When the value of field A of structure is not emtpy, the internal date format yyyymmdd gets moved to field A of structure b and not the extrenal layout.

Anyone has an idea how to solve the problem?

regards,

Markus

When the data is empty in these fields they have the internal value of '00000000'. Now i do want to

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
886

Hi markus,

1. Instead of using

field1 = field2,

2. u can use

WRITE field1 to field2.

regards,

amit m.

Hello

i have a structure A with 3 fields.

- Field A is of type DATS length 8.

- FIELD B is of type DEC length 5.

- FIELD C is of type CHAR length 7.

The problem is with datatypes of DATS the internal value is '0000000' when the value is initial.

Now i need to move the entries of the structure A to a structure B with 3 fields as well

- FIELD A is of type CHAR length 8.

- FIELD B is of type CHAR length 5.

- FIELD C is of type CHAR length 7.

I do have 2 problems now:

1.) when the value field A of structure A is emtpy, 0000000 gets move to field A of structure B. This shouldnt happen, or at least i need to clear it afterwards.

2.) When the value of field A of structure is not emtpy, the internal date format yyyymmdd gets moved to field A of structure b and not the extrenal layout.

Anyone has an idea how to solve the problem?

regards,

Markus

When the data is empty in these fields they have the internal value of '00000000'. Now i do want to

8 REPLIES 8
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
886

You will have to move the fields one at a time and handle the date field accordingly.

if not a-fielda is initial.
write a-fielda to b-fielda.  " This will give external format
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
886

1 and 2. Move the fieldA of Structure A to fieldA of structure B only when it is not initial.

Declare the fieldA as CHAR 10 to accomodate the external date format..

if not structureA-fieldA is initial.

write structureA-fieldA to structureB-fieldA.

endif.

Read only

Former Member
0 Likes
886

Have temporary intermediate variable of char type.

tempa(8).

tempa = a.

if tempa = '00000000'.

translate tempa using '0 '.

endif.

final_a = tempa.

Regards,

ravi

Read only

Former Member
0 Likes
887

Hi markus,

1. Instead of using

field1 = field2,

2. u can use

WRITE field1 to field2.

regards,

amit m.

Read only

0 Likes
886

Thx all for the reply, but i do want it to have it more dynamically.

Kinda loop over the components of structre A and B and assign dependent of the type the data.

Read only

0 Likes
886

Can you explain a bit more?

Read only

Former Member
0 Likes
886

Hi

FIELD-SYMBOLS: <FS_A> TYPE ANY,

<FS_B> TYPE ANY.

DO 3 TIMES.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE A TO <FS_A>.

ASSIGN COMPONENT SY-INDEX OF STRUCTURE B TO <FS_B>.

IF NOT <FS_A> IS INITIAL.

MOVE <FS_A> TO <FS_B>.

ENDIF.

ENDDO.

Max

Read only

0 Likes
886

Soo i got it working:

This is my code:

lo_type = cl_abap_structdescr=>describe_by_name( structure_A ).

lo_struc ?= lo_type.

lt_ddfields_A = lo_struc->get_ddic_field_list( p_including_substructres = 'X' ).

free lo_type. free lo_struc.

lo_type = cl_abap_structdescr=>describe_by_name( structure_B ).

lo_struc ?= lo_type.

lt_ddfields_B = lo_struc->get_ddic_field_list( p_including_substructres = 'X' ).

loop at lt_data into ls_data.

loop at lt_ddfields_B into ls_ddfields_B.

loop at lt_ddfields_A into ls_ddfields_A where fieldname = ls_ddfields_B-fieldname.

concatenate 'ls_data-' ls_ddfields_A-fieldname into l_field_A.

condense l_field_A no-gaps.

assign (l_field_A) to <field_A>.

concatenate 'ls_data-' ls_ddfields_A-fieldname into l_field_B.

condense l_field_B no-gaps.

assign (l_field_B) to <field_B>.

<field_B> = <field_A>.

if ls_ddfields_A-datatype = 'DATS' and <field_B> = '00000000'.

clear <field_B>.

elseif ls_ddfields_A-datatype = 'DATS' and not <field_B> = '00000000'.

call function 'CONVERSION_EXIT_MODAT_OUTPUT'

exporting

input = <field_B>

importing

output = <field_B>.

endif.

endloop.

endloop.

append ls_data to lt_data.

endloop.