*&---------------------------------------------------------------------*
*& REPORT ZEPB008
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZEPB008.
DATA: BEGIN OF GT_APLZL OCCURS 0,
LTXA2 LIKE AFVC-LTXA1,
LTXA1 LIKE AFVC-LTXA1,
APLZL LIKE AFVC-APLZL,
AUFPL LIKE AFVC-AUFPL,
ANLZU LIKE AFVC-ANLZU,
NUMBE(4) ,
SUM_VERPR LIKE MBEW-VERPR,
END OF GT_APLZL.
DATA: BEGIN OF GT_APLZL2 OCCURS 0,
APLZL LIKE AFVC-APLZL,
LTXA2 LIKE AFVC-LTXA1,
LTXA1 LIKE AFVC-LTXA1,
AUFPL LIKE AFVC-AUFPL,
ANLZU LIKE AFVC-ANLZU,
NUMBE(4) ,
SUM_VERPR LIKE MBEW-VERPR,
END OF GT_APLZL2.
DATA: G_APLZL LIKE AFVC-APLZL,
G_LTXA1 LIKE AFVC-LTXA1.
DATA: BEGIN OF GT_MATNR OCCURS 0,
MATNR(19) TYPE C,
MAKTX LIKE ZEPTM003-MAKTX,
MEINS LIKE RESB-MEINS,
BDMNG LIKE RESB-BDMNG,
APLZL LIKE AFVC-APLZL,
ZLINE TYPE TDLINE,
RSNUM LIKE RESB-RSNUM,
RSPOS LIKE RESB-RSPOS,
VERPR LIKE MBEW-VERPR,
SUM_VERPR LIKE MBEW-VERPR,
MSEHL LIKE T006A-MSEHL,
ABLAD LIKE RESB-ABLAD,
LGORT LIKE RESB-LGORT,
END OF GT_MATNR.
DATA: TDLINES TYPE TLINE OCCURS 0 WITH HEADER LINE.
DATA: ZNAME LIKE THEAD-TDNAME.
DATA: G_GNXYQ TYPE STRING.
DATA: G_BGNX TYPE STRING.
DATA: G_BGNX2 TYPE STRING.
DATA: G_GCZJE TYPE STRING.
DATA: G_GCZJE_BIG TYPE STRING.
DATA: ROW_INDEX TYPE I.
DATA: BEGIN OF GT_NUMBE OCCURS 0,
NUMBE(6) TYPE C,
END OF GT_NUMBE.
DATA: G_IND TYPE I VALUE 0,
G_SIN_NUM TYPE I,
G_DACH(3) TYPE C.
DATA: GR_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: GR_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
GR_CONTROL TYPE REF TO I_OI_CONTAINER_CONTROL,
GR_DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,
GR_SPREADSHEET TYPE REF TO I_OI_SPREADSHEET,
GR_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
* BUSINESS DOCUMENT SYSTEM
DATA: GR_BDS_DOCUMENTS TYPE REF TO CL_BDS_DOCUMENT_SET,
G_CLASSNAME TYPE SBDST_CLASSNAME,
G_CLASSTYPE TYPE SBDST_CLASSTYPE,
G_OBJECTKEY TYPE SBDST_OBJECT_KEY,
G_DOC_COMPONENTS TYPE SBDST_COMPONENTS,
G_DOC_SIGNATURE TYPE SBDST_SIGNATURE.
* TEMPLATE URL
DATA: GT_BDS_URIS TYPE SBDST_URI,
GS_BDS_URL LIKE LINE OF GT_BDS_URIS,
G_TEMPLATE_URL(256) TYPE C.
DATA: G_OBJNR TYPE J_OBJNR,
G_A6 TYPE STRING,
G_A5 TYPE STRING,
G_A4 TYPE STRING,
G_A3 TYPE STRING,
G_A2 TYPE STRING,
G_A1 TYPE STRING,
G_NACHN LIKE PA0002-NACHN,
G_VORNA LIKE PA0002-VORNA,
G_WERKS LIKE CAUFV-WERKS,
G_ADDROW(3) TYPE C VALUE 9,
G_ADDROW2 TYPE I,
G_IPHAS LIKE AFIH-IPHAS,
G_TABIX TYPE SY-TABIX..
DATA: GT_RANGES TYPE SOI_RANGE_LIST,
GS_RANGE TYPE SOI_RANGE_ITEM,
GT_CONTENTS TYPE SOI_GENERIC_TABLE,
GS_CONTENT TYPE SOI_GENERIC_ITEM.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
DATA: G_ILEN TYPE I.
DATA: G_SUM_VEPRP LIKE MBEW-VERPR.
DATA: G_TAX LIKE MBEW-VERPR VALUE 0.
DATA: G_SUM_MONEY LIKE MBEW-VERPR VALUE 0.
DATA: BEGIN OF WA_ZEP,
AUFNR TYPE CAUFV-AUFNR,
ERDAT TYPE CAUFV-ERDAT,
ATTACH(10) TYPE C,
ERNAM TYPE CAUFV-ERNAM,
KTEXT TYPE CAUFV-KTEXT,
WERKS TYPE CAUFV-WERKS,
MATNR TYPE RESB-MATNR,
RSPOS TYPE RESB-RSPOS,
LTXA1 TYPE AFVC-LTXA1,
VORNR TYPE AFVC-VORNR,
BDMNG TYPE RESB-BDMNG,
MEINS TYPE RESB-MEINS,
VERPR TYPE MBEW-VERPR,
NETWR TYPE EKPO-NETWR,
MAKTX TYPE ZEPTM003-MAKTX,
RSNUM TYPE RESB-RSNUM,
ZLINE TYPE TDLINE,
ANLZU TYPE AFVC-ANLZU,
END OF WA_ZEP.
DATA:ITAB_ZEP LIKE TABLE OF WA_ZEP.
DATA:G_GLLR TYPE EKPO-NETWR.
DATA:G_GLLR2 TYPE EKPO-NETWR.
DATA:G_UNAME TYPE SY-UNAME.
DATA: G_NETWR TYPE EKPO-NETWR,
G_VALUE TYPE F.
DEFINE WRITE_CONTENT_CELL.
GS_CONTENT-ROW = &1.
GS_CONTENT-COLUMN = &2.
GS_CONTENT-VALUE = &3.
APPEND GS_CONTENT TO GT_CONTENTS.
CLEAR GS_CONTENT.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK T1 WITH FRAME TITLE X1.
PARAMETERS : P_AUFNR LIKE CAUFV-AUFNR.
SELECTION-SCREEN END OF BLOCK T1.
AT SELECTION-SCREEN .
SELECT SINGLE IPHAS FROM AFIH
INTO G_IPHAS
WHERE AUFNR = P_AUFNR.
IF G_IPHAS <> 2.
MESSAGE E000(ZEP_CE) WITH '訂單未核發,無法列印'.
ENDIF.
INITIALIZATION.
X1 = '查詢條件'.
G_CLASSNAME = 'HRFPM_EXCEL_STANDARD'.
G_CLASSTYPE = 'OT'.
" G_OBJECTKEY = 'DOI_EXCEL'.
START-OF-SELECTION.
SELECT T2~APLZL T2~LTXA1 T2~ANLZU T2~AUFPL
INTO CORRESPONDING FIELDS OF TABLE GT_APLZL
FROM CAUFV AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
WHERE AUFNR = P_AUFNR.
CLEAR:G_NETWR,G_GLLR,G_GLLR2,G_UNAME,ITAB_ZEP,ITAB_ZEP[].
SELECT T1~AUFNR T1~ERDAT T1~ERNAM T1~KTEXT T2~MATNR T2~RSPOS T3~LTXA1 T3~VORNR T1~WERKS T2~BDMNG T2~MEINS T2~RSNUM T2~GPREIS AS VERPR T3~ANLZU
INTO CORRESPONDING FIELDS OF TABLE ITAB_ZEP
FROM CAUFV AS T1
JOIN RESB AS T2
ON T1~AUFNR = T2~AUFNR
JOIN AFVC AS T3
ON T2~AUFPL = T3~AUFPL
AND T2~APLZL = T3~APLZL
WHERE T2~XLOEK <> 'X'
AND T1~AUFNR = P_AUFNR.
LOOP AT ITAB_ZEP INTO WA_ZEP.
IF WA_ZEP-ANLZU = 0 AND WA_ZEP-ANLZU IS NOT INITIAL.
G_GLLR = WA_ZEP-BDMNG.
ENDIF.
IF WA_ZEP-VERPR IS INITIAL.
SELECT SINGLE VERPR
INTO WA_ZEP-VERPR
FROM MBEW
WHERE MATNR = WA_ZEP-MATNR
AND BWKEY = WA_ZEP-WERKS.
ENDIF.
IF WA_ZEP-MATNR IS INITIAL AND WA_ZEP-MEINS = '%' AND WA_ZEP-ANLZU IS INITIAL.
G_GLLR2 = WA_ZEP-BDMNG + G_GLLR2.
ENDIF.
WA_ZEP-NETWR = WA_ZEP-VERPR * WA_ZEP-BDMNG.
G_NETWR = WA_ZEP-NETWR + G_NETWR.
ENDLOOP.
G_GLLR = G_GLLR + G_GLLR2.
G_NETWR = G_NETWR * G_GLLR / 100 + G_NETWR .
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*& Form MAIN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM MAIN.
PERFORM GET_CONTAINER.
PERFORM CREATE_CONTAINER_CONTROL.
IF G_NETWR < 300000.
*-------小於30萬
G_OBJECTKEY = 'DOI_EXCEL'.
PERFORM GET_TEMPLATE_URL.
PERFORM OPEN_EXCEL_DOC.
PERFORM WRITE_DATA_TO_EXCEL_LT_30WAN.
ELSE.
*-------大於30萬
G_OBJECTKEY = 'DOI_EXCEL2'.
PERFORM GET_TEMPLATE_URL.
PERFORM OPEN_EXCEL_DOC.
PERFORM WRITE_DATA_TO_EXCEL_GT_30WAN.
ENDIF.
ENDFORM. "MAIN
*&---------------------------------------------------------------------*
*& MODULE STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
SET PF-STATUS '2000'.
CASE SY-UCOMM.
WHEN 'EXIT' OR 'BACK' OR 'CANCEL'.
IF NOT GR_DOCUMENT IS INITIAL.
CALL METHOD GR_DOCUMENT->CLOSE_DOCUMENT.
FREE GR_DOCUMENT.
ENDIF.
IF NOT GR_CONTROL IS INITIAL.
CALL METHOD GR_CONTROL->DESTROY_CONTROL.
FREE GR_CONTROL.
ENDIF.
IF GR_CONTAINER IS NOT INITIAL.
CALL METHOD GR_CONTAINER->FREE.
ENDIF.
LEAVE PROGRAM.
WHEN 'SAVE'.
PERFORM SAVE_EXCEL.
ENDCASE.
PERFORM MAIN.
ENDMODULE. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& MODULE USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT' OR 'BACK' OR 'CANCEL'.
IF NOT GR_DOCUMENT IS INITIAL.
CALL METHOD GR_DOCUMENT->CLOSE_DOCUMENT.
FREE GR_DOCUMENT.
ENDIF.
IF NOT GR_CONTROL IS INITIAL.
CALL METHOD GR_CONTROL->DESTROY_CONTROL.
FREE GR_CONTROL.
ENDIF.
IF GR_CONTAINER IS NOT INITIAL.
CALL METHOD GR_CONTAINER->FREE.
ENDIF.
LEAVE PROGRAM.
WHEN 'SAVE'.
PERFORM SAVE_EXCEL.
ENDCASE.
ENDMODULE. " USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*& FORM GET_CONTAINER
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GET_CONTAINER .
CREATE OBJECT GR_SPLITTER
EXPORTING
PARENT = CL_GUI_CONTAINER=>SCREEN0
ROWS = 1
COLUMNS = 1.
CALL METHOD GR_SPLITTER->SET_BORDER
EXPORTING
BORDER = CL_GUI_CFW=>FALSE.
GR_CONTAINER = GR_SPLITTER->GET_CONTAINER( ROW = 1 COLUMN = 1 ).
ENDFORM. " GET_CONTAINER
*&---------------------------------------------------------------------*
*& FORM CREATE_CONTAINER_CONTROL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM CREATE_CONTAINER_CONTROL .
* CREATE CONTAINER CONTROL
CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_CONTAINER_CONTROL
IMPORTING
CONTROL = GR_CONTROL.
* INITIALIZE CONTROL
CALL METHOD GR_CONTROL->INIT_CONTROL
EXPORTING
INPLACE_ENABLED = 'X '
INPLACE_SCROLL_DOCUMENTS = 'X'
REGISTER_ON_CLOSE_EVENT = 'X'
REGISTER_ON_CUSTOM_EVENT = 'X'
R3_APPLICATION_NAME = 'DOI CREATE BY ZXK'
PARENT = GR_CONTAINER.
ENDFORM. " CREATE_CONTAINER_CONTROL
*&---------------------------------------------------------------------*
*& FORM GET_TEMPLATE_URL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GET_TEMPLATE_URL .
CREATE OBJECT GR_BDS_DOCUMENTS.
CALL METHOD CL_BDS_DOCUMENT_SET=>GET_INFO
EXPORTING
CLASSNAME = G_CLASSNAME
CLASSTYPE = G_CLASSTYPE
OBJECT_KEY = G_OBJECTKEY
CHANGING
COMPONENTS = G_DOC_COMPONENTS
SIGNATURE = G_DOC_SIGNATURE.
CALL METHOD CL_BDS_DOCUMENT_SET=>GET_WITH_URL
EXPORTING
CLASSNAME = G_CLASSNAME
CLASSTYPE = G_CLASSTYPE
OBJECT_KEY = G_OBJECTKEY
CHANGING
URIS = GT_BDS_URIS
SIGNATURE = G_DOC_SIGNATURE.
FREE GR_BDS_DOCUMENTS.
READ TABLE GT_BDS_URIS INTO GS_BDS_URL INDEX 1.
G_TEMPLATE_URL = GS_BDS_URL-URI.
ENDFORM. " GET_TEMPLATE_URL
*&---------------------------------------------------------------------*
*& FORM OPEN_EXCEL_DOC
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM OPEN_EXCEL_DOC .
CALL METHOD GR_CONTROL->GET_DOCUMENT_PROXY
EXPORTING
DOCUMENT_TYPE = 'EXCEL.SHEET'
NO_FLUSH = 'X'
REGISTER_CONTAINER = 'X'
IMPORTING
DOCUMENT_PROXY = GR_DOCUMENT.
CALL METHOD GR_DOCUMENT->OPEN_DOCUMENT
EXPORTING
OPEN_INPLACE = 'X'
DOCUMENT_URL = G_TEMPLATE_URL.
DATA: AVAILABLE TYPE I.
CALL METHOD GR_DOCUMENT->HAS_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = 'X'
IMPORTING
IS_AVAILABLE = AVAILABLE.
CALL METHOD GR_DOCUMENT->GET_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = 'X'
IMPORTING
SHEET_INTERFACE = GR_SPREADSHEET.
CALL METHOD GR_SPREADSHEET->SELECT_SHEET
EXPORTING
NAME = '(小于30万)标单及大型(大于等于30万)工程多页标单'
NO_FLUSH = 'X'.
ENDFORM. " OPEN_EXCEL_DOC
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA_TO_EXCEL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM WRITE_DATA_TO_EXCEL_LT_30WAN .
DATA: COL_COUNT TYPE I VALUE 0,
ROW_COUNT TYPE I VALUE 0.
CLEAR:G_NACHN,G_VORNA,G_WERKS,G_A1,G_A2,G_A3,G_A4,G_A5,G_A6,G_OBJNR,G_TABIX.
SELECT SINGLE NACHN VORNA
INTO (G_NACHN,G_VORNA)
FROM PA0002
JOIN CAUFV
ON PA0002~PERNR = CAUFV~ERNAM
WHERE CAUFV~AUFNR = P_AUFNR.
IF G_NACHN IS NOT INITIAL AND G_VORNA IS NOT INITIAL.
CONCATENATE '業主聯絡人:' G_NACHN G_VORNA INTO G_A5.
ELSE.
SELECT SINGLE T3~NAME_LAST
INTO G_A5
FROM CAUFV AS T1
JOIN USR21 AS T2
ON T1~ERNAM = T2~BNAME
JOIN ADRP AS T3
ON T2~PERSNUMBER = T3~PERSNUMBER
WHERE AUFNR = P_AUFNR.
CONCATENATE '業主聯絡人:' G_A5 INTO G_A5.
ENDIF.
SELECT SINGLE KTEXT
INTO G_A4
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '工程名稱:' G_A4 INTO G_A4.
SELECT SINGLE KTEXT
INTO G_A2
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '(' G_A2 ')標準標單或標單首頁' INTO G_A2.
SELECT SINGLE BUTXT
INTO G_A1
FROM CAUFV
JOIN T001
ON CAUFV~BUKRS = T001~BUKRS
WHERE AUFNR = P_AUFNR.
SELECT SINGLE WERKS
INTO G_WERKS
FROM CAUFV
WHERE AUFNR = P_AUFNR.
IF G_WERKS = 'C301' OR G_WERKS = 'C303' OR G_WERKS = 'C304' OR G_WERKS = 'C305' OR G_WERKS = 'C306' OR G_WERKS = 'C307'.
CONCATENATE '業主名稱:' G_A1 '(團結廠)' INTO G_A3.
ELSEIF G_WERKS = 'C302' OR G_WERKS = 'C308' OR G_WERKS = 'C309' OR G_WERKS = 'C310' OR G_WERKS = 'C311' OR G_WERKS = 'C312' OR G_WERKS = 'C313'.
CONCATENATE '業主名稱:' G_A1 '(芙蓉廠)' INTO G_A3.
ELSEIF G_WERKS = 'C331' OR G_WERKS = 'C332' OR G_WERKS = 'C333'.
CONCATENATE '業主名稱:' G_A1 INTO G_A3.
ENDIF.
CONCATENATE 'OR' P_AUFNR INTO G_OBJNR.
SELECT SINGLE TPLNR
INTO G_A6
FROM MCIPMIS
WHERE OBJNR = G_OBJNR.
CONCATENATE '施工地點:' G_A6 INTO G_A6.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A1_A6'
NO_FLUSH = 'X'
TOP = 1
LEFT = 1
ROWS = 6
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A1_A6'.
GS_RANGE-ROWS = 6.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 G_A1.
WRITE_CONTENT_CELL 2 1 G_A2.
WRITE_CONTENT_CELL 3 1 G_A3.
WRITE_CONTENT_CELL 4 1 G_A4.
WRITE_CONTENT_CELL 5 1 G_A5.
WRITE_CONTENT_CELL 6 1 G_A6.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDLOOP.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
CLEAR:G_SUM_VEPRP.
LOOP AT GT_MATNR.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
CLEAR:ROW_COUNT,COL_COUNT.
CLEAR:GT_MATNR,GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
PERFORM SET_NO.
LOOP AT GT_MATNR .
G_TABIX = SY-TABIX.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
CLEAR:ZNAME,TDLINES,TDLINES[].
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
CLEAR G_VALUE.
CALL FUNCTION 'EVAL_FORMULA' "將字符串運算 直接算出結果
EXPORTING
FORMULA = GT_MATNR-ABLAD
IMPORTING
VALUE = G_VALUE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF G_VALUE IS NOT INITIAL.
GT_MATNR-VERPR = GT_MATNR-VERPR * G_VALUE.
ENDIF.
G_SUM_VEPRP = G_SUM_VEPRP + GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_MATNR-SUM_VERPR = GT_MATNR-VERPR * GT_MATNR-BDMNG.
SELECT SINGLE MSEHL
INTO GT_MATNR-MSEHL
FROM T006A
WHERE MSEHI = GT_MATNR-MEINS
AND SPRAS = 'M'.
IF GT_MATNR-MATNR IS NOT INITIAL.
GT_NUMBE-NUMBE = G_TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_NUMBE-NUMBE
IMPORTING
OUTPUT = GT_NUMBE-NUMBE.
APPEND GT_NUMBE.
ENDIF.
IF GT_MATNR-MATNR IS NOT INITIAL.
CONCATENATE '' '' GT_MATNR-MATNR INTO GT_MATNR-MATNR.
ENDIF.
CONCATENATE SY-MANDT GT_MATNR-RSNUM GT_MATNR-RSPOS INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'MATK'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
LOOP AT TDLINES.
CONCATENATE GT_MATNR-ZLINE TDLINES-TDLINE INTO GT_MATNR-ZLINE.
ENDLOOP.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
DESCRIBE TABLE GT_MATNR LINES ROW_COUNT.
ENDIF.
ENDIF.
COL_COUNT = 4.
ROW_COUNT = ROW_COUNT + 1.
*---------- 調用EXCEL VBA --->新增行
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT
PARAM2 = G_ADDROW
PARAM_COUNT = 2.
G_ADDROW2 = G_ADDROW.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'B_H'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 2
ROWS = ROW_COUNT
COLUMNS = 7.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'B_H'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 7.
GS_RANGE-CODE = 7.
APPEND GS_RANGE TO GT_RANGES.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
LOOP AT GT_MATNR.
WRITE_CONTENT_CELL ROW_INDEX 1 GT_MATNR-MATNR.
WRITE_CONTENT_CELL ROW_INDEX 2 GT_MATNR-MAKTX.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL ROW_INDEX 4 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL ROW_INDEX 5 GT_MATNR-VERPR.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_MATNR-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_MATNR-ZLINE.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
ELSE.
CLEAR:G_TAX, GT_CONTENTS[].
G_TAX = GT_MATNR-BDMNG * G_SUM_VEPRP / 100.
G_SUM_MONEY = G_SUM_MONEY + G_TAX.
LOOP AT GT_MATNR.
IF GT_MATNR-MEINS = '%'.
GT_MATNR-MSEHL = '式'.
GT_MATNR-BDMNG = 1.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL 1 4 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL 1 5 G_TAX.
WRITE_CONTENT_CELL 1 6 G_TAX.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 1.
ENDIF.
ELSE.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
ENDIF.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
CLEAR:GT_CONTENTS[].
G_ADDROW = G_ADDROW + ROW_COUNT.
ENDLOOP.
CLEAR:ROW_COUNT.
CLEAR:GT_NUMBE-NUMBE.
DO 1 TIMES.
G_SIN_NUM = G_SIN_NUM + 1.
PERFORM CASENUM.
APPEND GT_NUMBE.
CLEAR:GT_NUMBE-NUMBE.
ENDDO.
DESCRIBE TABLE GT_NUMBE LINES ROW_COUNT.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A9_LAST'
NO_FLUSH = 'X'
TOP = 9
LEFT = 1
ROWS = ROW_COUNT
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A9_LAST'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
LOOP AT GT_NUMBE.
WRITE_CONTENT_CELL SY-TABIX 1 GT_NUMBE-NUMBE.
ENDLOOP.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*---------工程總金額 BEGIN
G_SUM_MONEY = G_SUM_VEPRP + G_SUM_MONEY.
CLEAR:GT_CONTENTS[].
G_GCZJE = G_SUM_MONEY.
CONCATENATE '工程金額合計:' G_GCZJE INTO G_GCZJE.
ROW_COUNT = 8 + ROW_COUNT + 1.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GCZJE.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*---------工程總金額 END
*----------工程總金額 大寫 BEGIN
CLEAR:GT_CONTENTS[].
PERFORM S2B USING G_SUM_MONEY G_GCZJE_BIG.
CONCATENATE '工程金額合計(大寫):' G_GCZJE_BIG INTO G_GCZJE_BIG.
ROW_COUNT = ROW_COUNT + 1.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE_BIG'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE_BIG'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GCZJE_BIG.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------工程總金額 大寫 END
*----------功能性要求 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 1.
IF SY-SUBRC = 0 .
CLEAR:ZNAME,TDLINES,TDLINES[],G_GNXYQ.
CONCATENATE SY-MANDT GT_APLZL-AUFPL GT_APLZL-APLZL INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'AVOT'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
READ TABLE TDLINES INDEX 2.
IF SY-SUBRC = 0.
CONCATENATE '1.功能性要求:' TDLINES-TDLINE INTO G_GNXYQ.
ENDIF.
ELSE.
ENDIF.
ROW_COUNT = ROW_COUNT + 5.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GNXYQ'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GNXYQ'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GNXYQ.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------功能性要求 END
*----------保固年限 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 2.
IF SY-SUBRC = 0.
CLEAR:GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
ENDIF.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
G_BGNX = GT_MATNR-BDMNG .
SPLIT G_BGNX AT '.' INTO G_BGNX G_BGNX2.
CONCATENATE '1.本工程采责任施工,业主无书面变更说明不得追加,验收合格后保固(' G_BGNX
')年。' INTO G_BGNX.
ENDIF.
ROW_COUNT = ROW_COUNT + 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'BGNX'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'BGNX'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_BGNX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------保固年限 BEGIN
ENDFORM. " WRITE_DATA_TO_EXCEL
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA_TO_EXCEL_GT_30WAN
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM WRITE_DATA_TO_EXCEL_GT_30WAN .
DATA: COL_COUNT TYPE I VALUE 0,
ROW_COUNT TYPE I VALUE 0,
ROW_COUNT_30 TYPE I VALUE 0,
L_FLAG TYPE C.
DATA:L_CTEXT(20).
CLEAR:G_NACHN,G_VORNA,G_WERKS,G_A1,G_A2,G_A3,G_A4,G_A5,G_A6,G_OBJNR,G_TABIX.
SELECT SINGLE NACHN VORNA
INTO (G_NACHN,G_VORNA)
FROM PA0002
JOIN CAUFV
ON PA0002~PERNR = CAUFV~ERNAM
WHERE CAUFV~AUFNR = P_AUFNR.
IF G_NACHN IS NOT INITIAL AND G_VORNA IS NOT INITIAL.
CONCATENATE '業主聯絡人:' G_NACHN G_VORNA INTO G_A5.
ELSE.
SELECT SINGLE T3~NAME_LAST
INTO G_A5
FROM CAUFV AS T1
JOIN USR21 AS T2
ON T1~ERNAM = T2~BNAME
JOIN ADRP AS T3
ON T2~PERSNUMBER = T3~PERSNUMBER
WHERE AUFNR = P_AUFNR.
CONCATENATE '業主聯絡人:' G_A5 INTO G_A5.
ENDIF.
SELECT SINGLE KTEXT
INTO G_A4
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '工程名稱:' G_A4 INTO G_A4.
SELECT SINGLE KTEXT
INTO G_A2
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '(' G_A2 ')標準標單或標單首頁' INTO G_A2.
SELECT SINGLE BUTXT
INTO G_A1
FROM CAUFV
JOIN T001
ON CAUFV~BUKRS = T001~BUKRS
WHERE AUFNR = P_AUFNR.
SELECT SINGLE WERKS
INTO G_WERKS
FROM CAUFV
WHERE AUFNR = P_AUFNR.
IF G_WERKS = 'C301' OR G_WERKS = 'C303' OR G_WERKS = 'C304' OR G_WERKS = 'C305' OR G_WERKS = 'C306' OR G_WERKS = 'C307'.
CONCATENATE '業主名稱:' G_A1 '(團結廠)' INTO G_A3.
ELSEIF G_WERKS = 'C302' OR G_WERKS = 'C308' OR G_WERKS = 'C309' OR G_WERKS = 'C310' OR G_WERKS = 'C311' OR G_WERKS = 'C312' OR G_WERKS = 'C313'.
CONCATENATE '業主名稱:' G_A1 '(芙蓉廠)' INTO G_A3.
ELSEIF G_WERKS = 'C331' OR G_WERKS = 'C332' OR G_WERKS = 'C333'.
CONCATENATE '業主名稱:' G_A1 INTO G_A3.
ENDIF.
CONCATENATE 'OR' P_AUFNR INTO G_OBJNR.
SELECT SINGLE TPLNR
INTO G_A6
FROM MCIPMIS
WHERE OBJNR = G_OBJNR.
CONCATENATE '施工地點:' G_A6 INTO G_A6.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A1_A6'
NO_FLUSH = 'X'
TOP = 2
LEFT = 1
ROWS = 4
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A1_A6'.
GS_RANGE-ROWS = 4.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
" WRITE_CONTENT_CELL 1 1 ''.
" WRITE_CONTENT_CELL 2 1 G_A2.
WRITE_CONTENT_CELL 1 1 G_A3.
WRITE_CONTENT_CELL 2 1 G_A4.
WRITE_CONTENT_CELL 3 1 G_A5.
WRITE_CONTENT_CELL 4 1 G_A6.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SPLIT GT_APLZL-LTXA1 AT '-' INTO GT_APLZL2-LTXA1 L_CTEXT.
GT_APLZL2-APLZL = GT_APLZL-APLZL.
APPEND GT_APLZL2.
ENDLOOP.
SORT GT_APLZL BY LTXA1.
SORT GT_APLZL2 BY LTXA1 APLZL.
CLEAR:G_LTXA1,G_APLZL.
LOOP AT GT_APLZL2.
IF GT_APLZL2-LTXA1 = G_LTXA1.
GT_APLZL2-APLZL = G_APLZL.
ENDIF.
G_LTXA1 = GT_APLZL2-LTXA1.
G_APLZL = GT_APLZL2-APLZL.
MODIFY GT_APLZL2.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM GT_APLZL2 .
SORT GT_APLZL BY APLZL.
SORT GT_APLZL2 BY APLZL.
DESCRIBE TABLE GT_APLZL2 LINES ROW_COUNT_30.
*---------- 調用EXCEL VBA --->新增行
*---------- 後面才能計算合計價格,先插入幾行空著,算出價格后再把這幾行貼上去
DATA:LV_I TYPE I.
DATA:LV_J TYPE I.
DATA: L_VEPRP LIKE MBEW-VERPR.
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT_30
PARAM2 = 9
PARAM_COUNT = 2.
G_ADDROW2 = ROW_COUNT_30 + 30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A_H_LAST'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 1
ROWS = ROW_COUNT_30
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A_H_LAST'.
GS_RANGE-ROWS = ROW_COUNT_30.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
LOOP AT GT_APLZL2.
CLEAR:L_VEPRP,G_GCZJE_BIG.
L_VEPRP = SY-TABIX.
PERFORM S2B USING L_VEPRP G_GCZJE_BIG.
LV_I = STRLEN( G_GCZJE_BIG ).
LV_I = LV_I - 2.
G_GCZJE_BIG = G_GCZJE_BIG+0(LV_I).
WRITE_CONTENT_CELL ROW_INDEX 1 G_GCZJE_BIG.
WRITE_CONTENT_CELL ROW_INDEX 2 '/'.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_APLZL2-LTXA1.
WRITE_CONTENT_CELL ROW_INDEX 4 ''.
WRITE_CONTENT_CELL ROW_INDEX 5 ''.
WRITE_CONTENT_CELL ROW_INDEX 6 ''.
WRITE_CONTENT_CELL ROW_INDEX 7 ''.
WRITE_CONTENT_CELL ROW_INDEX 8 ''.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------功能性要求 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 1.
IF SY-SUBRC = 0 .
CLEAR:ZNAME,TDLINES,TDLINES[],G_GNXYQ.
CONCATENATE SY-MANDT GT_APLZL-AUFPL GT_APLZL-APLZL INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'AVOT'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
READ TABLE TDLINES INDEX 2.
IF SY-SUBRC = 0.
CONCATENATE '1.功能性要求:' TDLINES-TDLINE INTO G_GNXYQ.
ENDIF.
ELSE.
ENDIF.
ROW_COUNT_30 = ROW_COUNT_30 + 14.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GNXYQ'
NO_FLUSH = 'X'
TOP = ROW_COUNT_30
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GNXYQ'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GNXYQ.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------功能性要求 END
*----------保固年限 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 2.
IF SY-SUBRC = 0.
CLEAR:GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDIF.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
G_BGNX = GT_MATNR-BDMNG .
SPLIT G_BGNX AT '.' INTO G_BGNX G_BGNX2.
CONCATENATE '1.本工程采责任施工,业主无书面变更说明不得追加,验收合格后保固(' G_BGNX
')年。' INTO G_BGNX.
ENDIF.
ROW_COUNT_30 = ROW_COUNT_30 + 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'BGNX'
NO_FLUSH = 'X'
TOP = ROW_COUNT_30
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'BGNX'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_BGNX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------保固年限 END
*----------標單頁尾 明細資料 BEGIN
ROW_COUNT_30 = ROW_COUNT_30 + 14.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDLOOP.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
CLEAR:G_SUM_VEPRP.
LOOP AT GT_MATNR.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT GT_APLZL.
SPLIT GT_APLZL-LTXA1 AT '-' INTO GT_APLZL-LTXA2 L_CTEXT.
CLEAR:G_IND,G_ILEN.
GT_APLZL-NUMBE = SY-TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_APLZL-NUMBE
IMPORTING
OUTPUT = GT_APLZL-NUMBE.
G_ILEN = STRLEN( GT_APLZL-NUMBE ).
CLEAR:GT_NUMBE-NUMBE.
DO G_ILEN TIMES.
G_SIN_NUM = GT_APLZL-NUMBE+G_IND(1).
PERFORM CASENUM.
G_IND = G_IND + 1.
ENDDO.
GT_APLZL-NUMBE = GT_NUMBE-NUMBE.
MODIFY GT_APLZL.
ENDLOOP.
G_ADDROW2 = ROW_COUNT_30 + 1.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
CLEAR:ROW_COUNT,COL_COUNT.
CLEAR:GT_MATNR,GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
PERFORM SET_NO.
LOOP AT GT_MATNR .
CLEAR:ZNAME,TDLINES,TDLINES[],G_TABIX.
G_TABIX = SY-TABIX.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
CLEAR G_VALUE.
CALL FUNCTION 'EVAL_FORMULA' "將字符串運算 直接算出結果
EXPORTING
FORMULA = GT_MATNR-ABLAD
IMPORTING
VALUE = G_VALUE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF G_VALUE IS NOT INITIAL.
GT_MATNR-VERPR = GT_MATNR-VERPR * G_VALUE.
ENDIF.
G_SUM_VEPRP = G_SUM_VEPRP + GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_MATNR-SUM_VERPR = GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_APLZL-SUM_VERPR = GT_APLZL-SUM_VERPR + GT_MATNR-SUM_VERPR. " 計算每一個大類的總價格 -->有物料編碼
SELECT SINGLE MSEHL
INTO GT_MATNR-MSEHL
FROM T006A
WHERE MSEHI = GT_MATNR-MEINS
AND SPRAS = 'M'.
IF GT_MATNR-MATNR IS NOT INITIAL.
GT_NUMBE-NUMBE = G_TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_NUMBE-NUMBE
IMPORTING
OUTPUT = GT_NUMBE-NUMBE.
APPEND GT_NUMBE.
ENDIF.
IF GT_MATNR-MATNR IS NOT INITIAL.
CONCATENATE '' '' GT_MATNR-MATNR INTO GT_MATNR-MATNR.
ENDIF.
CONCATENATE SY-MANDT GT_MATNR-RSNUM GT_MATNR-RSPOS INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'MATK'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC = 4.
ENDIF.
LOOP AT TDLINES.
CONCATENATE GT_MATNR-ZLINE TDLINES-TDLINE INTO GT_MATNR-ZLINE.
ENDLOOP.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
DESCRIBE TABLE GT_MATNR LINES ROW_COUNT.
ENDIF.
ENDIF.
ROW_COUNT = ROW_COUNT + 1.
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT
PARAM2 = G_ADDROW2
PARAM_COUNT = 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'B_H'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 1
ROWS = ROW_COUNT
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'B_H'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
LOOP AT GT_MATNR.
WRITE_CONTENT_CELL ROW_INDEX 1 SY-TABIX.
WRITE_CONTENT_CELL ROW_INDEX 2 GT_MATNR-MATNR.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_MATNR-MAKTX.
WRITE_CONTENT_CELL ROW_INDEX 4 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL ROW_INDEX 5 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_MATNR-VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_MATNR-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 8 GT_MATNR-ZLINE.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
ELSE.
CLEAR:G_TAX, GT_CONTENTS[].
G_TAX = GT_MATNR-BDMNG * G_SUM_VEPRP / 100.
G_SUM_MONEY = G_SUM_MONEY + G_TAX.
LOOP AT GT_MATNR.
IF GT_MATNR-MEINS = '%'.
GT_MATNR-MSEHL = '式'.
GT_MATNR-BDMNG = 1.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL 1 5 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL 1 6 G_TAX.
WRITE_CONTENT_CELL 1 7 G_TAX.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 1.
GT_APLZL-SUM_VERPR = G_TAX. " 計算每一個大類的總價格 -->無物料編碼
ENDIF.
ELSE.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
ENDIF.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
MODIFY GT_APLZL.
CLEAR:L_FLAG.
AT END OF LTXA2.
G_ADDROW2 = G_ADDROW2 + ROW_COUNT + 1.
L_FLAG = 'X'.
ENDAT.
IF L_FLAG <> 'X'.
G_ADDROW2 = G_ADDROW2 + ROW_COUNT.
ENDIF.
ENDLOOP.
*----------標單頁尾 明細資料 END
*----------標單表頭 大項 BEGIN
LOOP AT GT_APLZL2 .
LOOP AT GT_APLZL WHERE LTXA2 = GT_APLZL2-LTXA1.
GT_APLZL2-SUM_VERPR = GT_APLZL2-SUM_VERPR + GT_APLZL-SUM_VERPR.
ENDLOOP.
MODIFY GT_APLZL2.
ENDLOOP.
CLEAR: ROW_COUNT_30.
DESCRIBE TABLE GT_APLZL2 LINES ROW_COUNT_30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A_H'
NO_FLUSH = 'X'
TOP = 9
LEFT = 1
ROWS = ROW_COUNT_30
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A_H'.
GS_RANGE-ROWS = ROW_COUNT_30.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
LOOP AT GT_APLZL2.
CLEAR:L_VEPRP,G_GCZJE_BIG.
L_VEPRP = SY-TABIX.
PERFORM S2B USING L_VEPRP G_GCZJE_BIG.
LV_I = STRLEN( G_GCZJE_BIG ).
LV_I = LV_I - 2.
G_GCZJE_BIG = G_GCZJE_BIG+0(LV_I).
WRITE_CONTENT_CELL ROW_INDEX 1 G_GCZJE_BIG.
WRITE_CONTENT_CELL ROW_INDEX 2 '/'.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_APLZL2-LTXA1.
WRITE_CONTENT_CELL ROW_INDEX 4 '式'.
WRITE_CONTENT_CELL ROW_INDEX 5 '1'.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_APLZL2-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_APLZL2-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 8 ''.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------標單表頭 大項 END
*----------標單 工程金額合計(RMB) BEGIN
DATA:L_SUM_VERPR LIKE MBEW-VERPR,
L_TOP_GCZJE TYPE I.
CLEAR:L_SUM_VERPR.
LOOP AT GT_APLZL2 .
L_SUM_VERPR = L_SUM_VERPR + GT_APLZL2-SUM_VERPR.
ENDLOOP.
L_TOP_GCZJE = 9 + ROW_COUNT_30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE'
NO_FLUSH = 'X'
TOP = L_TOP_GCZJE
LEFT = 3
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
WRITE_CONTENT_CELL 1 1 L_SUM_VERPR.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------標單 工程金額合計(RMB) END
ENDFORM. " WRITE_DATA_TO_EXCEL_GT_30WAN
*&---------------------------------------------------------------------*
*& FORM SET_NO
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SET_NO .
CLEAR:G_IND,G_ILEN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_APLZL-APLZL
IMPORTING
OUTPUT = GT_APLZL-APLZL.
G_ILEN = STRLEN( GT_APLZL-APLZL ).
CLEAR:GT_NUMBE-NUMBE.
DO G_ILEN TIMES.
G_SIN_NUM = GT_APLZL-APLZL+G_IND(1).
PERFORM CASENUM.
G_IND = G_IND + 1.
ENDDO.
APPEND GT_NUMBE.
ENDFORM. " SET_NO
*&---------------------------------------------------------------------*
*& FORM CASENUM
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM CASENUM .
CASE G_SIN_NUM.
WHEN 1.
G_DACH = '一'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 2.
G_DACH = '二'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 3.
G_DACH = '三'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 4.
G_DACH = '四'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 5.
G_DACH = '五'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 6.
G_DACH = '六'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 7.
G_DACH = '七'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 8.
G_DACH = '八'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 9.
G_DACH = '九'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 0.
G_DACH = '〇'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
ENDCASE.
ENDFORM. " CASENUM
*&---------------------------------------------------------------------*
*& FORM SAVE_EXCEL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SAVE_EXCEL .
DATA: LV_FILENAME TYPE STRING, "文件名
LV_WINTITLE TYPE STRING, "文件标题
LV_FILEPATH TYPE STRING, "路径
LV_FULLPATH TYPE STRING, "全路径
LV_DEFAULT TYPE STRING. "默认文件名
DATA: TITLE TYPE STRING VALUE '.XLS'.
DATA:G_ACTION TYPE I.
CLEAR:G_ACTION.
LV_WINTITLE = 'EXCEL文档'.
LV_DEFAULT = TITLE.
*&---打开保存对话框
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = LV_WINTITLE
DEFAULT_EXTENSION = 'XLS'
DEFAULT_FILE_NAME = LV_DEFAULT
FILE_FILTER = 'XLS'
* INITIAL_DIRECTORY =
CHANGING
FILENAME = LV_FILENAME
PATH = LV_FILEPATH
FULLPATH = LV_FULLPATH
USER_ACTION = G_ACTION
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
OTHERS = 3.
IF SY-SUBRC = 0 AND G_ACTION = 0.
DATA: P_FILE TYPE RLGRAP-FILENAME.
P_FILE = LV_FULLPATH.
*&---保存文件
CALL METHOD GR_DOCUMENT->SAVE_AS
EXPORTING
FILE_NAME = P_FILE.
IF SY-SUBRC = 0.
MESSAGE '文件已保存!' TYPE 'I'.
LEAVE TO SCREEN 0.
ENDIF.
ELSE.
CLEAR SY-UCOMM.
ENDIF.
ENDFORM. " SAVE_EXCEL
*&---------------------------------------------------------------------*
*& FORM S2B
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_G_SUM_MONEY TEXT
* -->P_G_GCZJE_BIG TEXT
*----------------------------------------------------------------------*
FORM S2B USING P_G_SUM_MONEY
P_G_GCZJE_BIG.
DATA:
V_S00(2) VALUE '零',
V_S01(2) VALUE '壹',
V_S02(2) VALUE '贰',
V_S03(2) VALUE '叁',
V_S04(2) VALUE '肆',
V_S05(2) VALUE '伍',
V_S06(2) VALUE '陆',
V_S07(2) VALUE '柒',
V_S08(2) VALUE '捌',
V_S09(2) VALUE '玖',
V_W00(2) VALUE '',
V_W01(2) VALUE '拾',
V_W02(2) VALUE '佰',
V_W03(2) VALUE '仟',
V_W04(2) VALUE '万',
V_W05(4) VALUE '拾',
V_W06(4) VALUE '佰',
V_W07(4) VALUE '仟',
V_W08(2) VALUE '亿',
V_W09(4) VALUE '拾',
V_W10(4) VALUE '佰',
V_W11(4) VALUE '仟',
V_W12(4) VALUE '万',
V_SY(2) VALUE '圆',
V_SJ(2) VALUE '角',
V_SF(2) VALUE '分',
V_AMOUNT(16), "将金额转换成字符型
V_LEN TYPE I, "V_AMOUNT或OUT的长度
V_VAR(5), "V_S0,V_S1,...,V_W0,V_W1,...
V_NUM(2) TYPE N, "每一位的数值
V_S_NUM(2), "V_S0,V_S1,...中的值
V_WEIGHT(2) TYPE N, "权数
V_W_NUM(4), "V_W0,V_W1,...中的值
V_FLAG0 TYPE I VALUE 0, "是否输出'零',0不输出,1输出
V_N TYPE I VALUE 0,
V_INDEX TYPE SY-INDEX.
V_AMOUNT = P_G_SUM_MONEY.
SHIFT V_AMOUNT LEFT DELETING LEADING SPACE.
SHIFT V_AMOUNT LEFT DELETING LEADING '0'.
*-计算分-----------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 1.
V_NUM = V_AMOUNT+V_LEN(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM V_SF P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-计算角-----------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 2.
V_NUM = V_AMOUNT+V_LEN(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM V_SJ P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-输出‘整’字-------------------------------------
IF P_G_GCZJE_BIG = ' '.
CONCATENATE '整' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-计算整数---------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 3.
IF V_LEN = 0.
EXIT.
ENDIF.
V_AMOUNT = V_AMOUNT(V_LEN). " 整数部分
*-输出‘元’字-------------------------------------
CONCATENATE V_SY P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_N = V_LEN - 1.
V_WEIGHT = 0.
DO V_LEN TIMES.
V_INDEX = SY-INDEX.
* 从个位开始
V_NUM = V_AMOUNT+V_N(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE 'V_W' V_WEIGHT INTO V_VAR.
WRITE (V_VAR) TO V_W_NUM.
CONCATENATE V_S_NUM V_W_NUM P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_FLAG0 = 1.
ELSE.
IF V_FLAG0 = 1.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_FLAG0 = 0.
ENDIF.
IF V_INDEX = 5 AND V_LEN > 5 AND V_LEN < 9 .
CONCATENATE '万' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ELSEIF V_INDEX = 9 AND V_LEN > 9.
CONCATENATE '亿' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
* CASE SY-INDEX.
* WHEN 5.CONCATENATE '万' OUT INTO OUT.
* WHEN 9.CONCATENATE '亿' OUT INTO OUT.
* ENDCASE.
ENDIF.
V_WEIGHT = V_WEIGHT + 1.
V_N = V_N - 1.
ENDDO.
*-删除个位可能出现'零'的情况-----------------
SEARCH P_G_GCZJE_BIG FOR '圆'.
IF SY-SUBRC = 0.
V_N = SY-FDPOS - 2.
IF V_N >= 0.
IF P_G_GCZJE_BIG+V_N(2) = V_S00.
V_LEN = STRLEN( P_G_GCZJE_BIG ).
CONCATENATE P_G_GCZJE_BIG(V_N) P_G_GCZJE_BIG+SY-FDPOS INTO P_G_GCZJE_BIG.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " S2B
*& REPORT ZEPB008
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZEPB008.
DATA: BEGIN OF GT_APLZL OCCURS 0,
LTXA2 LIKE AFVC-LTXA1,
LTXA1 LIKE AFVC-LTXA1,
APLZL LIKE AFVC-APLZL,
AUFPL LIKE AFVC-AUFPL,
ANLZU LIKE AFVC-ANLZU,
NUMBE(4) ,
SUM_VERPR LIKE MBEW-VERPR,
END OF GT_APLZL.
DATA: BEGIN OF GT_APLZL2 OCCURS 0,
APLZL LIKE AFVC-APLZL,
LTXA2 LIKE AFVC-LTXA1,
LTXA1 LIKE AFVC-LTXA1,
AUFPL LIKE AFVC-AUFPL,
ANLZU LIKE AFVC-ANLZU,
NUMBE(4) ,
SUM_VERPR LIKE MBEW-VERPR,
END OF GT_APLZL2.
DATA: G_APLZL LIKE AFVC-APLZL,
G_LTXA1 LIKE AFVC-LTXA1.
DATA: BEGIN OF GT_MATNR OCCURS 0,
MATNR(19) TYPE C,
MAKTX LIKE ZEPTM003-MAKTX,
MEINS LIKE RESB-MEINS,
BDMNG LIKE RESB-BDMNG,
APLZL LIKE AFVC-APLZL,
ZLINE TYPE TDLINE,
RSNUM LIKE RESB-RSNUM,
RSPOS LIKE RESB-RSPOS,
VERPR LIKE MBEW-VERPR,
SUM_VERPR LIKE MBEW-VERPR,
MSEHL LIKE T006A-MSEHL,
ABLAD LIKE RESB-ABLAD,
LGORT LIKE RESB-LGORT,
END OF GT_MATNR.
DATA: TDLINES TYPE TLINE OCCURS 0 WITH HEADER LINE.
DATA: ZNAME LIKE THEAD-TDNAME.
DATA: G_GNXYQ TYPE STRING.
DATA: G_BGNX TYPE STRING.
DATA: G_BGNX2 TYPE STRING.
DATA: G_GCZJE TYPE STRING.
DATA: G_GCZJE_BIG TYPE STRING.
DATA: ROW_INDEX TYPE I.
DATA: BEGIN OF GT_NUMBE OCCURS 0,
NUMBE(6) TYPE C,
END OF GT_NUMBE.
DATA: G_IND TYPE I VALUE 0,
G_SIN_NUM TYPE I,
G_DACH(3) TYPE C.
DATA: GR_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA: GR_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
GR_CONTROL TYPE REF TO I_OI_CONTAINER_CONTROL,
GR_DOCUMENT TYPE REF TO I_OI_DOCUMENT_PROXY,
GR_SPREADSHEET TYPE REF TO I_OI_SPREADSHEET,
GR_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
* BUSINESS DOCUMENT SYSTEM
DATA: GR_BDS_DOCUMENTS TYPE REF TO CL_BDS_DOCUMENT_SET,
G_CLASSNAME TYPE SBDST_CLASSNAME,
G_CLASSTYPE TYPE SBDST_CLASSTYPE,
G_OBJECTKEY TYPE SBDST_OBJECT_KEY,
G_DOC_COMPONENTS TYPE SBDST_COMPONENTS,
G_DOC_SIGNATURE TYPE SBDST_SIGNATURE.
* TEMPLATE URL
DATA: GT_BDS_URIS TYPE SBDST_URI,
GS_BDS_URL LIKE LINE OF GT_BDS_URIS,
G_TEMPLATE_URL(256) TYPE C.
DATA: G_OBJNR TYPE J_OBJNR,
G_A6 TYPE STRING,
G_A5 TYPE STRING,
G_A4 TYPE STRING,
G_A3 TYPE STRING,
G_A2 TYPE STRING,
G_A1 TYPE STRING,
G_NACHN LIKE PA0002-NACHN,
G_VORNA LIKE PA0002-VORNA,
G_WERKS LIKE CAUFV-WERKS,
G_ADDROW(3) TYPE C VALUE 9,
G_ADDROW2 TYPE I,
G_IPHAS LIKE AFIH-IPHAS,
G_TABIX TYPE SY-TABIX..
DATA: GT_RANGES TYPE SOI_RANGE_LIST,
GS_RANGE TYPE SOI_RANGE_ITEM,
GT_CONTENTS TYPE SOI_GENERIC_TABLE,
GS_CONTENT TYPE SOI_GENERIC_ITEM.
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
DATA: G_ILEN TYPE I.
DATA: G_SUM_VEPRP LIKE MBEW-VERPR.
DATA: G_TAX LIKE MBEW-VERPR VALUE 0.
DATA: G_SUM_MONEY LIKE MBEW-VERPR VALUE 0.
DATA: BEGIN OF WA_ZEP,
AUFNR TYPE CAUFV-AUFNR,
ERDAT TYPE CAUFV-ERDAT,
ATTACH(10) TYPE C,
ERNAM TYPE CAUFV-ERNAM,
KTEXT TYPE CAUFV-KTEXT,
WERKS TYPE CAUFV-WERKS,
MATNR TYPE RESB-MATNR,
RSPOS TYPE RESB-RSPOS,
LTXA1 TYPE AFVC-LTXA1,
VORNR TYPE AFVC-VORNR,
BDMNG TYPE RESB-BDMNG,
MEINS TYPE RESB-MEINS,
VERPR TYPE MBEW-VERPR,
NETWR TYPE EKPO-NETWR,
MAKTX TYPE ZEPTM003-MAKTX,
RSNUM TYPE RESB-RSNUM,
ZLINE TYPE TDLINE,
ANLZU TYPE AFVC-ANLZU,
END OF WA_ZEP.
DATA:ITAB_ZEP LIKE TABLE OF WA_ZEP.
DATA:G_GLLR TYPE EKPO-NETWR.
DATA:G_GLLR2 TYPE EKPO-NETWR.
DATA:G_UNAME TYPE SY-UNAME.
DATA: G_NETWR TYPE EKPO-NETWR,
G_VALUE TYPE F.
DEFINE WRITE_CONTENT_CELL.
GS_CONTENT-ROW = &1.
GS_CONTENT-COLUMN = &2.
GS_CONTENT-VALUE = &3.
APPEND GS_CONTENT TO GT_CONTENTS.
CLEAR GS_CONTENT.
END-OF-DEFINITION.
SELECTION-SCREEN BEGIN OF BLOCK T1 WITH FRAME TITLE X1.
PARAMETERS : P_AUFNR LIKE CAUFV-AUFNR.
SELECTION-SCREEN END OF BLOCK T1.
AT SELECTION-SCREEN .
SELECT SINGLE IPHAS FROM AFIH
INTO G_IPHAS
WHERE AUFNR = P_AUFNR.
IF G_IPHAS <> 2.
MESSAGE E000(ZEP_CE) WITH '訂單未核發,無法列印'.
ENDIF.
INITIALIZATION.
X1 = '查詢條件'.
G_CLASSNAME = 'HRFPM_EXCEL_STANDARD'.
G_CLASSTYPE = 'OT'.
" G_OBJECTKEY = 'DOI_EXCEL'.
START-OF-SELECTION.
SELECT T2~APLZL T2~LTXA1 T2~ANLZU T2~AUFPL
INTO CORRESPONDING FIELDS OF TABLE GT_APLZL
FROM CAUFV AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
WHERE AUFNR = P_AUFNR.
CLEAR:G_NETWR,G_GLLR,G_GLLR2,G_UNAME,ITAB_ZEP,ITAB_ZEP[].
SELECT T1~AUFNR T1~ERDAT T1~ERNAM T1~KTEXT T2~MATNR T2~RSPOS T3~LTXA1 T3~VORNR T1~WERKS T2~BDMNG T2~MEINS T2~RSNUM T2~GPREIS AS VERPR T3~ANLZU
INTO CORRESPONDING FIELDS OF TABLE ITAB_ZEP
FROM CAUFV AS T1
JOIN RESB AS T2
ON T1~AUFNR = T2~AUFNR
JOIN AFVC AS T3
ON T2~AUFPL = T3~AUFPL
AND T2~APLZL = T3~APLZL
WHERE T2~XLOEK <> 'X'
AND T1~AUFNR = P_AUFNR.
LOOP AT ITAB_ZEP INTO WA_ZEP.
IF WA_ZEP-ANLZU = 0 AND WA_ZEP-ANLZU IS NOT INITIAL.
G_GLLR = WA_ZEP-BDMNG.
ENDIF.
IF WA_ZEP-VERPR IS INITIAL.
SELECT SINGLE VERPR
INTO WA_ZEP-VERPR
FROM MBEW
WHERE MATNR = WA_ZEP-MATNR
AND BWKEY = WA_ZEP-WERKS.
ENDIF.
IF WA_ZEP-MATNR IS INITIAL AND WA_ZEP-MEINS = '%' AND WA_ZEP-ANLZU IS INITIAL.
G_GLLR2 = WA_ZEP-BDMNG + G_GLLR2.
ENDIF.
WA_ZEP-NETWR = WA_ZEP-VERPR * WA_ZEP-BDMNG.
G_NETWR = WA_ZEP-NETWR + G_NETWR.
ENDLOOP.
G_GLLR = G_GLLR + G_GLLR2.
G_NETWR = G_NETWR * G_GLLR / 100 + G_NETWR .
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*& Form MAIN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM MAIN.
PERFORM GET_CONTAINER.
PERFORM CREATE_CONTAINER_CONTROL.
IF G_NETWR < 300000.
*-------小於30萬
G_OBJECTKEY = 'DOI_EXCEL'.
PERFORM GET_TEMPLATE_URL.
PERFORM OPEN_EXCEL_DOC.
PERFORM WRITE_DATA_TO_EXCEL_LT_30WAN.
ELSE.
*-------大於30萬
G_OBJECTKEY = 'DOI_EXCEL2'.
PERFORM GET_TEMPLATE_URL.
PERFORM OPEN_EXCEL_DOC.
PERFORM WRITE_DATA_TO_EXCEL_GT_30WAN.
ENDIF.
ENDFORM. "MAIN
*&---------------------------------------------------------------------*
*& MODULE STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE STATUS_2000 OUTPUT.
SET PF-STATUS '2000'.
CASE SY-UCOMM.
WHEN 'EXIT' OR 'BACK' OR 'CANCEL'.
IF NOT GR_DOCUMENT IS INITIAL.
CALL METHOD GR_DOCUMENT->CLOSE_DOCUMENT.
FREE GR_DOCUMENT.
ENDIF.
IF NOT GR_CONTROL IS INITIAL.
CALL METHOD GR_CONTROL->DESTROY_CONTROL.
FREE GR_CONTROL.
ENDIF.
IF GR_CONTAINER IS NOT INITIAL.
CALL METHOD GR_CONTAINER->FREE.
ENDIF.
LEAVE PROGRAM.
WHEN 'SAVE'.
PERFORM SAVE_EXCEL.
ENDCASE.
PERFORM MAIN.
ENDMODULE. " STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
*& MODULE USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
MODULE USER_COMMAND_2000 INPUT.
CASE SY-UCOMM.
WHEN 'EXIT' OR 'BACK' OR 'CANCEL'.
IF NOT GR_DOCUMENT IS INITIAL.
CALL METHOD GR_DOCUMENT->CLOSE_DOCUMENT.
FREE GR_DOCUMENT.
ENDIF.
IF NOT GR_CONTROL IS INITIAL.
CALL METHOD GR_CONTROL->DESTROY_CONTROL.
FREE GR_CONTROL.
ENDIF.
IF GR_CONTAINER IS NOT INITIAL.
CALL METHOD GR_CONTAINER->FREE.
ENDIF.
LEAVE PROGRAM.
WHEN 'SAVE'.
PERFORM SAVE_EXCEL.
ENDCASE.
ENDMODULE. " USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
*& FORM GET_CONTAINER
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GET_CONTAINER .
CREATE OBJECT GR_SPLITTER
EXPORTING
PARENT = CL_GUI_CONTAINER=>SCREEN0
ROWS = 1
COLUMNS = 1.
CALL METHOD GR_SPLITTER->SET_BORDER
EXPORTING
BORDER = CL_GUI_CFW=>FALSE.
GR_CONTAINER = GR_SPLITTER->GET_CONTAINER( ROW = 1 COLUMN = 1 ).
ENDFORM. " GET_CONTAINER
*&---------------------------------------------------------------------*
*& FORM CREATE_CONTAINER_CONTROL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM CREATE_CONTAINER_CONTROL .
* CREATE CONTAINER CONTROL
CALL METHOD C_OI_CONTAINER_CONTROL_CREATOR=>GET_CONTAINER_CONTROL
IMPORTING
CONTROL = GR_CONTROL.
* INITIALIZE CONTROL
CALL METHOD GR_CONTROL->INIT_CONTROL
EXPORTING
INPLACE_ENABLED = 'X '
INPLACE_SCROLL_DOCUMENTS = 'X'
REGISTER_ON_CLOSE_EVENT = 'X'
REGISTER_ON_CUSTOM_EVENT = 'X'
R3_APPLICATION_NAME = 'DOI CREATE BY ZXK'
PARENT = GR_CONTAINER.
ENDFORM. " CREATE_CONTAINER_CONTROL
*&---------------------------------------------------------------------*
*& FORM GET_TEMPLATE_URL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM GET_TEMPLATE_URL .
CREATE OBJECT GR_BDS_DOCUMENTS.
CALL METHOD CL_BDS_DOCUMENT_SET=>GET_INFO
EXPORTING
CLASSNAME = G_CLASSNAME
CLASSTYPE = G_CLASSTYPE
OBJECT_KEY = G_OBJECTKEY
CHANGING
COMPONENTS = G_DOC_COMPONENTS
SIGNATURE = G_DOC_SIGNATURE.
CALL METHOD CL_BDS_DOCUMENT_SET=>GET_WITH_URL
EXPORTING
CLASSNAME = G_CLASSNAME
CLASSTYPE = G_CLASSTYPE
OBJECT_KEY = G_OBJECTKEY
CHANGING
URIS = GT_BDS_URIS
SIGNATURE = G_DOC_SIGNATURE.
FREE GR_BDS_DOCUMENTS.
READ TABLE GT_BDS_URIS INTO GS_BDS_URL INDEX 1.
G_TEMPLATE_URL = GS_BDS_URL-URI.
ENDFORM. " GET_TEMPLATE_URL
*&---------------------------------------------------------------------*
*& FORM OPEN_EXCEL_DOC
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM OPEN_EXCEL_DOC .
CALL METHOD GR_CONTROL->GET_DOCUMENT_PROXY
EXPORTING
DOCUMENT_TYPE = 'EXCEL.SHEET'
NO_FLUSH = 'X'
REGISTER_CONTAINER = 'X'
IMPORTING
DOCUMENT_PROXY = GR_DOCUMENT.
CALL METHOD GR_DOCUMENT->OPEN_DOCUMENT
EXPORTING
OPEN_INPLACE = 'X'
DOCUMENT_URL = G_TEMPLATE_URL.
DATA: AVAILABLE TYPE I.
CALL METHOD GR_DOCUMENT->HAS_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = 'X'
IMPORTING
IS_AVAILABLE = AVAILABLE.
CALL METHOD GR_DOCUMENT->GET_SPREADSHEET_INTERFACE
EXPORTING
NO_FLUSH = 'X'
IMPORTING
SHEET_INTERFACE = GR_SPREADSHEET.
CALL METHOD GR_SPREADSHEET->SELECT_SHEET
EXPORTING
NAME = '(小于30万)标单及大型(大于等于30万)工程多页标单'
NO_FLUSH = 'X'.
ENDFORM. " OPEN_EXCEL_DOC
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA_TO_EXCEL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM WRITE_DATA_TO_EXCEL_LT_30WAN .
DATA: COL_COUNT TYPE I VALUE 0,
ROW_COUNT TYPE I VALUE 0.
CLEAR:G_NACHN,G_VORNA,G_WERKS,G_A1,G_A2,G_A3,G_A4,G_A5,G_A6,G_OBJNR,G_TABIX.
SELECT SINGLE NACHN VORNA
INTO (G_NACHN,G_VORNA)
FROM PA0002
JOIN CAUFV
ON PA0002~PERNR = CAUFV~ERNAM
WHERE CAUFV~AUFNR = P_AUFNR.
IF G_NACHN IS NOT INITIAL AND G_VORNA IS NOT INITIAL.
CONCATENATE '業主聯絡人:' G_NACHN G_VORNA INTO G_A5.
ELSE.
SELECT SINGLE T3~NAME_LAST
INTO G_A5
FROM CAUFV AS T1
JOIN USR21 AS T2
ON T1~ERNAM = T2~BNAME
JOIN ADRP AS T3
ON T2~PERSNUMBER = T3~PERSNUMBER
WHERE AUFNR = P_AUFNR.
CONCATENATE '業主聯絡人:' G_A5 INTO G_A5.
ENDIF.
SELECT SINGLE KTEXT
INTO G_A4
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '工程名稱:' G_A4 INTO G_A4.
SELECT SINGLE KTEXT
INTO G_A2
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '(' G_A2 ')標準標單或標單首頁' INTO G_A2.
SELECT SINGLE BUTXT
INTO G_A1
FROM CAUFV
JOIN T001
ON CAUFV~BUKRS = T001~BUKRS
WHERE AUFNR = P_AUFNR.
SELECT SINGLE WERKS
INTO G_WERKS
FROM CAUFV
WHERE AUFNR = P_AUFNR.
IF G_WERKS = 'C301' OR G_WERKS = 'C303' OR G_WERKS = 'C304' OR G_WERKS = 'C305' OR G_WERKS = 'C306' OR G_WERKS = 'C307'.
CONCATENATE '業主名稱:' G_A1 '(團結廠)' INTO G_A3.
ELSEIF G_WERKS = 'C302' OR G_WERKS = 'C308' OR G_WERKS = 'C309' OR G_WERKS = 'C310' OR G_WERKS = 'C311' OR G_WERKS = 'C312' OR G_WERKS = 'C313'.
CONCATENATE '業主名稱:' G_A1 '(芙蓉廠)' INTO G_A3.
ELSEIF G_WERKS = 'C331' OR G_WERKS = 'C332' OR G_WERKS = 'C333'.
CONCATENATE '業主名稱:' G_A1 INTO G_A3.
ENDIF.
CONCATENATE 'OR' P_AUFNR INTO G_OBJNR.
SELECT SINGLE TPLNR
INTO G_A6
FROM MCIPMIS
WHERE OBJNR = G_OBJNR.
CONCATENATE '施工地點:' G_A6 INTO G_A6.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A1_A6'
NO_FLUSH = 'X'
TOP = 1
LEFT = 1
ROWS = 6
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A1_A6'.
GS_RANGE-ROWS = 6.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 G_A1.
WRITE_CONTENT_CELL 2 1 G_A2.
WRITE_CONTENT_CELL 3 1 G_A3.
WRITE_CONTENT_CELL 4 1 G_A4.
WRITE_CONTENT_CELL 5 1 G_A5.
WRITE_CONTENT_CELL 6 1 G_A6.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDLOOP.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
CLEAR:G_SUM_VEPRP.
LOOP AT GT_MATNR.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
CLEAR:ROW_COUNT,COL_COUNT.
CLEAR:GT_MATNR,GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
PERFORM SET_NO.
LOOP AT GT_MATNR .
G_TABIX = SY-TABIX.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
CLEAR:ZNAME,TDLINES,TDLINES[].
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
CLEAR G_VALUE.
CALL FUNCTION 'EVAL_FORMULA' "將字符串運算 直接算出結果
EXPORTING
FORMULA = GT_MATNR-ABLAD
IMPORTING
VALUE = G_VALUE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF G_VALUE IS NOT INITIAL.
GT_MATNR-VERPR = GT_MATNR-VERPR * G_VALUE.
ENDIF.
G_SUM_VEPRP = G_SUM_VEPRP + GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_MATNR-SUM_VERPR = GT_MATNR-VERPR * GT_MATNR-BDMNG.
SELECT SINGLE MSEHL
INTO GT_MATNR-MSEHL
FROM T006A
WHERE MSEHI = GT_MATNR-MEINS
AND SPRAS = 'M'.
IF GT_MATNR-MATNR IS NOT INITIAL.
GT_NUMBE-NUMBE = G_TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_NUMBE-NUMBE
IMPORTING
OUTPUT = GT_NUMBE-NUMBE.
APPEND GT_NUMBE.
ENDIF.
IF GT_MATNR-MATNR IS NOT INITIAL.
CONCATENATE '' '' GT_MATNR-MATNR INTO GT_MATNR-MATNR.
ENDIF.
CONCATENATE SY-MANDT GT_MATNR-RSNUM GT_MATNR-RSPOS INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'MATK'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
LOOP AT TDLINES.
CONCATENATE GT_MATNR-ZLINE TDLINES-TDLINE INTO GT_MATNR-ZLINE.
ENDLOOP.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
DESCRIBE TABLE GT_MATNR LINES ROW_COUNT.
ENDIF.
ENDIF.
COL_COUNT = 4.
ROW_COUNT = ROW_COUNT + 1.
*---------- 調用EXCEL VBA --->新增行
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT
PARAM2 = G_ADDROW
PARAM_COUNT = 2.
G_ADDROW2 = G_ADDROW.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'B_H'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 2
ROWS = ROW_COUNT
COLUMNS = 7.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'B_H'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 7.
GS_RANGE-CODE = 7.
APPEND GS_RANGE TO GT_RANGES.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
LOOP AT GT_MATNR.
WRITE_CONTENT_CELL ROW_INDEX 1 GT_MATNR-MATNR.
WRITE_CONTENT_CELL ROW_INDEX 2 GT_MATNR-MAKTX.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL ROW_INDEX 4 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL ROW_INDEX 5 GT_MATNR-VERPR.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_MATNR-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_MATNR-ZLINE.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
ELSE.
CLEAR:G_TAX, GT_CONTENTS[].
G_TAX = GT_MATNR-BDMNG * G_SUM_VEPRP / 100.
G_SUM_MONEY = G_SUM_MONEY + G_TAX.
LOOP AT GT_MATNR.
IF GT_MATNR-MEINS = '%'.
GT_MATNR-MSEHL = '式'.
GT_MATNR-BDMNG = 1.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL 1 4 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL 1 5 G_TAX.
WRITE_CONTENT_CELL 1 6 G_TAX.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 1.
ENDIF.
ELSE.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 2 ''.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
ENDIF.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
CLEAR:GT_CONTENTS[].
G_ADDROW = G_ADDROW + ROW_COUNT.
ENDLOOP.
CLEAR:ROW_COUNT.
CLEAR:GT_NUMBE-NUMBE.
DO 1 TIMES.
G_SIN_NUM = G_SIN_NUM + 1.
PERFORM CASENUM.
APPEND GT_NUMBE.
CLEAR:GT_NUMBE-NUMBE.
ENDDO.
DESCRIBE TABLE GT_NUMBE LINES ROW_COUNT.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A9_LAST'
NO_FLUSH = 'X'
TOP = 9
LEFT = 1
ROWS = ROW_COUNT
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A9_LAST'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
LOOP AT GT_NUMBE.
WRITE_CONTENT_CELL SY-TABIX 1 GT_NUMBE-NUMBE.
ENDLOOP.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*---------工程總金額 BEGIN
G_SUM_MONEY = G_SUM_VEPRP + G_SUM_MONEY.
CLEAR:GT_CONTENTS[].
G_GCZJE = G_SUM_MONEY.
CONCATENATE '工程金額合計:' G_GCZJE INTO G_GCZJE.
ROW_COUNT = 8 + ROW_COUNT + 1.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GCZJE.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*---------工程總金額 END
*----------工程總金額 大寫 BEGIN
CLEAR:GT_CONTENTS[].
PERFORM S2B USING G_SUM_MONEY G_GCZJE_BIG.
CONCATENATE '工程金額合計(大寫):' G_GCZJE_BIG INTO G_GCZJE_BIG.
ROW_COUNT = ROW_COUNT + 1.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE_BIG'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE_BIG'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GCZJE_BIG.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------工程總金額 大寫 END
*----------功能性要求 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 1.
IF SY-SUBRC = 0 .
CLEAR:ZNAME,TDLINES,TDLINES[],G_GNXYQ.
CONCATENATE SY-MANDT GT_APLZL-AUFPL GT_APLZL-APLZL INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'AVOT'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
READ TABLE TDLINES INDEX 2.
IF SY-SUBRC = 0.
CONCATENATE '1.功能性要求:' TDLINES-TDLINE INTO G_GNXYQ.
ENDIF.
ELSE.
ENDIF.
ROW_COUNT = ROW_COUNT + 5.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GNXYQ'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GNXYQ'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GNXYQ.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------功能性要求 END
*----------保固年限 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 2.
IF SY-SUBRC = 0.
CLEAR:GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
ENDIF.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
G_BGNX = GT_MATNR-BDMNG .
SPLIT G_BGNX AT '.' INTO G_BGNX G_BGNX2.
CONCATENATE '1.本工程采责任施工,业主无书面变更说明不得追加,验收合格后保固(' G_BGNX
')年。' INTO G_BGNX.
ENDIF.
ROW_COUNT = ROW_COUNT + 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'BGNX'
NO_FLUSH = 'X'
TOP = ROW_COUNT
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'BGNX'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_BGNX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------保固年限 BEGIN
ENDFORM. " WRITE_DATA_TO_EXCEL
*&---------------------------------------------------------------------*
*& FORM WRITE_DATA_TO_EXCEL_GT_30WAN
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM WRITE_DATA_TO_EXCEL_GT_30WAN .
DATA: COL_COUNT TYPE I VALUE 0,
ROW_COUNT TYPE I VALUE 0,
ROW_COUNT_30 TYPE I VALUE 0,
L_FLAG TYPE C.
DATA:L_CTEXT(20).
CLEAR:G_NACHN,G_VORNA,G_WERKS,G_A1,G_A2,G_A3,G_A4,G_A5,G_A6,G_OBJNR,G_TABIX.
SELECT SINGLE NACHN VORNA
INTO (G_NACHN,G_VORNA)
FROM PA0002
JOIN CAUFV
ON PA0002~PERNR = CAUFV~ERNAM
WHERE CAUFV~AUFNR = P_AUFNR.
IF G_NACHN IS NOT INITIAL AND G_VORNA IS NOT INITIAL.
CONCATENATE '業主聯絡人:' G_NACHN G_VORNA INTO G_A5.
ELSE.
SELECT SINGLE T3~NAME_LAST
INTO G_A5
FROM CAUFV AS T1
JOIN USR21 AS T2
ON T1~ERNAM = T2~BNAME
JOIN ADRP AS T3
ON T2~PERSNUMBER = T3~PERSNUMBER
WHERE AUFNR = P_AUFNR.
CONCATENATE '業主聯絡人:' G_A5 INTO G_A5.
ENDIF.
SELECT SINGLE KTEXT
INTO G_A4
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '工程名稱:' G_A4 INTO G_A4.
SELECT SINGLE KTEXT
INTO G_A2
FROM CAUFV
WHERE AUFNR = P_AUFNR.
CONCATENATE '(' G_A2 ')標準標單或標單首頁' INTO G_A2.
SELECT SINGLE BUTXT
INTO G_A1
FROM CAUFV
JOIN T001
ON CAUFV~BUKRS = T001~BUKRS
WHERE AUFNR = P_AUFNR.
SELECT SINGLE WERKS
INTO G_WERKS
FROM CAUFV
WHERE AUFNR = P_AUFNR.
IF G_WERKS = 'C301' OR G_WERKS = 'C303' OR G_WERKS = 'C304' OR G_WERKS = 'C305' OR G_WERKS = 'C306' OR G_WERKS = 'C307'.
CONCATENATE '業主名稱:' G_A1 '(團結廠)' INTO G_A3.
ELSEIF G_WERKS = 'C302' OR G_WERKS = 'C308' OR G_WERKS = 'C309' OR G_WERKS = 'C310' OR G_WERKS = 'C311' OR G_WERKS = 'C312' OR G_WERKS = 'C313'.
CONCATENATE '業主名稱:' G_A1 '(芙蓉廠)' INTO G_A3.
ELSEIF G_WERKS = 'C331' OR G_WERKS = 'C332' OR G_WERKS = 'C333'.
CONCATENATE '業主名稱:' G_A1 INTO G_A3.
ENDIF.
CONCATENATE 'OR' P_AUFNR INTO G_OBJNR.
SELECT SINGLE TPLNR
INTO G_A6
FROM MCIPMIS
WHERE OBJNR = G_OBJNR.
CONCATENATE '施工地點:' G_A6 INTO G_A6.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A1_A6'
NO_FLUSH = 'X'
TOP = 2
LEFT = 1
ROWS = 4
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A1_A6'.
GS_RANGE-ROWS = 4.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
" WRITE_CONTENT_CELL 1 1 ''.
" WRITE_CONTENT_CELL 2 1 G_A2.
WRITE_CONTENT_CELL 1 1 G_A3.
WRITE_CONTENT_CELL 2 1 G_A4.
WRITE_CONTENT_CELL 3 1 G_A5.
WRITE_CONTENT_CELL 4 1 G_A6.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SPLIT GT_APLZL-LTXA1 AT '-' INTO GT_APLZL2-LTXA1 L_CTEXT.
GT_APLZL2-APLZL = GT_APLZL-APLZL.
APPEND GT_APLZL2.
ENDLOOP.
SORT GT_APLZL BY LTXA1.
SORT GT_APLZL2 BY LTXA1 APLZL.
CLEAR:G_LTXA1,G_APLZL.
LOOP AT GT_APLZL2.
IF GT_APLZL2-LTXA1 = G_LTXA1.
GT_APLZL2-APLZL = G_APLZL.
ENDIF.
G_LTXA1 = GT_APLZL2-LTXA1.
G_APLZL = GT_APLZL2-APLZL.
MODIFY GT_APLZL2.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM GT_APLZL2 .
SORT GT_APLZL BY APLZL.
SORT GT_APLZL2 BY APLZL.
DESCRIBE TABLE GT_APLZL2 LINES ROW_COUNT_30.
*---------- 調用EXCEL VBA --->新增行
*---------- 後面才能計算合計價格,先插入幾行空著,算出價格后再把這幾行貼上去
DATA:LV_I TYPE I.
DATA:LV_J TYPE I.
DATA: L_VEPRP LIKE MBEW-VERPR.
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT_30
PARAM2 = 9
PARAM_COUNT = 2.
G_ADDROW2 = ROW_COUNT_30 + 30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A_H_LAST'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 1
ROWS = ROW_COUNT_30
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A_H_LAST'.
GS_RANGE-ROWS = ROW_COUNT_30.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
LOOP AT GT_APLZL2.
CLEAR:L_VEPRP,G_GCZJE_BIG.
L_VEPRP = SY-TABIX.
PERFORM S2B USING L_VEPRP G_GCZJE_BIG.
LV_I = STRLEN( G_GCZJE_BIG ).
LV_I = LV_I - 2.
G_GCZJE_BIG = G_GCZJE_BIG+0(LV_I).
WRITE_CONTENT_CELL ROW_INDEX 1 G_GCZJE_BIG.
WRITE_CONTENT_CELL ROW_INDEX 2 '/'.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_APLZL2-LTXA1.
WRITE_CONTENT_CELL ROW_INDEX 4 ''.
WRITE_CONTENT_CELL ROW_INDEX 5 ''.
WRITE_CONTENT_CELL ROW_INDEX 6 ''.
WRITE_CONTENT_CELL ROW_INDEX 7 ''.
WRITE_CONTENT_CELL ROW_INDEX 8 ''.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------功能性要求 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 1.
IF SY-SUBRC = 0 .
CLEAR:ZNAME,TDLINES,TDLINES[],G_GNXYQ.
CONCATENATE SY-MANDT GT_APLZL-AUFPL GT_APLZL-APLZL INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'AVOT'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
* ARCHIVE_HANDLE = 0
* LOCAL_CAT = ' '
* IMPORTING
* HEADER =
* OLD_LINE_COUNTER =
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF SY-SUBRC = 4.
ENDIF.
READ TABLE TDLINES INDEX 2.
IF SY-SUBRC = 0.
CONCATENATE '1.功能性要求:' TDLINES-TDLINE INTO G_GNXYQ.
ENDIF.
ELSE.
ENDIF.
ROW_COUNT_30 = ROW_COUNT_30 + 14.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GNXYQ'
NO_FLUSH = 'X'
TOP = ROW_COUNT_30
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GNXYQ'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_GNXYQ.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------功能性要求 END
*----------保固年限 BEGIN
CLEAR:GT_CONTENTS[].
READ TABLE GT_APLZL WITH KEY ANLZU = 2.
IF SY-SUBRC = 0.
CLEAR:GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDIF.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
G_BGNX = GT_MATNR-BDMNG .
SPLIT G_BGNX AT '.' INTO G_BGNX G_BGNX2.
CONCATENATE '1.本工程采责任施工,业主无书面变更说明不得追加,验收合格后保固(' G_BGNX
')年。' INTO G_BGNX.
ENDIF.
ROW_COUNT_30 = ROW_COUNT_30 + 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'BGNX'
NO_FLUSH = 'X'
TOP = ROW_COUNT_30
LEFT = 2
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'BGNX'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR ROW_INDEX.
WRITE_CONTENT_CELL 1 1 G_BGNX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS.
*----------保固年限 END
*----------標單頁尾 明細資料 BEGIN
ROW_COUNT_30 = ROW_COUNT_30 + 14.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
ENDLOOP.
LOOP AT GT_MATNR.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
CLEAR:G_SUM_VEPRP.
LOOP AT GT_MATNR.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT GT_APLZL.
SPLIT GT_APLZL-LTXA1 AT '-' INTO GT_APLZL-LTXA2 L_CTEXT.
CLEAR:G_IND,G_ILEN.
GT_APLZL-NUMBE = SY-TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_APLZL-NUMBE
IMPORTING
OUTPUT = GT_APLZL-NUMBE.
G_ILEN = STRLEN( GT_APLZL-NUMBE ).
CLEAR:GT_NUMBE-NUMBE.
DO G_ILEN TIMES.
G_SIN_NUM = GT_APLZL-NUMBE+G_IND(1).
PERFORM CASENUM.
G_IND = G_IND + 1.
ENDDO.
GT_APLZL-NUMBE = GT_NUMBE-NUMBE.
MODIFY GT_APLZL.
ENDLOOP.
G_ADDROW2 = ROW_COUNT_30 + 1.
LOOP AT GT_APLZL WHERE ANLZU <> 1
AND ANLZU <> 2.
CLEAR:ROW_COUNT,COL_COUNT.
CLEAR:GT_MATNR,GT_MATNR[].
SELECT T1~MATNR MEINS BDMNG T2~APLZL T1~RSNUM T1~RSPOS T1~GPREIS AS VERPR T1~ABLAD T1~LGORT
INTO CORRESPONDING FIELDS OF TABLE GT_MATNR
FROM RESB AS T1
JOIN AFVC AS T2
ON T1~AUFPL = T2~AUFPL
AND T1~APLZL = T2~APLZL
JOIN CAUFV AS T3
ON T1~AUFPL = T3~AUFPL
WHERE T3~AUFNR = P_AUFNR
AND T2~APLZL = GT_APLZL-APLZL.
PERFORM SET_NO.
LOOP AT GT_MATNR .
CLEAR:ZNAME,TDLINES,TDLINES[],G_TABIX.
G_TABIX = SY-TABIX.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM ZEPTM003
WHERE MATNR = GT_MATNR-MATNR.
IF GT_MATNR-MAKTX IS INITIAL.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ELSE.
SELECT SINGLE MAKTX
INTO GT_MATNR-MAKTX+0(40)
FROM MAKT
WHERE MATNR = GT_MATNR-MATNR.
ENDIF.
IF GT_MATNR-VERPR IS INITIAL.
IF GT_MATNR-LGORT <> 'TM11'.
SELECT SINGLE VERPR
INTO GT_MATNR-VERPR
FROM MBEW
WHERE BWKEY = G_WERKS
AND MATNR = GT_MATNR-MATNR.
ENDIF.
ENDIF.
CLEAR G_VALUE.
CALL FUNCTION 'EVAL_FORMULA' "將字符串運算 直接算出結果
EXPORTING
FORMULA = GT_MATNR-ABLAD
IMPORTING
VALUE = G_VALUE.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF G_VALUE IS NOT INITIAL.
GT_MATNR-VERPR = GT_MATNR-VERPR * G_VALUE.
ENDIF.
G_SUM_VEPRP = G_SUM_VEPRP + GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_MATNR-SUM_VERPR = GT_MATNR-VERPR * GT_MATNR-BDMNG.
GT_APLZL-SUM_VERPR = GT_APLZL-SUM_VERPR + GT_MATNR-SUM_VERPR. " 計算每一個大類的總價格 -->有物料編碼
SELECT SINGLE MSEHL
INTO GT_MATNR-MSEHL
FROM T006A
WHERE MSEHI = GT_MATNR-MEINS
AND SPRAS = 'M'.
IF GT_MATNR-MATNR IS NOT INITIAL.
GT_NUMBE-NUMBE = G_TABIX.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_NUMBE-NUMBE
IMPORTING
OUTPUT = GT_NUMBE-NUMBE.
APPEND GT_NUMBE.
ENDIF.
IF GT_MATNR-MATNR IS NOT INITIAL.
CONCATENATE '' '' GT_MATNR-MATNR INTO GT_MATNR-MATNR.
ENDIF.
CONCATENATE SY-MANDT GT_MATNR-RSNUM GT_MATNR-RSPOS INTO ZNAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'MATK'
LANGUAGE = SY-LANGU
NAME = ZNAME
OBJECT = 'AUFK'
TABLES
LINES = TDLINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC = 4.
ENDIF.
LOOP AT TDLINES.
CONCATENATE GT_MATNR-ZLINE TDLINES-TDLINE INTO GT_MATNR-ZLINE.
ENDLOOP.
MODIFY GT_MATNR.
ENDLOOP.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
DESCRIBE TABLE GT_MATNR LINES ROW_COUNT.
ENDIF.
ENDIF.
ROW_COUNT = ROW_COUNT + 1.
CALL METHOD GR_DOCUMENT->EXECUTE_MACRO
EXPORTING
MACRO_STRING = 'THISWORKBOOK.ADDROWS'
PARAM1 = ROW_COUNT
PARAM2 = G_ADDROW2
PARAM_COUNT = 2.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'B_H'
NO_FLUSH = 'X'
TOP = G_ADDROW2
LEFT = 1
ROWS = ROW_COUNT
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'B_H'.
GS_RANGE-ROWS = ROW_COUNT.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
READ TABLE GT_MATNR INDEX 1.
IF SY-SUBRC = 0.
IF GT_MATNR-MATNR IS NOT INITIAL.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
LOOP AT GT_MATNR.
WRITE_CONTENT_CELL ROW_INDEX 1 SY-TABIX.
WRITE_CONTENT_CELL ROW_INDEX 2 GT_MATNR-MATNR.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_MATNR-MAKTX.
WRITE_CONTENT_CELL ROW_INDEX 4 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL ROW_INDEX 5 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_MATNR-VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_MATNR-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 8 GT_MATNR-ZLINE.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
ELSE.
CLEAR:G_TAX, GT_CONTENTS[].
G_TAX = GT_MATNR-BDMNG * G_SUM_VEPRP / 100.
G_SUM_MONEY = G_SUM_MONEY + G_TAX.
LOOP AT GT_MATNR.
IF GT_MATNR-MEINS = '%'.
GT_MATNR-MSEHL = '式'.
GT_MATNR-BDMNG = 1.
ENDIF.
MODIFY GT_MATNR.
ENDLOOP.
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 GT_MATNR-MSEHL.
WRITE_CONTENT_CELL 1 5 GT_MATNR-BDMNG.
WRITE_CONTENT_CELL 1 6 G_TAX.
WRITE_CONTENT_CELL 1 7 G_TAX.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 1.
GT_APLZL-SUM_VERPR = G_TAX. " 計算每一個大類的總價格 -->無物料編碼
ENDIF.
ELSE.
CLEAR GT_CONTENTS[].
WRITE_CONTENT_CELL 1 1 ''. "GT_APLZL-NUMBE.
WRITE_CONTENT_CELL 1 2 GT_APLZL-LTXA1.
WRITE_CONTENT_CELL 1 3 ''.
WRITE_CONTENT_CELL 1 4 ''.
WRITE_CONTENT_CELL 1 5 ''.
WRITE_CONTENT_CELL 1 6 ''.
WRITE_CONTENT_CELL 1 7 ''.
WRITE_CONTENT_CELL 1 8 ''.
CLEAR ROW_INDEX.
ROW_INDEX = 2.
ENDIF.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
MODIFY GT_APLZL.
CLEAR:L_FLAG.
AT END OF LTXA2.
G_ADDROW2 = G_ADDROW2 + ROW_COUNT + 1.
L_FLAG = 'X'.
ENDAT.
IF L_FLAG <> 'X'.
G_ADDROW2 = G_ADDROW2 + ROW_COUNT.
ENDIF.
ENDLOOP.
*----------標單頁尾 明細資料 END
*----------標單表頭 大項 BEGIN
LOOP AT GT_APLZL2 .
LOOP AT GT_APLZL WHERE LTXA2 = GT_APLZL2-LTXA1.
GT_APLZL2-SUM_VERPR = GT_APLZL2-SUM_VERPR + GT_APLZL-SUM_VERPR.
ENDLOOP.
MODIFY GT_APLZL2.
ENDLOOP.
CLEAR: ROW_COUNT_30.
DESCRIBE TABLE GT_APLZL2 LINES ROW_COUNT_30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'A_H'
NO_FLUSH = 'X'
TOP = 9
LEFT = 1
ROWS = ROW_COUNT_30
COLUMNS = 8.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'A_H'.
GS_RANGE-ROWS = ROW_COUNT_30.
GS_RANGE-COLUMNS = 8.
GS_RANGE-CODE = 8.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
LOOP AT GT_APLZL2.
CLEAR:L_VEPRP,G_GCZJE_BIG.
L_VEPRP = SY-TABIX.
PERFORM S2B USING L_VEPRP G_GCZJE_BIG.
LV_I = STRLEN( G_GCZJE_BIG ).
LV_I = LV_I - 2.
G_GCZJE_BIG = G_GCZJE_BIG+0(LV_I).
WRITE_CONTENT_CELL ROW_INDEX 1 G_GCZJE_BIG.
WRITE_CONTENT_CELL ROW_INDEX 2 '/'.
WRITE_CONTENT_CELL ROW_INDEX 3 GT_APLZL2-LTXA1.
WRITE_CONTENT_CELL ROW_INDEX 4 '式'.
WRITE_CONTENT_CELL ROW_INDEX 5 '1'.
WRITE_CONTENT_CELL ROW_INDEX 6 GT_APLZL2-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 7 GT_APLZL2-SUM_VERPR.
WRITE_CONTENT_CELL ROW_INDEX 8 ''.
ROW_INDEX = ROW_INDEX + 1.
ENDLOOP.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------標單表頭 大項 END
*----------標單 工程金額合計(RMB) BEGIN
DATA:L_SUM_VERPR LIKE MBEW-VERPR,
L_TOP_GCZJE TYPE I.
CLEAR:L_SUM_VERPR.
LOOP AT GT_APLZL2 .
L_SUM_VERPR = L_SUM_VERPR + GT_APLZL2-SUM_VERPR.
ENDLOOP.
L_TOP_GCZJE = 9 + ROW_COUNT_30.
CALL METHOD GR_SPREADSHEET->INSERT_RANGE_DIM
EXPORTING
NAME = 'GCZJE'
NO_FLUSH = 'X'
TOP = L_TOP_GCZJE
LEFT = 3
ROWS = 1
COLUMNS = 1.
CLEAR GS_RANGE.
CLEAR GT_RANGES[].
GS_RANGE-NAME = 'GCZJE'.
GS_RANGE-ROWS = 1.
GS_RANGE-COLUMNS = 1.
GS_RANGE-CODE = 1.
APPEND GS_RANGE TO GT_RANGES.
CLEAR:GT_CONTENTS[].
ROW_INDEX = 1.
WRITE_CONTENT_CELL 1 1 L_SUM_VERPR.
CLEAR:ROW_INDEX.
CALL METHOD GR_SPREADSHEET->SET_RANGES_DATA
EXPORTING
RANGES = GT_RANGES
CONTENTS = GT_CONTENTS
NO_FLUSH = 'X'.
*----------標單 工程金額合計(RMB) END
ENDFORM. " WRITE_DATA_TO_EXCEL_GT_30WAN
*&---------------------------------------------------------------------*
*& FORM SET_NO
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SET_NO .
CLEAR:G_IND,G_ILEN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = GT_APLZL-APLZL
IMPORTING
OUTPUT = GT_APLZL-APLZL.
G_ILEN = STRLEN( GT_APLZL-APLZL ).
CLEAR:GT_NUMBE-NUMBE.
DO G_ILEN TIMES.
G_SIN_NUM = GT_APLZL-APLZL+G_IND(1).
PERFORM CASENUM.
G_IND = G_IND + 1.
ENDDO.
APPEND GT_NUMBE.
ENDFORM. " SET_NO
*&---------------------------------------------------------------------*
*& FORM CASENUM
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM CASENUM .
CASE G_SIN_NUM.
WHEN 1.
G_DACH = '一'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 2.
G_DACH = '二'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 3.
G_DACH = '三'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 4.
G_DACH = '四'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 5.
G_DACH = '五'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 6.
G_DACH = '六'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 7.
G_DACH = '七'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 8.
G_DACH = '八'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 9.
G_DACH = '九'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
WHEN 0.
G_DACH = '〇'.
CONCATENATE GT_NUMBE-NUMBE G_DACH INTO GT_NUMBE-NUMBE.
ENDCASE.
ENDFORM. " CASENUM
*&---------------------------------------------------------------------*
*& FORM SAVE_EXCEL
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
FORM SAVE_EXCEL .
DATA: LV_FILENAME TYPE STRING, "文件名
LV_WINTITLE TYPE STRING, "文件标题
LV_FILEPATH TYPE STRING, "路径
LV_FULLPATH TYPE STRING, "全路径
LV_DEFAULT TYPE STRING. "默认文件名
DATA: TITLE TYPE STRING VALUE '.XLS'.
DATA:G_ACTION TYPE I.
CLEAR:G_ACTION.
LV_WINTITLE = 'EXCEL文档'.
LV_DEFAULT = TITLE.
*&---打开保存对话框
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = LV_WINTITLE
DEFAULT_EXTENSION = 'XLS'
DEFAULT_FILE_NAME = LV_DEFAULT
FILE_FILTER = 'XLS'
* INITIAL_DIRECTORY =
CHANGING
FILENAME = LV_FILENAME
PATH = LV_FILEPATH
FULLPATH = LV_FULLPATH
USER_ACTION = G_ACTION
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
OTHERS = 3.
IF SY-SUBRC = 0 AND G_ACTION = 0.
DATA: P_FILE TYPE RLGRAP-FILENAME.
P_FILE = LV_FULLPATH.
*&---保存文件
CALL METHOD GR_DOCUMENT->SAVE_AS
EXPORTING
FILE_NAME = P_FILE.
IF SY-SUBRC = 0.
MESSAGE '文件已保存!' TYPE 'I'.
LEAVE TO SCREEN 0.
ENDIF.
ELSE.
CLEAR SY-UCOMM.
ENDIF.
ENDFORM. " SAVE_EXCEL
*&---------------------------------------------------------------------*
*& FORM S2B
*&---------------------------------------------------------------------*
* TEXT
*----------------------------------------------------------------------*
* -->P_G_SUM_MONEY TEXT
* -->P_G_GCZJE_BIG TEXT
*----------------------------------------------------------------------*
FORM S2B USING P_G_SUM_MONEY
P_G_GCZJE_BIG.
DATA:
V_S00(2) VALUE '零',
V_S01(2) VALUE '壹',
V_S02(2) VALUE '贰',
V_S03(2) VALUE '叁',
V_S04(2) VALUE '肆',
V_S05(2) VALUE '伍',
V_S06(2) VALUE '陆',
V_S07(2) VALUE '柒',
V_S08(2) VALUE '捌',
V_S09(2) VALUE '玖',
V_W00(2) VALUE '',
V_W01(2) VALUE '拾',
V_W02(2) VALUE '佰',
V_W03(2) VALUE '仟',
V_W04(2) VALUE '万',
V_W05(4) VALUE '拾',
V_W06(4) VALUE '佰',
V_W07(4) VALUE '仟',
V_W08(2) VALUE '亿',
V_W09(4) VALUE '拾',
V_W10(4) VALUE '佰',
V_W11(4) VALUE '仟',
V_W12(4) VALUE '万',
V_SY(2) VALUE '圆',
V_SJ(2) VALUE '角',
V_SF(2) VALUE '分',
V_AMOUNT(16), "将金额转换成字符型
V_LEN TYPE I, "V_AMOUNT或OUT的长度
V_VAR(5), "V_S0,V_S1,...,V_W0,V_W1,...
V_NUM(2) TYPE N, "每一位的数值
V_S_NUM(2), "V_S0,V_S1,...中的值
V_WEIGHT(2) TYPE N, "权数
V_W_NUM(4), "V_W0,V_W1,...中的值
V_FLAG0 TYPE I VALUE 0, "是否输出'零',0不输出,1输出
V_N TYPE I VALUE 0,
V_INDEX TYPE SY-INDEX.
V_AMOUNT = P_G_SUM_MONEY.
SHIFT V_AMOUNT LEFT DELETING LEADING SPACE.
SHIFT V_AMOUNT LEFT DELETING LEADING '0'.
*-计算分-----------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 1.
V_NUM = V_AMOUNT+V_LEN(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM V_SF P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-计算角-----------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 2.
V_NUM = V_AMOUNT+V_LEN(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM V_SJ P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-输出‘整’字-------------------------------------
IF P_G_GCZJE_BIG = ' '.
CONCATENATE '整' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
*-计算整数---------------------------------------
V_LEN = STRLEN( V_AMOUNT ).
V_LEN = V_LEN - 3.
IF V_LEN = 0.
EXIT.
ENDIF.
V_AMOUNT = V_AMOUNT(V_LEN). " 整数部分
*-输出‘元’字-------------------------------------
CONCATENATE V_SY P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_N = V_LEN - 1.
V_WEIGHT = 0.
DO V_LEN TIMES.
V_INDEX = SY-INDEX.
* 从个位开始
V_NUM = V_AMOUNT+V_N(1).
IF V_NUM <> '0'.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE 'V_W' V_WEIGHT INTO V_VAR.
WRITE (V_VAR) TO V_W_NUM.
CONCATENATE V_S_NUM V_W_NUM P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_FLAG0 = 1.
ELSE.
IF V_FLAG0 = 1.
CONCATENATE 'V_S' V_NUM INTO V_VAR.
WRITE (V_VAR) TO V_S_NUM.
CONCATENATE V_S_NUM P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
V_FLAG0 = 0.
ENDIF.
IF V_INDEX = 5 AND V_LEN > 5 AND V_LEN < 9 .
CONCATENATE '万' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ELSEIF V_INDEX = 9 AND V_LEN > 9.
CONCATENATE '亿' P_G_GCZJE_BIG INTO P_G_GCZJE_BIG.
ENDIF.
* CASE SY-INDEX.
* WHEN 5.CONCATENATE '万' OUT INTO OUT.
* WHEN 9.CONCATENATE '亿' OUT INTO OUT.
* ENDCASE.
ENDIF.
V_WEIGHT = V_WEIGHT + 1.
V_N = V_N - 1.
ENDDO.
*-删除个位可能出现'零'的情况-----------------
SEARCH P_G_GCZJE_BIG FOR '圆'.
IF SY-SUBRC = 0.
V_N = SY-FDPOS - 2.
IF V_N >= 0.
IF P_G_GCZJE_BIG+V_N(2) = V_S00.
V_LEN = STRLEN( P_G_GCZJE_BIG ).
CONCATENATE P_G_GCZJE_BIG(V_N) P_G_GCZJE_BIG+SY-FDPOS INTO P_G_GCZJE_BIG.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " S2B