恐怕很多了都很陌生吧。啥东西叫做出闸纸咯。咳!其实它为公司指示货柜堆场将吉柜(即空柜)交与本单持有人的书面凭证,重柜与吉柜进出码头均受到海关监控,出CY的柜须有“出闸放行条”(有人称“出闸纸”)。简单点引申为:放行条。大家先看看效果。列印中用到scriptform.有不了解的童鞋可以参考我之前的教程: SAP ScriptForms 教程系列 http://blog.csdn.net/jiali765/article/details/7041900。最终的效果为:
现在接着来看看代码:
*&---------------------------------------------------------------------*
*& Report ZVT003
*&---------------------------------------------------------------------*
* Author : Jasson.Lee
Date 2011.07.29
* Purpose :
* Modi Log: 2011.07.29 Gavin Create
* Modi Log: 2011.08.23 Gavin 出货数改为整数
* Modi Log: 2011.08.24 Gavin 出货数改为字符型,以便于报关修正
* Modi Log: 2011.08.25 Gavin 增加备注
* Modi Log: 2012.02.04 Gavin 增加名称栏位宽度
*----------------------------------------------------------------------
REPORT ZVT003.
TABLES: VTTK,VTTP,VEKP,VEPO.
TYPE-POOLS: SLIS.
*--------------------------------
* Selection Screen
*--------------------------------
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS:
P_TKNUM LIKE VTTK-TKNUM OBLIGATORY . "SHIPMETN NO.
SELECTION-SCREEN END OF BLOCK B1.
* For Line Items
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS:
P_CHK AS CHECKBOX DEFAULT '',
P1 TYPE I DEFAULT 0,
P2(50) TYPE C.
SELECTION-SCREEN END OF BLOCK B2.
*****************************************************************************
DATA: G_STATUS TYPE SLIS_FORMNAME VALUE 'STANDARD_02'. "加工具栏
DATA:
I_FIELDCAT_ALV TYPE SLIS_T_FIELDCAT_ALV,
I_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
I_LAYOUT TYPE SLIS_LAYOUT_ALV,
I_EVENTS TYPE SLIS_T_EVENT,
W_EVENTS LIKE LINE OF I_EVENTS,
I_LIST_COMMENTS TYPE SLIS_T_LISTHEADER,
W_LIST_COMMENTS LIKE LINE OF I_LIST_COMMENTS,
W_REPID LIKE SY-REPID.
DATA:
W_LOOP TYPE SY-TABIX,
L_PROD_NUM1 TYPE CO_PSMNG,
L_PROD_NUM2 TYPE CO_PSMNG.
DATA: BEGIN OF I_TAB0 OCCURS 0,
TKNUM LIKE VTTK-TKNUM,
ERDAT LIKE VTTK-ERDAT,
EXTI1 LIKE VTTK-EXTI1,
EXTI2 LIKE VTTK-EXTI2,
END OF I_TAB0.
DATA: BEGIN OF I_TAB1 OCCURS 0,
TKNUM LIKE VTTP-TKNUM,
VBELN LIKE LIPS-VBELN,
MATNR LIKE LIPS-MATNR,
ARKTX LIKE LIPS-ARKTX,
LFIMG LIKE LIPS-LFIMG,
VPOBJKEY LIKE VEKP-VPOBJKEY,
END OF I_TAB1.
DATA: BEGIN OF I_TAB2 OCCURS 0,
VENUM LIKE VEKP-VENUM,
VPOBJKEY LIKE VEKP-VPOBJKEY,
BRGEW LIKE VEKP-BRGEW,
VBELN LIKE VEPO-VBELN,
POSNR LIKE VEPO-POSNR,
MATNR LIKE VEPO-MATNR,
VEMNG LIKE VEPO-VEMNG,
END OF I_TAB2.
DATA: BEGIN OF I_TAB3 OCCURS 0,
MATNR LIKE LIPS-MATNR,
BRGEW LIKE VEKP-BRGEW,
VEMNG LIKE VEPO-VEMNG,
END OF I_TAB3.
DATA: BEGIN OF I_TAB4 OCCURS 0,
TKNUM LIKE VTTP-TKNUM,
MATNR LIKE LIPS-MATNR,
ARKTX LIKE LIPS-ARKTX,
LFIMG TYPE I,"LIKE LIPS-LFIMG,
VEMNG TYPE I,"LIKE VEPO-VEMNG,
BRGEW TYPE I,"LIKE VEKP-BRGEW,
VEMNG1 TYPE I,"LIKE VEPO-VEMNG,
BRGEW1 TYPE I,"LIKE VEKP-BRGEW,
LFIMG1(10) TYPE C,"LIKE LIPS-LFIMG,
END OF I_TAB4.
DATA: BEGIN OF I_TAB5 OCCURS 0,
TKNUM LIKE VTTP-TKNUM,
MATNR LIKE LIPS-MATNR,
ARKTX LIKE LIPS-ARKTX,
LFIMG TYPE I,"LIKE LIPS-LFIMG,
VEMNG TYPE I,"LIKE VEPO-VEMNG,
BRGEW TYPE I,"LIKE VEKP-BRGEW,
VEMNG1 TYPE I,"LIKE VEPO-VEMNG,
BRGEW1 TYPE I,"LIKE VEKP-BRGEW,
END OF I_TAB5.
DATA :P_COCO LIKE KNB1-BUKRS.
DATA :W_TOTAL(10) TYPE C.
DATA :W_LOOP1 LIKE SY-TABIX.
DATA :W_LOOP2 LIKE SY-TABIX.
DATA :W_LOOP3 LIKE SY-TABIX.
DATA SCOUNT(8).
DATA :RCOUNT LIKE SY-TABIX.
DATA LSTR(20).
DATA LSTR1(40).
DATA LSTR2(40).
DATA LSTR3(100).
DATA LSTR4(40).
DATA LSTR5(40).
*--------------------------------
* Initialization
*--------------------------------
INITIALIZATION.
*--------------------------------
* At Selection Screen PBO
*--------------------------------
AT SELECTION-SCREEN OUTPUT.
*--------------------------------
* Start of Selection
*--------------------------------
START-OF-SELECTION.
PERFORM GET_DATA.
PERFORM PROCESS_DATA.
PERFORM CAL_DATA.
PERFORM EVENTS_BUILD.
PERFORM LAYOUT_BUILD.
PERFORM FIELDS_BUILD.
PERFORM DISPLAY_DATA.
END-OF-SELECTION.
*--------------------------------
* Top of Page
*--------------------------------
TOP-OF-PAGE.
*&---------------------------------------------------------------------*
*& Form get_data
*&---------------------------------------------------------------------*
FORM GET_DATA.
* 主档
SELECT K~TKNUM K~ERDAT K~EXTI1 K~EXTI2 INTO TABLE I_TAB0
FROM VTTK AS K
WHERE K~TKNUM = P_TKNUM.
*
SELECT T~TKNUM P~VBELN P~MATNR P~ARKTX P~LFIMG INTO TABLE I_TAB1
FROM VTTP AS T INNER JOIN LIPS AS P ON T~VBELN = P~VBELN
WHERE T~TKNUM = P_TKNUM
AND P~LFIMG > 0 AND P~POSNR >= '900001' .
L_PROD_NUM1 = 0.
LOOP AT I_TAB1.
W_LOOP = SY-TABIX.
L_PROD_NUM1 = L_PROD_NUM1 + I_TAB1-LFIMG.
I_TAB1-VPOBJKEY = I_TAB1-VBELN.
MODIFY I_TAB1 INDEX W_LOOP.
SY-TABIX = W_LOOP + 1.
ENDLOOP.
* 取得出包装箱数
SELECT K~VENUM K~VPOBJKEY K~BRGEW P~VBELN P~POSNR P~MATNR P~VEMNG
INTO TABLE I_TAB2
FROM VEKP AS K LEFT JOIN VEPO AS P ON K~VENUM = P~VENUM
FOR ALL ENTRIES IN I_TAB1
WHERE K~VPOBJKEY = I_TAB1-VPOBJKEY AND K~STATUS = '0020'.
L_PROD_NUM2 = 0.
LOOP AT I_TAB2.
L_PROD_NUM2 = L_PROD_NUM2 + I_TAB2-BRGEW.
ENDLOOP.
ENDFORM. "get_data
*&---------------------------------------------------------------------*
*& Form process_data
*&---------------------------------------------------------------------*
FORM PROCESS_DATA .
LOOP AT I_TAB2.
W_LOOP = SY-TABIX.
I_TAB3-MATNR = I_TAB2-MATNR.
I_TAB3-BRGEW = I_TAB2-BRGEW.
I_TAB3-VEMNG = I_TAB2-VEMNG.
COLLECT I_TAB3.
SY-TABIX = W_LOOP + 1.
ENDLOOP.
LOOP AT I_TAB1.
W_LOOP = SY-TABIX.
I_TAB4-TKNUM = I_TAB1-TKNUM.
I_TAB4-MATNR = I_TAB1-MATNR.
I_TAB4-ARKTX = I_TAB1-ARKTX.
I_TAB4-LFIMG = I_TAB1-LFIMG.
COLLECT I_TAB4.
SY-TABIX = W_LOOP + 1.
ENDLOOP.
SORT I_TAB3 BY MATNR.
* SORT I_TAB4 BY MATNR.
LOOP AT I_TAB4.
W_LOOP = SY-TABIX.
CLEAR I_TAB3.
READ TABLE I_TAB3 WITH KEY MATNR = I_TAB4-MATNR BINARY SEARCH.
IF SY-SUBRC = 0.
I_TAB4-BRGEW = I_TAB3-BRGEW.
I_TAB4-VEMNG = I_TAB3-VEMNG. "输入前值
I_TAB4-LFIMG = I_TAB3-VEMNG. "
I_TAB4-BRGEW1 = L_PROD_NUM2.
I_TAB4-VEMNG1 = L_PROD_NUM1.
ENDIF.
I_TAB4-LFIMG1 = I_TAB4-LFIMG. "数量转成字符
MODIFY I_TAB4 INDEX W_LOOP.
SY-TABIX = W_LOOP + 1.
ENDLOOP.
I_TAB4-TKNUM = ''.
I_TAB4-MATNR = ''.
I_TAB4-ARKTX = ''.
I_TAB4-BRGEW = 0.
I_TAB4-VEMNG = 0. "输入前值
I_TAB4-LFIMG1 = '0'. "
I_TAB4-LFIMG = 0. "
I_TAB4-BRGEW1 = 0.
I_TAB4-VEMNG1 = 0.
IF P_CHK = 'X'.
DO P1 TIMES.
APPEND I_TAB4.
ENDDO.
ENDIF.
ENDFORM. " process_data
*&---------------------------------------------------------------------*
*& Form Form_Open
*&---------------------------------------------------------------------*
FORM FORM_OPEN .
CALL FUNCTION 'OPEN_FORM'
EXPORTING
FORM = 'ZSHIPMENT_DOC2'
LANGUAGE = SY-LANGU
DIALOG = 'X'
* DEVICE = SCREEN
EXCEPTIONS
OTHERS = 1.
ENDFORM. " Form_Open
*&---------------------------------------------------------------------*
*& Form write_form
*&---------------------------------------------------------------------*
FORM WRITE_FORM USING ELEMENT
WINDOW
TYPE.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
ELEMENT = ELEMENT
WINDOW = WINDOW
TYPE = TYPE.
ENDFORM. " write_form
*&---------------------------------------------------------------------*
*& Form FORM_CLOSE
*&---------------------------------------------------------------------*
FORM FORM_CLOSE.
CALL FUNCTION 'CLOSE_FORM'
EXCEPTIONS
OTHERS = 1.
ENDFORM. " FORM_CLOSE
*&---------------------------------------------------------------------*
*& Form CAL_DATA
*&---------------------------------------------------------------------*
FORM CAL_DATA .
DESCRIBE TABLE I_TAB4 LINES RCOUNT.
SCOUNT = RCOUNT.
CONCATENATE '符合条件的记录数:' SCOUNT INTO LSTR.
IF I_TAB4[] IS INITIAL .
MESSAGE I000(ZMSG) WITH '没找到对应的数据,请更改查询条件'.
LEAVE LIST-PROCESSING .
ENDIF.
ENDFORM. " CAL_DATA
*&---------------------------------------------------------------------*
*& Form EVENTS_BUILD
*&---------------------------------------------------------------------*
FORM EVENTS_BUILD .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS.
* 页眉
READ TABLE I_EVENTS WITH KEY NAME = 'TOP_OF_PAGE' INTO W_EVENTS.
IF SY-SUBRC = 0.
MOVE 'ALV_TOP_OF_PAGE' TO W_EVENTS-FORM.
MODIFY I_EVENTS FROM W_EVENTS INDEX SY-TABIX.
ENDIF.
* 页尾
READ TABLE I_EVENTS WITH KEY NAME = 'END_OF_LIST' INTO W_EVENTS.
IF SY-SUBRC = 0.
MOVE 'ALV_END_OF_LIST' TO W_EVENTS-FORM.
MODIFY I_EVENTS FROM W_EVENTS INDEX SY-TABIX.
ENDIF.
* 页跳转
READ TABLE I_EVENTS WITH KEY NAME = 'USER_COMMAND' INTO W_EVENTS.
IF SY-SUBRC = 0.
MOVE 'USER_COMMAND' TO W_EVENTS-FORM.
MODIFY I_EVENTS FROM W_EVENTS INDEX SY-TABIX.
ENDIF.
ENDFORM. " EVENTS_BUILD
*&--------------------------------------------------------------------*
*& Form ALV_END_OF_LIST
*&--------------------------------------------------------------------*
FORM ALV_TOP_OF_PAGE.
CLEAR: I_LIST_COMMENTS.
W_LIST_COMMENTS-TYP = 'H'.
W_LIST_COMMENTS-KEY = ''.
W_LIST_COMMENTS-INFO = ' '.
APPEND W_LIST_COMMENTS TO I_LIST_COMMENTS.
CLEAR W_LIST_COMMENTS.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_LIST_COMMENTS
I_END_OF_LIST_GRID = 'X'.
ENDFORM. "ALV_TOP_OF_PAGE
*&--------------------------------------------------------------------*
*& Form ALV_END_OF_LIST
*&--------------------------------------------------------------------*
FORM ALV_END_OF_LIST.
CLEAR: I_LIST_COMMENTS.
W_LIST_COMMENTS-TYP = 'H'.
W_LIST_COMMENTS-KEY = ''.
W_LIST_COMMENTS-INFO = LSTR.
APPEND W_LIST_COMMENTS TO I_LIST_COMMENTS.
CLEAR W_LIST_COMMENTS.
W_LIST_COMMENTS-TYP = 'S'.
W_LIST_COMMENTS-KEY = ''.
W_LIST_COMMENTS-INFO = ' 报表开发者:IT部--Jasson 重新开发日期:2011/07/29'.
APPEND W_LIST_COMMENTS TO I_LIST_COMMENTS.
CLEAR W_LIST_COMMENTS.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = I_LIST_COMMENTS
I_END_OF_LIST_GRID = 'X'.
ENDFORM. "ALV_END_OF_LIST
*&---------------------------------------------------------------------*
*& Form LAYOUT_BUILD
*&---------------------------------------------------------------------*
FORM LAYOUT_BUILD .
I_LAYOUT-ZEBRA = 'X' . " 显示界面成色带交替
I_LAYOUT-DETAIL_POPUP = 'X'. "弹出详细信息窗口
I_LAYOUT-INFO_FIELDNAME = 'COLOR'. "颜色值
* I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. "优化列宽选项
I_LAYOUT-DETAIL_INITIAL_LINES = 'X'.
I_LAYOUT-DETAIL_TITLEBAR = '出闸纸打印'.
I_LAYOUT-NO_COLHEAD =' '.
* I_LAYOUT-BOX_FIELDNAME = 'BOX' . " 指明复选框
W_REPID = SY-REPID.
ENDFORM. " LAYOUT_BUILD
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
FORM DISPLAY_DATA .
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_USER_COMMAND = 'USER_COMMAND' "用户触发事件
I_CALLBACK_PF_STATUS_SET = G_STATUS "调用用户事件和按钮事件
I_CALLBACK_PROGRAM = W_REPID "当前程序
IS_LAYOUT = I_LAYOUT "子函数layout_build填充的格式定义
IT_FIELDCAT = I_FIELDCAT_ALV[] "子函数fields填充的各列
IT_EVENTS = I_EVENTS[]
I_SAVE = 'A' "保存变式
TABLES
T_OUTTAB = I_TAB4. "假设数据都在itab内表中
ENDFORM. " DISPLAY_DATA
*-----------------------------------------------------------------------
* FORM PF_STATUS_SET 加工具栏
*-----------------------------------------------------------------------
FORM STANDARD_02 USING EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'STD' EXCLUDING EXTAB.
ENDFORM. "STANDARD_02
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING I_UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
CLEAR I_TAB5[].
IF P_CHK = ''.
LOOP AT I_TAB4 .
IF I_TAB4-TKNUM <> ''.
MOVE-CORRESPONDING I_TAB4 TO I_TAB5.
I_TAB5-LFIMG = I_TAB4-LFIMG1.
APPEND I_TAB5.
ENDIF.
ENDLOOP.
* I_TAB5[] = I_TAB4[].
ELSE.
L_PROD_NUM1 = 0.
L_PROD_NUM2 = 0.
LOOP AT I_TAB4.
I_TAB4-LFIMG = I_TAB4-LFIMG1.
L_PROD_NUM1 = L_PROD_NUM1 + I_TAB4-LFIMG.
L_PROD_NUM2 = L_PROD_NUM2 + I_TAB4-BRGEW.
ENDLOOP.
LOOP AT I_TAB4 .
IF I_TAB4-TKNUM <> ''.
I_TAB4-VEMNG = I_TAB4-LFIMG1.
I_TAB4-BRGEW1 = L_PROD_NUM2.
I_TAB4-VEMNG1 = L_PROD_NUM1.
MOVE-CORRESPONDING I_TAB4 TO I_TAB5.
I_TAB5-LFIMG = I_TAB4-LFIMG1.
APPEND I_TAB5.
ENDIF.
ENDLOOP.
ENDIF.
CASE I_UCOMM.
WHEN '&PRT'.
IF I_TAB5[] IS INITIAL.
MESSAGE I000(ZMSG) WITH '没有要打印的物料.'.
ELSE.
PERFORM FORM_OPEN.
IF SY-SUBRC = 0.
READ TABLE I_TAB0 INDEX 1.
PERFORM WRITE_FORM USING 'TITLE1' 'HEADER' 'BODY '.
PERFORM WRITE_FORM USING 'GENERAL_HEADER_DATA_TITLE' 'MAIN' 'BODY '.
* SORT I_TAB5 BY MATNR.
LOOP AT I_TAB5.
W_LOOP1 = SY-TABIX.
PERFORM WRITE_FORM USING 'DELIVERY_ITEM' 'MAIN' 'BODY '.
SY-TABIX = W_LOOP3.
ENDLOOP.
PERFORM WRITE_FORM USING 'SEGMENT_OVERVIEW_TITLE ' 'MAIN' 'BODY '.
PERFORM WRITE_FORM USING 'NEW' 'MAIN' 'BODY '.
PERFORM FORM_CLOSE.
ELSE.
PERFORM FORM_CLOSE.
ENDIF.
ENDIF.
WHEN OTHERS.
ENDCASE.
ENDFORM. "callback_ucomm
*&---------------------------------------------------------------------*
*& Form FIELDS_BUILD
*&---------------------------------------------------------------------*
FORM FIELDS_BUILD .
DATA TMP_POS TYPE I.
REFRESH I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
TMP_POS = TMP_POS + 1.
I_FIELDCAT-COL_POS = TMP_POS.
I_FIELDCAT-FIELDNAME = 'TKNUM'.
I_FIELDCAT-SELTEXT_L = '装运单号'.
I_FIELDCAT-OUTPUTLEN = 10.
I_FIELDCAT-NO_ZERO = 'X'.
I_FIELDCAT-KEY = 'X'.
IF P_CHK = 'X'.
I_FIELDCAT-INPUT = 'X'.
ENDIF.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
TMP_POS = TMP_POS + 1.
I_FIELDCAT-COL_POS = TMP_POS.
I_FIELDCAT-FIELDNAME = 'MATNR'.
I_FIELDCAT-SELTEXT_L = '物料编号'.
I_FIELDCAT-OUTPUTLEN = 18.
I_FIELDCAT-KEY = 'X'.
IF P_CHK = 'X'.
I_FIELDCAT-INPUT = 'X'.
ENDIF.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
TMP_POS = TMP_POS + 1.
I_FIELDCAT-COL_POS = TMP_POS.
I_FIELDCAT-FIELDNAME = 'ARKTX'.
I_FIELDCAT-SELTEXT_L = '物料名称'.
I_FIELDCAT-OUTPUTLEN = 60.
IF P_CHK = 'X'.
I_FIELDCAT-INPUT = 'X'.
ENDIF.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
TMP_POS = TMP_POS + 1.
I_FIELDCAT-COL_POS = TMP_POS.
I_FIELDCAT-FIELDNAME = 'LFIMG1'.
I_FIELDCAT-SELTEXT_L = '数量'.
I_FIELDCAT-OUTPUTLEN = 12.
I_FIELDCAT-NO_ZERO = 'X'.
IF P_CHK = 'X'.
I_FIELDCAT-INPUT = 'X'.
ENDIF.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
*
* TMP_POS = TMP_POS + 1.
* I_FIELDCAT-COL_POS = TMP_POS.
* I_FIELDCAT-FIELDNAME = 'VEMNG'.
* I_FIELDCAT-SELTEXT_L = '实出数'.
* I_FIELDCAT-OUTPUTLEN = 9.
* I_FIELDCAT-NO_ZERO = 'X'.
* APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
* CLEAR I_FIELDCAT.
TMP_POS = TMP_POS + 1.
I_FIELDCAT-COL_POS = TMP_POS.
I_FIELDCAT-FIELDNAME = 'BRGEW'.
I_FIELDCAT-SELTEXT_L = '箱数'.
I_FIELDCAT-OUTPUTLEN = 9.
I_FIELDCAT-NO_ZERO = 'X'.
IF P_CHK = 'X'.
I_FIELDCAT-INPUT = 'X'.
ENDIF.
APPEND I_FIELDCAT TO I_FIELDCAT_ALV.
CLEAR I_FIELDCAT.
ENDFORM. " FIELDS_BUILD
接着我们再来回顾一下se41.本程式用到的如下:
那么se71是否可以再看看它的设置。如下: