select vbrp.vgbel frOM vbrk vbrk INNER JOIN vbrp ON vbrk.vbeln = vbrp.vbeln
SELECT * FROM vbrk
INNER JOIN vbrp ON vbrk.vbeln = vbrp.vbeln
left join (SELECT distinct A.VBELN as x_VBELN ,e.VBELN as j_VBELN
FROM VBAK AS A
LEFT JOIN VBAP AS B ON A.VBELN = B.VBELN
LEFT JOIN VBPA AS D ON A.VBELN = D.VBELN AND D.PARVW = 'Z3'
LEFT JOIN VBKD ON B.VBELN = VBKD.VBELN AND B.POSNR = VBKD.POSNR
LEFT JOIN LIPS AS E ON B.VBELN = E.VGBEL AND B.POSNR = E.VGPOS
LEFT JOIN LIKP AS F ON E.VBELN = F.VBELN
WHERE 1=1
-- and A.VBELN = '0010000031'
and e.VBELN = '0080001285' ) vl on vl.j_VBELN = vbrp.vgbel
select VBAK.VBELN from LIPS as LIPS
left join VBAK as VBAK on VBAK.VBELN = LIPS.VGBEL
where LIPS.VBELN = '0080001285'
*&---------------------------------------------------------------------*
*& 程序名称/Program Name :ZsdP001
*& 程序名称/Program Des :销售发票打印
:
*&
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 摘要:
*&
*&---------------------------------------------------------------------*
*&变更记录:
*&Date Developer ReqNo Descriptions
*&============ ============= ============= ==========================
*&
*&---------------------------------------------------------------------*
REPORT ZSDP001.
TABLES: MSEG,MKPF,RBKP,SSCRFIELDS.
TABLES:vbak,vbap,vkdfs,lips,ekpo,tvfkt,kna1,makt,vbrk,mara,t134t.
TYPE-POOLS: SLIS.
"TYPES: BEGIN OF TY_PRINT,
" fkdat LIKE vkdfs-fkdat, "出具发票日期
" vkorg LIKE vbak-vkorg , "销售组织
" vkorg_txt LIKE tvkot-vtext, "描述
" kkber LIKE vbrk-kkber, "信贷范围
" kkbtx LIKE t014t-kkbtx, "信贷范围描述
" fkart LIKE vkdfs-fkart, "发票类型
" vtext LIKE tvfkt-vtext, "发票类型描述
" vbtyp LIKE vbrk-vbtyp, "凭证类别
" rfbsk LIKE vbrk-rfbsk, "传输到会计核算的状态
" rfbsk_txt TYPE string,
" kunag LIKE vbrk-kunag, "客户
" name LIKE kna1-name1, "客户名称
" kunrg LIKE vbrk-kunrg, "付款方
" name1 LIKE kna1-name1, "付款方名称
" land1 LIKE vbrk-land1, "国家
" regio LIKE vbrk-regio, "地区
" bezei LIKE t005u-bezei, "地区描述
" vbeln LIKE vbrk-vbeln, "单号
" posnr LIKE vbrp-posnr, "行号
" matnr LIKE vbap-matnr, "物料
" maktx LIKE makt-maktx, "物料描述
" fkimg LIKE vbrp-fkimg, "数量
" vrkme LIKE vbrp-vrkme, "单位
" mseht LIKE t006a-mseht, "单位描述
" netwr LIKE vbrp-netwr, "净值
" mwsbp LIKE vbrp-mwsbp, "税额
" kzwi1 LIKE vbrp-kzwi1, "总金额
" waerk LIKE vbrp-waerk, "货币
" fksto LIKE vbrk-fksto, "发票取消标识
" vgbel LIKE vbrp-vgbel, "参考单据的单据编号
" vgpos LIKE vbrp-vgpos, "参考项目的项目号
" podat LIKE likp-podat,
" wadat_ist LIKE likp-wadat_ist,
" vin TYPE char100, "VIN号拼接 20201027
" vbrp like vbrp-ERNAM,
" END OF TY_PRINT.
TYPES: BEGIN OF TY_PRINT,
vbeln LIKE vbrk-vbeln, "单号
fkdat LIKE vkdfs-fkdat, "出具发票日期
kunag LIKE vbrk-kunag, "客户
name LIKE kna1-name1, "客户名称
XSDDH type string, "销售订单号
vgbel LIKE vbrp-vgbel, "参考单据的单据编号
vkorg_txt LIKE tvkot-vtext, "销售组织描述
posnr LIKE vbrp-posnr, "行号
matnr LIKE vbap-matnr, "物料
maktx LIKE makt-maktx, "物料描述
vin TYPE char100, "VIN号拼接 20201027
mseht LIKE t006a-mseht, "单位描述
fkimg LIKE vbrp-fkimg, "数量
netwr LIKE vbrp-netwr, "净值
mwsbp LIKE vbrp-mwsbp, "税额
kzwi1 LIKE vbrp-kzwi1, "总金额
ERNAM like vbrp-ERNAM,
END OF TY_PRINT.
TYPES: BEGIN OF line1,
fkdat LIKE vkdfs-fkdat, "出具发票日期
vkorg LIKE vbak-vkorg , "销售组织
vkorg_txt LIKE tvkot-vtext, "描述
kkber LIKE vbrk-kkber, "信贷范围
kkbtx LIKE t014t-kkbtx, "信贷范围描述
fkart LIKE vkdfs-fkart, "发票类型
vtext LIKE tvfkt-vtext, "发票类型描述
vbtyp LIKE vbrk-vbtyp, "凭证类别
rfbsk LIKE vbrk-rfbsk, "传输到会计核算的状态
rfbsk_txt TYPE string,
kunag LIKE vbrk-kunag, "客户
name LIKE kna1-name1, "客户名称
XSDDH type string, "销售订单号
kunrg LIKE vbrk-kunrg, "付款方
name1 LIKE kna1-name1, "付款方名称
land1 LIKE vbrk-land1, "国家
regio LIKE vbrk-regio, "地区
bezei LIKE t005u-bezei, "地区描述
vbeln LIKE vbrk-vbeln, "单号
posnr LIKE vbrp-posnr, "行号
matnr LIKE vbap-matnr, "物料
maktx LIKE makt-maktx, "物料描述
* MTART LIKE MARA-MTART, "物料类型
* MTBEZ LIKE T134T-MTBEZ, "描述
fkimg LIKE vbrp-fkimg, "数量
vrkme LIKE vbrp-vrkme, "单位
mseht LIKE t006a-mseht, "单位描述
netwr LIKE vbrp-netwr, "净值
mwsbp LIKE vbrp-mwsbp, "税额
kzwi1 LIKE vbrp-kzwi1, "总金额
waerk LIKE vbrp-waerk, "货币
fksto LIKE vbrk-fksto, "发票取消标识
vgbel LIKE vbrp-vgbel, "参考单据的单据编号
vgpos LIKE vbrp-vgpos, "参考项目的项目号
podat LIKE likp-podat,
wadat_ist LIKE likp-wadat_ist,
* NETPR LIKE VBAP-NETPR,"单价
* STPRS LIKE MBEW-STPRS,"成本价
vin TYPE char100, "VIN号拼接 20201027
ERNAM like vbrp-ERNAM,
END OF line1.
TYPES: BEGIN OF TY_ALV.
INCLUDE TYPE line1." 视图
TYPES: ZBOX TYPE CHAR1,
RETPO_TEXT TYPE STRING,
REPOS_TEXT TYPE STRING,
USNAM_TEXT TYPE STRING,
ERNAM_TEXT TYPE STRING,
MENGE1 TYPE MENGE_D,
BKTXT TYPE MKPF-BKTXT,
SGTXT TYPE MSEG-SGTXT,
END OF TY_ALV.
TYPES: BEGIN OF line2,
vbeln LIKE vbpa-vbeln,
parvw LIKE vbpa-parvw,
kunnr LIKE vbpa-kunnr,
name1 LIKE kna1-name1,
END OF line2.
DATA: zkzwi1 LIKE vbap-kzwi1,
znetwr LIKE vbap-netwr,
zmwsbp LIKE vbap-mwsbp,
zkwmeng LIKE vbap-kwmeng,
vprsv LIKE mbew-vprsv.
DATA: it_out TYPE TY_ALV OCCURS 0 WITH HEADER LINE.
DATA: it_vbpa1 TYPE line2 OCCURS 0 WITH HEADER LINE,
it_vbpa2 TYPE line2 OCCURS 0 WITH HEADER LINE.
DATA: it_vkdfs TYPE vkdfs OCCURS 0 WITH HEADER LINE.
DATA: it_lips TYPE lips OCCURS 0 WITH HEADER LINE,
it_likp TYPE likp OCCURS 0 WITH HEADER LINE.
DATA: it_vbap TYPE vbap OCCURS 0 WITH HEADER LINE,
it_vbak TYPE vbak OCCURS 0 WITH HEADER LINE,
it_vbak1 TYPE vbak OCCURS 0 WITH HEADER LINE,
it_vbap1 TYPE vbap OCCURS 0 WITH HEADER LINE.
DATA: it_tvkot TYPE tvkot OCCURS 0 WITH HEADER LINE,
it_t014t TYPE t014t OCCURS 0 WITH HEADER LINE,
it_t014t_dn TYPE t014t OCCURS 0 WITH HEADER LINE,
it_t014t_so TYPE t014t OCCURS 0 WITH HEADER LINE,
it_tvfkt TYPE tvfkt OCCURS 0 WITH HEADER LINE,
it_kna1 TYPE kna1 OCCURS 0 WITH HEADER LINE,
it_kna2 TYPE kna1 OCCURS 0 WITH HEADER LINE,
it_t005u TYPE t005u OCCURS 0 WITH HEADER LINE,
it_makt TYPE makt OCCURS 0 WITH HEADER LINE,
it_makt_dn TYPE makt OCCURS 0 WITH HEADER LINE,
it_makt_so TYPE makt OCCURS 0 WITH HEADER LINE,
it_t006a TYPE t006a OCCURS 0 WITH HEADER LINE,
it_t006a_so TYPE t006a OCCURS 0 WITH HEADER LINE,
it_t006a_dn TYPE t006a OCCURS 0 WITH HEADER LINE.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat,
v_repid LIKE sy-repid,
wa_layout TYPE slis_layout_alv,
lr_grid TYPE REF TO cl_gui_alv_grid,
ls_variant TYPE disvariant.
DATA: GT_ALV TYPE TABLE OF TY_ALV,
GS_ALV TYPE TY_ALV,
GT_PRINT TYPE TABLE OF TY_PRINT,
GS_PRINT TYPE TY_PRINT.
DATA: GS_LAYOUT TYPE LVC_S_LAYO,
GT_FIELDCAT TYPE LVC_T_FCAT,
GS_FIELDCAT TYPE LVC_S_FCAT.
DATA: GO TYPE C,
DOWN TYPE C.
DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.
DATA: EXCL_CUA_FUNCT TYPE TABLE OF VIMEXCLFUN WITH HEADER LINE.
DATA: IT_ZPRINTTEMP TYPE ZMMDOC3000 OCCURS 0 WITH HEADER LINE.
*&------------------------------------------------------------------
****SELECTION-SCREEN.
*&------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS:
s_vkorg FOR vbak-vkorg OBLIGATORY DEFAULT 1000,
s_kunnr FOR vbak-kunnr,
s_matnr FOR vbap-matnr,
s_fkart FOR vbrk-fkart,
s_vbeln FOR vbrk-vbeln,
s_fksto FOR vbrk-fksto,
s_erdat FOR sy-datum OBLIGATORY .
SELECTION-SCREEN: FUNCTION KEY 3.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME DEFAULT 'C:\REPORT\' NO-DISPLAY .
SELECTION-SCREEN END OF BLOCK B1.
*&------------------------------------------------------------------
****INITIALIZATION.
*&------------------------------------------------------------------
INITIALIZATION.
SSCRFIELDS-FUNCTXT_02 = '维护打印格式'.
SSCRFIELDS-FUNCTXT_01 = '维护打印类别'.
SSCRFIELDS-FUNCTXT_03 = '更新打印模板'.
**&--------------------------------------------------------------------*
** AT SELECTION-SCREEN OUTPUT
**&--------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
PERFORM FRM_CONTROL_SCREEN.
*&---------------------------------------------------------------------*
* AT SELECTION-SCREEN
*&---------------------------------------------------------------------*
AT SELECTION-SCREEN.
PERFORM FRM_UCOMM.
*&------------------------------------------------------------------
****START OF SELECTION
*&------------------------------------------------------------------
START-OF-SELECTION.
PERFORM FRM_GET_DATA1.
*&------------------------------------------------------------------
****END OF SELECTION
*&------------------------------------------------------------------
END-OF-SELECTION.
PERFORM FROM_SHOW_ALV.
*&---------------------------------------------------------------------*
*& Form FRM_UCOMM
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_UCOMM .
CASE SSCRFIELDS-UCOMM.
WHEN 'FC01'.
MOVE 'ANZG' TO EXCL_CUA_FUNCT-FUNCTION.
APPEND EXCL_CUA_FUNCT.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
ACTION = 'S'
VIEW_NAME = 'ZMVTYT3000'
TABLES
* DBA_SELLIST = IT_DBA_SELLIST
EXCL_CUA_FUNCT = EXCL_CUA_FUNCT
EXCEPTIONS
CLIENT_REFERENCE = 1
FOREIGN_LOCK = 2
INVALID_ACTION = 3
NO_CLIENTINDEPENDENT_AUTH = 4
NO_DATABASE_FUNCTION = 5
NO_EDITOR_FUNCTION = 6
NO_SHOW_AUTH = 7
NO_TVDIR_ENTRY = 8
NO_UPD_AUTH = 9
ONLY_SHOW_ALLOWED = 10
SYSTEM_FAILURE = 11
UNKNOWN_FIELD_IN_DBA_SELLIST = 12
VIEW_NOT_FOUND = 13
MAINTENANCE_PROHIBITED = 14
OTHERS = 15.
WHEN 'FC02'.
MOVE 'ANZG' TO EXCL_CUA_FUNCT-FUNCTION. APPEND EXCL_CUA_FUNCT.
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
ACTION = 'S'
VIEW_NAME = 'ZMMDOC3000'
TABLES
EXCL_CUA_FUNCT = EXCL_CUA_FUNCT
EXCEPTIONS
CLIENT_REFERENCE = 1
FOREIGN_LOCK = 2
INVALID_ACTION = 3
NO_CLIENTINDEPENDENT_AUTH = 4
NO_DATABASE_FUNCTION = 5
NO_EDITOR_FUNCTION = 6
NO_SHOW_AUTH = 7
NO_TVDIR_ENTRY = 8
NO_UPD_AUTH = 9
ONLY_SHOW_ALLOWED = 10
SYSTEM_FAILURE = 11
UNKNOWN_FIELD_IN_DBA_SELLIST = 12
VIEW_NOT_FOUND = 13
MAINTENANCE_PROHIBITED = 14
OTHERS = 15.
WHEN 'FC03'.
DATA: G_FILEN LIKE WWWDATATAB-OBJID VALUE 'ZSDP001' ." 要下载的模板名称
DATA: LV_OBJDATA LIKE WWWDATATAB,
LV_OBJ_NAME LIKE WWWDATATAB-OBJID,
LV_DESTINATION LIKE RLGRAP-FILENAME,
LV_OBJID LIKE SY-REPID,
LV_SUBRC LIKE SY-SUBRC.
DATA: LV_FILE TYPE RLGRAP-FILENAME,
LS_FILE TYPE STRING.
MOVE G_FILEN TO LV_OBJ_NAME.
SELECT RELID OBJID INTO CORRESPONDING FIELDS OF LV_OBJDATA
FROM WWWDATA UP TO 1 ROWS
WHERE SRTF2 = 0 AND RELID = 'MI'
AND OBJID = LV_OBJ_NAME.
ENDSELECT.
CONCATENATE P_FILE 'ZSDP001.XLS' INTO LV_FILE.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
KEY = LV_OBJDATA
DESTINATION = LV_FILE
IMPORTING
RC = LV_SUBRC.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_get_data1 .
CLEAR: IT_ZPRINTTEMP[].
SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_ZPRINTTEMP FROM ZMMDOC3000 WHERE MVTYP = 'T4'.
SELECT vbrk~fkdat vbrk~vbeln vbrk~fkart vbrk~vkorg vbrk~kunag vbrk~kunrg vbrk~kkber vbrk~rfbsk vbrk~regio vbrk~land1 vbrk~fksto vbrk~vbtyp
vbrp~posnr vbrp~matnr vbrp~fkimg vbrp~vrkme vbrp~netwr vbrp~mwsbp vbrp~kzwi1 vbrp~vgbel vbrp~vgpos vbrp~waerk vbrp~ERNAM VBAK~VBELN as XSDDH
INTO CORRESPONDING FIELDS OF TABLE it_out FROM vbrk INNER JOIN vbrp ON vbrk~vbeln = vbrp~vbeln
inner join LIPS as LIPS on LIPS~VBELN = vbrp~vgbel
inner join VBAK as VBAK on VBAK~VBELN = LIPS~VGBEL
"select VBAK.VBELN from LIPS as LIPS
"left join VBAK as VBAK on VBAK.VBELN = LIPS.VGBEL
"where LIPS.VBELN = '0080001285'
WHERE vbrk~vkorg IN s_vkorg
AND vbrk~fkart IN s_fkart
and vbrk~fkart in ('ZZF2','ZZRE','ZPF2','ZPRE') " 发票类型时整车
AND vbrk~kunag IN s_kunnr
AND vbrp~matnr IN s_matnr
AND vbrk~fkdat IN s_erdat
AND vbrk~fksto IN s_fksto
AND vbrk~vbeln IN s_vbeln
AND vbrk~sfakn EQ ''. "VBRK~VBTYP IN ( 'M','O','P' )."排除掉冲销发票凭证
SORT it_out BY vbeln matnr .
DELETE ADJACENT DUPLICATES FROM it_out COMPARING vbeln matnr XSDDH .
DELETE it_out WHERE fkimg IS INITIAL. "发货时批次拆分的汇总行去掉
IF it_out[] IS NOT INITIAL.
SELECT *
FROM zv_zsd005_cds01
INTO TABLE @DATA(lt_sernr)
FOR ALL ENTRIES IN @it_out
WHERE lief_nr = @it_out-vgbel
AND posnr = @it_out-vgpos.
SORT lt_sernr BY lief_nr posnr.
ENDIF.
" 销售订单号
"销售组织描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_tvkot FROM tvkot
FOR ALL ENTRIES IN it_out
WHERE vkorg = it_out-vkorg
AND spras = sy-langu.
"信贷控制范围描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_t014t FROM t014t
FOR ALL ENTRIES IN it_out
WHERE kkber = it_out-kkber
AND spras = sy-langu.
"发票类型描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_tvfkt FROM tvfkt
FOR ALL ENTRIES IN it_out
WHERE fkart = it_out-fkart
AND spras = sy-langu.
"客户名称
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_kna1 FROM kna1
FOR ALL ENTRIES IN it_out
WHERE kunnr = it_out-kunag.
"付款方名称
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_kna2 FROM kna1
FOR ALL ENTRIES IN it_out
WHERE kunnr = it_out-kunrg.
"地区描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_t005u FROM t005u
FOR ALL ENTRIES IN it_out
WHERE bland = it_out-regio
AND land1 = it_out-land1
AND spras = sy-langu.
"物料描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_makt FROM makt
FOR ALL ENTRIES IN it_out
WHERE matnr = it_out-matnr
AND spras = sy-langu.
"单位描述
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_t006a FROM t006a
FOR ALL ENTRIES IN it_out
WHERE msehi = it_out-vrkme
AND spras = sy-langu.
" 新增 交货单过账日期 POD过账日期 20210204 by zwj BEGIN
SELECT vbeln,
wadat_ist,
podat
FROM likp INTO TABLE @DATA(lt_likp)
FOR ALL ENTRIES IN @it_out
WHERE vbeln = @it_out-vgbel.
" 新增 交货单过账日期 POD过账日期 20210204 by zwj end
LOOP AT it_out.
" 销售订单号
READ TABLE it_tvkot WITH KEY vkorg = it_out-vkorg.
it_out-vkorg_txt = it_tvkot-vtext.
READ TABLE it_t014t WITH KEY kkber = it_out-kkber.
it_out-kkbtx = it_t014t-kkbtx.
READ TABLE it_tvfkt WITH KEY fkart = it_out-fkart.
it_out-vtext = it_tvfkt-vtext.
READ TABLE it_kna1 WITH KEY kunnr = it_out-kunag.
it_out-name = it_kna1-name1.
READ TABLE it_kna2 WITH KEY kunnr = it_out-kunag.
it_out-name1 = it_kna2-name1.
READ TABLE it_t005u WITH KEY bland = it_out-regio land1 = it_out-land1.
it_out-bezei = it_t005u-bezei.
READ TABLE it_makt WITH KEY matnr = it_out-matnr.
it_out-maktx = it_makt-maktx.
READ TABLE it_t006a WITH KEY msehi = it_out-vrkme.
it_out-mseht = it_t006a-mseht.
" 20210204 BY ZWJ begin
READ TABLE lt_likp INTO DATA(ls_likp) WITH KEY vbeln = it_out-vgbel.
it_out-wadat_ist = ls_likp-wadat_ist.
it_out-podat = ls_likp-podat.
" 20210204 BY ZWJ end
IF it_out-rfbsk = 'C'.
it_out-rfbsk_txt = '已过账'.
ELSE.
it_out-rfbsk_txt = '未过账'.
ENDIF.
"取序列号 20201027
READ TABLE lt_sernr TRANSPORTING NO FIELDS WITH KEY lief_nr = it_out-vgbel
posnr = it_out-vgpos BINARY SEARCH.
IF sy-subrc = 0.
DATA(lv_index) = sy-tabix.
LOOP AT lt_sernr INTO DATA(ls_sernr) FROM lv_index.
IF ls_sernr-lief_nr <> it_out-vgbel OR ls_sernr-posnr <> it_out-vgpos.
EXIT.
ENDIF.
IF it_out-vin IS INITIAL.
it_out-vin = ls_sernr-sernr.
ELSE.
CONCATENATE it_out-vin ',' ls_sernr-sernr INTO it_out-vin.
ENDIF.
CLEAR: ls_sernr.
ENDLOOP.
ENDIF.
"取序列号 20201027
IF it_out-vbtyp = 'O'."退货/贷项
it_out-fkimg = -1 * it_out-fkimg.
it_out-netwr = -1 * it_out-netwr.
it_out-mwsbp = -1 * it_out-mwsbp.
it_out-kzwi1 = -1 * it_out-kzwi1.
ENDIF.
MODIFY it_out.
CLEAR:it_out,it_tvkot,it_t014t,it_tvfkt,it_kna1,it_kna2,it_t005u,it_makt,it_t006a.
ENDLOOP.
CLEAR: GT_ALV.
Append lines of it_out to GT_ALV.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FROM_SHOW_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FROM_SHOW_ALV .
data : p_rd2 type string value 'X'.
GS_LAYOUT-ZEBRA = ABAP_TRUE.
GS_LAYOUT-CWIDTH_OPT = ABAP_TRUE.
GS_LAYOUT-SEL_MODE = 'B'.
CLEAR GT_FIELDCAT.
PERFORM FRM_SET_FIELDCAT USING 'ZBOX' '选择' '' '' 'X' ''.
PERFORM FRM_SET_FIELDCAT USING 'VBELN' '单号(销售发票号)' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'FKDAT' '出具发票日期' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'VKORG_TXT' '销售组织' '' '' 'X' '' .
*PERFORM FRM_SET_FIELDCAT USING 'KKBER' '信贷范围' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'KKBTX' '信贷范围' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'FKART' '发票类型' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'VTEXT' '描述' '' '' 'X' '' .
*PERFORM FRM_SET_FIELDCAT USING 'RFBSK' '过账状态' '' '' 'X' '' .
IF p_rd2 = 'X'.
PERFORM FRM_SET_FIELDCAT USING 'RFBSK_TXT' '过账状态' '' '' 'X' '' .
ENDIF.
PERFORM FRM_SET_FIELDCAT USING 'KUNAG' '客户' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'NAME' '客户名称' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'KUNRG' '付款方' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'NAME1' '付款方名称' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'LAND1' '国家' '' '' 'X' '' .
IF p_rd2 = 'X'.
PERFORM FRM_SET_FIELDCAT USING 'REGIO' '地区' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'BEZEI' '地区' '' '' 'X' '' .
ENDIF.
PERFORM FRM_SET_FIELDCAT USING 'POSNR' '行号' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'MATNR' '物料' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'MAKTX' '物料描述' '' '' 'X' '' .
*PERFORM FRM_SET_FIELDCAT USING 'MTART' '物料类型' '' '' 'X' '' .
*PERFORM FRM_SET_FIELDCAT USING 'MTBEZ' '物料类型' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'FKIMG' '数量' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'MSEHT' '单位' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'NETWR' '净值' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'MWSBP' '税额' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'KZWI1' '总金额' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'WAERK' '货币' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'PODAT' 'POD过账日期' '' '' 'X' '' . "20210204 by ZWJ
PERFORM FRM_SET_FIELDCAT USING 'WADAT_IST' '交货单过账日期' '' '' 'X' '' . "20210204 by ZWJ
IF p_rd2 = 'X'.
PERFORM FRM_SET_FIELDCAT USING 'FKSTO' '取消标识' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'VGBEL' '参考单号(交货单号)' '' '' 'X' '' .
PERFORM FRM_SET_FIELDCAT USING 'VGPOS' '参考单据行号' '' '' 'X' '' .
ENDIF.
LOOP AT it_fieldcat[] INTO wa_fieldcat WHERE fieldname = 'MATNR'.
wa_fieldcat-outputlen = '40'.
MODIFY it_fieldcat[] FROM wa_fieldcat.
ENDLOOP.
PERFORM FRM_SET_FIELDCAT USING 'VIN' 'VIN码' '' '' '' '' .
PERFORM FRM_SET_FIELDCAT USING 'ERNAM' '制单人' '' '' '' '' .
DATA: LDF_GRID_SETTINGS TYPE LVC_S_GLAY.
LDF_GRID_SETTINGS-EDT_CLL_CB = 'X'. "刷新
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_GRID_SETTINGS = LDF_GRID_SETTINGS
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = GT_FIELDCAT
* it_events = gt_event
I_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET'
I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'
I_SAVE = 'A'
TABLES
T_OUTTAB = GT_ALV
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
"* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*& --> P_
*&---------------------------------------------------------------------*
FORM FRM_SET_FIELDCAT USING VALUE(P_FIELDNAME)
VALUE(P_COLTEXT)
VALUE(P_REF_FIELD)
VALUE(P_REF_TABLE)
VALUE(P_EDIT)
VALUE(P_TEMP).
CLEAR GS_FIELDCAT.
GS_FIELDCAT-FIELDNAME = P_FIELDNAME.
GS_FIELDCAT-COLTEXT = P_COLTEXT.
GS_FIELDCAT-REF_FIELD = P_REF_FIELD.
GS_FIELDCAT-REF_TABLE = P_REF_TABLE.
GS_FIELDCAT-EDIT = P_EDIT.
* GS_FIELDCAT-FIX_COLUMN = P_TEMP.
IF P_FIELDNAME EQ 'ZBOX'.
GS_FIELDCAT-CHECKBOX = 'X'.
ENDIF.
APPEND GS_FIELDCAT TO GT_FIELDCAT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_STATUS_SET
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_STATUS_SET USING RT_EXTAB TYPE SLIS_T_EXTAB.
DATA: LS_EXTAB TYPE SLIS_EXTAB.
SET PF-STATUS 'ZSTANDARD'.
SET TITLEBAR 'ZTITLEBAR1'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_USER_COMMAND USING
R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA: LO_GRID TYPE REF TO CL_GUI_ALV_GRID.
* 设置刷新模式,行列保持不变
RS_SELFIELD-REFRESH = 'X'.
RS_SELFIELD-COL_STABLE = 'X'.
RS_SELFIELD-ROW_STABLE = 'X'.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LO_GRID.
CALL METHOD LO_GRID->CHECK_CHANGED_DATA.
"自定义按钮事件
CASE R_UCOMM.
WHEN 'ALL'.
LOOP AT GT_ALV ASSIGNING FIELD-SYMBOL(<FS_ALV>) WHERE ZBOX IS INITIAL.
<FS_ALV>-ZBOX = 'X'.
ENDLOOP.
WHEN 'SAL'.
LOOP AT GT_ALV ASSIGNING <FS_ALV> WHERE ZBOX IS NOT INITIAL.
CLEAR <FS_ALV>-ZBOX.
ENDLOOP.
WHEN 'PRI'. "D打印
PERFORM FRM_PRINT.
WHEN OTHERS.
ENDCASE.
* 设置刷新模式,行列保持不变
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LO_GRID.
CALL METHOD LO_GRID->CHECK_CHANGED_DATA.
ENDFORM .
*&---------------------------------------------------------------------*
*& Form FRM_PRINT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_PRINT .
DATA: I TYPE I.
DATA: LT_ALV TYPE TABLE OF TY_ALV,
LS_ALV TYPE TY_ALV.
DATA: EXCL_CUA_FUNCT TYPE TABLE OF VIMEXCLFUN WITH HEADER LINE.
IF LINES( IT_ZPRINTTEMP[] ) = 0.
MESSAGE W001(00) WITH '没有定义' 'T4' '打印模板!' .
EXIT.
ENDIF.
CLEAR: GT_PRINT.
LOOP AT GT_ALV INTO GS_ALV WHERE ZBOX IS NOT INITIAL.
COLLECT GS_ALV INTO LT_ALV.
CLEAR: GS_ALV.
ENDLOOP.
SORT LT_ALV BY vbeln.
"去重
DELETE ADJACENT DUPLICATES FROM LT_ALV COMPARING vbeln XSDDH."LFBNR
* 填充数据
LOOP AT LT_ALV INTO LS_ALV.
DATA:
GT_ALV2 TYPE TABLE OF TY_ALV,
GS_ALV2 TYPE TY_ALV,
GT_PRINT2 TYPE TABLE OF TY_PRINT,
GS_PRINT2 TYPE TY_PRINT.
LOOP AT GT_ALV INTO GS_ALV WHERE vbeln = LS_ALV-vbeln .
ENDLOOP.
LOOP AT GT_ALV INTO GS_ALV WHERE vbeln = LS_ALV-vbeln .
MOVE-CORRESPONDING GS_ALV TO GS_PRINT.
APPEND GS_PRINT TO GT_PRINT.
CLEAR: GS_PRINT,GS_ALV.
ENDLOOP.
CLEAR: LS_ALV.
ENDLOOP.
CHECK GT_PRINT IS NOT INITIAL.
SORT GT_PRINT BY vbeln ."LFBNR
" 扣款记录数据加到打印里
Append lines of GT_PRINT2 to GT_PRINT.
DATA: FILENAME LIKE RLGRAP-FILENAME.
CONCATENATE P_FILE 'ZSDPRINTP001.DAT' INTO FILENAME.
SORT IT_ZPRINTTEMP BY POSNR.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
* CODEPAGE = '8400'
FILENAME = FILENAME
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_ZPRINTTEMP.
down = 'X'.
CALL FUNCTION 'Z_EXCEL_DISPLAY'
EXPORTING
FILE_PATH = P_FILE
FILE_NAME = 'ZSDP001'
DOWN = DOWN
TABLES
ITAB = GT_PRINT.
* CLEAR: gt_print.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CONTROL_SCREEN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_CONTROL_SCREEN .
DATA: WA_ZMVTYT TYPE ZMVTYT3000.
CLEAR LIST.
SELECT * INTO WA_ZMVTYT
FROM ZMVTYT3000.
NAME = 'P_MVTYP'.
VALUE-KEY = WA_ZMVTYT-MVTYP.
CONCATENATE '-' WA_ZMVTYT-TXT20 INTO VALUE-TEXT .
APPEND VALUE TO LIST.
ENDSELECT.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'P_MVTYP'
VALUES = LIST[].
ENDFORM.