Vous êtes sur la page 1sur 19

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

--------------*
*& Report ZSALES_3
*&
*&-------------------------------------------------------
--------------*
*&
*&
*&-------------------------------------------------------
--------------*

REPORT zsales_3.

*"Table declarations.....................................
.........................
TABLES: likp, vbak. " SD Document: Delivery Header Data
*"Selection Screen Elements..............................
.......................
SELECT-OPTIONS:
s_vkorg FOR vbak-vkorg, " Sales organisation
s_dldate FOR likp-lfdat. " Delivery Date
*"-------------------------------------------------------
-------------------------------*
* Type declaration of the structure to hold specified del
ivery header data *
*"-------------------------------------------------------
--------------------------------*
TYPES :
BEGIN OF type_s_likp,
vbeln TYPE likp-vbeln, " Delivery
lfdat TYPE likp-lfdat, " Delivery Date
kunnr TYPE likp-kunnr, " Ship-to party
END OF type_s_likp.
*"-------------------------------------------------------
--------------------------------*
* Type declaration of the structure to hold specified del
ivery item data *
*"-------------------------------------------------------
--------------------------------*
TYPES :
BEGIN OF type_s_lips,
vbeln TYPE lips-vbeln, " Delivery
posnr TYPE lips-posnr, " Delivery Item
vgbel TYPE lips-
vgbel, " Document number of the reference document
vgpos TYPE lips-
vgpos, " Item number of the reference item
lfimg TYPE lips-
lfimg, " Actual quantity delivered (insales units)
vrkme TYPE lips-vrkme, " Sales unit
END OF type_s_lips.
*"-------------------------------------------------------
-------------------------------*
* Type declaration of the structure to hold specified dat
a in Customer Master *
*"-------------------------------------------------------
--------------------------------*
TYPES :
BEGIN OF type_s_kna1,
kunnr TYPE kna1-kunnr, " Customer Number 1
name1 TYPE kna1-
name1, " Name 1
END OF type_s_kna1.
*" Type declarations.....................................
.....................................
*"-------------------------------------------------------
-----------------------------------------*
* Type declaration of the structure to hold specified sal
es document header data *
*"-------------------------------------------------------
-----------------------------------------*
TYPES :
BEGIN OF type_s_vbak,
vbeln TYPE vbak-vbeln, " Sales Document
erdat TYPE vbak-
erdat, " Date on Which Record Was Created
aufnr TYPE vbak-aufnr, " Order Number
END OF type_s_vbak.
*"-------------------------------------------------------
---------------------------------------*
* Type declaration of the structure to hold specified sal
es document item data *
*"-------------------------------------------------------
--------------------------------------*
TYPES :
BEGIN OF type_s_vbap,
vbeln TYPE vbak-vbeln, " Sales Document
posnr TYPE vbap-posnr, " Sales Document Item
matnr TYPE vbap-matnr, " Material Number
arktx TYPE vbap-arktx, " Short text for sales orderitem
kwmeng TYPE vbap-
kwmeng, " Cumulative Order Quantity in sales Units
vrkme TYPE vbap-vrkme, " Sales unit
END OF type_s_vbap.
*"-------------------------------------------------------
-------------------------------------*
* Type declaration of the structure to hold specified bil
ling item data *
*"-------------------------------------------------------
-------------------------------------*
TYPES :
BEGIN OF type_s_vbrp,
vbeln TYPE vbrp-vbeln, " Billing Document
posnr TYPE vbrp-posnr, " Billing item
vgbel TYPE vbrp-
vgbel, " Document number of the reference document
vgpos TYPE vbrp-
vgpos, " Item number of the reference item
fklmg TYPE vbrp-
fklmg, " Billing quantity in stockkeeping unit
vrkme TYPE vbrp-vrkme, " Sales unit
END OF type_s_vbrp.
*"-------------------------------------------------------
------------------------------------*
* Type declaration of the structure to hold specified sal
es socument *
* header,sales document item data,delivery item data,bill
ing item data *
*"-------------------------------------------------------
------------------------------------*
TYPES:
BEGIN OF type_s_order,
vbeln TYPE vbap-vbeln, " Sales Document
posnr TYPE vbap-posnr, " Sales Document Item
erdat TYPE vbak-erdat, " Date on Which Record Was Created
kunnr TYPE likp-kunnr, " Sold-to party
name1 TYPE kna1-
name1, " Name 1
aufnr TYPE vbak-aufnr, " Order Number
matnr TYPE vbap-matnr, " Material Number
arktx TYPE vbap-arktx, " Short text for sales orderitem
kwmeng TYPE vbap-
kwmeng, " Cumulative Order Quantity in sales Units
vrkme TYPE vbap-vrkme, " Sales unit
vbeln1 TYPE lips-vbeln, " Delivery
posnr1 TYPE lips-posnr, " Delivery Item
lfimg TYPE lips-
lfimg, " Actual quantity delivered in sales units
vrkme1 TYPE lips-vrkme, " Sales unit
vbeln2 TYPE vbrp-vbeln, " Billing Document
posnr2 TYPE vbrp-posnr, " Billing item
fklmg TYPE vbrp-
fklmg, " Billing quantity in stockkeeping unit
vrkme2 TYPE vbrp-vrkme, " Sales unit
END OF type_s_order.
*" Data declarations.....................................
.................................
*"-------------------------------------------------------
------------------------------------*
* Work variables

*
*"-------------------------------------------------------
------------------------------------*
DATA :
w_container TYPE REF TO cl_gui_custom_container," Referen
ce variable for

"container
w_grid TYPE REF TO cl_gui_alv_grid. " Reference variable
for grid
*" Field String declarations.............................
.................................
*"-------------------------------------------------------
-----------------------------------*
* Field string variable to hold sales socument header,sal
es document *
* item data,delivery item data,billing item data,fieldcat
alog,layout record *
*"-------------------------------------------------------
------------- --------------------*
DATA :
fs_kna1 TYPE type_s_kna1, " Holds Customer master record
fs_vbak TYPE type_s_vbak, " Holds sales header record
fs_vbap TYPE type_s_vbap, " Holds sales item record
fs_likp TYPE type_s_likp, " Holds delivery header record
fs_lips TYPE type_s_lips, " Holds delivery item record
fs_vbrp TYPE type_s_vbrp, " Holds billing item record
fs_order TYPE type_s_order, " Holds sales order record
fs_cat TYPE lvc_s_fcat, " Holds fieldcatalog record
fs_lay TYPE lvc_s_layo. " Holds layout record

*" Internal Table declarations...........................


................................
**"------------------------------------------------------
-----------------------------------*
** Internal Table to hold hold sales socument header,sale
s document *
* item data,delivery item data,billing item data,fieldcat
alog,layout records *
**"------------------------------------------------------
-------------------------------------*
DATA :
t_kna1 LIKE STANDARD TABLE OF fs_kna1, " Internal table t
o hold customer master records
t_vbak LIKE STANDARD TABLE OF fs_vbak, " Internal table t
o hold sales header records
t_vbap LIKE STANDARD TABLE OF fs_vbap, " Internal table t
o hold sales item records
t_likp LIKE STANDARD TABLE OF fs_likp, " Internal table t
o hold delivery header records
t_lips LIKE STANDARD TABLE OF fs_lips, " Internal table t
o hold delivery item records
t_vbrp LIKE STANDARD TABLE OF fs_vbrp, " Internal table t
o hold billing item records
t_order LIKE STANDARD TABLE OF fs_order, " Internal table
to hold sales order records
t_cat TYPE lvc_t_fcat. " Internal table to hold field
FIELD-SYMBOLS <fs_order> TYPE type_s_order.
DATA:
p_file TYPE rlgrap-filename,
p_path TYPE rlgrap-filename.

*PARAMETERS : a_file like p_file.


PARAMETERS : a_file TYPE IBIPPARMS-PATH.

p_file = a_file.
" catalog records
*"-------------------------------------------------------
-----------------------------------------*
* AT SELECTION-SCREEN EVENT *
*"-------------------------------------------------------
-----------------------------------------*
AT SELECTION-SCREEN .
PERFORM check_for_initial.
*"-------------------------------------------------------
-------------------------------------------*
* AT SELECTION-SCREEN ON S_DELDOC EVENT *
*"-------------------------------------------------------
-------------------------------------------*
AT SELECTION-SCREEN ON s_vkorg.
PERFORM check_sales_org.
*"-------------------------------------------------------
------------------------------------------*
* AT SELECTION-SCREEN ON S_DLDATE EVENT *
*"-------------------------------------------------------
-----------------------------------------*
AT SELECTION-SCREEN ON s_dldate.
PERFORM check_delivery_date.
*"-------------------------------------------------------
------------------------------------------*
* AT SELECTION-SCREEN ON A_FILE EVENT *
*"-------------------------------------------------------
-----------------------------------------*
AT SELECTION-SCREEN ON VALUE-REQUEST FOR a_file.
PERFORM appln_ser_path.
*"-------------------------------------------------------
-----------------------------------------*
* START-OF-SELECTION EVENT *
*"-------------------------------------------------------
------------------------------------------*
START-OF-SELECTION.
PERFORM data_selection.
PERFORM upload_file.
*&amp;---------------------------------------------------
-----------------------------------------------*
*&amp; Form DATA_SELECTION
*&amp;---------------------------------------------------
------------------*
* This subroutine is used to select required fields from
sales header,
* sales item,delivery header,delivery item ,customer mast
er tables
*--------------------------------------------------------
--------------*
* There are no interface parameters to be passed to this
subroutine
*--------------------------------------------------------
--------------*
FORM data_selection .
* Get delivery document number,delivery date,customer num
ber from
* delivery header table
SELECT vbeln " Delivery
lfdat " Delivery Date
kunnr " Customer Number 1
FROM likp
INTO TABLE t_likp
WHERE lfdat IN s_dldate.
IF sy-subrc EQ 0.
* Get Customer name for customer numbers from Customer ma
ster table
SELECT kunnr " Customer Number 1
name1
" Name 1
FROM kna1
INTO TABLE t_kna1
FOR ALL ENTRIES IN t_likp
WHERE kunnr EQ t_likp-kunnr.
IF sy-subrc EQ 0.
* Get delivery item number,sales document number,sales it
em number,
* delivery quantity from delivery item table
SELECT vbeln " Delivery
posnr " Delivery Item
vgbel " Document number of
" reference document
vgpos " Item number of reference item
lfimg " Actual quantity delivered
vrkme " Sales unit
FROM lips
INTO TABLE t_lips
FOR ALL ENTRIES IN t_likp
WHERE vbeln EQ t_likp-vbeln.
IF sy-subrc EQ 0.
* Get sales document number,item number,material,material
description,
* ordered quantity from sales item table
SELECT vbeln " Sales Document
posnr " Sales Document Item
matnr " Material Number
arktx " Short text for sales order
" item
kwmeng " Cumulative Order Quantity
vrkme " Sales unit
FROM vbap
INTO TABLE t_vbap
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel
AND posnr EQ t_lips-vgpos.
IF sy-subrc EQ 0.
* Get sales document number ,created date,purchase order
number from
* sales header table
SELECT vbeln " Sales Document
erdat " Date on Which Record Was " Created
aufnr " Order Number
FROM vbak
INTO TABLE t_vbak
FOR ALL ENTRIES IN t_lips
WHERE vbeln EQ t_lips-vgbel
AND vkorg in s_vkorg.
IF sy-subrc EQ 0.
* * GET BILLING DOCUMENT NUMBER,BILLING ITEM,
REFERENCE DELIVERY DOCUMENT
* number,delivery item number,billing item from billing i
tem table
SELECT vbeln " Billing Document
posnr " Billing item
vgbel " Document number of the
" reference document
vgpos " Item number of the
" reference
" item
fklmg " Billing quantity in
" stockkeeping unit
vrkme " Sales unit
FROM vbrp
INTO TABLE t_vbrp
FOR ALL ENTRIES IN t_lips
WHERE vgbel EQ t_lips-vbeln
AND vgpos EQ t_lips-posnr.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ELSE.
* Display message if records are not found for entered va
lues
MESSAGE 'No Records found' TYPE 'I'.
EXIT.
ENDIF. " IF SY-SUBRC EQ 0
* Looping Delivery item internal table to assign values t
o order
* internal table
LOOP AT t_lips INTO fs_lips.
* Get delivery date and customer number for delivery docu
ment number
* from delivery header internal table
READ TABLE t_likp WITH KEY vbeln = fs_lips-vbeln
INTO fs_likp.
* Get customer name for customer number from customer mas
ter internal
* table
IF sy-subrc EQ 0.
READ TABLE t_kna1 WITH KEY kunnr = fs_likp-kunnr
INTO fs_kna1.
* Get sales document number,item number,ordered quantity
for delivery
* document number,item number from sales item internal ta
ble
IF sy-subrc EQ 0.
READ TABLE t_vbap WITH KEY vbeln = fs_lips-vgbel
posnr = fs_lips-vgpos INTO fs_vbap.
* Get goods issue date and purchase order number for sale
s document
* number from sales header internal table
IF sy-subrc EQ 0.
READ TABLE t_vbak WITH KEY vbeln = fs_vbap-
vbeln INTO fs_vbak.
IF sy-subrc EQ 0.
* Get billing document number,billing item,billing quanti
ty for delivery
* document number,delivery item number from billing item
internal table
READ TABLE t_vbrp WITH KEY vgbel = fs_lips-
vbeln
vgpos = fs_lips-posnr INTO
fs_vbrp.
* Assign sales,delivery,billing fields into respective fi
elds of sales
* order internal table
IF sy-subrc EQ 0.
fs_order-vbeln = fs_vbap-vbeln.
fs_order-posnr = fs_vbap-posnr.
fs_order-erdat = fs_vbak-erdat.
fs_order-kunnr = fs_likp-kunnr.
fs_order-name1 = fs_kna1-name1.
fs_order-aufnr = fs_vbak-aufnr.
fs_order-matnr = fs_vbap-matnr.
fs_order-arktx = fs_vbap-arktx.
fs_order-kwmeng = fs_vbap-kwmeng.
fs_order-vrkme = fs_vbap-vrkme.
fs_order-vbeln1 = fs_lips-vbeln.
fs_order-posnr1 = fs_lips-posnr.
fs_order-lfimg = fs_lips-lfimg.
fs_order-vrkme1 = fs_lips-vrkme.
fs_order-vbeln2 = fs_vbrp-vbeln.
fs_order-posnr2 = fs_vbrp-posnr.
fs_order-fklmg = fs_vbrp-fklmg.
fs_order-vrkme2 = fs_vbrp-vrkme.
APPEND fs_order TO t_order.
CLEAR fs_order.
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
ENDLOOP. " LOOP AT T_LIPS INTO FS_LIPS
* Check if the final table is initia
IF t_order IS INITIAL.
MESSAGE 'No Data Found' TYPE 'I'.
EXIT.
ELSE.
* Calling screen to display the sales order records
CALL SCREEN 1500.
ENDIF. " IF T_ORDER IS INITIAL
ENDFORM. " DATA_SELECTION
*&amp;---------------------------------------------------
------------------*
*&amp; Form CHECK_FOR_INITIAL
*&amp;---------------------------------------------------
------------------*
* This subroutine is used to validate selection screen el
ements
*--------------------------------------------------------
--------------*
* There are no interface parameters to be passed to this
subroutine
*--------------------------------------------------------
--------------*
FORM check_for_initial .
* Check if either sales Org and delivery date is not
* entered
IF s_vkorg IS INITIAL AND s_dldate IS INITIAL.
MESSAGE 'Please provide input' TYPE 'E' DISPLAY LIKE
'S'.
ENDIF. " IF S_DELDOC IS INITIAL AND....
ENDFORM. " CHECK_FOR_INITIAL
*&amp;---------------------------------------------------
------------------*
*&amp; Form check_sales_org
*&amp;---------------------------------------------------
------------------*
* This subroutine is used to perform validation on Sales
organisation
*
*--------------------------------------------------------
--------------*
* There are no interface parameters to be passed to this
subroutine
*--------------------------------------------------------
--------------*
FORM check_sales_org .
* Check if high value is entered without lowvalue
IF s_vkorg-low IS INITIAL AND s_vkorg-
high IS NOT INITIAL.
MESSAGE 'Mandatory' TYPE 'E' DISPLAY LIKE 'S'.
ELSE.
DATA: vkorg TYPE vbak-vkorg.

SELECT SINGLE vkorg


FROM tvko
INTO vkorg
WHERE vkorg IN s_vkorg.

IF sy-subrc <> 0.
MESSAGE 'Sales Org is not Valid' TYPE 'E'.
ENDIF.
ENDIF.
ENDFORM. " CHECK_DELIVERY_DOCUMENT
*&amp;---------------------------------------------------
------------------*
*&amp; Form CHECK_DELIVERY_DATE
*&amp;---------------------------------------------------
------------------*
* This subroutine is used to perform validation on goods
issue date
*--------------------------------------------------------
--------------*
* There are no interface parameters to be passed to this
subroutine
*--------------------------------------------------------
--------------*
FORM check_delivery_date .
* Check if high value is entered without lowvalue
IF s_dldate-low IS INITIAL AND s_dldate-
high IS NOT INITIAL.
MESSAGE 'Please provide the input' TYPE 'E' DISPLAY L
IKE 'S'.
ELSE.
* Check if delivery date is in delivery header table
SELECT lfdat " Date on which record is created
FROM likp
UP TO 1 ROWS
INTO fs_likp-lfdat
WHERE lfdat IN s_dldate.
ENDSELECT.
CLEAR fs_likp.
* Displays message if there is no record for entered deli
very date
IF sy-subrc NE 0.
MESSAGE 'Data not found in the range ' TYPE 'E' DIS
PLAY LIKE 'S'.
ENDIF. " IF SY_SUBC NE 0
ENDIF. " IF S_DLDATE-LOW IS INITIAL...
ENDFORM. " CHECK_DELIVERY_DATE
*&amp;---------------------------------------------------
------------------*
*&amp; Module STATUS_1500 OUTPUT
*&amp;---------------------------------------------------
------------------*
* This module is used to hold pfstatus for the ALV list d
isplay
*--------------------------------------------------------
--------------*
MODULE status_1500 OUTPUT.
* Holds pf-status for the screen 1500
SET PF-STATUS 'SALES_ORDER'.
* Assigns title to the list output
SET TITLEBAR 'SALES'.
ENDMODULE. " STATUS_1500 OUTPUT
*&-------------------------------------------------------
--------------*
*& Module USER_COMMAND_1500 INPUT
*&-------------------------------------------------------
--------------*
* This module is used to hold user command for screen nav
igation
*--------------------------------------------------------
--------------*
MODULE user_command_1500 INPUT.
* Navigates screen on back,exit,return user commands
CASE sy-ucomm.
WHEN 'BACK' OR '%EX' OR 'RW'.
SET SCREEN '0'.
ENDCASE. " CASE SY-UCOMM
ENDMODULE. " USER_COMMAND_1500 INPUT
*&-------------------------------------------------------
--------------*
*& Module SALES_DISPLAY OUTPUT
*&-------------------------------------------------------
--------------*
* This module is used to populate fieldcatalogue and layo
ut and *
* create container and grid and call method of grid to di
splay sales *
* order *
*--------------------------------------------------------
--------------*
MODULE sales_display OUTPUT.
* Calling subroutine to populate values into fieldcatalog
ue
PERFORM pop_fcat USING 'VBELN'(006) 'Sales Doc.'(007) '
1' .
PERFORM pop_fcat USING 'POSNR'(008) 'Item'(009) '2' .
PERFORM pop_fcat USING 'ERDAT'(010) 'Goods Issue'(011)
'3' .
PERFORM pop_fcat USING 'KUNNR'(012) 'Sold-
to Party'(013) '4' .
PERFORM pop_fcat USING 'NAME1'(014) 'Sold-
to Desciption'(015) '5' .
PERFORM pop_fcat USING 'AUFNR'(016) 'Purchase Order No.
'(017) '6' .
PERFORM pop_fcat USING 'MATNR'(018) 'Material'(019) '7'
.
PERFORM pop_fcat USING 'ARTKX'(020) 'Material Descripti
on'(021) '8'.
PERFORM pop_fcat USING 'KWMENG'(022) 'Ordered Quantity'
(023) '9' .
PERFORM pop_fcat USING 'VRKME'(024) 'Sales Unit'(025) '
10' .
PERFORM pop_fcat USING 'VBELN1'(026) 'Delivery Doc. No.
'(027) '11' .
PERFORM pop_fcat USING 'POSNR1'(028) 'Delivery Item '(0
29) '12' .
PERFORM pop_fcat USING 'LFIMG'(030) 'Delivery Quantity'
(031) '13' .
PERFORM pop_fcat USING 'VRKME1'(032) 'Sales Unit'(025)
'14' .
PERFORM pop_fcat USING 'VBELN2'(033) 'Billing doc. No.'
(034) '15' .
PERFORM pop_fcat USING 'POSNR2'(035) 'Billing Item'(036
) '16' .
PERFORM pop_fcat USING 'FKLMG'(037) 'Billing Quantity'(
038) '17' .
PERFORM pop_fcat USING 'VRKME2'(039) 'Sales Unit'(025)
'18' .
* Assigning title of layout
fs_lay-
grid_title = 'List to display sales order details'(040).
* Creating container for displaying records
CREATE OBJECT w_container
EXPORTING
* parent =
container_name = 'CCONTAINER'.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Creating grid for the container
CREATE OBJECT w_grid
EXPORTING
* i_shellstyle = 0
* i_lifetime =
i_parent = w_container.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY_SUBRC NE 0
* Calling method of grid to display table contents
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
i_structure_name = 'FS_ORDER'
is_layout = fs_lay
CHANGING
it_outtab = t_order
it_fieldcatalog = t_cat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. " IF SY_SUBRC NE 0
ENDMODULE. " SALES_DISPLAY OUTPUT
*&amp;---------------------------------------------------
------------------*
*&amp; Form POP_FCAT
*&amp;---------------------------------------------------
------------------*
* This subroutine is used to populate fieldcatalogue for
required
* fields
*--------------------------------------------------------
--------------*
* -->P_FNAME Holds fieldname
* -->P_CTEXT Holds column text
* -->P_CPOS Holds column position
*--------------------------------------------------------
--------------*
FORM pop_fcat USING VALUE(p_fname) TYPE c
VALUE(p_ctext) TYPE c
VALUE(p_cpos) TYPE i.
* Assigning fieldname,column text,column position to fiel
d catalog
fs_cat-fieldname = p_fname.
fs_cat-coltext = p_ctext.
fs_cat-col_pos = p_cpos.
APPEND fs_cat TO t_cat.
CLEAR fs_cat.
ENDFORM. " POP_FCAT
*&-------------------------------------------------------
--------------*
*& Form UPLOAD_FILE
*&-------------------------------------------------------
--------------*
* text
*--------------------------------------------------------
--------------*
* --> p1 text
* <-- p2 text
*--------------------------------------------------------
--------------*
FORM upload_file .

**& Path for the Application Server to drop the file


* CALL FUNCTION '/SAPDMC/LSM_F4_SERVER_FILE'
* IMPORTING
* serverfile = p_file
* EXCEPTIONS
* canceled_by_user = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
* MESSAGE 'Error Message' TYPE 'I'.
* ENDIF.

CONSTANTS: l_backslash TYPE char1 VALUE '\',

l_frontslash TYPE char1 VALUE '/',


l_excelextn TYPE char4 VALUE 'xls'.
CONCATENATE p_file l_backslash sy-datum sy-
uzeit l_excelextn INTO p_file.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'


EXPORTING
* i_field_seperator = ld_i_field_seperator
* i_line_header = ld_i_line_header
i_filename = p_file
* i_appl_keep = ld_i_appl_keep
TABLES
i_tab_sap_data = t_order
* CHANGING
* i_tab_converted_data = ld_i_tab_converted_dat
a
EXCEPTIONS
conversion_failed = 1. " SAP_CONVERT_TO_XLS_FORMAT
.
IF sy-subrc NE 0.
MESSAGE ' Unable to open file' TYPE 'I'.
ELSE.
CONCATENATE p_file l_frontslash sy-datum sy-
uzeit l_excelextn INTO p_file.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING
DEFAULT.
IF sy-subrc NE 0.
MESSAGE 'Unable to open file' TYPE 'I'.
ENDIF.
ENDIF.
LOOP AT T_ORDER ASSIGNING <fs_order>.
TRANSFER <fs_order> TO p_file.
ENDLOOP.
CLOSE DATASET p_file.
ENDFORM. " UPLOAD_FILE
*&-------------------------------------------------------
--------------*
*& Form APPLN_SER_PATH
*&-------------------------------------------------------
--------------*
* text
*--------------------------------------------------------
--------------*
* --> p1 text
* <-- p2 text
*--------------------------------------------------------
--------------*
FORM appln_ser_path .
CALL FUNCTION 'F4_FILENAME_SERVER'
EXPORTING
pfad = a_file
* IMPORTING
* FILE_NAME =
* EXCEPTIONS
* NO_FILE_ON_SERVER = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " APPLN_SER_PATH

Vous aimerez peut-être aussi