You are on page 1of 4

*&---------------------------------------------------------------------*

*& Report ZSAMPLE_BDC


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

*include zbdc.

REPORT zsample_bdc.
TYPE-POOLS: truxs.

PARAMETERS: p_file TYPE rlgrap-filename.

TYPES: BEGIN OF t_datatab,


col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
col4(30) TYPE c,
col5(30) TYPE c,
col6(30) TYPE c,
col7(30) TYPE c,
col8(30) TYPE c,
col9(30) TYPE c,
col10(30) TYPE c,
col11(30) TYPE c,
col12(30) TYPE c,
END OF t_datatab.

DATA: it_datatab TYPE STANDARD TABLE OF t_datatab,


wa_datatab TYPE t_datatab,
lv_txt(30) TYPE c.

DATA: it_raw TYPE truxs_t_text_data.


DATA : v_file TYPE string.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.

***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
MOVE p_file TO v_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = 'X'
dat_mode = ''
TABLES
data_tab = it_raw
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'


EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

***********************************************************************

END-OF-SELECTION.

DELETE it_datatab FROM 1 TO 2.


LOOP AT it_datatab INTO wa_datatab.
IF wa_datatab-col8 CA 'Jan'.
lv_txt = wa_datatab-col8.
REPLACE 'Jan-' WITH '01' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Feb'.
lv_txt = wa_datatab-col8.
REPLACE 'Feb-' WITH '02' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Mar'.
lv_txt = wa_datatab-col8.
REPLACE 'Mar-' WITH '03' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Apr'.
lv_txt = wa_datatab-col8.
REPLACE 'Apr-' WITH '04' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'May'.
lv_txt = wa_datatab-col8.
REPLACE 'May-' WITH '05' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Jun'.
lv_txt = wa_datatab-col8.
REPLACE 'Jun-' WITH '06' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Jul'.
lv_txt = wa_datatab-col8.
REPLACE 'Jul-' WITH '07' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Aug'.
lv_txt = wa_datatab-col8.
REPLACE 'Aug-' WITH '08' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Sep'.
lv_txt = wa_datatab-col8.
REPLACE 'Sep-' WITH '09' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Oct'.
lv_txt = wa_datatab-col8.
REPLACE 'Oct-' WITH '10' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Nov'.
lv_txt = wa_datatab-col8.
REPLACE 'Nov-' WITH '11' INTO lv_txt.
wa_datatab-col8 = lv_txt.
ELSEIF wa_datatab-col8 CA 'Dec'.
lv_txt = wa_datatab-col8.
REPLACE 'Dec-' WITH '12' INTO lv_txt.
wa_datatab-col8 = lv_txt.

ENDIF.

WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3,
wa_datatab-col4,
wa_datatab-col5,
wa_datatab-col6,
wa_datatab-col7,
wa_datatab-col8,
wa_datatab-col9,
wa_datatab-col10,
wa_datatab-col11,
wa_datatab-col12.
ENDLOOP.