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

Conversion Routines and Function Modules

Former Member
0 Likes
2,891

Hi All,

I have to write the Conversion Routines and Transformation Process for below Fields,

I have a situation, where am having text files with the data having below fields, and before uploading the data to Database i have to do conversion.

So anybody Plz help me regarding this conversion topic how to write the process and how to write the code.

Table Field Name Type Length Short Text

BKPF BLART CHAR 2 Document Type

BKPF BUKRS CHAR 4 Company Code

BSEG BUKRS CHAR 4 Company Code

BSEG HKONT CHAR 10 General Ledger Account

BSEG KOSTL CHAR 10 Cost Center

BSEG VERTN CHAR 13 Contract Number

KNA1 KUNNR CHAR 10 Customer Number

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,209

1. You know the fields which are coming from text file.

define an internal table with same structure as text file record.

1. you have to upload the data from text file.

use FM 'ws_upload', this will read all the records into internal table ITAB.

2. loop into internal table, use CONVERSION_EXIT_ALPHA_INPUT and modify the table.

e.g.:-

loop at ITAB.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = ITAB-kunnr

IMPORTING

output = ITAB-kunnr.

...

do the same for other fields.

*modify the internal table with new values.

modify ITAB.-kunnr transporting kunnr.

endloop.

21 REPLIES 21
Read only

Former Member
0 Likes
2,209

No need to write, you already have alpha. use the existing one.

e.g.:-

loop at lt_kunnr.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = lt_kunnr-kunnr

IMPORTING

output = lt_kunnr-kunnr.

modify lt_kunnr-kunnr transporting kunnr.

endloop.

Read only

0 Likes
2,209

Hi Shefali,

just tell me how to write the process in words.

Read only

0 Likes
2,209

Can anybody plz Help me for this conversion part.

Balu.

Read only

Former Member
0 Likes
2,210

1. You know the fields which are coming from text file.

define an internal table with same structure as text file record.

1. you have to upload the data from text file.

use FM 'ws_upload', this will read all the records into internal table ITAB.

2. loop into internal table, use CONVERSION_EXIT_ALPHA_INPUT and modify the table.

e.g.:-

loop at ITAB.

call function 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = ITAB-kunnr

IMPORTING

output = ITAB-kunnr.

...

do the same for other fields.

*modify the internal table with new values.

modify ITAB.-kunnr transporting kunnr.

endloop.

Read only

0 Likes
2,209

Hi all again,

Can i use this function module('CONVERSION_EXIT_ALPHA_INPUT') for all the fields for conversion.

BALU.

Read only

0 Likes
2,209

Yes you have to use that FM 'CONVERSION_EXIT_ALPHA_INPUT'

1. if your value is 234 and the field is of character 5 ,

after using 'CONVERSION_EXIT_ALPHA_INPUT' that value will become 00234

2. If ur value is 00234 and if u use 'CONVERSION_EXIT_ALPHA_OUTPUT' ur value will be 234

Read only

0 Likes
2,209

Hi Bala

Supposing all the fields exist in internal table itab. You can add the code simple as below:

loop at itab.
   .....
   perform conv_fld changing: itab-bukrs, 
                              itab-blart,
                              itab-hkont,
                              itab-kostl,
                              itab-vertn,
                              itab-kunnr.
   .....
   .....
endloop.
                           
*&---------------------------------------------------------------------*
*&      Form  conv_fld
*&---------------------------------------------------------------------*
FORM conv_fld  CHANGING fld.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    INPUT         = fld
 IMPORTING
   OUTPUT        = fld.

ENDFORM.                    " conv_fld

So for each field depending on its length the conversion routine acts and gives the right output. Please make sure, that your internal table if defined with the right field references or length.

Kind Regards

Eswar

Read only

0 Likes
2,209

Hi Chandrasekhar Jagarlamudi ,

How can i use this function module for Document type and company code ,

my requirement is that i have to do conversion for all those fields,

and before doing the coding part for this Plz tell me the transformation process for all these fields.

BALU.

Read only

0 Likes
2,209

Hi Bala chandar,

Ther is no need of Conversion routines for Document types and Company codes as they will be completely filled with its full length

Read only

0 Likes
2,209

Hi Eswar Rao,

Thnk u for ur response,

Plz Tell me the transformation process for all these fields,

give me the documentation for this if possible.

BALU.

Read only

0 Likes
2,209

Am not sure what you mean by transformation process. Can you be more specific...

Kind Regards

Eswar

Read only

0 Likes
2,209

Hi Eswar,

Go through below,

All dates in format MM/DD/YYYY

All times should be in format HH:MM:SS

Currency should be in format xxxxxxx.xx (without comma separation).

Quantity should be in format xxxxxxx.xxx (without comma separation).

So like this i have to write the Transformation process, could u plz help me in this.

BALU.

Read only

0 Likes
2,209

Hi Bala

For this, check the format of data that is coming in the file and then manipulate accordingly. This can vary for company to company, hence will not be generic. So proceed as per the info below:

If the format for date is yyyymmdd.

Define a variable of type char and length 10. Eg: for_date(10) type c.

ITAB has field DATE to hold the date coming from file then do like this:

concantenate itab-date4(2) itab-date6(2) itab(4) into for_date separated by '/'.

Now for_date will have the format MM/DD/YYYY.

Similary you can handle for Time.

For currency, declare a char variable for required lenght. Move the value to char. So the formatting option like COMMA will disappear.

Hope this helps.

Kind Regards

Eswar

Read only

0 Likes
2,209

Thank u Eswar,

I have mentioned some fields na, for those fields i have to take conversion part,

i am extracting the data from BKPF and BSEG table and using Gui_Download FM am creating text files, in those text fiels am extracting the data for all these fields and now the files are ready for conversion. And to convert, the fields are those i had mentioned before.

So in the code where i have to mention these conversion coding part.

BALU.

Read only

0 Likes
2,209

Hi Eswar,

Could u plz help me.

Go through below.

I have mentioned some fields na, for those fields i have to take conversion part,

i am extracting the data from BKPF and BSEG table and using Gui_Download FM am creating text files, in those text fiels am extracting the data for all these fields and now the files are ready for conversion. And to convert, the fields are those i had mentioned before.

So in the code where i have to mention these conversion coding part.

BALU.

Read only

0 Likes
2,209

Hello all,

Help me Plz.

Read only

0 Likes
2,209

HI Bala

Seems i have lost.

As per my understanding, you are extracting data from tables BKPF and BSEG to an internal table.

Now you are downloading the data as text files using FM: GUI_DOWNLOAD.

So in this case, you dont need the other conversions. I guess you just need to re-format the data for Date and Time.

Please correct me if my understanding is wrong.

Kind Regards

Eswar

Read only

0 Likes
2,209

No Eswar,

I have to do conversion for those fields i have mentioned.

BALU.

Read only

0 Likes
2,209

Help me Eswar,

BALU.

Read only

0 Likes
2,209

Hi ,

Actually am doing the comparison for two text files,

first am going to create one text file1 using GUI_download and after that i am going to create another text file2 using GUI_download .

now i have to do conversion for those fileds i had mentioned , that is for old values(file1) and new values(file2).

Help me.

BALU.

Read only

0 Likes
2,209

Bala

Can you post your code, maybe that can help for some understanding.

Regards

Eswar