You are on page 1of 17

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

*& Report ZBPS_HOJA_3


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zbps_hoja_3.
* Type Pools
TYPE-POOLS ole2 .
*----------------------------------------------------------------------*
*
CLASS lcl_data DEFINITION
*----------------------------------------------------------------------*
* Local Class Definition
*----------------------------------------------------------------------*
CLASS lcl_data DEFINITION FINAL.
PUBLIC SECTION.
*--------------------------------------------------------------------*
* Types
TYPES: BEGIN OF t_ska1,
ktopl TYPE ska1-ktopl,
saknr TYPE ska1-saknr,
xbilk TYPE ska1-xbilk,
END OF t_ska1.
TYPES : BEGIN OF t_skat,
spras TYPE skat-spras,
ktopl TYPE skat-ktopl,
saknr TYPE skat-saknr,
txt20 TYPE skat-txt20,
END OF t_skat.
TYPES: BEGIN OF t_output,
field1 TYPE char40,
field2 TYPE umxxo,
field3 TYPE umxxo,
field4 TYPE umxxo,
field5 TYPE umxxo,
field6 TYPE umxxo,
field7 TYPE umxxo,
field8 TYPE umxxo,
field9 TYPE umxxo,
END OF t_output.
TYPES:
BEGIN OF t_header,
field1 TYPE string,
field2 TYPE string,
field3 TYPE string,
field4 TYPE string,
field5 TYPE string,
field6 TYPE string,
field7 TYPE string,
field8 TYPE string,
field9 TYPE string,
END OF t_header.
*--------------------------------------------------------------------*
* Internal tables
DATA:

i_ska1
TYPE TABLE OF t_ska1,
i_skat
TYPE TABLE OF t_skat,
i_output TYPE TABLE OF t_output,
i_header TYPE TABLE OF t_header,
i_header_1 TYPE TABLE OF t_header.
*--------------------------------------------------------------------*
* Work areas
DATA:
i_ska1_line
TYPE t_ska1,
i_skat_line
TYPE t_skat,
i_output_line TYPE t_output,
i_header_line TYPE t_header,
i_header_line3 TYPE t_header,
i_header_line4 TYPE t_header.
*--------------------------------------------------------------------*
* Data
DATA: g_ktopl
TYPE ska1-ktopl,
g_saknr
TYPE ska1-saknr,
g_bukrs
TYPE skb1-bukrs,
g_gjahr
TYPE skc1a-gjahr,
g_fullpath TYPE string,
g_name
TYPE t7ru9a-regno.
DATA:
i_glt0
TYPE fagl_t_glt0,
i_glt0_line TYPE glt0.
*--------------------------------------------------------------------*
* Methods
METHODS:
validate_ktopl,
" Validate Chart of Accounts
validate_sankr,
" Validate G/L Account Number
validate_bukrs,
" Validate Company Code
validate_gjahr,
" Validate Fiscal Year
validate_month,
" Validate Month
get_data,
" Get Data
get_text,
" Get short text
get_accounts,
" Get Account Details
output_table,
" Output table
download_data,
" Download data
excl_format,
" Format the Excl Sheet
header_data.
" Header data
ENDCLASS.
* Local class Referance Object
DATA : obj_data TYPE REF TO lcl_data.

" Lcl_data DEFINITION

**********************************************************************
* Initialization
*
**********************************************************************
INITIALIZATION.
CREATE OBJECT obj_data.
**********************************************************************
* Selection-screen
*
**********************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-001.
* Select options
SELECT-OPTIONS: s_ktopl
FOR obj_data->g_ktopl,
s_saknr
FOR obj_data->g_saknr MATCHCODE OBJECT sako,
s_bukrs
FOR obj_data->g_bukrs OBLIGATORY,
s_gjahr
FOR obj_data->g_gjahr OBLIGATORY NO INTERVALS.
PARAMETERS: p_monat TYPE bkpf-monat OBLIGATORY .

SELECTION-SCREEN END OF BLOCK b01.


**********************************************************************
* Selection-screen Events
*
**********************************************************************
AT SELECTION-SCREEN ON s_ktopl.
* Validate Chart of Accounts
CALL METHOD obj_data->validate_ktopl.
AT SELECTION-SCREEN ON s_saknr.
* Validate G/L Account Number
CALL METHOD obj_data->validate_sankr.
AT SELECTION-SCREEN ON s_bukrs.
* Validate Company Code
CALL METHOD obj_data->validate_bukrs.
AT SELECTION-SCREEN ON s_gjahr.
* Validate year
CALL METHOD obj_data->validate_gjahr.
AT SELECTION-SCREEN ON p_monat.
* Validate month
CALL METHOD obj_data->validate_month.
**********************************************************************
* Start of Selection
*
**********************************************************************
START-OF-SELECTION.
* Data retrieval
CALL METHOD obj_data->get_data.
**********************************************************************
* End of Selection
*
**********************************************************************
END-OF-SELECTION.
* Initial check
IF obj_data->i_glt0 IS INITIAL.
MESSAGE 'No data found for the Selection'(007) TYPE 'S'
DISPLAY LIKE 'E'.
RETURN.
ENDIF.
" IF obj_data->i_glt0 IS INITIA
L.
* For Populating Output table
CALL METHOD obj_data->output_table.
* For Download the Excl Format
CALL METHOD obj_data->download_data.
*----------------------------------------------------------------------*
*
CLASS lcl_data IMPLEMENTATION
*----------------------------------------------------------------------*
* Local class Implementation
*----------------------------------------------------------------------*
CLASS lcl_data IMPLEMENTATION.
**********************************************************************
* Validate Chart of Accounts
**********************************************************************
METHOD validate_ktopl.
IF s_ktopl IS NOT INITIAL.

* Validate the Chart of Accounts in G/L Account Master (Chart of Accounts)


SELECT ktopl
INTO g_ktopl
FROM t004
UP TO 1 ROWS
WHERE ktopl IN s_ktopl.
ENDSELECT.
" FROM t004
IF sy-subrc NE 0.
MESSAGE e000(oo) WITH 'Please enter a valid Chart of Accounts'(002).
ENDIF.
" IF sy-subrc NE 0.
ENDIF.
" IF s_ktopl IS NOT INITIAL.
ENDMETHOD.
" Validate_ktopl
**********************************************************************
* Validate G/L Account Number
**********************************************************************
METHOD validate_sankr.
IF s_saknr IS NOT INITIAL.
* Validate the G/L Account Number in G/L Account Master (Chart of Accounts)
SELECT saknr
INTO g_saknr
FROM ska1
UP TO 1 ROWS
WHERE ktopl IN s_ktopl
AND saknr IN s_saknr.
ENDSELECT.
" FROM ska1
IF sy-subrc NE 0.
MESSAGE e000(oo) WITH 'Please enter a valid G/L Account Number'(003).
ENDIF.
" IF sy-subrc NE 0.
ENDIF.
" IF s_saknr IS NOT INITIAL.
ENDMETHOD.
" Validate_sankr
**********************************************************************
* Validate Company Code
**********************************************************************
METHOD validate_bukrs.
* Validate the Company Code in Company Codes
SELECT bukrs
INTO g_bukrs
FROM t001
UP TO 1 ROWS
WHERE bukrs IN s_bukrs.
ENDSELECT.
" FROM t001
IF sy-subrc NE 0.
MESSAGE e000(oo) WITH 'Please enter a valid Company Code'(004).
ENDIF.
" IF sy-subrc NE 0
ENDMETHOD.
" Validate_ktopl
**********************************************************************
* Validate year
**********************************************************************
METHOD validate_gjahr.
IF s_gjahr CS '0123456789'.
MESSAGE e000(oo) WITH 'Please enter a valid year'(005).
ENDIF.
" IF s_gjahr CS '0123456789'
ENDMETHOD.
" Validate_gjahr
**********************************************************************
* Validate month

**********************************************************************
METHOD validate_month.
CONSTANTS lc_12(2) TYPE n VALUE '12'.
IF p_monat GE 1 AND p_monat LE lc_12.
* Month name in genitive case
CALL FUNCTION 'HR_RU_MONTH_NAME_IN_GENITIVE'
EXPORTING
month = p_monat
IMPORTING
name = g_name.
ELSE.
MESSAGE e000(oo) WITH 'Please enter a valid month'(006).
ENDIF.
" IF p_monat GE 1 AND p_monat L
E 12.
ENDMETHOD.
" Validate_month
**********************************************************************
* Get data
**********************************************************************
METHOD get_data.
* Get data from G/L Account Master (Chart of Accounts)
SELECT ktopl
saknr
xbilk
FROM ska1
INTO TABLE i_ska1
WHERE ktopl IN s_ktopl
AND saknr IN s_saknr.
* Get Short Text
CALL METHOD get_text.
* Get Account details
CALL METHOD get_accounts.
ENDMETHOD.
" Get_data
**********************************************************************
* Get Description
**********************************************************************
METHOD get_text.
* get data from G/L Account Master Record (Chart of Accounts: Description)
SELECT spras
ktopl
saknr
txt20
FROM skat
INTO TABLE i_skat
WHERE spras = sy-langu
AND ktopl IN s_ktopl
AND saknr IN s_saknr.
ENDMETHOD.
" Get_text
**********************************************************************
* Get acoounts
**********************************************************************
METHOD get_accounts.
* Ranges
DATA : r_bukrs TYPE fagl_range_t_bukrs,
r_sankr TYPE fagl_range_t_racct,
r_gjahr TYPE fagl_range_t_ryear,
r_ktopl TYPE fagl_range_t_rrcty.

DATA:
r_ktopl_line TYPE fagl_range_rrcty,
r_sankr_lne TYPE fagl_range_racct.
* Range tables
APPEND s_bukrs TO r_bukrs.
APPEND s_gjahr TO r_gjahr.

IF s_ktopl IS INITIAL.
r_ktopl_line-sign = 'I'.
r_ktopl_line-option = 'NB'.
APPEND r_ktopl_line TO r_ktopl.
ELSE.
APPEND s_ktopl TO r_ktopl.
ENDIF.

" IF s_ktopl IS INITIAL.

IF s_saknr IS INITIAL.
r_sankr_lne-sign = 'I'.
r_sankr_lne-option = 'NB'.
APPEND r_sankr_lne TO r_sankr.
ELSE.
APPEND s_saknr TO r_sankr.
ENDIF.

" IF s_ktopl IS INITIAL.

Access to New GL Totals Table


CALL FUNCTION 'FAGL_GET_GLT0'
EXPORTING
i_range_rrcty
= r_ktopl
i_range_bukrs
= r_bukrs
i_range_ryear
= r_gjahr
i_range_racct
= r_sankr
IMPORTING
et_glt0
= i_glt0
EXCEPTIONS
invalid_selection = 1
OTHERS
= 2.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF.
" IF sy-subrc NE 0
ENDMETHOD.
" Get_acoounts
**********************************************************************
* Output
**********************************************************************
METHOD output_table.
* Local Types
TYPES: BEGIN OF lt_glt0,
bukrs TYPE glt0-bukrs,
ryear TYPE glt0-ryear,
racct TYPE glt0-racct,
rbusa TYPE glt0-rbusa,
rtcur TYPE glt0-rtcur,
field2 TYPE glt0-hsl01,
field3 TYPE glt0-hsl01,
END OF lt_glt0.
* Data
DATA:
li_glt0
TYPE TABLE OF lt_glt0,
li_sum
TYPE t_output,
li_glt0_line TYPE lt_glt0.

DATA:
l_diff TYPE glt0-hsl01,
l_diff1 TYPE glt0-hsl01,
l_umxx TYPE glt0-hsl01.
LOOP AT i_glt0 INTO i_glt0_line.
li_glt0_line-bukrs = i_glt0_line-bukrs.
li_glt0_line-ryear = i_glt0_line-ryear.
li_glt0_line-racct = i_glt0_line-racct.
li_glt0_line-rbusa = i_glt0_line-rbusa.
li_glt0_line-rtcur = i_glt0_line-rtcur.
* Find the Currency Value for the month
DO p_monat TIMES
VARYING l_umxx FROM i_glt0_line-hsl01 NEXT i_glt0_line-hsl02.
IF sy-subrc NE 0.
RETURN.
ENDIF.
" IF sy-subrc NE 0
ENDDO.
" DO p_monat TIMES
* Check the Credit or Debit
IF i_glt0_line-drcrk EQ 'S'.
li_glt0_line-field2 = l_umxx.
ELSEIF i_glt0_line-drcrk EQ 'H'.
li_glt0_line-field3 = l_umxx.
ENDIF.
" IF i_glt0_line-drcrk EQ 'S'
* Collect the internal table
COLLECT li_glt0_line INTO li_glt0.
ENDLOOP.
" LOOP AT i_glt0 INTO i_glt0_li
ne.
*--------------------------------------------------------------------*
* Output table populate
SORT i_skat
BY spras
saknr.
SORT i_ska1
BY saknr.
LOOP AT li_glt0 INTO li_glt0_line.
* Read the G/L Account Master Record table
CLEAR i_output_line.
READ TABLE i_skat
INTO i_skat_line
WITH KEY spras = sy-langu
saknr = li_glt0_line-racct
BINARY SEARCH.
IF sy-subrc EQ 0.
CONCATENATE i_skat_line-saknr i_skat_line-txt20
INTO i_output_line-field1
SEPARATED BY space.
ENDIF.
* For Credit or Debit
i_output_line-field2 = li_glt0_line-field2.
li_sum-field2 = li_sum-field2 + i_output_line-field2.
i_output_line-field3 = - li_glt0_line-field3.
li_sum-field3 = li_sum-field3 + i_output_line-field3.
l_diff = li_glt0_line-field2 + li_glt0_line-field3.
l_diff1 = sign( l_diff ).
* For Differance
IF l_diff1 EQ '1'.
i_output_line-field4 = l_diff.

li_sum-field4 = li_sum-field4 + i_output_line-field4.


ELSE.
i_output_line-field5 = - l_diff.
li_sum-field5 = li_sum-field5 + i_output_line-field5.
ENDIF.
" IF l_diff1 EQ '1'.
* Read the G/L Account Master
READ TABLE i_ska1
INTO i_ska1_line
WITH KEY saknr = li_glt0_line-racct
BINARY SEARCH.
IF i_ska1_line-xbilk EQ 'X'.
* Inventario
IF l_diff1 EQ '1'.
i_output_line-field6 = l_diff.
li_sum-field6 = li_sum-field6 + i_output_line-field6.
ELSE.
i_output_line-field7 = - l_diff.
li_sum-field7 = li_sum-field7 + i_output_line-field7.
ENDIF.
" IF l_diff1 EQ '1'.
ELSE.
* Profit/loss
IF l_diff1 EQ '1'.
i_output_line-field8 = l_diff.
li_sum-field8 = li_sum-field8 + i_output_line-field8.
ELSE.
i_output_line-field9 = - l_diff.
li_sum-field9 = li_sum-field9 + i_output_line-field9.
ENDIF.
" IF l_diff1 EQ '1'.
ENDIF.
" IF i_ska1_line-xbilk EQ 'X'.
APPEND i_output_line TO i_output.
ENDLOOP.
" IF i_glt0_line-drcrk EQ 'S'
* sub totals
li_sum-field1 = 'Sub-Totales'(010).
APPEND li_sum TO i_output.
ENDMETHOD.
" Output_table
**********************************************************************
* Download data
**********************************************************************
METHOD download_data.
* Local data for Save dialog
DATA: l_filename TYPE string,
l_path
TYPE string,
l_result TYPE i.
CONSTANTS lc_name TYPE string VALUE 'Accounts'.
* Shows a File Save Dialog
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension
= 'XLS'
default_file_name
= lc_name
initial_directory
= 'c:\'
CHANGING
filename
= l_filename
path
= l_path
fullpath
= g_fullpath
user_action
= l_result
EXCEPTIONS
cntl_error
= 1
error_no_gui
= 2
not_supported_by_gui = 3
OTHERS
= 4.

IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF.
* Check user did not cancel request
IF l_result EQ '0'.
CALL METHOD obj_data->excl_format.
ENDIF.
* Excl Sheet formation

" IF sy-subrc NE 0

" IF l_result EQ '0

ENDMETHOD.
" Download_data
**********************************************************************
* Excl formation
**********************************************************************
METHOD excl_format.
* local data for EXCL Format
DATA: l_application TYPE
l_workbook
TYPE
l_sheet
TYPE
l_cells
TYPE
l_cell1
TYPE
l_cell2
TYPE
l_range
TYPE
l_font
TYPE
l_column
TYPE
l_border
TYPE
DATA: l_colindx TYPE i,
l_rowindx TYPE i,
l_index TYPE i,
l_index_r TYPE i,
l_tabix TYPE i.

ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object,
ole2_object.

* Field symbol to hold values


FIELD-SYMBOLS: <fs> TYPE any.
* Constants
CONSTANTS:
lc_4108 TYPE i VALUE '-4108',
lc_12(2) TYPE c VALUE '12'.
* Header data
CALL METHOD header_data.
*--------------------------------------------------------------------*
* Excl Sheet
CREATE OBJECT l_application 'excel.application'(009).
SET PROPERTY OF l_application 'visible'(008) = 0.
CALL METHOD OF
l_application
'Workbooks' = l_workbook.
*

Create new worksheet


SET PROPERTY OF l_application 'SheetsInNewWorkbook' = 1.
CALL METHOD OF
l_workbook
'Add'.

* Create first Excel Sheet

CALL METHOD OF
l_application
'Worksheets' = l_sheet
EXPORTING
#1
= 1.
CALL METHOD OF
l_sheet
'Activate'.
SET PROPERTY OF l_sheet 'Name'(012) = 'Sheet1'(013).
*--------------------------------------------------------------------*
* First header data
l_rowindx = 1.
"start at row 1 for headings
LOOP AT i_header INTO i_header_line.
*Use sy-tabix for row index
l_rowindx = sy-tabix.
* Fill columns for current row
CLEAR l_colindx.
DO.
*
Assign <fs> to table columns
ASSIGN COMPONENT sy-index OF STRUCTURE i_header_line TO <fs>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
CALL METHOD OF
l_sheet
'Cells' = l_cells
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
SET PROPERTY OF l_cells 'Value'(014) = <fs> .
IF sy-index EQ 9.
SET PROPERTY OF l_cells 'Style' = 'Date'.
SET PROPERTY OF l_cells 'NumberFormat' = 'yyyy/dd/mm;@'.
ENDIF.
ENDDO.
" DO.
ENDLOOP.
" LOOP AT i_header INTO i_heade
r_line.
*--------------------------------------------------------------------*
* For Title lines
*
**
**
*

CALL METHOD OF
l_application
'Worksheets' = l_sheet
EXPORTING
#1
= 2.
CLEAR: l_colindx,i_header_line.
CLEAR i_header_line.
LOOP AT i_header_1 INTO i_header_line.
l_rowindx = l_rowindx + 1.
CLEAR l_colindx.
*

DO.
Assign <fs> to table columns

ASSIGN COMPONENT sy-index OF STRUCTURE i_header_line TO <fs>.


IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
CALL METHOD OF
l_application
'Cells'
EXPORTING
#1
#2
CALL METHOD OF
l_application
'Cells'
EXPORTING
#1
#2
CALL METHOD OF
l_application
'Range'
EXPORTING
#1
#2

= l_cell1
= l_rowindx
= l_colindx.
= l_cell2
= l_rowindx
= 9.
= l_cells
= l_cell1
= l_cell2.

CALL METHOD OF
l_cells
'Select'.
*--Merging
CALL METHOD OF
l_cells
'Merge'.
*--Setting title data
CALL METHOD OF
l_application
'Cells'
= l_cell1
EXPORTING
#1
= l_rowindx
#2
= 1.
SET PROPERTY OF l_cell1 'Value'(014) = <fs> .
SET PROPERTY OF l_cell1 'HorizontalAlignment' = lc_4108 .
ENDDO.
" DO.
ENDLOOP.
" LOOP AT i_header_1 INTO i_hea
der_line.
*--------------------------------------------------------------------*
* For empty row
* Fill columns for current row
CLEAR l_colindx.
l_rowindx = l_rowindx + 1.
CLEAR i_header_line.
DO.
*
Assign <fs> to table columns
ASSIGN COMPONENT sy-index OF STRUCTURE i_header_line TO <fs>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
CALL METHOD OF

l_sheet
'Cells' = l_cells
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
SET PROPERTY OF l_cells 'Value'(014) = <fs> .
ENDDO.
" DO.
l_index_r = l_rowindx + 1.
*--------------------------------------------------------------------*
* For Header line 3
CALL METHOD OF
l_application
'Worksheets' = l_sheet
EXPORTING
#1
= 3.
l_rowindx = l_rowindx + 1.
* Fill columns for current row
CLEAR l_colindx.
DO.
*
Assign <fs> to table columns
ASSIGN COMPONENT sy-index OF STRUCTURE i_header_line3 TO <fs>.

IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
IF sy-index EQ 1.
l_colindx = sy-index.
CALL METHOD OF
l_sheet
'Cells' = l_cells
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
SET PROPERTY OF l_cells 'Value'(014) = <fs>.
ELSE.
l_colindx = l_colindx + 1.
l_index = l_colindx.
CALL METHOD OF
l_application
'Cells'
= l_cell1
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
l_colindx = l_colindx + 1.
CALL METHOD OF
l_application
'Cells'
= l_cell2
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
CALL METHOD OF
l_application
'Range'
= l_cells

EXPORTING
#1
#2

= l_cell1
= l_cell2.

CALL METHOD OF
l_cells
'Select'.
*--Merging
CALL METHOD OF
l_cells
'Merge'.
*--Setting title data
CALL METHOD OF
l_application
'Cells'
= l_cell1
EXPORTING
#1
= l_rowindx
#2
= l_index.
SET PROPERTY OF l_cell1 'Value'(014) = <fs> .
SET PROPERTY OF l_cell1 'HorizontalAlignment' = lc_4108.
exit.
IF l_colindx GE 9.
EXIT.
ENDIF.
" IF l_colindx GE 9.
ENDIF.
" IF sy-index EQ 1.
ENDDO.
" DO.
*--------------------------------------------------------------------*
* for Header 4
CALL METHOD OF
l_application
'Worksheets' = l_sheet
EXPORTING
#1
= 3.
*

l_rowindx = l_rowindx + 1.

CLEAR l_colindx.
DO.
Assign <fs> to table columns
ASSIGN COMPONENT sy-index OF STRUCTURE i_header_line4 TO <fs>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
CALL METHOD OF
l_sheet
'Cells' = l_cells
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
SET PROPERTY OF l_cells 'Value'(014) = <fs> .
ENDDO.
" DO.

*--------------------------------------------------------------------*
* Output data
CALL METHOD OF

l_application
'Worksheets' = l_sheet
EXPORTING
#1
= 3.
DESCRIBE TABLE i_output LINES l_tabix.
* Output Table
LOOP AT i_output INTO i_output_line.
l_rowindx = l_rowindx + 1.
CLEAR l_colindx.
DO.
*
Assign <fs> to table columns
ASSIGN COMPONENT sy-index OF STRUCTURE i_output_line TO <fs> .
IF sy-subrc NE 0.
EXIT.
ENDIF.
" IF sy-subrc NE 0.
l_colindx = sy-index.
CALL METHOD OF
l_sheet
'Cells' = l_cells
EXPORTING
#1
= l_rowindx
#2
= l_colindx.
SET PROPERTY OF l_cells 'Value'(014) = <fs> .
*
*

SET PROPERTY OF l_cells 'Style' = 'currency'.


SET PROPERTY OF l_cells 'Ss' = 'None'.

SET PROPERTY OF l_cells 'NumberFormat' = '###,###,###,##0.00'.


IF sy-tabix EQ l_tabix.
CALL METHOD OF
l_application
'Range'
= l_range
EXPORTING
#1
= l_cells
#2
= l_cells.
GET PROPERTY OF l_range 'Font'(015) = l_font.
SET PROPERTY OF l_font 'Bold'(016) = 1.
ENDIF.
ENDDO.
" DO.
ENDLOOP.
" LOOP AT i_output INTO i_outpu
t_line.
**********************************************************************
FREE l_range.
l_index_r = l_index_r + 1.
CALL METHOD OF l_application 'Cells' = l_cell1 "start cell
EXPORTING
#1 = 1
"down
#2 = 1.
"across
CALL METHOD OF l_application 'Cells' = l_cell2 "end cell
EXPORTING
#1 = l_index_r
"down
#2 = 9. "across
CALL METHOD OF

l_application
'Range'
= l_range
EXPORTING
#1
= l_cell1
#2
= l_cell2.
*--------------------------------------------------------------------*
* Modify properties of cell range
* SET FONT DETAILS of range
GET PROPERTY OF l_range 'Font'(015) = l_font.
SET PROPERTY OF l_font 'Bold'(016) = 1.
SET PROPERTY OF l_font 'Size'(017) = lc_12.
*--------------------------------------------------------------------*
* Set Columns to auto fit to width of text
CALL METHOD OF
l_application
'Columns'
= l_column.
CALL METHOD OF
l_column
'Autofit'.
FREE OBJECT l_column.
*--------------------------------------------------------------------*
* border Properties
l_index_r = l_index_r - 1.
FREE l_range.
CALL METHOD OF l_application 'Cells' = l_cell1 "start cell
EXPORTING
#1 = l_index_r
#2 = 1.
CALL METHOD OF l_application 'Cells' = l_cell2 "end cell
EXPORTING
#1 = l_rowindx
#2 = 9.
CALL METHOD OF
l_application
'Range'
= l_range
EXPORTING
#1
= l_cell1
#2
= l_cell2.
CALL METHOD OF
l_range
'BORDERS' = l_border
EXPORTING
#1
= '1'. "left
SET PROPERTY OF l_border 'LineStyle' = '1'. "line style solid, dashed...
SET PROPERTY OF l_border 'WEIGHT' = 2.
"max = 4
FREE OBJECT l_border.
CALL METHOD OF
l_range
'BORDERS' =
EXPORTING
#1
=
SET PROPERTY OF
SET PROPERTY OF

l_border
'2'. "right
l_border 'LineStyle' = '1'.
l_border 'WEIGHT' = 2.

"max = 4

FREE OBJECT l_border.


CALL METHOD OF
l_range
'BORDERS' = l_border
EXPORTING
#1
= '3'. "top
SET PROPERTY OF l_border 'LineStyle' = '1'.
SET PROPERTY OF l_border 'WEIGHT' = 2.
FREE OBJECT l_border.
CALL METHOD OF
l_range
'BORDERS' = l_border
EXPORTING
#1
= '4'. "bottom
SET PROPERTY OF l_border 'LineStyle' = '1'.
SET PROPERTY OF l_border 'WEIGHT' = 2.
FREE OBJECT l_border.

"max = 4

"max = 4

*--------------------------------------------------------------------*
* Modify properties of cell range
* SET FONT DETAILS of range
GET PROPERTY OF l_range 'Font'(015) = l_font.
SET PROPERTY OF l_font 'Size'(017) = 10.
*--------------------------------------------------------------------*
* Set Columns to auto fit to width of text
*
*
*
*
*
**
**
**
**

CALL METHOD OF
l_application
'Columns'
= l_column.
set PROPERTY OF l_column 'ColumnWidth' = '30'.
CALL METHOD OF
l_column
'Autofit'.
FREE OBJECT l_column.

*--------------------------------------------------------------------*
* Save excel speadsheet to particular filename
CALL METHOD OF
l_sheet
'SaveAs'
EXPORTING
#1
= g_fullpath "'c:\temp\exceldoc2.xls'
"filename
#2
= 1.
IF sy-subrc EQ 0.
MESSAGE s000(oo) WITH'Successfully download the Excel Sheet'(011).
ENDIF.
* Free
FREE OBJECT l_sheet.
FREE OBJECT l_workbook.
FREE OBJECT l_application.
ENDMETHOD.
" Excl_format
**********************************************************************
* header data
**********************************************************************

METHOD header_data.
DATA l_index TYPE c.
* Header 1
DO 6 TIMES.
l_index = sy-index.
CONCATENATE 'HEADER' l_index INTO i_header_line-field1 SEPARATED BY space.
IF sy-index EQ 6.
i_header_line-field8 = 'Fecha :'(033).
i_header_line-field9 = sy-datum .
ENDIF.
APPEND i_header_line TO i_header.
ENDDO.
" DO 6 TIMES.
CLEAR i_header_line.
APPEND i_header_line TO i_header.
* Header 2
CLEAR i_header_line.
i_header_line-field9 = 'Balance Tributario'(032).
APPEND i_header_line TO i_header_1.
CLEAR i_header_line.
i_header_line-field9 = 'Acumulado mes/ao'(031).
APPEND i_header_line TO i_header_1.
CLEAR i_header_line.
CONCATENATE g_name s_gjahr-low INTO i_header_line-field9
SEPARATED BY `-`.
APPEND i_header_line TO i_header_1.
* Header 3
i_header_line3-field1
i_header_line3-field2
i_header_line3-field3
i_header_line3-field4
i_header_line3-field5

=
=
=
=
=

'Cuenta Contable'(030).
'Valores Acumulados'(029).
'Saldos'(028).
'Inventario'(027).
'Resultados'(026).

* Header 4
i_header_line4-field1
i_header_line4-field2
i_header_line4-field3
i_header_line4-field4
i_header_line4-field5
i_header_line4-field6
i_header_line4-field7
i_header_line4-field8
i_header_line4-field9

=
=
=
=
=
=
=
=
=

' '.
'Dbitos'(025).
'Crditos'(024).
'Deudor'(023).
'Acreedor'(022).
'Activo'(021).
'Pasivo'(020).
'Prdida'(019).
'Ganancia'(018).

ENDMETHOD.
ENDCLASS.

" Header_data
" Lcl_data IMPLEMENTATION

You might also like