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: 

Convert into CHAR

Former Member
0 Kudos

Hi to all..

please go through the following and please tell me hwo to convert the INT4 , QUNA ....INTO CHAR fields....

I have tried but it is not executing in OPENDATA SET...AND in debugging fields are not converted....so please correct me...

TABLES: MARD, /UPM/GTB10 , EKKO, /UPM/GTB11.

*TYPES : CHAR2(10) TYPE C.

  • DATA : KILOMETER TO CHARFIELD. "INT4 (LENGTH 10)

  • QUANTITY TYPE CHAR2, "QUAN (LENGTH 13)

  • STANDARDPREIS TYPE CHAR2, "CURR (LENGTH 11)

  • BEDAT TYPE CHAR2, "DATS (LENGTH 08)

DATA: BEGIN OF ITAB1 OCCURS 0,

MATNR TYPE MARD-MATNR,

LABST TYPE MARD-LABST,

END OF ITAB1.

DATA: BEGIN OF ITAB2 OCCURS 0,

MATNR LIKE /UPM/GTB10-MATNR,

EXTMATLGRP LIKE /UPM/GTB10-EXTMATLGRP,

LAGERORT LIKE /UPM/GTB10-LAGERORT,

LAGERPLATZ LIKE /UPM/GTB10-LAGERPLATZ,

BESCHREIBUNG LIKE /UPM/GTB10-BESCHREIBUNG,

VCOLOR LIKE /UPM/GTB10-VCOLOR,

VIN LIKE /UPM/GTB10-VIN,

ENOTIZ LIKE /UPM/GTB10-ENOTIZ,

HERSTELLER LIKE /UPM/GTB10-HERSTELLER,

  • KILOMETER LIKE /UPM/GTB10-KILOMETER, "INT4 (LENGTH 10)

  • STANDARDPREIS LIKE /UPM/GTB11-NETPR, "CURR (LENGTH 11)

  • PSTNG_DATE LIKE EKKO-BEDAT, "DATS (LENGTH 08)

  • QUANTITY LIKE MARD-LABST, "QUAN (LENGTH 13)

END OF ITAB2.

data: file type string.

*******************************SELECT OPTION*************************

PARAMETERS: P_FNAME LIKE rlgrap-filename

DEFAULT 'c:\temp\test.TXT' OBLIGATORY. " File Nameselect

**************************SELECT*************************************

at selection-screen on value-request for P_FNAME.

call function 'WS_FILENAME_GET'

exporting

  • DEF_FILENAME = ' '

def_path = P_FNAME

mask = ',.txt,.txt.'

mode = 'O'

  • TITLE = ' '

importing

filename = P_FNAME

  • RC =

exceptions

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

others = 5.

START-OF-SELECTION.

select matnr LABST from mard into table itab1 where labst gt 0.

check sy-subrc = 0.

sort itab1 ascending by matnr.

SELECT * FROM /UPM/GTB10 INTO CORRESPONDING FIELDS OF TABLE ITAB2

for all entries in ITAB1 WHERE MATNR = ITAB1-MATNR.

END-OF-SELECTION.

***********************OPEN DATASET***********************************

OPEN DATASET P_FNAME IN TEXT MODE ENCODING DEFAULT FOR OUTPUT.

check sy-subrc = 0.

loop at itab2.

transfer itab2 to P_FNAME.

endloop.

close dataset P_FNAME.

if sy-subrc = 0.

endif.

***********************************CALL FUNCTION GUI DOWNLOAD*********

file = p_fname.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = file

FILETYPE = 'ASC'

TABLES

DATA_TAB = ITAB2

EXCEPTIONS

others = 22.

IF SY-SUBRC <> 0.

ENDIF.

Raju,,

1 ACCEPTED SOLUTION

former_member186741
Active Contributor
0 Kudos

hI mPR,

you will have to have another structure which has all the same elements as itab2 but they will all be char or num fields as appropriate. Then change your loop slightly:

loop at itab2.

move-corresponding itab2 to work_struc.

transfer work_struc to P_FNAME.

endloop.

5 REPLIES 5

former_member186741
Active Contributor
0 Kudos

hI mPR,

you will have to have another structure which has all the same elements as itab2 but they will all be char or num fields as appropriate. Then change your loop slightly:

loop at itab2.

move-corresponding itab2 to work_struc.

transfer work_struc to P_FNAME.

endloop.

former_member181962
Active Contributor
0 Kudos

Hi raju,

Once you get the data into itab1 and itab2, transafer the contents to say itab3 and itab4 of plain character data types. and use them for the open datset and gui_download.

data: begin of itab3 occurs 0,

data(40),

end of itab3.

data: begin of itab4 occurs 0,

data(400),

end of itab4.

loop at itab1.

itab3 = itab1.

append itab3.

endloop.

loop at itab2.

itab4 = itab2.

append itab4.

endloop.

Regards,

ravi

former_member188685
Active Contributor
0 Kudos
Loop at itab.
move-corresponding fields of itab1 to itab2.
write itab1-curr to itab2-char. "of same output length
similarly for other fields...(non char)
append itab2.
endloop.

try that..

Former Member
0 Kudos

Hi Raju,

Declare another final internal table with required fields of type CHAR.

Then move your data into this Internal table by putting Loop in the Main table. Then Write to App. server.

Regards,

Sudhakar.

Former Member
0 Kudos

Hi,

Try FM's

C14W_CHAR_NUMBER_CONVERSION

C14W_NUMBER_CHAR_CONVERSION

CHAR_INT_CONVERSION

for the conversion

Lokesh

Pls. reward appropriate points