复制程序应该有部分对象需要自行创建,需要调试,仅供参考
需要打印的模板
程序代码
*&---------------------------------------------------------------------*
*& 程序名称/Program Name :ZMMP001
*& 程序名称/Program Des :采购发票:
*&
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& 摘要:
*&
*&---------------------------------------------------------------------*
*&变更记录:
*&Date Developer ReqNo Descriptions
*&============ ============= ============= ==========================
*&
*&---------------------------------------------------------------------*
REPORT ZMMP002.TABLES: MSEG,MKPF,RBKP,SSCRFIELDS.
TYPE-POOLS: SLIS.TYPES: BEGIN OF TY_ALV.INCLUDE TYPE ZV_MMP001_MSEG.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 TY_PRINT,"MANDT TYPE RBKP-MANDT,BELNR TYPE RBKP-BELNR, ""发票号BLDAT TYPE RBKP-BLDAT, "发票日期NAME1_BU TYPE T001W-NAME1,"财务组织 RBKP-BUKRS"NAME1_BU type T001W-NAME1,LIFNR TYPE LFA1-LIFNR," 供应商编码NAME1 TYPE LFA1-NAME1, "供应商名"EKNAM TYPE T024-EKNAM,EKGRP TYPE T024-EKNAM,""采购部门 EKNAM TYPE T024-EKNAM,""采购部门描述KGXJV type STRING,""扣款小计WMWST1 TYPE RBKP-WMWST1,""税额YFJEV type STRING,""应付金额BANKL TYPE LFBK-BANKL,""开户行KOINH TYPE LFBK-KOINH,""账户名称BANKN TYPE LFBK-BANKN, ""银行帐户号码BKTXT type BKTXT,"抬头备注"BUZEI type RSEG-BUZEI,""行号MATNR TYPE MAKT-MATNR,""物料编号MAKTX TYPE MAKT-MAKTX,GROES TYPE MARA-GROES,BSTME TYPE RSEG-BSTME,MENGE TYPE RSEG-MENGE,""数量WSDJ TYPE String,""单价WRBTR type RSEG-WRBTR,"无税金额"SGTXT type STRING,""备注LFBNR TYPE RSEG-LFBNR,""入库凭证号"USNAM TYPE RBKP-USNAM,USNAM type ADRP-NAME_TEXT,"ERNAM TYPE EKKO-ERNAM,END OF TY_PRINT.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.
*PARAMETERS: p_mvtyp(2) AS LISTBOX OBLIGATORY VISIBLE LENGTH 20 .*SELECT-OPTIONS: S_MBLNR FOR MSEG-MBLNR.
SELECT-OPTIONS: S_BELNR FOR RBKP-BELNR. "发票号
SELECT-OPTIONS: S_BUKRS FOR MSEG-BUKRS. "财务组织
SELECT-OPTIONS: S_BUDAT FOR MKPF-BLDAT . "发票日期
SELECT-OPTIONS: S_LIFNR FOR MSEG-LIFNR MODIF ID S1.
SELECT-OPTIONS: S_USNAM FOR MKPF-USNAM.*SELECTION-SCREEN: FUNCTION KEY 1.
*SELECTION-SCREEN: FUNCTION KEY 2.
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_DATA.*&------------------------------------------------------------------
****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'EXPORTINGACTION = 'S'VIEW_NAME = 'ZMVTYT3000'TABLES
* DBA_SELLIST = IT_DBA_SELLISTEXCL_CUA_FUNCT = EXCL_CUA_FUNCTEXCEPTIONSCLIENT_REFERENCE = 1FOREIGN_LOCK = 2INVALID_ACTION = 3NO_CLIENTINDEPENDENT_AUTH = 4NO_DATABASE_FUNCTION = 5NO_EDITOR_FUNCTION = 6NO_SHOW_AUTH = 7NO_TVDIR_ENTRY = 8NO_UPD_AUTH = 9ONLY_SHOW_ALLOWED = 10SYSTEM_FAILURE = 11UNKNOWN_FIELD_IN_DBA_SELLIST = 12VIEW_NOT_FOUND = 13MAINTENANCE_PROHIBITED = 14OTHERS = 15.WHEN 'FC02'.MOVE 'ANZG' TO EXCL_CUA_FUNCT-FUNCTION. APPEND EXCL_CUA_FUNCT.CALL FUNCTION 'VIEW_MAINTENANCE_CALL'EXPORTINGACTION = 'S'VIEW_NAME = 'ZMMDOC3000'TABLESEXCL_CUA_FUNCT = EXCL_CUA_FUNCTEXCEPTIONSCLIENT_REFERENCE = 1FOREIGN_LOCK = 2INVALID_ACTION = 3NO_CLIENTINDEPENDENT_AUTH = 4NO_DATABASE_FUNCTION = 5NO_EDITOR_FUNCTION = 6NO_SHOW_AUTH = 7NO_TVDIR_ENTRY = 8NO_UPD_AUTH = 9ONLY_SHOW_ALLOWED = 10SYSTEM_FAILURE = 11UNKNOWN_FIELD_IN_DBA_SELLIST = 12VIEW_NOT_FOUND = 13MAINTENANCE_PROHIBITED = 14OTHERS = 15.WHEN 'FC03'.DATA: G_FILEN LIKE WWWDATATAB-OBJID VALUE 'ZMMP001' ." 要下载的模板名称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_OBJDATAFROM WWWDATA UP TO 1 ROWSWHERE SRTF2 = 0 AND RELID = 'MI'AND OBJID = LV_OBJ_NAME.ENDSELECT.CONCATENATE P_FILE 'ZMMP001.XLS' INTO LV_FILE.CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'EXPORTINGKEY = LV_OBJDATADESTINATION = LV_FILEIMPORTINGRC = LV_SUBRC.ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA .CLEAR: IT_ZPRINTTEMP[].SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_ZPRINTTEMP FROM ZMMDOC3000 WHERE MVTYP = 'T2'.* SELECT *
* FROM ZV_MMP001_MSEG
* INTO CORRESPONDING FIELDS OF TABLE GT_ALV
* WHERE BELNR in S_BELNR "发票号
* AND BLDAT IN S_BUDAT "日期
* and BUKRS in S_BUKRS " 财务组织
* AND LIFNR IN S_LIFNR " 供应商
* AND USNAM IN S_USNAM. " 制单人SELECTRBKP~BUKRST001W~NAME1 as NAME1_BURBKP~MANDTRBKP~BELNRRBKP~BLDATLFA1~NAME1LFA1~LIFNRT024~EKNAM"EKKO~EKGRPT024~EKNAM as EKGRPT024~EKNAMRBKP~WMWST1LFBK~BANKLLFBK~KOINHLFBK~BANKNMAKT~MATNRMAKT~MAKTXMARA~GROESRSEG~BSTMERSEG~MENGEEKPO~NETPRRSEG~WRBTRRSEG~LFBNR"RBKP~USNAMADRP~NAME_TEXT as USNAM " 用户EKKO~ERNAMRSEG~BUZEIRSEG~EBELPINTO CORRESPONDING FIELDS OF TABLE GT_ALV
from RBKP
inner join RSEG on RBKP~MANDT = RSEG~MANDT and RSEG~BELNR = RBKP~BELNR
inner join EKKO on EKKO~MANDT = RSEG~MANDT and EKKO~EBELN = RSEG~EBELN
inner join LFA1 on LFA1~MANDT = RSEG~MANDT and LFA1~LIFNR = EKKO~LIFNR
inner join MARA on MARA~MANDT = RSEG~MANDT and MARA~MATNR = RSEG~MATNR
inner join MAKT on MAKT~MANDT = RSEG~MANDT and MAKT~MATNR = RSEG~MATNR
inner join EKPO on EKPO~MANDT = RSEG~MANDT and EKPO~EBELN = RSEG~EBELN and EKPO~EBELP = RSEG~EBELP
inner join T024 on T024~MANDT = RSEG~MANDT and EKKO~EKGRP = T024~EKGRP
left JOIN LFBK on LFBK~MANDT = RSEG~MANDT and LFBK~LIFNR = RSEG~LIFNR
inner join USR21 on USR21~BNAME = RBKP~USNAM
inner join ADRP on ADRP~PERSNUMBER = USR21~PERSNUMBER
inner join T001W on T001W~MANDT = RSEG~MANDT and T001W~WERKS = RBKP~BUKRSwhere MAKT~SPRAS = '1'
and RBKP~BELNR in S_BELNR "发票号
AND RBKP~BLDAT IN S_BUDAT "日期
and RBKP~BUKRS in S_BUKRS " 财务组织
AND LFA1~LIFNR IN S_LIFNR " 供应商
AND RBKP~USNAM IN S_USNAM. " 制单人"LOOP AT GT_ALV ASSIGNING FIELD-SYMBOL(<FS_ALV>).* IF S_BUKRS[] IS INITIAL.
* AUTHORITY-CHECK OBJECT 'ZMMP01_WRK' "权限对象 SU21
* ID 'BUKRS' FIELD <FS_ALV>-BUKRS.
* IF SY-SUBRC <> 0.
* DELETE GT_ALV.
* DATA(LV_MSG) = '权限不足,部分数据未显示'.
* CONTINUE.
* ENDIF.
* ENDIF.* SELECT SINGLE NAME_TEXT
* FROM ADRP
* INNER JOIN USR21
* ON ADRP~PERSNUMBER = USR21~PERSNUMBER
* INTO <FS_ALV>-USNAM_TEXT
* WHERE BNAME = <FS_ALV>-USNAM.
*
* SELECT SINGLE NAME_TEXT
* FROM ADRP
* INNER JOIN USR21
* ON ADRP~PERSNUMBER = USR21~PERSNUMBER
* INTO <FS_ALV>-ERNAM_TEXT
* WHERE BNAME = <FS_ALV>-ERNAM."是否是退货项目 转换为文本
* IF <FS_ALV>-RETPO EQ 'X' .
* <FS_ALV>-RETPO_TEXT = '是'.
* ENDIF.
*
* IF <FS_ALV>-REPOS IS INITIAL .
* <FS_ALV>-REPOS_TEXT = '是'.
* ENDIF.
* 计算
"<FS_ALV>-MENGE1 = <FS_ALV>-MENGE ." ENDLOOP.SORT GT_ALV BY BELNR LFBNR BUZEI.DELETE ADJACENT DUPLICATES FROM GT_ALV COMPARING BELNR LFBNR BUZEI."权限
* IF LV_MSG IS NOT INITIAL.
* MESSAGE LV_MSG TYPE 'S' DISPLAY LIKE 'W'.
* ENDIF.ENDFORM.
*&---------------------------------------------------------------------*
*& Form FROM_SHOW_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM FROM_SHOW_ALV .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 'BUKRS' '财务组织' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BELNR' '发票凭证编号' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BLDAT' '凭证中的凭证日期' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'NAME1' '供应商名称' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'LIFNR' '供应商' 'LIFNR' 'MSEG' '' ''.PERFORM FRM_SET_FIELDCAT USING 'EKNAM' '采购组的描述' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'EKGRP' '采购组' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'WMWST1' '税额' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BANKL' '开户行' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'KOINH' '帐户持有人姓名' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BANKN' '银行帐户号码' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BUZEI' '发票凭证项目' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'MATNR' '物料编号' 'MATNR' 'MARA' '' ''.PERFORM FRM_SET_FIELDCAT USING 'MAKTX' '物料描述' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'GROES' '规格' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BSTME' '单位' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'MENGE' '数量' 'ERFMG' 'MSEG' '' ''.PERFORM FRM_SET_FIELDCAT USING 'WRBTR' '以凭证货币计的金额' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'LFBNR' '物料凭证' 'MBLNR' 'MSEG' '' ''.PERFORM FRM_SET_FIELDCAT USING 'USNAM' '制单人' '' '' '' ''.PERFORM FRM_SET_FIELDCAT USING 'BKTXT' '抬头备注' '' '' '' ''. " 抬头备注PERFORM FRM_SET_FIELDCAT USING 'SGTXT' '备注' '' '' '' ''. " 明细备注DATA: LDF_GRID_SETTINGS TYPE LVC_S_GLAY.LDF_GRID_SETTINGS-EDT_CLL_CB = 'X'. "刷新CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'EXPORTINGI_CALLBACK_PROGRAM = SY-REPIDI_GRID_SETTINGS = LDF_GRID_SETTINGSIS_LAYOUT_LVC = GS_LAYOUTIT_FIELDCAT_LVC = GT_FIELDCAT
* it_events = gt_eventI_CALLBACK_PF_STATUS_SET = 'FRM_STATUS_SET'I_CALLBACK_USER_COMMAND = 'FRM_USER_COMMAND'I_SAVE = 'A'TABLEST_OUTTAB = GT_ALVEXCEPTIONSPROGRAM_ERROR = 1OTHERS = 2.IF SY-SUBRC <> 0."* Implement suitable error handling hereENDIF.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 USINGR_UCOMM LIKE SY-UCOMMRS_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'IMPORTINGE_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'IMPORTINGE_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 '没有定义' 'T2' '打印模板!' .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 BELNR LFBNR ."去重DELETE ADJACENT DUPLICATES FROM LT_ALV COMPARING BELNR LFBNR."LFBNR
* 填充数据LOOP AT LT_ALV INTO LS_ALV.*============ 扣款小计 sTYPES: BEGIN OF TY_KK,BELNR TYPE RBKP-BELNR, ""发票号BUZEI TYPE RSEG-BUZEI,"行号MATNR TYPE MAKT-MATNR,"物料编号MAKTX TYPE MAKT-MAKTX,"物料描述GROES TYPE MARA-GROES," 规格BSTME TYPE RSEG-BSTME," 单位MENGE TYPE RSEG-MENGE," 数量WSDJ TYPE STRING," 单价WRBTR TYPE RSEG-WRBTR,"无税金额 "扣款金额SGTXT TYPE STRING,"备注LFBNR TYPE RSEG-LFBNR,"参考入库凭证号END OF TY_KK.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.DATA: Z_SUM TYPE P DECIMALS 9 ." 扣款金额 sumselectZTMM037~RE_BELNR as BELNR ""发票号ZTMM008_ITEM~EBELP_KK as BUZEI "BUZEI TYPE RSEG-BUZEI,"行号ZTMM037~MATNR as MATNR "MATNR TYPE MAKT-MATNR,"物料编号ZTMM008_ITEM~TXT02_KK as MAKTX "MAKTX TYPE MAKT-MAKTX,"物料描述"GROES TYPE MARA-GROES," 规格ZTMM037~BSTME as BSTME "BSTME TYPE RSEG-BSTME," 单位ZTMM037~BSTMG as MENGE "MENGE TYPE RSEG-MENGE," 数量"WSDJ TYPE STRING," 单价ZTMM037~TOT_NETWR as WRBTR " 扣款金额 "ZTMM008_HEAD~NETWR_LJ 累计扣款金额 " WRBTR TYPE RSEG-WRBTR,"无税金额ZTMM008_HEAD~TXT01 as SGTXT " SGTXT TYPE STRING,"备注"LFBNR TYPE RSEG-LFBNR,"参考入库凭证号ZTMM037~BUKRS as BUKRSINTO CORRESPONDING FIELDS OF TABLE GT_ALV2from ZTMM008_HEADleft join ZTMM037 on ( ZTMM008_HEAD~MANDT = ZTMM037~MANDT and ZTMM037~MBLNR = ZTMM008_HEAD~EBELN_KK and ZTMM037~SHKZG = 'H' and ZTMM037~RE_BELNR = LS_ALV-BELNR )inner join ZTMM008_ITEM on ( ZTMM008_ITEM~MANDT = ZTMM008_HEAD~MANDT and ZTMM008_ITEM~EBELN_KK = ZTMM008_HEAD~EBELN_KKand ZTMM008_ITEM~EBELP_KK = ZTMM037~ZEILE)."where ZTMM037~RE_BELNR = ''"LS_ALV-BELNR'.LOOP AT GT_ALV2 INTO GS_ALV2.Z_SUM = Z_SUM + GS_ALV2-WRBTR.ENDLOOP."GS_ALV-KGXJV = Z_SUM.LOOP AT GT_ALV2 INTO GS_ALV2 WHERE BELNR = LS_ALV-BELNR .MOVE-CORRESPONDING GS_ALV2 TO GS_PRINT2.GS_PRINT2-KGXJV = ABS( Z_SUM )."扣款小计GS_PRINT2-BELNR = LS_ALV-BELNR.""发票号GS_PRINT2-BLDAT = LS_ALV-BLDAT."发票日期GS_PRINT2-NAME1_BU = LS_ALV-NAME1_BU."财务组织"GS_PRINT2-NAME1_BU = LS_ALV-NAME1_BU."财务组织GS_PRINT2-LIFNR = LS_ALV-LIFNR." 供应商编码GS_PRINT2-NAME1 = LS_ALV-NAME1."供应商名GS_PRINT2-EKGRP = LS_ALV-EKGRP.""采购部门GS_PRINT2-WMWST1 = LS_ALV-WMWST1.""税额"GS_PRINT2-YFJEV = LS_ALV-YFJEV.""应付金额GS_PRINT2-BANKL = LS_ALV-BANKL.""开户行GS_PRINT2-KOINH = LS_ALV-KOINH.""账户名称GS_PRINT2-BANKN = LS_ALV-BANKN.""银行帐户号码GS_PRINT2-BKTXT = LS_ALV-BKTXT."抬头备注"GS_PRINT2-USNAM = LS_ALV-USNAM.APPEND GS_PRINT2 TO GT_PRINT2.CLEAR: GS_PRINT2,GS_ALV2.ENDLOOP.*============ 扣款小计 sLOOP AT GT_ALV INTO GS_ALV WHERE BELNR = LS_ALV-BELNR .MOVE-CORRESPONDING GS_ALV TO GS_PRINT.GS_PRINT-USNAM = GS_ALV-USNAM.GS_PRINT-MENGE = GS_ALV-MENGE. "数量GS_PRINT-KGXJV = ABS( Z_SUM )."扣款小计""计算单价DATA : dat1 TYPE p DECIMALS 9 .DATA dat2 TYPE p DECIMALS 9 .dat2 = GS_ALV-WRBTR / GS_ALV-MENGE.
* 方法二CALL FUNCTION 'ROUND'EXPORTINGdecimals = 4 " 保留多少位小数input = dat2sign = '+' " + 向上取舍 - 向下取舍 (负数也一样)IMPORTINGoutput = dat1 " 输出返回结果EXCEPTIONSinput_invalid = 1overflow = 2type_invalid = 3OTHERS = 4."WRITE: / dat2, ' => ' ,dat1.GS_PRINT-WSDJ = dat1.""计算单价APPEND GS_PRINT TO GT_PRINT.CLEAR: GS_PRINT,GS_ALV.ENDLOOP." 扣款记录数据加到打印里"Append lines of GT_PRINT2 to GT_PRINT.CLEAR: LS_ALV.ENDLOOP.CHECK GT_PRINT IS NOT INITIAL.SORT GT_PRINT BY BELNR LFBNR ."LFBNR
" 扣款记录数据加到打印里Append lines of GT_PRINT2 to GT_PRINT.DATA: FILENAME LIKE RLGRAP-FILENAME.CONCATENATE P_FILE 'ZPRINTP001.DAT' INTO FILENAME.SORT IT_ZPRINTTEMP BY POSNR.CALL FUNCTION 'WS_DOWNLOAD'EXPORTING
* CODEPAGE = '8400'FILENAME = FILENAMEFILETYPE = 'DAT'TABLESDATA_TAB = IT_ZPRINTTEMP.down = 'X'.CALL FUNCTION 'Z_EXCEL_DISPLAY'EXPORTINGFILE_PATH = P_FILEFILE_NAME = 'ZMMP001'DOWN = DOWNTABLESITAB = 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_ZMVTYTFROM 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'EXPORTINGID = 'P_MVTYP'VALUES = LIST[].ENDFORM.
双击 zstandard 创建状态
创建后可见工具栏
设置选择条件文本元素
定义了视图,因为程序做的有点潦草所以用视图只做 TYPE 使用,视图不用作取数据,可以自己修改掉垃圾代码
视图(ZV_MMP001_MSEG)
数据 通过程序里查询获取
定义打印模板样式
SM30
样式弄好之后上传Excel模板 要修改的字段需要在宏程序里做调整
提供模板仅供参考 ( MM采购打印模板.rar )
SMW0
路径放在c盘 C://REPORT 目录下
没有模板条目需要先创建再导入 Excel模板