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: 

translate field of many internal table in one go

Former Member
0 Kudos

Hello,

i know i can translate a field of particular internal table to upper case using keyword 'TRANSLATE itab-field TO UPPER CASE'.

my requirement is i have 15 internal table. i want to create one subroutine which if given name of internal table will convert all the lower case values in that table to upper case.

data : int_table(50).

int_table = 'name_of_internal_table'.

perform translate_to_upper_case using int_table.

is this possible, is there any FM for this.

please advice.

regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The code you have written is correct.

But pass the parameter field as <b>CHANGING</b> not

<b>USING</b>. Within the implementation part of this

perform wirte this.

FORM translate_to_upper_case <b>CHANGING</b> int_table1

LOOP at int_table1.

TRANSLATE int_table1-field TO UPPER CASE.

MODIFY int_table 1.

ENDLOOP.

ENDFORM.

Ensure that the contents of the internal table are characters or texts.

Please reward points if this explanation is useful.

Regards,

Siva

21 REPLIES 21

Former Member
0 Kudos

Hi,

Try this.

form translator_to_upper_case using tab_name.

field-symbols: <itab> type standard table,

<wa> type any.

assign (tab_name) to <itab>.

loop at <itab> assigning <wa>.

TRANSLATE <wa> TO UPPER CASE.

endloop.

endform.

Svetlin

0 Kudos

Hi Svetlin,

this is great logic, but very tedious, so i stick to my old logic.

But i need your advice in following logic given by you

form translator_to_upper_case using tab_name.

field-symbols: <itab> type standard table,

<wa> type any.

assign (tab_name) to <itab>.

loop at <itab> assigning <wa>.

TRANSLATE <wa> TO UPPER CASE.

endloop.

endform.

i was trying this, but at runtime i get error

ASSIGN_TYPE_CONFLICT

for code :: assign (tab_name) to <itab>.

please advice how to remove this

regards

Former Member
0 Kudos

Hi,

The code you have written is correct.

But pass the parameter field as <b>CHANGING</b> not

<b>USING</b>. Within the implementation part of this

perform wirte this.

FORM translate_to_upper_case <b>CHANGING</b> int_table1

LOOP at int_table1.

TRANSLATE int_table1-field TO UPPER CASE.

MODIFY int_table 1.

ENDLOOP.

ENDFORM.

Ensure that the contents of the internal table are characters or texts.

Please reward points if this explanation is useful.

Regards,

Siva

0 Kudos

Hello everyone,

yes i have solved it.

first i tried field symbol, but could not work with them.

then i tried method told by siva, but still could not get the results.

but in the end i figured out how to do it

i did it by passing name of int_table as value.

Hi Siva

int_table = 'name_of_internal_table'.

so i need to pass its value.

so i did this

form translate_to_upper_case changing VALUE(P_INT_TABLE)

if p_int_table = 'name_of_internal_table'.

loop at name_of_internal_table'

translate name_of_internal_table-field to upper case.

modify name_of_interal_table transporting field.

endloop.

endif.

*so on you could have if and endif for all internal tables

endform.

but i wish the same could be possible throu field-symbols

if you could figure out this , please do share.

thanks once again for your help

your help was very important and put me in right direction

regards

0 Kudos

Hi

form translate_to_upper_case changing VALUE(P_INT_TABLE)

FIELD-SYMBOLS: <TABLE> TYPE TABLE,

<WA> TYPE ANY

<FIELD> TYPE ANY.

ASSIGN (P_INT_TABLE) TO <TABLE>.

LOOP AT <TABLE> ASSIGNING <WA>.

ASSIGN COMPONENT FIELD OF STRUCTURE <WA> TO <FIELD>.

TRANSLATE <FIELD> UPPER CASE.

modify <TABLE> FROM <WA>.

endloop.

Max

0 Kudos

Hi,

It's strange that you didn't succeed it with field-symbols. Do you recieve any errors ? Post your code, using field-symbols.

Svetlin

0 Kudos

sorry for not reply soon.

i have gone home and now i am back.

Hi Svetlin,

I will try the way Max has told , the error i was getting with code told by you was that

<wa> is not compatible.

But one more thing is that i don't want to translate all the fields of internal table.

let me try that also

regards

0 Kudos

Hi,

This code is simular to Max's, but for more than one field.

REPORT ztest2.

data mytable type table of bsik.

data: begin of field_str,

field(20),

end of field_str.

data field_itab like table of field_str.

select * from bsik into table mytable up to 10 rows.

field_str-field = 'SGTXT'.

append field_str to field_itab.

perform translator_to_upper_case tables field_itab

using 'mytable' .

form translator_to_upper_case tables fields like field_itab

using tab_name.

field-symbols: <itab> type standard table,

<wa> type any,

<fd> type any.

assign (tab_name) to <itab>.

loop at <itab> assigning <wa>.

loop at fields into field_str.

assign component field_str-field

of structure <wa> to <fd>.

TRANSLATE <fd> TO UPPER CASE.

endloop.

endloop.

endform.

0 Kudos

Hello Max,

in following st.

ASSIGN COMPONENT FIELD OF STRUCTURE <WA> TO <FIELD>.

what is FIELD, here , is it field of internal table which i want to translate,

I tried that, but i get error that that field don't exist.

please advice

regards

0 Kudos

Hello Svetlin,

sorry i am little weak in field-symbols.

i could not understand this code

so in order to translate many field of internal table , i have to create one more internal table(field_itab) , which will contain name of the fields of the internal table(mytable).

Am i right.

if wrong then please guide

regards

0 Kudos

Yes,

In my code you have to create a table with the names of the fields to be translated.

Svetlin

0 Kudos

Hello Max,

i was trying this

FORM TRANSLATE_TO_UPPER_CASE USING VALUE(P_INT_TABLE) .

FIELD-SYMBOLS: <TABLE> TYPE ANY TABLE ,

<WA> TYPE ANY.

ASSIGN (P_INT_TABLE) TO <TABLE>.

LOOP AT <TABLE> ASSIGNING <WA>.

TRANSLATE <WA> TO UPPER CASE.

ENDLOOP.

ENDFORM.

But at runtime i am getting assign type conflict error

for code ASSIGN (P_INT_TABLE) TO <TABLE>.

Can you explain , why this is happening

regards

0 Kudos

The parameters you are getting in is not being seen as Table, try to define change your form statemetn

form <formname> using <input paramet> like <table name>

or define a macro as follows and

use can call this as

download_to_unix_raw <tablename>

define download_to_unix_raw.

loop at &1.

transfer &1 to &1.

modify &1

endloop.

end-of-definition.

0 Kudos

Hello Jagrag Dhillon,

Thanks for replying.

Here::

The parameters you are getting in is not being seen as Table, try to define change your form statemetn

form <formname> using <input paramet> like <table name>

i can't give <table name> as i want to translate data in 15 internal table . i am sending name of these table using value(p_int_table).

may be i am unable to under stand.

can you please explain in little detail.

regards

bal

0 Kudos

Hi Surpreet ,

Your code is perfect . But I guess you are passing the ITAB header line to P_INT_TABLE.

Check this it works wonders -

DATA : BEGIN OF ITAB OCCURS 0,

NAME(30),

END OF ITAB.

DATA P_INT_TABLE(50).

ITAB-NAME = 'surpreet'.

APPEND ITAB.

P_INT_TABLE = <b>'ITAB[]'</b>.

PERFORM TRANSLATE_TO_UPPER_CASE USING P_INT_TABLE.

LOOP AT ITAB.

WRITE 😕 ITAB-NAME.

ENDLOOP.

FORM TRANSLATE_TO_UPPER_CASE USING VALUE(P_INT_TABLE) .

FIELD-SYMBOLS: <TABLE> TYPE ANY TABLE ,

<WA> TYPE ANY.

ASSIGN (P_INT_TABLE) TO <TABLE>.

LOOP AT <TABLE> ASSIGNING <WA>.

TRANSLATE <WA> TO UPPER CASE.

ENDLOOP.

ENDFORM. "TRANSLATE_TO_UPPER_CASE

Cheers

( Dont forget to reward if answers were helpful ).

0 Kudos

then you can use the Macro as follow

define <macroname>

loop at &1

do what ever you want to do.

modify &1.

endloop.

end-of-definition.

call this macro as

<macroname> <parameter1> ...<parameters2>

or you can use following command which give you the stucture of the passed parameters if it is internal table

assign &2 to <itab_structure>.

describe field <itab_structure> type t_type components t_components.

then loop on t_components.

each line will be field and type will be the type of the field like "char, dat..."

following is the code for loop at t_compoents

do t_components times.

assign component sy-index of structure <itab_structure> to <field>.

describe field <field> type t_type.

if t_type eq 'P'.

if <field> lt 0.

write <field> to number_field. " no-zero.

shift number_field right circular.

condense number_field no-gaps.

assign number_field to <field>.

else.

write <field> to number_field. " no-zero.

condense number_field no-gaps.

assign number_field to <field>.

endif.

elseif t_type eq 'C'.

write <field> to t_text_field.

  • DO.

  • REPLACE '"' with ' ' into t_text_field.

  • IF SY-SUBRC NE 0.

  • EXIT.

  • ENDIF.

  • ENDDO.

concatenate t_text_field '' into text_field.

assign text_field to <field>.

endif.

t_pos = strlen( unixfile-field1 ).

move <field> to unixfile-field1+t_pos.

check sy-index lt t_components.

t_pos = strlen( unixfile-field1 ).

if delimeter is initial.

move t_delimeter to unixfile-field1+t_pos.

else.

move delimeter to unixfile-field1+t_pos.

endif.

enddo.

&1 is parameter1

&2 is paramter2 and so on.

0 Kudos

Hello Sanjay,

you are great.

Your analysis is perfect, yes this was cause of error.

I was passing header and not body of internal table.

This was first thing I corrected in the morning.

I have corrected this and now it is working great.

I will remain thankful to you for this.

regards

surpreet

0 Kudos

Hello Jagraj Dhillon,

Thanks for detailed reply on macros.

But with my only 8 months experience, i was not able to understand it completely.

I need to work hard little bit more.

And with the help of SDN forum , i am daily learning something new.

I have never used macros.

But now i will surely try them and try to learn

Once again Thanks for replying.

regards

Bal

0 Kudos

Hi

when you run this statament:

ASSIGN (P_INT_TABLE) TO <TABLE>.

an error occurs because the field-symbols <TABLE> is a table and you are probably assigning the workarea of P_INT_TABLE and not all data of P_INT_TABLE.

When you want to pass whole table to field-symbols if P_INT_TABLE is only the name of internal table you should write:

DATA: ALL_TABLE(3O) TYPE C.

CONCATENATE P_INT_TABLE '[]' INTO ALL_TABLE.

ASSIGN (ALL_TABLE) TO <TABLE>.

Or you change the type of parameter of form:

FORM TRANSLATE_TO_UPPER_CASE

USING P_INT_TABLE TYPE TABLE.

Now you write:

ASSIGN P_INT_TABLE TO <TABLE>.

But when you run this routine you have to write:

PERFORM TRANSLATE_TO_UPPER_CASE MY_YABLE[].

Anyway in this case the field-symbols <TABLE> is useless because you can directly use the parameter:

FORM TRANSLATE_TO_UPPER_CASE

USING P_INT_TABLE TYPE TABLE.

FIELD-SYMBOLS: <WA> TYPE ANY.

LOOP AT P_INT_TABLE ASSIGNING <WA>.

TRANSLATE <WA> TO UPPER CASE.

ENDLOOP.

ENDFORM.

Max

ChristianFi
Active Participant
0 Kudos

This is just pseudocode but you will get the idea.

In this case you do not pass the name of the internal table but the internal table itself

p_field is the field to be translated.

perform translate_table using 'COMPONENT' int_table[].

HTH

Christian


form translate_table using p_field type dd02l-fieldname
                     changing pit_itab type any table.

  field-symbols: <l_field> type any. 
  field-symbols: <lwa_line> type any. 

  loop at pit_itab assigning <lwa_line>. 
    assign component (p_field) of structure <lwa_line>
                               to <L_field>. 
    if sy-subrc ne 0. exit. endif. 
       translate <l_field> to upper case.  
    endif. 
 endloop.  
endform. 

Message was edited by: Christian Finkbeiner

Ahh too slow....

0 Kudos

Thanks a lot to all of you.

i think my problem will be solved with field symbols.

please give me some time to do it and i will get back to you

once again thanks for your help

regards