0% found this document useful (0 votes)
149 views11 pages

Upload & Download

This report updates installation facts for employees in SAP. It allows uploading new fact data from an Excel file, inserting the new data into internal tables, and displaying any errors. The report includes forms for file selection, downloading a sample data file, uploading the Excel data, inserting records into tables, and displaying errors. Data types and internal tables are defined to store the uploaded data and new/old fact records.

Uploaded by

Sachin Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views11 pages

Upload & Download

This report updates installation facts for employees in SAP. It allows uploading new fact data from an Excel file, inserting the new data into internal tables, and displaying any errors. The report includes forms for file selection, downloading a sample data file, uploading the Excel data, inserting records into tables, and displaying errors. Data types and internal tables are defined to store the uploaded data and new/old fact records.

Uploaded by

Sachin Sawant
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

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

*& Report ZBIR_INST_EMP_FACT_UPDATE


*&
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Author
: ANIL REDDY BOKKA
* Creation Date
: 25-AUG-2014
* Transaction
: ZBIR_FACT_UPDATE
* Technical design: <Technical design document name>
* Description
: <Short description of the functionality of the
*
program>
*----------------------------------------------------------------------*
* Modification Information
*----------------------------------------------------------------------*
* Date
: <DD-MMM-YYYY>
* Author
: <Name of the programmer/Programmer user ID>
* Change request : <Change request number>
* Transport number: <Transport number>
* Description
: <Short description of changes>
*----------------------------------------------------------------------*

REPORT zbir_inst_emp_fact_update NO STANDARD PAGE HEADING.


*&---------------------------------------------------------------------*
* Types Declaration
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_udata,
anlage TYPE anlage,
operand TYPE e_operand,
ab
TYPE char10,
bis
TYPE char10,
value
TYPE char20,
END OF ty_udata.
TYPES: BEGIN OF ty_te221,
operand TYPE e_operand,
optyp
TYPE e_optyp,
END OF ty_te221.
TYPES: BEGIN OF ty_elog,
anlage TYPE anlage,
operand TYPE e_operand,
value
TYPE char20,
remark TYPE string,
END OF ty_elog.

DATA: it_udata TYPE TABLE OF ty_udata,


*
it_udata TYPE TABLE OF ty_udata,
it_elog TYPE TABLE OF ty_elog,
it_ettifn_new TYPE TABLE OF ettifn,
it_ettifn_old TYPE TABLE OF ettifn.
DATA: it_te221 TYPE TABLE OF ty_te221,
wa_te221 TYPE ty_te221.

DATA: wa_udata TYPE ty_udata,


wa_elog TYPE ty_elog,
wa_ettifn_new TYPE ettifn,
wa_ettifn_old TYPE ettifn.

DATA: lv_ab TYPE dats,


lv_bis TYPE dats.
*&---------------------------------------------------------------------*
* Selection Screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
PARAMETERS: p_r1 RADIOBUTTON GROUP auto USER-COMMAND flag ,
p_r2 RADIOBUTTON GROUP auto DEFAULT 'X'.
SELECTION-SCREEN SKIP.
PARAMETERS p_file LIKE rlgrap-filename MEMORY ID tpc1 MODIF ID mod.
*SELECT-OPTIONS s_date FOR sy-datum NO-DISPLAY. "MEMORY ID tpc1 MODIF ID m
od OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.

*&---------------------------------------------------------------------*
* At Selection Screen
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN .
IF p_r1 = 'X' AND
screen-active =
ENDIF.
IF p_r2 = 'X' AND
screen-active =
ENDIF.
MODIFY SCREEN.
ENDLOOP.

screen-group1 = 'MOD'.
'1'.
screen-group1 = 'MOD'.
'0'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.


* Perform to upload the file.
PERFORM file_f4 USING p_file.
INCLUDE zbir_inst_emp_fact_update_ff01.

*&---------------------------------------------------------------------*
* Start Of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
IF p_r2 IS NOT INITIAL.
* Perform To Download Sample Data to Upload facts.
PERFORM download_sample_data.
ENDIF.
IF p_r1 IS NOT INITIAL.

PERFORM upload_data.
PERFORM insert_ettifn_table.
IF it_elog IS NOT INITIAL.
PERFORM display_error_log.
ENDIF.
ENDIF.

*----------------------------------------------------------------------*
***INCLUDE ZBIR_INST_EMP_FACT_UPDATE_FF01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&
Form FILE_F4
*&---------------------------------------------------------------------*
*
Providing F4 Help to Upload The File
*----------------------------------------------------------------------*
FORM file_f4 USING
p_p_file.
DATA: lv_subrc LIKE sy-subrc,
lt_it_tab TYPE filetable.
CONSTANTS: lc_window_title
TYPE string VALUE 'Select Source Excel Fil
e',
lc_default_filename TYPE string VALUE '*.xls'.
* Display File Open Dialog control/screen
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title
= lc_window_title
default_filename = lc_default_filename
multiselection
= ' '
CHANGING
file_table
= lt_it_tab
rc
= lv_subrc.
* Write path on input parameter
LOOP AT lt_it_tab INTO p_p_file.
ENDLOOP.
ENDFORM.
" FILE_F4
*&---------------------------------------------------------------------*
*&
Form DOWNLOAD_SAMPLE_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM download_sample_data .
TYPES: BEGIN OF t_raw,
anlage TYPE anlage ,
operand TYPE e_operand,

ab
bis
value
text
END
OF

TYPE char10,
TYPE char10,
TYPE char12,
TYPE char50,
t_raw.

DATA: it_excel TYPE TABLE OF t_raw,


wa_excel TYPE t_raw.
DATA: lt_fieldname TYPE STANDARD TABLE OF cats_fieldname,
wa_fieldname TYPE cats_fieldname.
DATA: file_n TYPE string,
file_p TYPE string,
full_p TYPE string.
CONSTANTS: lc_window_title
lc_default_extension
lc_default_file_name
ate_format',
lc_initial_directory
lc_x
lc_filetype
lc_header

TYPE string
TYPE string
TYPE string

VALUE 'Select File path',


VALUE 'xls',
VALUE 'Installation_fact_upd

TYPE
TYPE
TYPE
TYPE

VALUE
VALUE
VALUE
VALUE

string
c
char10
xstring

'C:\',
'X',
'DAT',
'00'.

wa_fieldname-fieldname = text-t01.
APPEND wa_fieldname TO lt_fieldname.
CLEAR wa_fieldname.
wa_fieldname-fieldname = text-t02.
APPEND wa_fieldname TO lt_fieldname.
CLEAR wa_fieldname.
wa_fieldname-fieldname = text-t04.
APPEND wa_fieldname TO lt_fieldname.
CLEAR wa_fieldname.
wa_fieldname-fieldname = text-t05.
APPEND wa_fieldname TO lt_fieldname.
CLEAR wa_fieldname.
wa_fieldname-fieldname = text-t03.
APPEND wa_fieldname TO lt_fieldname.
CLEAR wa_fieldname.
wa_excel-anlage =
wa_excel-operand =
wa_excel-ab
=
wa_excel-bis
=
wa_excel-value
=
wa_excel-text
=
APPEND wa_excel TO
CLEAR wa_excel.

'3000001846'. " Sample Value


'F_EMPLOYEE'.
'01.01.2014'.
'31.01.2014'.
'X'.
'Value should be updated as X or Blank'.
it_excel.

wa_excel-anlage = '3000001846'.
wa_excel-operand = 'QUARTER_NO'.
wa_excel-value
= 'Z/WING-321'.

" Sample Value

wa_excel-ab
=
wa_excel-bis
=
wa_excel-text
=
APPEND wa_excel TO
CLEAR wa_excel.

'01.01.2014'.
'31.01.2014'.
'Value should be updated with Char10'.
it_excel.

wa_excel-anlage =
wa_excel-operand =
wa_excel-value
=
wa_excel-ab
=
wa_excel-bis
=
wa_excel-text
=
APPEND wa_excel TO
CLEAR wa_excel.

'3000001846'. " Sample Value


'EMPLOYE_NO'.
'202121'.
'01.01.2014'.
'31.01.2014'.
'Value should be updated with Char10'.
it_excel.

wa_excel-anlage =
wa_excel-operand =
wa_excel-value
=
wa_excel-ab
=
wa_excel-bis
=
wa_excel-text
=
APPEND wa_excel TO
CLEAR wa_excel.

'3000001846'. " Sample Value


'KWH_T'.
'500'.
'01.01.2014'.
'31.01.2014'.
'This value should be updated with DEC16'.
it_excel.

wa_excel-anlage =
wa_excel-operand =
wa_excel-value
=
wa_excel-ab
=
wa_excel-bis
=
wa_excel-text
=
APPEND wa_excel TO
CLEAR wa_excel.

'3000001846'. " Sample Value


'WP_LT'.
'WP_LT2CCOM'.
'01.01.2014'.
'31.01.2014'.
'This value should be updated in Fact Group'.
it_excel.

CALL METHOD cl_gui_frontend_services=>file_save_dialog


EXPORTING
window_title
= lc_window_title
default_extension
= lc_default_extension
default_file_name
= lc_default_file_name
initial_directory
= lc_initial_directory
prompt_on_overwrite = lc_x
CHANGING
filename
= file_n
path
= file_p
fullpath
= full_p
EXCEPTIONS
cntl_error
= 1
error_no_gui
= 2
not_supported_by_gui = 3
OTHERS
= 4.
IF full_p IS NOT INITIAL.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename
= full_p
filetype
= lc_filetype
write_field_separator = lc_x
header
= lc_header

TABLES
data_tab
= it_excel
fieldnames
= lt_fieldname.
ENDIF.
ENDFORM.
" DOWNLOAD_SAMPLE_DATA
*&---------------------------------------------------------------------*
*&
Form UPLOAD_DATA
*&---------------------------------------------------------------------*
*
Upload Data From Flat File (XL Sheet)
*----------------------------------------------------------------------*
FORM upload_data .
IF p_file IS NOT INITIAL.
* Uploading Data from XLS file to Internal Table
CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
EXPORTING
i_filename = p_file
TABLES
e_itab
= it_udata
EXCEPTIONS
file_error = 1
OTHERS
= 2.
IF sy-subrc <> 0.
*
MESSAGE ''006.'
ENDIF.

DELETE it_udata INDEX 1.


ENDIF.
ENDFORM.
" UPLOAD_DATA
*&---------------------------------------------------------------------*
*&
Form PREPARE_NEW_DATA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM prepare_new_data .
wa_ettifn_new-anlage

wa_ettifn_new-ab
wa_ettifn_new-bis
*
*
*
*
*
*
*
*
*
*
*
*

= wa_udata-anlage.

= lv_ab.
= lv_bis.

IF wa_udata-operand = 'F_EMPLOYEE'.
wa_ettifn_new-string3 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_udata-operand = 'QUARTER_NO'.
wa_ettifn_new-string1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_udata-operand = 'EMPLOYE_NO'.
wa_ettifn_new-string1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.

*
*
*
*
*

ELSEIF wa_udata-operand = 'KWH_T'.


wa_ettifn_new-wert1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSE.
READ TABLE it_te221 INTO wa_te221
WITH KEY operand = wa_udata-operand BINARY SEARCH.
IF sy-subrc = 0.
IF wa_te221-optyp = 'FACTOR'.
wa_ettifn_new-wert1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'AMOUNT'.
wa_ettifn_new-betrag = wa_udata-value.
wa_ettifn_new-waers = 'INR'.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'INTEGER'.
wa_ettifn_new-wert1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'FLAG'.
wa_ettifn_new-string3 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'USERDEF'.
wa_ettifn_new-string1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'QUANT'.
wa_ettifn_new-wert1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'DEMAND'.
wa_ettifn_new-wert1 = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
ELSEIF wa_te221-optyp = 'RATETYPE'.
wa_ettifn_new-kondigr = wa_udata-value.
wa_ettifn_new-operand = wa_udata-operand.
IF wa_udata-operand = 'WP_LT'.
wa_ettifn_new-tarifart = 'WP_LT'.
ELSEIF wa_udata-operand = 'WP_TRIGGER'.
wa_ettifn_new-tarifart = 'WP_ENERG'.
ENDIF.

ENDIF.
ENDIF.
ENDIF.
IF wa_ettifn_new-operand IS INITIAL.
wa_elog-anlage

= wa_udata-anlage.

wa_elog-operand = wa_udata-operand.
wa_elog-value
= wa_udata-value.
wa_elog-remark = 'Operand Not Exist'.
APPEND wa_elog TO it_elog.
CLEAR wa_elog.
ELSE.
APPEND wa_ettifn_new TO it_ettifn_new.
CLEAR wa_ettifn_new.
ENDIF.
ENDFORM.
" PREPARE_NEW_DATA
*&---------------------------------------------------------------------*
*&
Form DISPLAY_ERROR_LOG
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM display_error_log .
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
wa_fieldcat-col_pos
= 1.
wa_fieldcat-fieldname = 'ANLAGE'.
wa_fieldcat-tabname
= 'LT_ELOG'.
wa_fieldcat-seltext_l = 'Installation'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos
= 2.
wa_fieldcat-fieldname = 'OPERAND'.
wa_fieldcat-tabname
= 'LT_ELOG'.
wa_fieldcat-seltext_l = 'Operand'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos
= 3.
wa_fieldcat-fieldname = 'VALUE'.
wa_fieldcat-tabname
= 'LT_ELOG'.
wa_fieldcat-seltext_l = 'Value'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos
= 4.
wa_fieldcat-fieldname = 'REMARK'.
wa_fieldcat-tabname
= 'LT_ELOG'.
wa_fieldcat-seltext_l = 'Remark'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING
i_callback_program = sy-repid
i_grid_title
= 'Error Log'
it_fieldcat
= it_fieldcat
TABLES
t_outtab
= it_elog.
ENDFORM.
" DISPLAY_ERROR_LOG
*&---------------------------------------------------------------------*
*&
Form INSERT_ETTIFN_TABLE
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM insert_ettifn_table .

DATA: lv_scount TYPE char10,


lv_sstring TYPE string.

IF it_udata IS NOT INITIAL.


SELECT
FROM
INTO
FOR
WHERE
AND

*
ettifn
TABLE it_ettifn_old
ALL ENTRIES IN it_udata
anlage = it_udata-anlage
operand = it_udata-operand.

IF sy-subrc = 0.
SORT it_ettifn_old BY anlage operand bis DESCENDING .
DELETE ADJACENT DUPLICATES FROM it_ettifn_old COMPARING anlage operan
d.
ENDIF.
SELECT operand
optyp
FROM te221
INTO TABLE it_te221
FOR ALL ENTRIES IN it_udata
WHERE operand = it_udata-operand.
IF sy-subrc = 0.
SORT it_te221 BY operand.
DELETE ADJACENT DUPLICATES FROM it_te221 COMPARING operand.
SORT it_te221 BY operand.
ENDIF.

LOOP AT it_udata INTO wa_udata.

CONCATENATE wa_udata-ab+6(4) wa_udata-ab+3(2) wa_udata-ab+0(2) INT


O lv_ab.
CONCATENATE wa_udata-bis+6(4) wa_udata-bis+3(2) wa_udata-bis+0(2) INT
O lv_bis.
IF lv_ab LE lv_bis.
READ TABLE it_ettifn_old INTO wa_ettifn_old
WITH KEY anlage = wa_udata-anlage
operand = wa_udata-operand.
IF sy-subrc NE 0.
PERFORM prepare_new_data.

ELSEIF sy-subrc = 0 AND wa_ettifn_old-bis < lv_ab.


PERFORM prepare_new_data.
ELSEIF sy-subrc = 0 AND wa_ettifn_old-bis > lv_ab.
wa_elog-anlage =
wa_elog-operand =
wa_elog-value
=
wa_elog-remark =
APPEND wa_elog TO
CLEAR wa_elog.
ENDIF.
ELSE.
wa_elog-anlage =
wa_elog-operand =
wa_elog-value
=
wa_elog-remark =
APPEND wa_elog TO
CLEAR wa_elog.
ENDIF.

wa_udata-anlage.
wa_udata-operand.
wa_udata-value.
'Data Already Exist For Same Period'.
it_elog.

wa_udata-anlage.
wa_udata-operand.
wa_udata-value.
'End Date Is Less Than Start Date'.
it_elog.

ENDLOOP.
IF it_ettifn_new IS NOT INITIAL.
CALL FUNCTION 'ISU_DB_ETTIFN_UPDATE'
EXPORTING
x_upd_mode = 'I'
x_iettifn = it_ettifn_new.
IF sy-subrc = 0.
COMMIT WORK.
DESCRIBE TABLE it_ettifn_new LINES lv_scount.
CONCATENATE lv_scount text-m10
INTO lv_sstring SEPARATED BY space.
MESSAGE lv_sstring TYPE 'I'.
ENDIF.
ENDIF.
ELSE.

MESSAGE 'No Data Uploaded' TYPE 'I'.


ENDIF.
ENDFORM.
" INSERT_ETTIFN_TABLE

You might also like