*&---------------------------------------------------------------------*
*& Report ZSJ_TESTING12
*&
*&---------------------------------------------------------------------*
*& Author :
*& Date : 05-04-2012
*& Purpose :
*&---------------------------------------------------------------------*
*& Date Changed by Tag Description
*&
*&---------------------------------------------------------------------*
REPORT yidic_jk.
*&---------------------------------------------------------------------*
*& Report ZUTL_IDOC_DOWNLOAD_TEST
*&
*&---------------------------------------------------------------------*
*& Author :
*& Date : 12-01-2012
*& Purpose :
*&---------------------------------------------------------------------*
*& Date Changed by Tag Description
*&
*&---------------------------------------------------------------------*
* Global Data Declaration
* Table
TABLES: edidc, edid4,sscrfields.
* type-pool declaration
TYPE-POOLS: slis, ole2.
* Constants
CONSTANTS: time_0 LIKE edidc-updtim VALUE '000000',
time_24 LIKE edidc-updtim VALUE '235959'.
* Type Declaration
TYPES: BEGIN OF typ_excel,
line(5000) TYPE c,
END OF typ_excel.
DATA: gv_dy_line TYPE REF TO data.
* Data declaration to have dynamic workarea
FIELD-SYMBOLS: <gs_dyn_tab> TYPE ANY.
* Internal Tables Declaration.
DATA: gt_edidc TYPE TABLE OF edidc,
gs_edidc TYPE edidc.
DATA: gt_edid4 TYPE TABLE OF edid4,
gs_edid4 TYPE edid4.
DATA: gt_edids TYPE TABLE OF edids,
gs_edids TYPE edids.
DATA: gt_excel TYPE TABLE OF typ_excel,
gs_excel TYPE typ_excel.
DATA: gt_edimsg TYPE TABLE OF edimsg,
gs_edimsg TYPE edimsg.
* OLE objects Declarations
DATA: gs_exc TYPE ole2_object,
gs_workbook TYPE ole2_object,
gs_worksheet TYPE ole2_object,
gs_columns TYPE ole2_object,
gs_int TYPE ole2_object,
gs_range TYPE ole2_object,
gs_sheet TYPE ole2_object,
gv_rc TYPE i,
gv_count TYPE i VALUE 0,
gv_string TYPE string.
DATA : flag.
TYPES: BEGIN OF typ_idocsyn,
sel_flag(1),
segtyp TYPE dd02t-tabname,
END OF typ_idocsyn.
TYPES: BEGIN OF typ_edisegt,
sel_flag(1),
segtyp TYPE dd02t-tabname,
langua TYPE edisegt-langua,
descrp TYPE edisegt-descrp,
END OF typ_edisegt.
TYPES : BEGIN OF ty_fields,
key TYPE c,
seg_name TYPE dd02t-tabname,
fields TYPE slis_fieldname,
END OF ty_fields.
***************JK *******************************************************
TYPES : BEGIN OF ty_fields2,
* key type c,
seg_name TYPE dd02t-tabname,
fields TYPE dd02t-tabname,"slis_fieldname,
END OF ty_fields2.
DATA : it_sel_idocsyn TYPE TABLE OF typ_edisegt WITH HEADER LINE,
wa_sel_idocsyn TYPE typ_edisegt,
gdf_flag TYPE i.
DATA: ls_fieldcat_1 TYPE slis_fieldcat_alv,
lt_fieldcat_1 TYPE TABLE OF slis_fieldcat_alv.
**************JK********************************************************
DATA : gt_idocsyn TYPE TABLE OF typ_edisegt,
wa_gt_idocsyn TYPE typ_edisegt.
DATA: lt_fieldcat TYPE TABLE OF slis_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv.
DATA : ls_fieldcat TYPE STANDARD TABLE OF ty_fields,
* ls_fieldcat type TABLE OF slis_fieldcat_alv,
wa_ls_fieldcat TYPE ty_fields.
DATA ls_fieldcat2 TYPE STANDARD TABLE OF ty_fields2.
DATA ldf_strname TYPE dd02l-tabname.
* Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK sb1 WITH FRAME TITLE text-sb1.
SELECT-OPTIONS: s_cretim FOR edidc-cretim DEFAULT time_0 TO time_24,
s_credat FOR edidc-credat DEFAULT sy-datum TO sy-datum,
s_updtim FOR edidc-updtim,
s_upddat FOR edidc-upddat,
s_direct FOR edidc-direct NO-EXTENSION NO INTERVALS,
s_docnum FOR edidc-docnum,
s_status FOR edidc-status.
PARAMETERS: p_idoctp LIKE edidc-idoctp.
*Begin of change Siji 04.05.2012 15:33:15
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(10) text-090 USER-COMMAND but1.
SELECTION-SCREEN END OF LINE.
*End of change Siji 04.05.2012 15:33:15
PARAMETERS: p_cimtyp LIKE edidc-cimtyp,
p_mestyp LIKE edidc-mestyp.
SELECT-OPTIONS: s_mescod FOR edidc-mescod,
s_mesfct FOR edidc-mesfct,
s_rcvpor FOR edidc-rcvpor,
s_rcvprn FOR edidc-rcvprn,
s_rcvprt FOR edidc-rcvprt,
s_rcvpfc FOR edidc-rcvpfc,
s_segnam FOR edid4-segnam.
PARAMETERS: p_rec TYPE sy-tabix DEFAULT '500' OBLIGATORY.
SELECTION-SCREEN END OF BLOCK sb1.
SELECTION-SCREEN BEGIN OF BLOCK sb2 WITH FRAME TITLE text-sb2.
SELECT-OPTIONS: s_refint FOR edidc-refint,
s_refgrp FOR edidc-refgrp,
s_refmes FOR edidc-refmes,
s_arckey FOR edidc-arckey,
s_std FOR edidc-std,
s_stdvrs FOR edidc-stdvrs,
s_stdmes FOR edidc-stdmes.
SELECTION-SCREEN END OF BLOCK sb2.
DATA wa_segnam LIKE LINE OF s_segnam.
DATA: lv_cond TYPE string,
lt_idocsyn_tmp TYPE TABLE OF edi_iapi02,
ls_idocsyn_tmp TYPE edi_iapi02,
lt_idocsynext_tmp TYPE TABLE OF edi_iapi06,
ls_idocsynext_tmp TYPE edi_iapi06,
ls_idocsyn TYPE typ_idocsyn,
lt_idocsyn TYPE TABLE OF typ_idocsyn,
lt_edisegt TYPE TABLE OF typ_edisegt.
DATA it_return TYPE STANDARD TABLE OF ddshretval.
DATA it_return1 TYPE STANDARD TABLE OF ddshretval.
DATA it_return2 TYPE STANDARD TABLE OF ddshretval.
DATA it_return3 TYPE STANDARD TABLE OF ddshretval.
DATA wa_return LIKE LINE OF it_return.
DATA it_fieldtab TYPE STANDARD TABLE OF dfies.
DATA: is_return1 TYPE ddshretval,
gs_idocsyn TYPE typ_edisegt.
TYPES: BEGIN OF ty_filter,
fieldname TYPE fieldname,
fieldval TYPE shvalue_d,
flag TYPE flag,
END OF ty_filter.
DATA: it_filter TYPE TABLE OF ty_filter,
wa_filter TYPE ty_filter.
AT SELECTION-SCREEN.
* Get Idoc Type from Config
CLEAR: lv_cond.
IF p_mestyp IS NOT INITIAL.
lv_cond = 'mestyp = p_mestyp'.
ENDIF.
IF p_idoctp IS NOT INITIAL.
IF lv_cond IS NOT INITIAL.
CONCATENATE lv_cond 'AND'
'idoctyp = p_idoctp'
INTO lv_cond
SEPARATED BY space.
ELSE.
lv_cond = 'idoctyp = p_idoctp'.
ENDIF.
ENDIF.
IF p_cimtyp IS NOT INITIAL.
IF lv_cond IS NOT INITIAL.
CONCATENATE lv_cond 'AND'
'cimtyp = p_cimtyp'
INTO lv_cond
SEPARATED BY space.
ELSE.
lv_cond = 'cimtyp = p_cimtyp'.
ENDIF.
ENDIF.
* Check if selection is present
CHECK lv_cond IS NOT INITIAL.
* Collect IDOC Types
SELECT * INTO TABLE gt_edimsg
FROM edimsg
WHERE (lv_cond).
* Loop and collect IDOC segments
REFRESH: lt_idocsyn.
LOOP AT gt_edimsg INTO gs_edimsg.
* Check if Extension is used
IF gs_edimsg-cimtyp IS INITIAL.
* Read IDOC structure
REFRESH: lt_idocsyn_tmp.
CALL FUNCTION 'IDOCTYPE_READ'
EXPORTING
pi_idoctyp = gs_edimsg-idoctyp
pi_check_authority = ' '
pi_read_devc = 'X'
TABLES
pt_syntax = lt_idocsyn_tmp[]
EXCEPTIONS
object_not_found = 1
db_error = 2
no_authority = 3
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT lt_idocsyn_tmp INTO ls_idocsyn_tmp.
ls_idocsyn-segtyp = ls_idocsyn_tmp-segtyp.
APPEND ls_idocsyn TO lt_idocsyn.
ENDLOOP.
ENDIF.
ELSE.
* Read IDOC structure
REFRESH: lt_idocsynext_tmp.
CALL FUNCTION 'EXTTYPE_READ'
EXPORTING
pi_cimtyp = gs_edimsg-cimtyp
pi_check_authority = ' '
pi_read_devc = 'X'
TABLES
pt_int_syntax = lt_idocsynext_tmp[]
EXCEPTIONS
object_not_found = 1
db_error = 2
no_authority = 3
OTHERS = 4.
IF sy-subrc = 0.
LOOP AT lt_idocsynext_tmp INTO ls_idocsynext_tmp.
ls_idocsyn-segtyp = ls_idocsynext_tmp-segtyp.
APPEND ls_idocsyn TO lt_idocsyn.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.
SELECT tabname AS segtyp
ddlanguage AS langua
ddtext AS descrp
INTO CORRESPONDING FIELDS OF TABLE lt_edisegt
FROM dd02t
FOR ALL ENTRIES IN lt_idocsyn
WHERE tabname = lt_idocsyn-segtyp AND
ddlanguage = sy-langu.
MOVE lt_edisegt TO gt_idocsyn.
*Begin of change Siji 04.05.2012 14:50:38
CASE sscrfields.
WHEN 'BUT1'.
flag = '1'.
* import gt_idocsyn FROM MEMORY id 'ZS1'.
****************Start Of Change JK 5/11/2012******************************
DATA : L_EXIT,
ls_private TYPE slis_data_caller_exit.
ls_private-columnopt = 'X'.
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
* I_TITLE =
I_SELECTION = 'X'
* I_ALLOW_NO_SELECTION =
* I_ZEBRA = 'X'
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
I_CHECKBOX_FIELDNAME = 'SEGTYP'
* I_LINEMARK_FIELDNAME =
* I_SCROLL_TO_SEL_LINE = 'X'
I_TABNAME = 'GT_IDOCSYN'
I_STRUCTURE_NAME = 'DDSHRETVAL'"ldf_strname
IT_FIELDCAT = LT_FIELDCAT
* IT_EXCLUDING =
* I_CALLBACK_PROGRAM =
* I_CALLBACK_USER_COMMAND =
IS_PRIVATE = ls_private
IMPORTING
* ES_SELFIELD =
E_EXIT = L_EXIT
TABLES
T_OUTTAB = it_return1
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
CHECK L_EXIT = SPACE.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'SEGTYP'
window_title = 'Segment Type'
value_org = 'S'
multiple_choice = 'X' "allows you select multiple entries from the popup
TABLES
value_tab = gt_idocsyn
return_tab = it_return1
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
APPEND LINES OF it_return1 TO it_return.
*start of Priya
*LOOP AT it_return1 INTO is_return1.
* if is_return1-recordpos IS NOT INITIAl.
* READ TABLE gt_idocsyn INTO gs_idocsyn WITH KEY segtyp = is_return1-fieldval.
* if sy-subrc = 0.
* gs_idocsyn-sel_flag = 'X'.
* MODIFY gt_idocsyn FROM gs_idocsyn INDEX sy-tabix.
* endif.
* endif.
*ENDLOOP.
*export gt_idocsyn TO MEMORY id 'ZS1'.
*end of Priya
REFRESH ls_fieldcat[].
LOOP AT it_return INTO wa_return.
CONDENSE wa_return-fieldval NO-GAPS.
MODIFY it_return FROM wa_return TRANSPORTING fieldval.
ldf_strname = wa_return-fieldval.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = ldf_strname
CHANGING
ct_fieldcat = lt_fieldcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR ls_fieldcat2.
LOOP AT lt_fieldcat INTO wa_fieldcat .
wa_ls_fieldcat-seg_name = wa_return-fieldval.
wa_ls_fieldcat-fields = wa_fieldcat-fieldname.
APPEND wa_ls_fieldcat TO ls_fieldcat2.
CLEAR wa_fieldcat.
ENDLOOP.
refresh lt_fieldcat .
CLEAR: wa_return,lt_fieldcat.
ENDLOOP.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'FIELDS'
window_title = 'Segment Fields'
value_org = 'S'
multiple_choice = 'X' "allows you select multiple entries from the popup
TABLES
value_tab = ls_fieldcat2
* field_tab = it_fieldtab
return_tab = it_return3
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
APPEND LINES OF it_return3 TO it_return2.
ENDCASE.
****************End Of Change JK 5/11/2012******************************
CLEAR: gv_string.
CONCATENATE p_idoctp p_cimtyp p_mestyp INTO gv_string.
IF gv_string IS INITIAL.
MESSAGE: 'Please enter Basic Type, Extension or Message Type'(001) TYPE 'E'.
ELSE.
CONCATENATE gv_string '.XLS' INTO gv_string.
CONDENSE gv_string NO-GAPS.
ENDIF.
START-OF-SELECTION.
****************Start Of Change JK 5/11/2012******************************
LOOP AT it_return2 INTO wa_return.
CONDENSE wa_return-fieldval NO-GAPS.
MODIFY it_return2 FROM wa_return TRANSPORTING fieldval.
wa_filter-fieldname = wa_return-fieldname .
wa_filter-fieldval = wa_return-fieldval .
APPEND wa_filter TO it_filter.
CLEAR wa_return.
ENDLOOP.
LOOP AT it_return INTO wa_return.
wa_segnam-sign = 'I'.
wa_segnam-option = 'EQ'.
wa_segnam-low = wa_return-fieldval.
APPEND wa_segnam TO s_segnam.
CLEAR wa_return.
ENDLOOP.
****************End Of Change JK 5/11/2012******************************
* Refresh all global variables
PERFORM refresh_global_data.
* Collect data
PERFORM collect_data.
* Process data
PERFORM process_data.
*&---------------------------------------------------------------------*
*& Form REFRESH_GLOBAL_DATA
*&---------------------------------------------------------------------*
* Refresh global variables.
*----------------------------------------------------------------------*
FORM refresh_global_data.
REFRESH: gt_edidc,
gt_edids,
gt_edid4,
gt_excel,
gt_edimsg.
ENDFORM. " REFRESH_GLOBAL_DATA
*&---------------------------------------------------------------------*
*& Form COLLECT_DATA
*&---------------------------------------------------------------------*
* Collect data.
*----------------------------------------------------------------------*
FORM collect_data.
* Local data declaration
DATA: lr_idoctp TYPE RANGE OF edidc-idoctp,
ls_idoctp LIKE LINE OF lr_idoctp,
lr_cimtyp TYPE RANGE OF edidc-cimtyp,
ls_cimtyp LIKE LINE OF lr_cimtyp,
lr_mestyp TYPE RANGE OF edidc-mestyp,
ls_mestyp LIKE LINE OF lr_mestyp.
* Build range tables
REFRESH: lr_idoctp, lr_cimtyp, lr_mestyp.
IF p_idoctp IS NOT INITIAL.
ls_idoctp-sign = 'I'.
ls_idoctp-option = 'EQ'.
ls_idoctp-low = p_idoctp.
APPEND ls_idoctp TO lr_idoctp.
ENDIF.
IF p_cimtyp IS NOT INITIAL.
ls_cimtyp-sign = 'I'.
ls_cimtyp-option = 'EQ'.
ls_cimtyp-low = p_cimtyp.
APPEND ls_cimtyp TO lr_cimtyp.
ENDIF.
IF p_mestyp IS NOT INITIAL.
ls_mestyp-sign = 'I'.
ls_mestyp-option = 'EQ'.
ls_mestyp-low = p_mestyp.
APPEND ls_mestyp TO lr_mestyp.
ENDIF.
* Collecting data from edidc table
SELECT * FROM edidc INTO TABLE gt_edidc UP TO p_rec ROWS
WHERE upddat IN s_upddat
AND docnum IN s_docnum
AND status IN s_status
AND direct IN s_direct
AND idoctp IN lr_idoctp
AND cimtyp IN lr_cimtyp
AND mestyp IN lr_mestyp
AND mescod IN s_mescod
AND mesfct IN s_mesfct
AND rcvpor IN s_rcvpor
AND rcvprt IN s_rcvprt
AND rcvpfc IN s_rcvpfc
AND rcvprn IN s_rcvprn
AND status IN s_status
AND credat IN s_credat
AND cretim IN s_cretim
AND upddat IN s_upddat
AND updtim IN s_updtim
AND refint IN s_refint
AND refgrp IN s_refgrp
AND refmes IN s_refmes
AND arckey IN s_arckey
AND std IN s_std
AND stdvrs IN s_stdvrs
AND stdmes IN s_stdmes
ORDER BY PRIMARY KEY.
IF gt_edidc IS NOT INITIAL.
* Collect segment data
SELECT * FROM edid4
INTO TABLE gt_edid4
FOR ALL ENTRIES IN gt_edidc
WHERE docnum = gt_edidc-docnum AND
segnam IN s_segnam.
* Collect status records
SELECT * FROM edids
INTO TABLE gt_edids
FOR ALL ENTRIES IN gt_edidc
WHERE docnum = gt_edidc-docnum.
ENDIF.
ENDFORM. " COLLECT_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* Process Data. *
*----------------------------------------------------------------------*
FORM process_data.
* Local data declaration
DATA: lt_edid4 LIKE TABLE OF edid4,
ls_edid4 LIKE LINE OF lt_edid4,
lv_noofsheets TYPE sy-tabix,
lv_fval TYPE string,
lv_count TYPE i,
lv_nooflines TYPE i.
FIELD-SYMBOLS: <lv_field> TYPE ANY.
* Check if any data found for current selection
IF gt_edid4 IS NOT INITIAL.
* Get no of worksheets to be created
SORT gt_edid4 BY segnam ASCENDING.
lt_edid4[] = gt_edid4[].
DELETE ADJACENT DUPLICATES FROM lt_edid4 COMPARING segnam.
DESCRIBE TABLE lt_edid4 LINES lv_noofsheets.
* Build excel file
CHECK gs_exc-handle = 0.
CHECK gs_exc-header = space.
CREATE OBJECT gs_exc 'Excel.Application'. "Create object for Excel
SET PROPERTY OF gs_exc 'Visible' = 1. "In background Mode
CALL METHOD OF gs_exc 'Workbooks' = gs_workbook.
CALL METHOD OF gs_workbook 'ADD'.
SET PROPERTY OF gs_exc 'SheetsInNewWorkbook' = 1.
* Add two worksheets for Control & Status records
lv_noofsheets = lv_noofsheets + 2.
* Add required number of worksheets
DO lv_noofsheets TIMES.
IF sy-index > 1.
CALL METHOD OF gs_exc 'WORKSHEETS' = gs_sheet.
CALL METHOD OF gs_sheet 'ADD'.
FREE OBJECT gs_sheet.
ENDIF.
ENDDO.
* Build worksheet for Control Record
* Get header line
PERFORM get_header_line USING 'EDIDC' 'X'.
* Check and append header line
IF gs_excel IS NOT INITIAL.
APPEND gs_excel TO gt_excel.
ENDIF.
LOOP AT gt_edidc INTO gs_edidc.
* Delete current line
DELETE gt_edidc INDEX sy-tabix.
* Build excel table with Tab Delimited character
CLEAR: gs_excel.
DO.
CHECK sy-index <> 1.
UNASSIGN <lv_field>.
ASSIGN COMPONENT sy-index OF STRUCTURE gs_edidc
TO <lv_field>.
IF <lv_field> IS ASSIGNED.
CLEAR: lv_fval.
lv_fval = <lv_field>.
* Perform transformation based on the column type
PERFORM transform_colval USING lv_fval <lv_field>.
IF gs_excel-line IS NOT INITIAL.
CONCATENATE gs_excel-line lv_fval
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
gs_excel-line = lv_fval.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
APPEND gs_excel TO gt_excel.
ENDLOOP.
* Check if there are any entries in excel table
IF gt_excel[] IS NOT INITIAL.
PERFORM download_sheet TABLES gt_excel USING gv_count 'EDIDC'.
GET PROPERTY OF gs_exc 'ActiveSheet' = gs_worksheet.
ENDIF.
* Loop at all segments and build segmentwise worksheets
LOOP AT lt_edid4 INTO ls_edid4.
* Unassign field symbols
UNASSIGN: <gs_dyn_tab>.
* Build dynamic work area
CREATE DATA gv_dy_line TYPE (ls_edid4-segnam).
ASSIGN gv_dy_line->* TO <gs_dyn_tab>.
* Check if field-symbols is assigned
IF <gs_dyn_tab> IS ASSIGNED.
****************Start Of Change JK 5/11/2012******************************
* Get header line for current segment
PERFORM get_header_line2 USING ls_edid4-segnam space.
****************End Of Change JK 5/11/2012******************************
* Add IDOC Number as a first column
CONCATENATE text-h01 gs_excel-line
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
* Check and append header line
IF gs_excel IS NOT INITIAL.
APPEND gs_excel TO gt_excel.
ENDIF.
ENDIF.
LOOP AT gt_edid4 INTO gs_edid4 FROM 1
WHERE segnam = ls_edid4-segnam.
* Delete current line
DELETE gt_edid4 INDEX sy-tabix.
* Get segment data in dynamic structure
<gs_dyn_tab> = gs_edid4-sdata.
* Build excel table with Tab Delimited character
CLEAR: gs_excel.
CONCATENATE '="' gs_edid4-docnum '"'
INTO gs_excel-line.
* DO. Commented by JK
* UNASSIGN <lv_field>.
* ASSIGN COMPONENT sy-index OF STRUCTURE <gs_dyn_tab>
* TO <lv_field>.
*
* IF <lv_field> IS ASSIGNED.
* CLEAR: lv_fval.
* lv_fval = <lv_field>.
*
** Perform transformation based on the column type
* PERFORM transform_colval USING lv_fval <lv_field>.
*
* CONCATENATE gs_excel-line lv_fval
* INTO gs_excel-line
* SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
* ELSE.
* EXIT.
* ENDIF.
* ENDDO. Commented by JK
**********************************************************************
CLEAR lv_count .
DO .
lv_count = lv_count + 1.
UNASSIGN <lv_field>.
ASSIGN COMPONENT sy-index OF STRUCTURE <gs_dyn_tab>
TO <lv_field>.
IF <lv_field> IS ASSIGNED.
CLEAR: lv_fval.
lv_fval = <lv_field>.
*IF wa_filter-flag = sy-tabix.
****************Start Of Change JK 5/11/2012******************************
CLEAR :ls_fieldcat_1,wa_return.
PERFORM transform_colval USING lv_fval <lv_field>.
READ TABLE lt_fieldcat_1 INTO ls_fieldcat_1 INDEX lv_count.
IF sy-subrc IS INITIAL.
DESCRIBE TABLE it_return2 LINES lv_nooflines.
IF lv_nooflines eq 0.
CONCATENATE gs_excel-line lv_fval
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
READ TABLE it_return2 INTO wa_return WITH KEY fieldval = ls_fieldcat_1-fieldname.
IF sy-subrc IS INITIAL.
* Perform transformation based on the column type
CONCATENATE gs_excel-line lv_fval
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ENDIF.
ENDIF.
ENDIF.
****************End Of Change JK 5/11/2012******************************
ELSE.
EXIT.
ENDIF.
* ENDIF.
ENDDO.
*ENDLOOP.
**********************************************************************
APPEND gs_excel TO gt_excel.
ENDLOOP.
* Check if there are any entries in excel table
IF gt_excel[] IS NOT INITIAL.
PERFORM download_sheet TABLES gt_excel USING gv_count gs_edid4-segnam.
GET PROPERTY OF gs_exc 'ActiveSheet' = gs_worksheet.
ENDIF.
ENDLOOP.
* Build worksheet for Status Record
PERFORM get_header_line USING 'EDIDS' 'X'.
* Check and append header line
IF gs_excel IS NOT INITIAL.
APPEND gs_excel TO gt_excel.
ENDIF.
LOOP AT gt_edids INTO gs_edids.
* Delete current line
DELETE gt_edids INDEX sy-tabix.
* Build excel table with Tab Delimited character
CLEAR: gs_excel.
DO.
CHECK sy-index <> 1.
UNASSIGN <lv_field>.
ASSIGN COMPONENT sy-index OF STRUCTURE gs_edids
TO <lv_field>.
IF <lv_field> IS ASSIGNED.
CLEAR: lv_fval.
lv_fval = <lv_field>.
* Perform transformation based on the column type
PERFORM transform_colval USING lv_fval <lv_field>.
IF gs_excel-line IS NOT INITIAL.
CONCATENATE gs_excel-line lv_fval
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
gs_excel-line = lv_fval.
ENDIF.
ELSE.
EXIT.
ENDIF.
ENDDO.
APPEND gs_excel TO gt_excel.
ENDLOOP.
* Check if there are any entries in excel table
IF gt_excel[] IS NOT INITIAL.
PERFORM download_sheet TABLES gt_excel USING gv_count 'EDIDS'.
GET PROPERTY OF gs_exc 'ActiveSheet' = gs_worksheet.
ENDIF.
MESSAGE s208(00) WITH text-s02.
FREE OBJECT: gs_worksheet, gs_exc.
ELSE.
MESSAGE s208(00) WITH text-s01.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_SHEET
*&---------------------------------------------------------------------*
* Download data to Worksheet.
*----------------------------------------------------------------------*
FORM download_sheet TABLES p_tab
USING p_sheet TYPE i
p_name TYPE any.
p_sheet = p_sheet + 1.
CALL METHOD OF gs_exc 'WORKSHEETS' = gs_worksheet
EXPORTING
#1 = p_sheet.
CALL METHOD OF gs_worksheet 'ACTIVATE'.
SET PROPERTY OF gs_worksheet 'NAME' = p_name.
CALL METHOD OF gs_exc 'Range' = gs_range
EXPORTING
#1 = 'A1'
#2 = 'Z1'.
CALL METHOD OF gs_range 'INTERIOR' = gs_int.
SET PROPERTY OF gs_int 'ColorIndex' = 6.
SET PROPERTY OF gs_int 'Pattern' = 1.
* Initially unlock all the columns( by default all the columns are locked )
CALL METHOD OF gs_exc 'Columns' = gs_columns.
SET PROPERTY OF gs_columns 'Locked' = 0.
* Export the contents in the internal table to the clipboard
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = p_tab[]
CHANGING
rc = gv_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
* Paste the contents in the clipboard to the worksheet
CALL METHOD OF gs_worksheet 'Paste'.
* Autofit the columns according to the contents
CALL METHOD OF gs_exc 'Columns' = gs_columns.
CALL METHOD OF gs_columns 'AutoFit'.
FREE OBJECT: gs_columns, gs_range, gs_int, gs_worksheet.
REFRESH: p_tab[].
ENDFORM. "download_sheet
*&---------------------------------------------------------------------*
*& Form GET_HEADER_LINE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_header_line USING pi_tabname TYPE dd02l-tabname
pi_skipmandt TYPE char1.
* Local data declaration
DATA: ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE TABLE OF slis_fieldcat_alv.
REFRESH: lt_fieldcat,
gt_excel.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = pi_tabname
CHANGING
ct_fieldcat = lt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CLEAR: gs_excel.
LOOP AT lt_fieldcat INTO ls_fieldcat.
IF pi_skipmandt = 'X' AND
sy-tabix = 1.
CONTINUE.
ENDIF.
IF ls_fieldcat-reptext_ddic IS INITIAL.
ls_fieldcat-reptext_ddic = ls_fieldcat-fieldname.
ELSE.
CONCATENATE ls_fieldcat-fieldname '-'
ls_fieldcat-reptext_ddic
INTO ls_fieldcat-reptext_ddic.
ENDIF.
IF gs_excel-line IS NOT INITIAL.
CONCATENATE gs_excel-line ls_fieldcat-reptext_ddic
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
gs_excel-line = ls_fieldcat-reptext_ddic.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " GET_HEADER_LINE
*&---------------------------------------------------------------------*
*& Form TRANSFORM_COLVAL
*&---------------------------------------------------------------------*
* Perform transformation based on the column type. *
*----------------------------------------------------------------------*
FORM transform_colval USING pi_fval TYPE string
pi_fieldsym TYPE any.
* Local data declaration
DATA: lv_type TYPE c,
lv_datechar(10) TYPE c,
lv_timechar(8) TYPE c,
lv_pchar(15) TYPE c,
lv_date LIKE sy-datum,
lv_time LIKE sy-uzeit.
CONSTANTS: lc_datetype VALUE 'D',
lc_packtype VALUE 'P',
lc_timetype VALUE 'T',
lc_chartyp VALUE 'C',
lc_numtyp VALUE 'N'.
* Get the component type
CLEAR: lv_type.
DESCRIBE FIELD pi_fieldsym TYPE lv_type.
* If data type is DATE
IF lv_type = lc_datetype.
lv_date = pi_fval.
WRITE lv_date TO lv_datechar MM/DD/YYYY.
pi_fval = lv_datechar .
ENDIF.
* If data type is TIME
IF lv_type = lc_timetype.
lv_time = pi_fval.
WRITE lv_time TO lv_timechar.
pi_fval = lv_timechar.
ENDIF.
* If data type is Packed Decimal, then pad negative sign
* in front by moving it to character variable
IF lv_type = lc_packtype.
IF pi_fieldsym < 0.
pi_fval = pi_fval * ( -1 ).
lv_pchar = pi_fval.
CONDENSE lv_pchar NO-GAPS.
CONCATENATE '-' lv_pchar INTO lv_pchar.
WRITE lv_pchar TO lv_pchar RIGHT-JUSTIFIED.
ELSE.
CONDENSE pi_fval NO-GAPS.
WRITE pi_fval TO lv_pchar RIGHT-JUSTIFIED.
ENDIF.
CLEAR: pi_fval.
pi_fval = lv_pchar.
ENDIF.
* If data type is characters, retain zeros if
* required
IF lv_type = lc_chartyp OR
lv_type = lc_numtyp.
IF pi_fval IS NOT INITIAL.
IF pi_fval CO '0123456789 '.
CONCATENATE '="' pi_fval '"'
INTO pi_fval.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " TRANSFORM_COLVAL
*&---------------------------------------------------------------------*
*& Form get_header_line2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PI_TABNAME text
* -->PI_SKIPMANDT text
*----------------------------------------------------------------------*
FORM get_header_line2 USING pi_tabname TYPE dd02l-tabname
pi_skipmandt TYPE char1.
* Local data declaration
DATA: ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE TABLE OF slis_fieldcat_alv,
l_tabix TYPE sy-tabix,
lv_nooflines TYPE i.
REFRESH: lt_fieldcat,
gt_excel.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = pi_tabname
CHANGING
ct_fieldcat = lt_fieldcat[]
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
lt_fieldcat_1[] = lt_fieldcat[].
LOOP AT lt_fieldcat INTO ls_fieldcat.
l_tabix = sy-tabix .
DESCRIBE TABLE it_return2 LINES lv_nooflines.
IF lv_nooflines GT 0.
READ TABLE it_return2 TRANSPORTING NO FIELDS WITH KEY fieldval = ls_fieldcat-fieldname.
IF sy-subrc NE 0.
DELETE lt_fieldcat WHERE fieldname = ls_fieldcat-fieldname.
ELSE.
* wa_filter-flag = l_tabix .
* MODIFY it_filter FROM wa_filter INDEX sy-tabix TRANSPORTING flag .
ENDIF.
ENDIF.
CLEAR: ls_fieldcat,l_tabix.
ENDLOOP.
CLEAR: gs_excel.
LOOP AT lt_fieldcat INTO ls_fieldcat.
IF pi_skipmandt = 'X' AND
sy-tabix = 1.
CONTINUE.
ENDIF.
IF ls_fieldcat-reptext_ddic IS INITIAL.
ls_fieldcat-reptext_ddic = ls_fieldcat-fieldname.
ELSE.
CONCATENATE ls_fieldcat-fieldname '-'
ls_fieldcat-reptext_ddic
INTO ls_fieldcat-reptext_ddic.
ENDIF.
IF gs_excel-line IS NOT INITIAL.
CONCATENATE gs_excel-line ls_fieldcat-reptext_ddic
INTO gs_excel-line
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
ELSE.
gs_excel-line = ls_fieldcat-reptext_ddic.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM. " GET_HEADER_LINE2
No comments:
Post a Comment