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

Generic fm for Unicode Conversion ?

former_member194669
Active Contributor
0 Likes
1,853

All,

I have requirement to write common function module to convert data from itab --> string and string --> itab in unicode environment. I am planning to use class cl_abap_container_utilities and methods

1). FILL_CONTAINER_C

2). READ_CONTAINER_C

The following is the function module for string --> itab


function z_test_unicode.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(XINPUT) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     REFERENCE(XOUTPUT) TYPE  STANDARD TABLE
*"----------------------------------------------------------------------
  class cl_abap_container_utilities definition load.
  call method cl_abap_container_utilities=>read_container_c
    exporting
      im_container           = xinput
    importing
      ex_value               = xoutput
    exceptions
      illegal_parameter_type = 1
      others                 = 2.
endfunction.

and i am calling this in the program


report zaRs
       no standard page heading
       line-size 255.

data: begin of itab occurs 0,
        detail(2047)   type c,
      end   of itab.

data: begin of i_yatt occurs 0.
data: mandt     like sy-mandt.
data: docno     like vbak-vbeln.
data: end of i_yatt.

move '0301000' to itab-detail.
append itab.

loop at itab.
call function 'Z_TEST_UNICODE'
 EXPORTING
   XINPUT        = itab-detail
 IMPORTING
   XOUTPUT       = i_yatt.
 append i_yatt.
endloop.

But i am getting DUMP

"Type conflict when calling a function module."

How to overcome this , i need to work with all input length and all xoutput internal tables?

Any info?

a®

13 REPLIES 13
Read only

former_member194669
Active Contributor
0 Likes
1,521

Any takers?

a®

Read only

Former Member
0 Likes
1,521

inside the loop you pass the itab-detail value to one string variable and pass it to function module.

Read only

0 Likes
1,521

Alagu,

It not nothing related to loop. real problem is type conflict error in INPUT and OUTPUT . My input parameter always not of string. length varied every instance.

and the OUTPUT internal table is also not static it will get differed on each call

a®

Read only

0 Likes
1,521

Hi a®s,

i tried its mainly of type conflict with input and output. check my previous code.

Regards

Muthu

Read only

Former Member
0 Likes
1,521

Try like this

REPORT ZTEST_FUNCTION

*report zaRs

no standard page heading

line-size 255.

data: begin of itab occurs 0,

detail(2047) type c,

end of itab.

types: begin of w_yatt ,

mandt like sy-mandt,

docno like vbak-vbeln,

end of w_yatt.

data: i_yatt type table of w_yatt,

wa_yatt type w_yatt.

move '0301000' to itab-detail.

append itab.

data v_string type string.

loop at itab.

clear v_string.

v_string = itab-detail.

break-point.

call function 'ZTEST_FM'

EXPORTING

XINPUT = v_string

IMPORTING

XOUTPUT = i_yatt.

  • append wa_yatt to i_yatt.

endloop.

Read only

Former Member
0 Likes
1,521

as XINPUT is type string, why dont you make itab-detail also of type string ?

Isn't that the reason why tis giving a dump ?

Read only

0 Likes
1,521

Sugamol,

I cannot declare the ITAB-DETAIL as string in every code . and also i cannot able to do like Alagu asked for


move data v_string type string. 

This is where i stuck.

a®

Read only

0 Likes
1,521

Do like this.

data v_string type string.

loop at itab.

clear v_string.

v_string = itab-detail. " move your detail value to v_string

call function 'ZTEST_FM'

EXPORTING

XINPUT = v_string

IMPORTING

XOUTPUT = i_yatt.

Its working for me. check again

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,521

In you function, make the importing parameter without any type, and then move the importing parameter to a STRING type field internally.

function z_test_unicode.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(XINPUT) 
*"  EXPORTING
*"     REFERENCE(XOUTPUT) TYPE  STANDARD TABLE
*"----------------------------------------------------------------------

data: lv_string type string.

lv_string = xinput.

  class cl_abap_container_utilities definition load.
  call method cl_abap_container_utilities=>read_container_c
    exporting
      im_container           = lv_string    "<--- Change here
  importing
      ex_value               = xoutput
    exceptions
      illegal_parameter_type = 1
      others                 = 2.


endfunction.

Regards,

Rich Heilman

Read only

0 Likes
1,521

Oh, and also, if XOUTPUT is typed as a STANDARD TABLE, then this is wrong as well....

loop at itab.
call function 'Z_TEST_UNICODE'
 EXPORTING
   XINPUT        = itab-detail
 IMPORTING
   XOUTPUT       = i_yatt.    "<-- this represents the header line, not the table
 append i_yatt.    
endloop.

So you should actually have a sepearete workaread for you header line, but if you don't want to do that, then you need brakets here I think.

loop at itab.
call function 'Z_TEST_UNICODE'
 EXPORTING
   XINPUT        = itab-detail
 IMPORTING
   XOUTPUT       = i_yatt[].    "<--Brakets to specify the table body
 append i_yatt.       "<-- and you wouldn't need this
endloop.

Also, I'm not 100% sure that the STATIC method within the function will actually bring back a table, hence making all this invalid as well..

Regards,

Rich Heilman

Read only

0 Likes
1,521

Yes correct. either you need to declare seperate work area or brackets you need to add. and no need for append there.

Read only

0 Likes
1,521

Rich you are right.

after the cl_abap_container_utilities=>read_container_c system is not returning the value.

May be i need to look some other alternative.

a®

Read only

0 Likes
1,521

Thanks All,

Issued solved.

a®