Skip to Content

Introduction: –

Display dynamic information (data) in three different formats.

  1. Simple ALV
  2. MS-Excel Sheet
  3. MS-Word Document

Topic Cover: –

  1. Dynamic Internal Table Creation
  2. Field-symbol Dynamic Programming
  3. OLE Automation Process on MS-Excel and MS-Document.

Step 1.

Enter a valid table name if Table input field and click “Show Columns”, button to get all columns of respective table.

All columns will display in below Table Control with their respective short description in column Name & Text.

Step 2.

Information would be display in three different formats based on the user selection.

By the “No of Rows” option user can restrict the information for display.

As well as user can display only those columns information which he/she wants to display with the help of the selection of column from table control.

Step 3.

After select some of the columns from Table control or not, by the clicking on “ALV Display” button, we will get the simple ALV Display type output in new screen.


In output user will get only those column records what they selected or it will display all columns records.

On top of the page the selected table description will display.

And by the selection of any one of the columns value, it will generate a pop-up message which will display the selected column with selected value.

Step 4: –

As the same way, by the clicking of “Excel Display” button a Browser will open to Select a folder, where the generated excel file would be save.

After selecting a folder, again a pop-up message will display, where user need to select a option to display the generated excel file or it will process in back ground.


By the selection of above pop-up message, excel will display in front end or process will be in background.

The Excel file will create with the respective information’s.

The OLE Process is little bit time taking process, so if we run the particular program for the large number of information it will take time to generate the final file.

Step 5: –

In the same way, by the clicking of “Word Display” button a Browser will open to select a folder, where the generated Word File would be saved.

After selecting a folder, again a pop-up message will display, where user need to select an option to display the generated word file or it will process in back ground.

By the selection of above pop-up message, word will display in front end or process will be in background.

Basically the current MS-Word file only support for 63 columns. If the selected column number is more then 63, then it will not process for word document.

Summary: –

Displaying and downloading the information in three different ways. Based on the Present scenario, it’s covering the customer main requirement in there won declared format, what they used to seek in output.

Source Code: –

It’s a Module Pool programming.

Two include are defined here.

  1. ZDATA_DISPLAY_TOP
  2. ZDATA_DISPLAY_PAI

In the ZDATA_DISPLAY_TOP Include, all global variables are declared.

*&———————————————————————*
*& Include ZDATA_DISPLAY_TOP                                 Module Pool      ZDATA_DISPLAY
*&
*&———————————————————————*

PROGRAM  ZDATA_DISPLAY.

TYPE-POOLS:   OLE2, ABAP, SLIS.
TABLES:       DD03L, DD02VV.

*&—————————–TYPE FOR DISPLAY THE SELECTED TABLE COLUMNS AND RESPECTIVE COLUMN TEXT
TYPES:       
BEGIN OF  S_INFO,
MARK,
FLDNAM 
TYPE DD03L-FIELDNAME,
FLDTXT 
TYPE AS4TEXT,
LEN    
TYPE I,
END OF    S_INFO.
*&—————————–TYPE FOR DISPLAY THE SELECTED TABLE COLUMNS AND RESPECTIVE COLUMN TEXT

*&—————————–TABLE CONTROL FOR DISPLAY THE SEELCTED TBALE COLUMNS AND TEXT
CONTROLS:     TB_MAIN
TYPE TABLEVIEW USING SCREEN ‘9000’.
*&—————————–TABLE CONTROL FOR DISPLAY THE SEELCTED TBALE COLUMNS AND TEXT

DATA:         G_TABNAME   TYPE TABNAME.                   “TABLE NAME

DATA:         GIT_INFO    TYPE TABLE OF S_INFO,           “INTERNAL TABLE TO STORE TABLE’S COLUMNS AND COLUMN TEXT
GFL_INFO   
LIKE LINE OF GIT_INFO.          “WORK AREA FOR READING THE GIT_INFO INTERNAL TABLE

DATA:         G_OK        TYPE SY-UCOMM,                  “FOR READ THE USER INTERACTION
G_SAVE     
TYPE SY-UCOMM.

DATA:         GIT_TABINFO TYPE ABAP_COMPDESCR_TAB,        “INTERNAL TABLE FOR STORE THE SELECTED TABLE COLUMNS INFORMATION
GFL_TABINFO
TYPE ABAP_COMPDESCR.            “WORK AREA FOR READ THE GIT_TABINFO INTERNAL TABLE
DATA:         CL_ABAP
TYPE REF TO CL_ABAP_STRUCTDESCR.    “CLASS OBJECT TO READ THE SELECTED TABLE COLUMNS INFORMATION

DATA:         G_RECS      TYPE I.                         “GLOBAL INTEGER VARIABLE

DATA:         G_ROWS      TYPE I.                         “ROW INFORMATION TO DISPLAY INFORMATION IN RESPECTIVE SELECTED METHOD

DATA:         GIT_FLDS    TYPE LVC_T_FCAT,                “INTERNAL TABLE TO STORE THE COLUMNS & TEXT INFORMATION FOR CREATE THE DYNAMIC TABLE
GFL_FLDS   
TYPE LVC_S_FCAT.                “WORK AREA FOR READ THE GIT_FLDS INTERNAL TABLE

DATA:         GIT         TYPE REF TO DATA,               “INTERNAL TABLE FOR DYNAMIC TABLE
GFL        
TYPE REF TO DATA.               “WORK AREA FOR THE DYNAMIC TABLE

FIELD-SYMBOLS:  <GIT>     TYPE STANDARD TABLE,
<GFL>,
<VAL>.

DATA:         GIT_FCAT    TYPE SLIS_T_FIELDCAT_ALV,     “INTERNAL TABLE FOR THE FIELD CATALOG INFORMATION FOR RESUE ALV GRID DISPLAY FUNCTION MODULE
GFL_FCAT   
TYPE SLIS_FIELDCAT_ALV.       “WORK AREA FOR THE GIT_FCAT INTERNAL TABLE.

DATA:         GIT_EVENT   TYPE SLIS_T_EVENT,            “INTERNAL TABLE FOR ALV EVENT INFORMATION FOR TOP OF THE PAGE
GFL_EVENT  
TYPE SLIS_ALV_EVENT.          “WORK AREA FOR GIT_EVENT INTERNAL TABLE
DATA:         GIT_TOP    
TYPE SLIS_T_LISTHEADER,       “ALV TOP OF THE PAGE
GFL_TOP    
TYPE SLIS_LISTHEADER.         “WORK AREA FOR GIT_TOP

DATA:         G_SAVE_PATH TYPE STRING.                  “PATH INFORMATION TO SAVE THE XL/DOC FILE
DATA:         G_VISB     
TYPE C.                       “VISIBLE OR INVISIBLE XL/DOC FILE

DATA:         OBJ_XCL     TYPE OLE2_OBJECT,
OBJ_SHT    
TYPE OLE2_OBJECT,
OBJ_WBK    
TYPE OLE2_OBJECT,
OBJ_CEL    
TYPE OLE2_OBJECT,
OBJ_ROW    
TYPE OLE2_OBJECT,
OBJ_FNT    
TYPE OLE2_OBJECT,
OBJ_CLR    
TYPE OLE2_OBJECT,
OBJ_RNG    
TYPE OLE2_OBJECT,
OBJ_INT    
TYPE OLE2_OBJECT,
OBJ_BRD    
TYPE OLE2_OBJECT,
OBJ_COL    
TYPE OLE2_OBJECT.

TYPES:        BEGIN OF S_CELL,
CELL 
TYPE STRING,
POS  
TYPE C,
END OF   S_CELL.
DATA:         GIT_CELL 
TYPE TABLE OF S_CELL,
GFL_CELL 
LIKE LINE OF GIT_CELL.

DATA:         OBJ_WRD     TYPE OLE2_OBJECT,
OBJ_DOC    
TYPE OLE2_OBJECT,
OBJ_DCS    
TYPE OLE2_OBJECT,
OBJ_SLC    
TYPE OLE2_OBJECT,
OBJ_ADC    
TYPE OLE2_OBJECT,
OBJ_APP    
TYPE OLE2_OBJECT,
OBJ_ALG    
TYPE OLE2_OBJECT,
OBJ_TBS    
TYPE OLE2_OBJECT,
OBJ_TAB    
TYPE OLE2_OBJECT.

——————————————————————– ZDATA_DISPLAY_TOP———————————–

In the ZDATA_DISPLAY_PAI Include all logic are declared with suitable understandable information’s.

*&———————————————————————*
*&  Include           ZDATA_DISPLAY_PAI
*&———————————————————————*

module STATUS_9000 output.
**  SET PF-STATUS ‘xxxxxxxx’.
SET TITLEBAR ‘INFO’.
DESCRIBE TABLE GIT_INFO LINES TB_MAIN-LINES.
endmodule.                
” STATUS_9000  OUTPUT

*———————————————————————-*
***INCLUDE ZPRV_INFO_PAI .
*———————————————————————-*
*&———————————————————————*
*&      Module  USER_COMMAND_9000  INPUT
*&———————————————————————*
*       text
*———————————————————————-*
module USER_COMMAND_9000 input.
G_SAVE = G_OK.
CLEAR: G_OK.
CASE G_SAVE.
WHEN ‘CLICK’.
PERFORM SUB_GET_TABLE_INFO USING G_TABNAME.
WHEN ‘ALV’.
PERFORM SUB_CREATE_DYNAMIC_TABLE.
PERFORM SUB_SELECT_TABLE.
PERFORM SUB_DISPLAY_ALV.
WHEN ‘XL’.
PERFORM SUB_CREATE_DYNAMIC_TABLE.
PERFORM SUB_SELECT_TABLE.
PERFORM SUB_DISPLAY_INFO_XL.
WHEN ‘DOC’.
PERFORM SUB_CREATE_DYNAMIC_TABLE.
IF <GIT> IS NOT ASSIGNED.
EXIT.
ENDIF.
PERFORM SUB_SELECT_TABLE.
PERFORM SUB_DISPLAY_INFO_WORD.

ENDCASE.
endmodule.                 ” USER_COMMAND_9000  INPUT
*&———————————————————————*
*&      Form  SUB_GET_TABLE_INFO
*&———————————————————————*
*       Fetching the Table information based on the Table Name
*———————————————————————-*
*      –>P_TABNAME  TYPE TABNAME
*———————————————————————-*
form SUB_GET_TABLE_INFO  using    p_tabname TYPE TABNAME.
PERFORM SUB_IS_VALID_TABLE USING P_TABNAME.
IF P_TABNAME EQ .
EXIT.
ENDIF.
REFRESH: GIT_TABINFO.
CLEAR: CL_ABAP.
CL_ABAP ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_NAME( p_tabname ).
GIT_TABINFO  = CL_ABAP->COMPONENTS[].
DESCRIBE TABLE GIT_TABINFO LINES G_RECS.
IF G_RECS EQ 0.
MESSAGE ‘Not a Valid Table’ TYPE ‘I’.
CLEAR: P_TABNAME.
EXIT.
ENDIF.
REFRESH: GIT_INFO.
LOOP AT GIT_TABINFO INTO GFL_TABINFO.
CLEAR: GFL_INFO.
GFL_INFO-FLDNAM = GFL_TABINFO-NAME.
GFL_INFO-LEN    = GFL_TABINFO-LENGTH /
2.
PERFORM SUB_GET_FIELD_TEXT USING p_tabname GFL_TABINFO-NAME GFL_INFO-FLDTXT.
APPEND GFL_INFO TO GIT_INFO.
ENDLOOP.
endform.                   
” SUB_GET_TABLE_INFO
*&———————————————————————*
*&      Form  SUB_GET_FIELD_TEXT
*&———————————————————————*
*       Getting the Field Text based on the Field Name
*———————————————————————-*
*      –>P_NAME
*      –>P_TXT
*———————————————————————-*
form SUB_GET_FIELD_TEXT  using    P_TABLE TYPE ddobjname
p_name
TYPE FIELDNAME
p_txt TYPE AS4TEXT.
DATA: LIT_DDT
TYPE DFIES OCCURS 0,
LFL_DDT
LIKE LINE OF LIT_DDT.
CALL FUNCTION ‘DDIF_FIELDINFO_GET’
EXPORTING
tabname              = P_TABLE
FIELDNAME            = P_NAME
LANGU                = SY-LANGU
TABLES
DFIES_TAB            = LIT_DDT
EXCEPTIONS
NOT_FOUND            =
1
INTERNAL_ERROR       =
2
OTHERS               = 3
.
IF sy-subrc EQ 0.
LOOP AT LIT_DDT INTO LFL_DDT.
P_TXT = LFL_DDT-FIELDTEXT.
EXIT.
ENDLOOP.
ENDIF.
endform.                   
” SUB_GET_FIELD_TEXT
*&———————————————————————*
*&      Form  SUB_DISPLAY_ALV
*&———————————————————————*
*       Display the Selected table information in ALV Grid based on the
*       Selected Columns or Whole Table & Number of Rows Entered for Display
*———————————————————————-*
form SUB_DISPLAY_ALV .
DESCRIBE TABLE <GIT> LINES G_RECS.
IF G_RECS EQ 0.
MESSAGE ‘No Records Selected for Display’ TYPE ‘I’.
EXIT.
ENDIF.
PERFORM SUB_CREATE_FLD_CAT.
G_RECS =
1.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM                = SY-REPID
I_CALLBACK_TOP_OF_PAGE            =
‘TOP_OF_PAGE’
I_CALLBACK_USER_COMMAND           =
‘USER_COMMAND’
IT_FIELDCAT                       = GIT_FCAT
I_SAVE                            =
‘A’
TABLES
t_outtab                          = <GIT>
EXCEPTIONS
PROGRAM_ERROR                     =
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.

endform.                    ” SUB_DISPLAY_ALV
*&———————————————————————*
*&      Form  SUB_CREATE_DYNAMIC_COLS
*&———————————————————————*
*       Creating the FieldCatalog based on the Field Name and Field Text
*———————————————————————-*
*      –>P_FLDNAM  text
*      –>P_FLDTXT  text
*———————————————————————-*
form SUB_CREATE_DYNAMIC_COLS  using    p_fldnam TYPE LVC_FNAME
p_fldtxt
P_LEN .
CLEAR: GFL_FLDS.
DATA: LFL_DD03L
TYPE DD03L.
GFL_FLDS-FIELDNAME  = p_fldnam.
GFL_FLDS-OUTPUTLEN  = P_LEN.
GFL_FLDS-COLTEXT    = p_fldtxt.
CLEAR: LFL_DD03L.
SELECT SINGLE * FROM DD03L INTO LFL_DD03L WHERE TABNAME EQ G_TABNAME AND FIELDNAME EQ p_fldnam.
IF SY-SUBRC EQ 0.
GFL_FLDS-DATATYPE      = LFL_DD03L-DATATYPE.
GFL_FLDS-ROLLNAME      = LFL_DD03L-ROLLNAME.
GFL_FLDS-INTTYPE       = LFL_DD03L-INTTYPE.
GFL_FLDS-DOMNAME       = LFL_DD03L-DOMNAME.
GFL_FLDS-CHECKTABLE    = LFL_DD03L-CHECKTABLE.
ENDIF.
APPEND GFL_FLDS TO GIT_FLDS.
endform.                   
” SUB_CREATE_DYNAMIC_COLS
*&———————————————————————*
*&      Form  SUB_CREATE_DYNAMIC_TABLE
*&———————————————————————*
*       Create Dynamic table based on the Selected column or All columns of the selected table
*———————————————————————-*
form SUB_CREATE_DYNAMIC_TABLE .
REFRESH: GIT_FLDS.
LOOP AT GIT_INFO INTO GFL_INFO WHERE MARK EQ ‘X’.
PERFORM SUB_CREATE_DYNAMIC_COLS USING GFL_INFO-FLDNAM GFL_INFO-FLDTXT GFL_INFO-LEN.
ENDLOOP.
DESCRIBE TABLE GIT_FLDS LINES G_RECS.
IF G_RECS EQ 0.
LOOP AT GIT_INFO INTO GFL_INFO.
PERFORM SUB_CREATE_DYNAMIC_COLS USING GFL_INFO-FLDNAM GFL_INFO-FLDTXT GFL_INFO-LEN.
ENDLOOP.
ENDIF.
DESCRIBE TABLE GIT_FLDS LINES G_RECS.
IF G_RECS GT 67.
MESSAGE ‘MS-Word Only Support 67 Column in Table, Cannot Proceed.’ TYPE ‘I’.
EXIT.
ENDIF.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = GIT_FLDS
IMPORTING
EP_TABLE        = GIT.
IF <GIT> IS ASSIGNED.
UNASSIGN <GIT>.
ENDIF.
ASSIGN GIT->* TO <GIT>.
CREATE DATA GFL LIKE LINE OF <GIT>.
IF <GFL> IS ASSIGNED.
UNASSIGN <GFL>.
ENDIF.
ASSIGN GFL->* TO <GFL>.
endform.                   
” SUB_CREATE_DYNAMIC_TABLE
*&———————————————————————*
*&      Form  SUB_CREATE_FLD_CAT
*&———————————————————————*
*       Creating the Field Catalog for REUSE_ALV_GRID_DISPLAY Function Module
*———————————————————————-*
form SUB_CREATE_FLD_CAT .
REFRESH: GIT_FCAT.
LOOP AT GIT_FLDS INTO GFL_FLDS.
PERFORM SUB_CREATE_CATALOG USING GFL_FLDS-FIELDNAME GFL_FLDS-COLTEXT SPACE  SPACE  ‘L’ ‘<GIT>’ GFL_FLDS-OUTPUTLEN.
ENDLOOP.
endform.                   
” SUB_CREATE_FLD_CAT

*&———————————————————————*
*&      Form  SUB_CREATE_CATALOG
*&———————————————————————*
*       text
*———————————————————————-*
*      –>VALUE(P_FLDNAME)  text
*      –>P_COL_HEADING     text
*      –>VALUE(P_HOTSPOT)  text
*      –>VALUE(P_DOSUM)    text
*      –>VALUE(P_FORMAT)   text
*      –>VALUE(C_TABNAME)  text
*———————————————————————-*
FORM SUB_CREATE_CATALOG USING VALUE(P_FLDNAME) TYPE SLIS_FIELDNAME
P_COL_HEADING   
TYPE SCRTEXT_L
VALUE(P_HOTSPOT)
TYPE C
VALUE(P_DOSUM)  
TYPE C
VALUE(P_FORMAT) 
TYPE C
VALUE(C_TABNAME)
TYPE SLIS_TABNAME
VALUE(LEN).

GFL_FCAT-TABNAME   = C_TABNAME.                 ” Table name
GFL_FCAT-FIELDNAME = P_FLDNAME.                
” Field name
GFL_FCAT-SELTEXT_L = P_COL_HEADING.            
” Column heading
GFL_FCAT-HOTSPOT   = P_HOTSPOT.                
” Hot Spot
GFL_FCAT-DO_SUM    = P_DOSUM.                  
” Sum
GFL_FCAT-JUST      = P_FORMAT.                 
” Format
GFL_FCAT-OUTPUTLEN =  LEN.

APPEND GFL_FCAT TO GIT_FCAT.
CLEAR GFL_FCAT.

ENDFORM.                    “sub_create_catalog
*&———————————————————————*
*&      Module  MOD_UPDATE_INFO  INPUT
*&———————————————————————*
*       Updating the selection information in Internal Table
*———————————————————————-*
module MOD_UPDATE_INFO input.
MOVE-CORRESPONDING GFL_INFO TO GFL_INFO.
MODIFY  GIT_INFO FROM GFL_INFO INDEX TB_MAIN-CURRENT_LINE.
endmodule.                
” MOD_UPDATE_INFO  INPUT
*&———————————————————————*
*&      Form  TOP_OF_PAGE
*&———————————————————————*
*       FOR TOP OF THE PAGE INFORMATION OF THE ALV GRID
*———————————————————————-*
form TOP_OF_PAGE .
IF G_RECS EQ 1.
GFL_TOP-TYP =
‘H’.
PERFORM SUB_GET_TABLE_DESC USING G_TABNAME GFL_TOP-INFO.
CONCATENATE ‘Table’ GFL_TOP-INFO ‘Report’ INTO GFL_TOP-INFO SEPARATED BY SPACE.
APPEND GFL_TOP TO GIT_TOP.

CALL FUNCTION ‘REUSE_ALV_COMMENTARY_WRITE’
EXPORTING
it_list_commentary       = GIT_TOP
.
G_RECS =
2.
ENDIF.
endform.                   
” SUB_TOP_OF_PAGE

FORM USER_COMMAND USING UCOMM   TYPE SY-UCOMM
FLDSEL 
TYPE SLIS_SELFIELD.
READ TABLE <GIT> INTO <GFL> INDEX FLDSEL-TABINDEX.
IF SY-SUBRC EQ 0.
DATA: L_MSG
TYPE STRING.
ASSIGN COMPONENT  FLDSEL-FIELDNAME OF STRUCTURE <GFL> TO <VAL>.
CLEAR: GFL_INFO.
READ TABLE GIT_INFO INTO GFL_INFO WITH KEY FLDNAM = FLDSEL-FIELDNAME.
CONCATENATE ‘Column’ GFL_INFO-FLDTXT  ‘Value is’ <VAL> INTO L_MSG SEPARATED BY SPACE.
MESSAGE L_MSG TYPE ‘I’.
ENDIF.
ENDFORM.
*&———————————————————————*
*&      Form  SUB_SELECT_TABLE
*&———————————————————————*
*       Select the table information
*———————————————————————-*
form SUB_SELECT_TABLE .
IF NOT <GIT> IS ASSIGNED.
EXIT.
ENDIF.
IF G_ROWS EQ 0.
SELECT * FROM (G_TABNAME) INTO CORRESPONDING FIELDS OF TABLE <GIT>.
ELSE.
SELECT * FROM (G_TABNAME) UP TO G_ROWS ROWS INTO CORRESPONDING FIELDS OF TABLE <GIT>.
ENDIF.
endform.                   
” SUB_SELECT_TABLE
*&———————————————————————*
*&      Form  SUB_DISPLAY_INFO_XL
*&———————————————————————*
*       Display the Selected Table information in Excel File
*———————————————————————-*
form SUB_DISPLAY_INFO_XL .
DESCRIBE TABLE <GIT> LINES G_RECS.
IF G_RECS EQ 0.
EXIT.
ENDIF.
PERFORM SUB_CREATE_XL_APP.
IF OBJ_XCL IS INITIAL.
EXIT.
ENDIF.
DATA: L_INFO
TYPE STRING.
CLEAR: G_SAVE_PATH.
PERFORM SUB_GET_PATH.
IF G_SAVE_PATH EQ .
FREE OBJECT OBJ_XCL.
EXIT.
ENDIF.
PERFORM SUB_GET_VISIBLE_INFO.
PERFORM SUB_DISPLAY_XL.
PERFORM SUB_XL_ADD_WBOOK.
PERFORM SUB_XL_WORK_SHEET.
PERFORM SUB_XL_ACTIVE.
PERFORM SUB_XL_MERGE_COLS USING ‘D2’ ‘P4’.
PERFORM SUB_XL_SET_BORDER USING ‘D2’ ‘P4’.
PERFORM SUB_XL_SET_FONT USING ‘D2’ ‘ALGERIAN’ ’25’ 1 0 1.
PERFORM SUB_XL_ALIGN USING 3 2.
PERFORM SUB_GET_TABLE_DESC USING G_TABNAME L_INFO.
CONCATENATE ‘Table’ L_INFO ‘Report’ INTO L_INFO SEPARATED BY SPACE.
PERFORM SUB_XL_WRITE USING L_INFO.
PERFORM SUB_XL_FILL_COLOR USING ’20’ ‘2’ ‘2’.
PERFORM SUB_XL_SET_FONT_COLOR USING ‘5’.

DATA: L_CELL  TYPE string VALUE ‘B6’,
L_STR  
TYPE STRING,
L_REC  
TYPE I.
LOOP AT GIT_FLDS INTO GFL_FLDS.
G_RECS = SY-TABIX.
FREE OBJECT OBJ_CEL.
PERFORM SUB_XL_SET_FONT USING L_CELL ‘ARIAL BLACK’ ’11’ 1 0 1.
PERFORM SUB_XL_ALIGN USING 3 2.
PERFORM SUB_XL_WRITE USING GFL_FLDS-COLTEXT.
PERFORM SUB_XL_FILL_COLOR USING ’15’ ‘2’ ‘2’.
PERFORM SUB_XL_SET_FONT_COLOR USING ‘4’.
PERFORM SUB_XL_SET_BORDER USING L_CELL L_CELL.
IF GFL_FLDS-OUTPUTLEN LT 3.
GFL_FLDS-OUTPUTLEN = STRLEN( GFL_FLDS-COLTEXT ).
ENDIF.
PERFORM SUB_XL_COLUMN_WIDTH USING L_CELL GFL_FLDS-OUTPUTLEN.
FREE OBJECT OBJ_CEL.
PERFORM sub_get_next_cell USING L_CELL L_CELL ‘H’.
ENDLOOP.
L_CELL =
‘B7’.
LOOP AT <GIT> INTO <GFL>.
G_RECS = SY-TABIX.
L_STR = G_RECS +
6.
CONCATENATE ‘B’ L_STR INTO L_CELL.
LOOP AT GIT_FLDS INTO GFL_FLDS.
L_REC = SY-TABIX.
FREE OBJECT OBJ_CEL.
ASSIGN COMPONENT GFL_FLDS-FIELDNAME OF STRUCTURE <GFL> TO <VAL>.
PERFORM SUB_XL_SET_FONT USING L_CELL ‘ARIAL’ ’10’ 1 0 1.
PERFORM SUB_XL_WRITE USING <VAL>.
FREE OBJECT OBJ_CEL.
PERFORM sub_get_next_cell USING L_CELL L_CELL ‘H’.
ENDLOOP.
ENDLOOP.
PERFORM SUB_XL_SAVEAS.
endform.                   
” SUB_DISPLAY_INFO_XL
*&———————————————————————*
*&      Form  SUB_CREATE_XL_APP
*&———————————————————————*
*       Creating Excel Application Object
*———————————————————————-*
form SUB_CREATE_XL_APP.
CREATE OBJECT OBJ_XCL ‘EXCEL.APPLICATION’.
IF SY-SUBRC NE 0.
MESSAGE ‘Problem to Creating Excel File’ TYPE ‘I’.
ENDIF.
endform.                   
” SUB_CREATE_XL_APP
*&———————————————————————*
*&      Form  SUB_GET_PATH
*&———————————————————————*
*       Get the Path information for save the file
*———————————————————————-*
form SUB_GET_PATH .
DATA: CL_SERV
TYPE REF TO CL_GUI_FRONTEND_SERVICES.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title         =
‘Select Folder to Save File’
*      initial_folder       =
CHANGING
selected_folder      = G_SAVE_PATH
EXCEPTIONS
cntl_error           =
1
error_no_gui         =
2
not_supported_by_gui =
3
others               = 4
.
IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

endform.                    ” SUB_GET_PATH
*&———————————————————————*
*&      Form  SUB_GET_VISIBLE_INFO
*&———————————————————————*
*       GET THE VISIBLE INFORMATION OF THE CREATED FILE
*———————————————————————-*
form SUB_GET_VISIBLE_INFO .
DATA: ANSWER 
TYPE C.
CALL FUNCTION ‘POPUP_TO_CONFIRM’
EXPORTING
TITLEBAR                    = ‘Display Mode’
*   DIAGNOSE_OBJECT             = ‘ ‘
text_question               =
‘Will File will Display? Display mode may take time to complete’
TEXT_BUTTON_1               =
‘YES’
*   ICON_BUTTON_1               = ‘ ‘
TEXT_BUTTON_2               =
‘NO’
*   ICON_BUTTON_2               = ‘ ‘
*   DEFAULT_BUTTON              = ‘1’
*   DISPLAY_CANCEL_BUTTON       = ‘X’
*   USERDEFINED_F1_HELP         = ‘ ‘
*   START_COLUMN                = 25
*   START_ROW                   = 6
*   POPUP_TYPE                  =
*   IV_QUICKINFO_BUTTON_1       = ‘ ‘
*   IV_QUICKINFO_BUTTON_2       = ‘ ‘
IMPORTING
ANSWER                      = ANSWER
* TABLES
*   PARAMETER                   =
EXCEPTIONS
TEXT_NOT_FOUND              =
1
OTHERS                      = 2
.
IF sy-subrc EQ 0.
IF ANSWER EQ ‘1’.
G_VISB =
‘1’.
ELSE.
G_VISB =
‘0’.
ENDIF.
ENDIF.

endform.                    ” SUB_GET_VISIBLE_INFO
*&———————————————————————*
*&      Form  SUB_DISPLAY_XL
*&———————————————————————*
*       Display the XL File based on the Visible Mode
*———————————————————————-*
form SUB_DISPLAY_XL .
SET PROPERTY OF OBJ_XCL ‘VISIBLE’ = G_VISB.
endform.                   
” SUB_DISPLAY_XL
*&———————————————————————*
*&      Form  SUB_XL_WORK_SHEET
*&———————————————————————*
*      Creating a Work Sheet on Created Excel Obejct
*———————————————————————-*
form SUB_XL_WORK_SHEET .
CALL METHOD OF OBJ_XCL ‘WORKSHEETS’ = OBJ_SHT
EXPORTING #1  = 1.
endform.                   
” SUB_XL_WORK_SHEET

*&———————————————————————*
*&      Form  SUB_XL_ADD_WBOOK
*&———————————————————————*
*       Adding a Work Book on Created Excel Object
*———————————————————————-*
form SUB_XL_ADD_WBOOK .
CALL METHOD OF OBJ_XCL ‘WORKBOOKS’ = OBJ_WBK.
CALL METHOD OF OBJ_WBK ‘ADD’.
endform.                   
” SUB_XL_ADD_WBOOK
*&———————————————————————*
*&      Form  SUB_XL_ACTIVE
*&———————————————————————*
*       Active the Current Excel Sheet
*———————————————————————-*
form SUB_XL_ACTIVE .
CALL METHOD OF OBJ_SHT ‘ACTIVATE’.
endform.                   
” SUB_XL_ACTIVE
*&———————————————————————*
*&      Form  SUB_XL_MERGE_COLS
*&———————————————————————*
*       Merge the Columns Based on the Giving Range
*———————————————————————-*
*      –>P_FROM   text
*      –>P_TO   text
*———————————————————————-*
form SUB_XL_MERGE_COLS  using    value(p_FROM)
value(p_TO).
CALL METHOD OF OBJ_SHT ‘RANGE’ = OBJ_RNG NO FLUSH
EXPORTING #1    = P_FROM
#2    = P_TO.
CALL METHOD OF OBJ_RNG ‘SELECT’ NO FLUSH.
SET PROPERTY OF OBJ_RNG ‘MERGE’ = 1 NO FLUSH.
FREE OBJECT OBJ_RNG.
endform.                   
” SUB_XL_MERGE_COLS
*&———————————————————————*
*&      Form  SUB_XL_SET_BORDER
*&———————————————————————*
*       Set the Border
*———————————————————————-*
*      –>P_FROM   text
*      –>P_TO   text
*———————————————————————-*
form SUB_XL_SET_BORDER  using    value(p_FROM)
value(p_TO).
DATA: l_int
TYPE i.
PERFORM sub_get_border_cells USING p_from p_to.
DESCRIBE TABLE git_cell LINES l_int.
IF l_int EQ 0.
EXIT.
ENDIF.
FREE OBJECT   OBJ_CEL.
LOOP AT git_cell INTO gfl_cell.
CALL METHOD OF OBJ_SHT ‘RANGE’ = OBJ_CEL
EXPORTING #1 = gfl_cell-cell.
IF gfl_cell-pos EQ ‘U’.
PERFORM sub_set_border USING OBJ_CEL OBJ_BRD ‘3’ ‘1’ ‘4’.
ELSEIF gfl_cell-pos EQ ‘B’.
PERFORM sub_set_border USING OBJ_CEL OBJ_BRD ‘4’ ‘1’ ‘4’.
ELSEIF gfl_cell-pos EQ ‘L’.
PERFORM sub_set_border USING OBJ_CEL OBJ_BRD ‘1’ ‘1’ ‘4’.
ELSEIF gfl_cell-pos EQ ‘R’.
PERFORM sub_set_border USING OBJ_CEL OBJ_BRD ‘2’ ‘1’ ‘4’.
ENDIF.
ENDLOOP.

endform.                    ” SUB_XL_SET_BORDER

*&———————————————————————*
*&      Form  SUB_GET_BORDER_CELLS
*&———————————————————————*
*       Get the all Border information
*———————————————————————-*
*      –>P_P_FROM  text
*      –>P_P_TO  text
*———————————————————————-*
FORM sub_get_border_cells  USING    value(p_from)
value(p_to).
“‘D1’ ‘M3’
DATA: l_ncols
TYPE i,
l_rows 
TYPE i.
DATA: l_tot
TYPE i,
l_str
TYPE string,
l_int
TYPE i.
DATA: l_ncell1
TYPE string,
l_ncell2
TYPE string.
l_str = p_from.
l_int = STRLEN( l_str ).
PERFORM sub_get_no_cols USING p_from p_to l_ncols.
PERFORM sub_get_no_rows USING p_from p_to l_rows.
CLEAR:    git_cell.
REFRESH:  git_cell.
PERFORM sub_get_upper_cells USING p_from l_ncols l_ncell1 ‘U’.
PERFORM sub_get_side_cells USING p_from l_rows l_ncell2 ‘L’.
PERFORM sub_get_upper_cells USING l_ncell2 l_ncols l_ncell2 ‘B’.
PERFORM sub_get_side_cells USING l_ncell1 l_rows l_ncell2 ‘R’.
ENDFORM.                   
” SUB_GET_BORDER_CELLS

*&———————————————————————*
*&      Form  SUB_GET_NO_COLS
*&———————————————————————*
*       Get the total No fo Columns are exist in Giving Merge Differnece
*———————————————————————-*
*      –>P_FONT  text
*      –>P_TO  text
*      –>P_NCOLS  text
*———————————————————————-*
FORM sub_get_no_cols  USING    p_from
p_to
p_ncols
TYPE i.
DATA: l_str  
TYPE i,
l_end  
TYPE i.
PERFORM sub_get_column_no USING p_from
l_str.
PERFORM sub_get_column_no USING p_to
l_end.
p_ncols = l_end – l_str.
ENDFORM.                   
” SUB_GET_NO_COLS

*&———————————————————————*
*&      Form  SUB_GET_NO_ROWS
*&———————————————————————*
*       Getting the Rows information based on the given Cell
*———————————————————————-*
*      –>P_FROM  text
*      –>P_TO  text
*      –>P_ROWS  text
*———————————————————————-*
FORM sub_get_no_rows  USING    p_from
p_to
p_rows
TYPE i.
DATA: l_f
TYPE i,
l_t
TYPE i.
PERFORM sub_get_number USING p_from l_f.
PERFORM sub_get_number USING p_to l_t.
p_rows = l_t – l_f.
ENDFORM.                   
” SUB_GET_NO_ROWS

*&———————————————————————*
*&      Form  SUB_GET_UPPER_CELLS
*&———————————————————————*
*       Getting rhe Upper level of Excel’s Cells information
*———————————————————————-*
*      –>P_FROM  text
*      –>P_TO  text
*      –>P_NC  text
*———————————————————————-*
FORM sub_get_upper_cells  USING    value(p_from)
value(p_nc)
TYPE i
p_nfrm
p_up
TYPE c.
DATA: p_ncel 
TYPE string.
CLEAR: gfl_cell, p_nfrm.
gfl_cell-cell = p_from.
gfl_cell-pos  = p_up.
APPEND gfl_cell TO git_cell.
DO p_nc TIMES.
PERFORM sub_get_next_cell USING p_from p_ncel ‘H’.
CLEAR: gfl_cell.
gfl_cell-cell = p_ncel.
gfl_cell-pos  = p_up.
APPEND gfl_cell TO git_cell.
p_from = p_ncel.
ENDDO.
p_nfrm = p_from.
ENDFORM.                   
” SUB_GET_UPPER_CELLS

*&———————————————————————*
*&      Form  SUB_GET_LEFT_CELLS
*&———————————————————————*
*       Getting the all Left Side Cells information
*———————————————————————-*
*      –>P_P_FROM  text
*      –>P_P_TO  text
*———————————————————————-*
FORM sub_get_side_cells  USING    p_from
p_rows
TYPE i
p_nfrm
p_lr 
TYPE c.
DATA:  p_ncel 
TYPE string.
CLEAR: p_nfrm, gfl_cell.
gfl_cell-cell = p_from.
gfl_cell-pos  = p_lr.
APPEND gfl_cell TO git_cell.
DO p_rows TIMES.
PERFORM sub_get_next_cell USING p_from p_ncel ‘V’.
CLEAR: gfl_cell.
gfl_cell-cell = p_ncel.
gfl_cell-pos  = p_lr.
APPEND gfl_cell TO git_cell.
p_from = p_ncel.
ENDDO.
p_nfrm = p_from.
ENDFORM.                   
” SUB_GET_LEFT_CELLS

*&———————————————————————*
*&      Form  SUB_GET_NUMBER
*&———————————————————————*
*       Get the Cell Number
*———————————————————————-*
*      –>P_FROM  text
*      –>P_NO  text
*———————————————————————-*
FORM sub_get_number  USING    p_cell
p_no
TYPE i.
DATA: int
TYPE i,
l_i
TYPE i,
str
TYPE string,
alp
TYPE c.
l_i = STRLEN( p_cell ).
IF l_i EQ 2.
str = p_cell+1(1).
ELSE.
int =
0.
DO l_i TIMES.
alp = p_cell+int(1).
IF alp CN sy-abcde.
EXIT.
ENDIF.
int = int +
1.
ENDDO.
l_i = l_i – int.
str = p_cell+int(l_i).
ENDIF.
p_no =  str.
ENDFORM.                   
” SUB_GET_NUMBER

*&———————————————————————*
*&      Form  SUB_GET_COLUMN_NO
*&———————————————————————*
*       Get the Cell Column Number
*———————————————————————-*
*      –>P_FROM  text
*      –>P_COLN  text
*———————————————————————-*
FORM sub_get_column_no  USING    p_from
p_coln
TYPE i.
DATA: l_str
TYPE string,
l_alp
TYPE c,
l_int
TYPE i.
l_int = STRLEN( p_from ).
IF l_int EQ 2.
l_alp = p_from+0(1).
PERFORM sub_get_alphabate_no USING  l_alp
p_coln.
ELSEIF l_int EQ 3.
l_alp = p_from+0(1).
PERFORM sub_get_alphabate_no USING  l_alp
l_int.
l_int = l_int *
26.
l_alp = p_from+1(2).
PERFORM sub_get_alphabate_no USING  l_alp
p_coln.
p_coln = p_coln + l_int.
ENDIF.

ENDFORM.                    ” SUB_GET_COLUMN_NO

*&———————————————————————*
*&      Form  SUB_GET_NEXT_CELL
*&———————————————————————*
*       Get the Next Cell information based on the current giving Cell and Postion (H/V)
*———————————————————————-*
*      –>P_CELL  text
*      –>P_NCEL  text
*      –>P_POS  text
*———————————————————————-*
FORM sub_get_next_cell  USING    value(p_cell)
p_ncel
p_pos
TYPE c.
DATA: int
TYPE i,
l_i
TYPE i,
str
TYPE string,
alp
TYPE c,
l_s
TYPE string.

CLEAR: p_ncel.
CONDENSE p_cell.
IF p_pos EQ ‘H’.
l_i = STRLEN( p_cell ).
IF l_i EQ 2.
IF p_cell+0(1) EQ ‘Z’.
CONCATENATE ‘A’ ‘A’ p_cell+1(1) INTO p_ncel.
ELSE.
alp = p_cell+0(1).
PERFORM sub_get_next_alpha USING alp  alp.
CONCATENATE alp p_cell+1(1) INTO p_ncel.
ENDIF.
ELSE.
int =
0.
DO l_i TIMES.
alp = p_cell+int(1).
IF alp NA sy-abcde.
EXIT.
ENDIF.
int = int +
1.
ENDDO.
IF int EQ 1.
alp = p_cell+0(1).
l_i = l_i – int.
IF alp EQ ‘Z’.
CONCATENATE ‘AA’ p_cell+int(l_i) INTO p_ncel.
ELSE.
PERFORM sub_get_next_alpha USING alp alp.
CONCATENATE alp p_cell+int(l_i) INTO p_ncel.
ENDIF.
ELSE.
l_i = l_i – int.
l_s = p_cell+0(int).
IF int EQ 2.
IF l_s+1(1) EQ ‘Z’.
alp = l_s+0(1).
PERFORM sub_get_next_alpha USING alp alp.
CONCATENATE alp ‘A’ p_cell+int(l_i) INTO p_ncel.
ELSE.
alp = l_s+1(1).
PERFORM sub_get_next_alpha USING alp alp.
CONCATENATE l_s+0(1) alp p_cell+int(l_i) INTO p_ncel.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ELSEIF p_pos EQ ‘V’.
l_i = STRLEN( p_cell ).
IF l_i EQ ‘2’.
str = p_cell+1(1).
ELSE.
int =
0.
DO l_i TIMES.
alp = p_cell+int(1).
IF alp NS sy-abcde.
EXIT.
ENDIF.
int = int +
1.
ENDDO.
l_i = STRLEN( p_cell ) – int.
str = p_cell+int(l_i).
ENDIF.
int = str.
int = int +
1.
str = int.
CONCATENATE p_cell+0(1) str INTO p_ncel.
ENDIF.
ENDFORM.                   
” SUB_GET_NEXT_CELL

*&———————————————————————*
*&      Form  SUB_SET_BORDER
*&———————————————————————*
*       Set the Border of Cell line
*———————————————————————-*
*      –>P_G_CELL  text
*      –>P_G_BRDR  text
*      –>P_LINE  text
*      –>P_WIDT  text
*———————————————————————-*
FORM sub_set_border  USING    p_cell  TYPE ole2_object
p_brdr 
TYPE ole2_object
p_line
p_styl
p_widt.
*&——————————–
*  IF P_LINE EQ 3 THEN UPPER LEVEL OF CELL WILL BORDER
*  IF P_LINE EQ 4 THEN BOTTOM LEVEL OF CELL WILL BORDER
*  IF P_LINE EQ 1 THEN LEFT SIDE OF CELL
*  AND IF P_LINE EQ 2 THEN RIGHT SIDE OF CELL
*&——————————–
CALL METHOD OF p_cell ‘BORDERS’ = p_brdr
EXPORTING
#1 = p_line.
SET PROPERTY OF p_brdr ‘LINESTYLE’ = p_styl.
SET PROPERTY OF p_brdr ‘WEIGHT’    = p_widt.
FREE OBJECT p_brdr.
ENDFORM.                   
” SUB_SET_BORDER

*&———————————————————————*
*&      Form  SUB_GET_ALPHABATE_NO
*&———————————————————————*
*       Get the Alphabate No
*———————————————————————-*
*      –>P_P_ALP  text
*      –>P_P_COLN  text
*———————————————————————-*
FORM sub_get_alphabate_no  USING    p_alp
p_coln
TYPE i.
CASE p_alp.
WHEN ‘A’.
p_coln =
1.
WHEN ‘B’.
p_coln =
2.
WHEN ‘C’.
p_coln =
3.
WHEN ‘D’.
p_coln =
4.
WHEN ‘E’.
p_coln =
5.
WHEN ‘F’.
p_coln =
6.
WHEN ‘G’.
p_coln =
7.
WHEN ‘H’.
p_coln =
8.
WHEN ‘I’.
p_coln =
9.
WHEN ‘J’.
p_coln =
10.
WHEN ‘K’.
p_coln =
11.
WHEN ‘L’.
p_coln =
12.
WHEN ‘M’.
p_coln =
13.
WHEN ‘N’.
p_coln =
14.
WHEN ‘O’.
p_coln =
15.
WHEN ‘P’.
p_coln =
16.
WHEN ‘Q’.
p_coln =
17.
WHEN ‘R’.
p_coln =
18.
WHEN ‘S’.
p_coln =
19.
WHEN ‘T’.
p_coln =
20.
WHEN ‘U’.
p_coln =
21.
WHEN ‘V’.
p_coln =
22.
WHEN ‘W’.
p_coln =
23.
WHEN ‘X’.
p_coln =
24.
WHEN ‘Y’.
p_coln =
25.
WHEN ‘Z’.
p_coln =
26.
ENDCASE.
ENDFORM.                   
” SUB_GET_ALPHABATE_NO

*&———————————————————————*
*&      Form  SUB_GET_NEXT_ALPHA
*&———————————————————————*
*       Get the Next Alphabate based on the Giving Alphabate
*———————————————————————-*
*      –>P_1253   text
*      –>P_ALP  text
*———————————————————————-*
FORM sub_get_next_alpha  USING    p_gal
p_alp
TYPE c.
CONDENSE p_gal.
CASE p_gal.
WHEN ‘A’.
p_alp =
‘B’.
WHEN ‘B’.
p_alp =
‘C’.
WHEN ‘C’.
p_alp =
‘D’.
WHEN ‘D’.
p_alp =
‘E’.
WHEN ‘E’.
p_alp =
‘F’.
WHEN ‘F’.
p_alp =
‘G’.
WHEN ‘G’.
p_alp =
‘H’.
WHEN ‘H’.
p_alp =
‘I’.
WHEN ‘I’.
p_alp =
‘J’.
WHEN ‘J’.
p_alp =
‘K’.
WHEN ‘K’.
p_alp =
‘L’.
WHEN ‘L’.
p_alp =
‘M’.
WHEN ‘M’.
p_alp =
‘N’.
WHEN ‘N’.
p_alp =
‘O’.
WHEN ‘O’.
p_alp =
‘P’.
WHEN ‘P’.
p_alp =
‘Q’.
WHEN ‘Q’.
p_alp =
‘R’.
WHEN ‘R’.
p_alp =
‘S’.
WHEN ‘S’.
p_alp =
‘T’.
WHEN ‘T’.
p_alp =
‘U’.
WHEN ‘U’.
p_alp =
‘V’.
WHEN ‘V’.
p_alp =
‘W’.
WHEN ‘W’.
p_alp =
‘X’.
WHEN ‘X’.
p_alp =
‘Y’.
WHEN ‘Y’.
p_alp =
‘Z’.
WHEN ‘Z’.
p_alp =
‘A’.
ENDCASE.
ENDFORM.                   
” SUB_GET_NEXT_ALPHA
*&———————————————————————*
*&      Form  SUB_XL_SET_FONT
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_CELL   text
*      –>P_NAME   text
*      –>P_SIZE   text
*      –>P_BOLD   text
*      –>P_ITAL   text
*      –>P_UNDL   text
*———————————————————————-*
form SUB_XL_SET_FONT  using    value(p_CELL)
value(p_NAME)
value(p_SIZE)
value(p_BOLD)
value(p_ITAL)
value(p_UNDL).
CALL METHOD OF OBJ_SHT ‘RANGE’      =   OBJ_CEL
EXPORTING  #1        =   P_CELL.
CALL METHOD OF OBJ_CEL  ‘FONT’      =   OBJ_FNT.
SET PROPERTY OF OBJ_FNT ‘NAME’      =   P_NAME.
SET PROPERTY OF OBJ_FNT ‘BOLD’      =   P_BOLD.
SET PROPERTY OF OBJ_FNT ‘SIZE’      =   P_SIZE.
SET PROPERTY OF OBJ_FNT ‘ITALIC’    =   P_ITAL.
SET PROPERTY OF OBJ_FNT ‘UNDERLINE’ =   P_UNDL.
FREE OBJECT OBJ_FNT.

endform.                    ” SUB_XL_SET_FONT
*&———————————————————————*
*&      Form  SUB_XL_ALIGN
*&———————————————————————*
*       Make the Alignment
*———————————————————————-*
*      –>P_3      text
*      –>P_2      text
*———————————————————————-*
form SUB_XL_ALIGN  using    value(p_HVAL)
value(p_VERT).
SET PROPERTY OF OBJ_CEL  ‘HORIZONTALALIGNMENT’  = P_HVAL.
SET PROPERTY OF OBJ_CEL  ‘VERTICALALIGNMENT’    = P_VERT.
endform.                   
” SUB_XL_ALIGN
*&———————————————————————*
*&      Form  SUB_XL_WRITE
*&———————————————————————*
*       Writing the information in Cell
*———————————————————————-*
*      –>P_0656   text
*———————————————————————-*
form SUB_XL_WRITE  using    value(p_VAL).
SET PROPERTY OF OBJ_CEL ‘VALUE’ = P_VAL.
endform.                   
” SUB_XL_WRITE
*&———————————————————————*
*&      Form  SUB_XL_FILL_COLOR
*&———————————————————————*
*       Fill Color on Respective Cell
*———————————————————————-*
*      –>P_INDX   text
*      –>P_PTRN   text
*      –>P_ALIGN   text
*———————————————————————-*
form SUB_XL_FILL_COLOR  using    value(p_INDX)
value(p_PTRN)
value(p_ALIGN).
FREE OBJECT OBJ_INT.
CALL METHOD OF OBJ_CEL ‘INTERIOR’     = OBJ_INT.
SET PROPERTY OF OBJ_INT ‘COLORINDEX’  = P_INDX.
SET PROPERTY OF OBJ_INT ‘PATTERN’     = P_PTRN.
SET PROPERTY OF OBJ_INT ‘ALIGN’       = P_ALIGN.
FREE OBJECT OBJ_INT.
endform.                   
” SUB_XL_FILL_COLOR
*&———————————————————————*
*&      Form  SUB_XL_SET_FONT_COLOR
*&———————————————————————*
*       Setting the Font Color
*———————————————————————-*
*      –>P_0666   text
*———————————————————————-*
form SUB_XL_SET_FONT_COLOR  using    value(p_VAL).
FREE OBJECT OBJ_FNT.
GET PROPERTY OF OBJ_CEL ‘FONT’        =  OBJ_FNT.
SET PROPERTY OF OBJ_FNT ‘COLORINDEX’  =  P_VAL.
FREE OBJECT OBJ_FNT.
endform.                   
” SUB_XL_SET_FONT_COLOR
*&———————————————————————*
*&      Form  SUB_XL_SAVEAS
*&———————————————————————*
*       Saving the Generate XL file in Selected Path
*———————————————————————-*
form SUB_XL_SAVEAS .
CONCATENATE G_SAVE_PATH ‘\’ G_TABNAME ‘.XLS’ INTO G_SAVE_PATH.
CALL METHOD OF OBJ_SHT ‘SAVEAS’
EXPORTING #1 = G_SAVE_PATH.
CALL METHOD OF OBJ_SHT ‘QUIT’.
SET PROPERTY OF OBJ_XCL ‘VISIBLE’ = 0.
FREE OBJECT OBJ_SHT.
**  FREE OBJECT OBJ_WBK.
**  FREE OBJECT OBJ_XCL.
endform.                   
” SUB_XL_SAVEAS
*&———————————————————————*
*&      Form  SUB_XL_COLUMN_WIDTH
*&———————————————————————*
*       Setting Columns Width
*———————————————————————-*
*      –>P_CELL  text
*      –>P_LEN  text
*———————————————————————-*
form SUB_XL_COLUMN_WIDTH  using    p_cell
p_len.
CALL METHOD OF OBJ_XCL ‘RANGE’ = OBJ_COL
EXPORTING  #1   = P_CELL.
SET PROPERTY OF OBJ_COL ‘COLUMNWIDTH’ = P_LEN.
FREE OBJECT OBJ_COL.
endform.                   
” SUB_XL_COLUMN_WIDTH
*&———————————————————————*
*&      Form  SUB_DISPLAY_INFO_WORD
*&———————————————————————*
*       Display and Save the information in Word File
*———————————————————————-*
form SUB_DISPLAY_INFO_WORD .
DESCRIBE TABLE <GIT> LINES G_RECS.
IF G_RECS EQ 0.
EXIT.
ENDIF.
PERFORM SUB_CREATE_WORD_APP.
IF OBJ_WRD IS INITIAL.
EXIT.
ENDIF.
DATA: L_INFO
TYPE STRING.
CLEAR: G_SAVE_PATH.
PERFORM SUB_GET_PATH.
IF G_SAVE_PATH EQ .
FREE OBJECT OBJ_WRD.
EXIT.
ENDIF.
DATA: L_ROW 
TYPE I,
L_COL
TYPE I.
PERFORM SUB_GET_VISIBLE_INFO.
PERFORM SUB_WRD_DISPLAY.
PERFORM SUB_WRD_ADD_NEW.
PERFORM SUB_WRD_ACTIVE.
PERFORM SUB_GET_TABLE_DESC USING G_TABNAME L_INFO.
CONCATENATE ‘Table’ L_INFO ‘Report’ INTO L_INFO SEPARATED BY SPACE.
PERFORM SUB_WRD_SET_FONT USING ‘ALGERIAN’ ’25’ 1 1 1 1 5.
PERFORM SUB_WRD_WRITE USING L_INFO.

PERFORM SUB_WRD_NEW_LINE.
PERFORM SUB_WRD_SET_FONT USING ‘ARIAL’ ’12’ 0 0 0 1 15.
DESCRIBE TABLE GIT_FLDS LINES L_COL.
DESCRIBE TABLE <GIT> LINES L_ROW.
L_ROW = L_ROW +
1.
PERFORM SUB_WRD_CREATE_TABLE USING L_COL L_ROW.
PERFORM SUB_WRD_SET_BORDER USING ‘1’.
DATA: L_REC 
TYPE I.
LOOP AT GIT_FLDS INTO GFL_FLDS.
L_REC = SY-TABIX.
FREE OBJECT OBJ_CEL.
PERFORM SUB_WRD_CELL USING 1 L_REC.
PERFORM SUB_WRD_CELL_WRITE USING GFL_FLDS-FIELDNAME.
ENDLOOP.

LOOP AT <GIT> INTO <GFL>.
G_RECS = SY-TABIX.
G_RECS = G_RECS +
1.
LOOP AT GIT_FLDS INTO GFL_FLDS.
L_REC = SY-TABIX.
ASSIGN COMPONENT  GFL_FLDS-FIELDNAME OF STRUCTURE <GFL> TO <VAL>.
FREE OBJECT OBJ_CEL.
PERFORM SUB_WRD_CELL USING G_RECS L_REC.
PERFORM SUB_WRD_CELL_WRITE USING <VAL>.
ENDLOOP.
ENDLOOP.
PERFORM SUB_WRD_SAVEAS.
endform.                   
” SUB_DISPLAY_INFO_WORD
*&———————————————————————*
*&      Form  SUB_CREATE_WORD_APP
*&———————————————————————*
*       Creating the Word Document Object
*———————————————————————-*
form SUB_CREATE_WORD_APP .
CREATE OBJECT OBJ_WRD ‘WORD.APPLICATION’.
IF SY-SUBRC NE 0.
MESSAGE ‘Problem to Create Word Document Object’ TYPE ‘I’.
FREE OBJECT OBJ_WRD.
ENDIF.
endform.                   
” SUB_CREATE_WORD_APP
*&———————————————————————*
*&      Form  SUB_WRD_DISPLAY
*&———————————————————————*
*       Display the Created Word file based on the Visible mode
*———————————————————————-*
form SUB_WRD_DISPLAY .
IF G_VISB EQ ‘1’.
SET PROPERTY OF OBJ_WRD ‘VISIBLE’ = ‘1’.
ELSE.
SET PROPERTY OF OBJ_WRD ‘VISIBLE’ = ‘0’.
ENDIF.
endform.                   
” SUB_WRD_DISPLAY
*&———————————————————————*
*&      Form  SUB_WRD_ADD_NEW
*&———————————————————————*
*       Adding new word sheet for process.
*———————————————————————-*
form SUB_WRD_ADD_NEW .
CALL METHOD OF OBJ_WRD ‘DOCUMENTS’ = OBJ_DOC.
CALL METHOD OF OBJ_DOC ‘ADD’       = OBJ_DCS.
endform.                   
” SUB_WRD_ADD_NEW
*&———————————————————————*
*&      Form  SUB_WRD_ACTIVE
*&———————————————————————*
*      Activating the Current Word Document
*———————————————————————-*
form SUB_WRD_ACTIVE .
CALL METHOD OF OBJ_DCS ‘ACTIVATE’.
GET PROPERTY OF OBJ_WRD ‘ACTIVEDOCUMENT’  = OBJ_ADC.
GET PROPERTY OF OBJ_ADC ‘APPLICATION’     = OBJ_APP.
endform.                   
” SUB_WRD_ACTIVE
*&———————————————————————*
*&      Form  SUB_WRD_WRITE
*&———————————————————————*
*       Writing the information
*———————————————————————-*
form SUB_WRD_WRITE  using    value(p_VAL).
CALL METHOD OF OBJ_WRD ‘SELECTION’ = OBJ_SLC.
CALL METHOD OF OBJ_SLC ‘TYPETEXT’
EXPORTING #1 = P_VAL.
endform.                   
” SUB_WRD_WRITE
*&———————————————————————*
*&      Form  SUB_WRD_SET_FONT
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_NAME   text
*      –>P_SIZE   text
*      –>P_BOLD   text
*      –>P_ITAL   text
*      –>P_UDLN   text
*———————————————————————-*
form SUB_WRD_SET_FONT  using    value(p_NAME)
value(p_SIZE)
value(p_BOLD)
value(p_ITAL)
value(p_UNDL)
VALUE(P_ALIGN)
VALUE(P_COLR).
GET PROPERTY OF OBJ_APP ‘SELECTION’       = OBJ_SLC.
GET PROPERTY OF OBJ_SLC ‘PARAGRAPHFORMAT’ = OBJ_ALG.
GET PROPERTY OF OBJ_SLC ‘FONT’            = OBJ_FNT.
SET PROPERTY OF OBJ_FNT ‘NAME’            = P_NAME.
SET PROPERTY OF OBJ_FNT ‘SIZE’            = p_SIZE.
SET PROPERTY OF OBJ_FNT ‘BOLD’            = P_BOLD.
SET PROPERTY OF OBJ_FNT ‘ITALIC’          = p_ITAL.
SET PROPERTY OF OBJ_FNT ‘UNDERLINE’       = p_UNDL.
SET PROPERTY OF OBJ_ALG ‘ALIGNMENT’       = P_ALIGN.
SET PROPERTY OF OBJ_FNT ‘COLORINDEX’      = P_COLR.
FREE OBJECT OBJ_FNT.

endform.                    ” SUB_WRD_SET_FONT
*&———————————————————————*
*&      Form  SUB_WRD_CREATE_TABLE
*&———————————————————————*
*       Creating A table in Word Document.
*———————————————————————-*
*      –>P_COL  text
*      –>P_ROW  text
*———————————————————————-*
form SUB_WRD_CREATE_TABLE  using    p_col
p_row.
GET PROPERTY OF OBJ_SLC ‘TABLES’  = OBJ_TBS.
GET PROPERTY OF OBJ_SLC ‘RANGE’   = OBJ_RNG.
CALL METHOD OF OBJ_TBS ‘ADD’      = OBJ_TAB
EXPORTING #1       = OBJ_RNG
#2       = P_ROW
#3       = P_COL.
endform.                   
” SUB_WRD_CREATE_TABLE
*&———————————————————————*
*&      Form  SUB_WRD_NEW_LINE
*&———————————————————————*
*       Go to next Line
*———————————————————————-*
form SUB_WRD_NEW_LINE.
CALL METHOD OF OBJ_SLC ‘TYPEPARAGRAPH’.
endform.                   
” SUB_WRD_NEW_LINE
*&———————————————————————*
*&      Form  SUB_WRD_SET_BORDER
*&———————————————————————*
*       Set Boder of Created Table
*———————————————————————-*
*      –>P_VAL   text
*———————————————————————-*
form SUB_WRD_SET_BORDER  using    value(p_VAL).
GET PROPERTY OF OBJ_TAB ‘BORDERS’ = OBJ_BRD.
SET PROPERTY OF OBJ_BRD ‘ENABLE’  = P_VAL.
endform.                   
” SUB_WRD_SET_BORDER
*&———————————————————————*
*&      Form  SUB_WRD_CELL
*&———————————————————————*
*       Select Table Cell for Process
*———————————————————————-*
*      –>P_ROW  text
*      –>P_COL  text
*———————————————————————-*
form SUB_WRD_CELL  using    p_row
p_col.
CALL METHOD OF OBJ_TAB  ‘CELL’  = OBJ_CEL
EXPORTING  #1    = P_ROW
#2    = P_COL.
endform.                   
” SUB_WRD_CELL
*&———————————————————————*
*&      Form  SUB_WRD_CELL_WRITE
*&———————————————————————*
*       Write information in Table’s Cell
*———————————————————————-*
*      –>P_TEXT  text
*———————————————————————-*
form SUB_WRD_CELL_WRITE  using    p_text.
FREE OBJECT OBJ_RNG.
GET PROPERTY OF OBJ_CEL ‘RANGE’ = OBJ_RNG.
SET PROPERTY OF OBJ_RNG ‘TEXT’  = P_TEXT.
endform.                   
” SUB_WRD_CELL_WRITE
*&———————————————————————*
*&      Form  SUB_WRD_SAVEAS
*&———————————————————————*
*       Save Word File
*———————————————————————-*
form SUB_WRD_SAVEAS .
CONCATENATE G_SAVE_PATH ‘\’ G_TABNAME ‘.doc’ INTO G_SAVE_PATH.
CALL METHOD OF OBJ_DOC ‘SAVEAS’
EXPORTING #1 = G_SAVE_PATH.
endform.                   
” SUB_WRD_SAVEAS
*&———————————————————————*
*&      Form  SUB_IS_VALID_TABLE
*&———————————————————————*
*       Checking, Given table is valid table or not.
*———————————————————————-*
*      –>P_TABNAME  text
*———————————————————————-*
FORM SUB_IS_VALID_TABLE  USING    P_TABNAME.
DATA: LFL_DD 
TYPE DD03L.
SELECT SINGLE * FROM DD03L INTO LFL_DD WHERE TABNAME EQ P_TABNAME.
IF SY-SUBRC NE 0.
MESSAGE ‘Kindly enter a valid table’ TYPE ‘I’.
CLEAR: P_TABNAME.
EXIT.
ENDIF.
ENDFORM.                   
” SUB_IS_VALID_TABLE
*&———————————————————————*
*&      Form  SUB_GET_TABLE_DESC
*&———————————————————————*
*       Fecthing the table information
*———————————————————————-*
*      –>P_G_TABNAME  text
*———————————————————————-*
FORM SUB_GET_TABLE_DESC  USING    P_TABNAME
P_INFO.
DATA: LFL_DD 
TYPE DD02VV.
SELECT SINGLE * FROM DD02VV
INTO LFL_DD
WHERE DDLANGUAGE EQ SY-LANGU
AND   TABNAME EQ P_TABNAME.
IF SY-SUBRC EQ 0.
P_INFO = LFL_DD-DDTEXT.
ENDIF.
ENDFORM.                   
” SUB_GET_TABLE_DESC

——————————————ZDATA_DISPLAY_PAI————–

Screen 9000 Codes: –

PROCESS BEFORE OUTPUT.
MODULE STATUS_9000.
LOOP AT GIT_INFO INTO GFL_INFO WITH CONTROL TB_MAIN.
ENDLOOP.
*
PROCESS AFTER INPUT.
LOOP AT GIT_INFO.
MODULE MOD_UPDATE_INFO.
ENDLOOP.
MODULE USER_COMMAND_9000.

Thank You

Praveer Kumar Sen.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply