利用alv显所有查询订单抬头信息,双击行实现一个订单详情的smartforms打印,smartforms实现一个强制分页,里面还有点乱,没怎么规划,主要用到EKKO与EKPO两张表。
*&---------------------------------------------------------------------*
*& Report Z_SSX_TEST_ALV_01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SSX_TEST_ALV_01.
TYPE-POOLS: SLIS.
TABLES EKKO.
TYPES:
BEGIN OF TY_EKKO,
EBELN TYPE EKKO-EBELN,
BUKRS TYPE EKKO-BUKRS,
WAERS TYPE EKKO-WAERS,
LLIEF TYPE EKKO-LLIEF,
END OF TY_EKKO,
BEGIN OF TY_EKPO,
EBELN TYPE EKPO-EBELN,
MATNR TYPE EKPO-MATNR,
MENGE TYPE EKPO-MENGE,
MEINS TYPE EKPO-MEINS,
PEINH TYPE EKPO-PEINH,
END OF TY_EKPO.
DEFINE FIELDCATSET.
LW_FIELDCAT-FIELDNAME = &1.
LW_FIELDCAT-SELTEXT_L = &2.
APPEND LW_FIELDCAT TO GT_FIELDCAT.
CLEAR LW_FIELDCAT.
END-OF-DEFINITION.
DATA:
MYREPID LIKE SY-REPID,
GT_OUTPUT TYPE ZSTB_TEST_PO_INPUT,
GT_EKKO TYPE STANDARD TABLE OF TY_EKKO,
GT_EKPO TYPE STANDARD TABLE OF TY_EKPO,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GW_LAYOUT TYPE SLIS_LAYOUT_ALV.
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-001.
*PARAMETERS: P_EBELN TYPE EKKO-EBELN OBLIGATORY.
SELECT-OPTIONS:P_EBELN FOR EKKO-EBELN.
SELECTION-SCREEN END OF BLOCK BLK1.
INITIALIZATION. "初始值
AT SELECTION-SCREEN OUTPUT. " PBO 控制屏幕字段属性
AT SELECTION-SCREEN. "PAI 检查输入是否正确
START-OF-SELECTION.
PERFORM FRM_SELECT_DATA.
* PERFORM FRM_EDIT_DATA.
END-OF-SELECTION.
* PERFORM FRM_DIS_DATA.
PERFORM FRM_SHOW_ALV_DATA.
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_DATA .
SELECT EBELN
BUKRS
WAERS
LLIEF
FROM EKKO
INTO CORRESPONDING FIELDS OF TABLE GT_EKKO
WHERE EBELN IN P_EBELN.
*
* CHECK GT_EKKO IS NOT INITIAL.
* LT_TEMP = GT_EKKO.
* SORT LT_TEMP BY EBELN.
* DELETE ADJACENT DUPLICATES FROM LT_TEMP COMPARING EBELN.
*
* SELECT EBELN
* MATNR
* MENGE
* MEINS
* PEINH
* FROM EKPO
* INTO CORRESPONDING FIELDS OF TABLE GT_EKPO
* FOR ALL ENTRIES IN LT_TEMP
* WHERE EBELN = LT_TEMP-EBELN.
ENDFORM. " FRM_SELECT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_EDIT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_EDIT_DATA .
DATA:
LW_OUTPUT LIKE LINE OF GT_OUTPUT,
LT_ITEM TYPE ZSTB_TEST_PO_ITEM,
LW_ITEM LIKE LINE OF LT_ITEM,
LW_EKKO TYPE TY_EKKO,
LW_EKPO TYPE TY_EKPO,
L_LINE TYPE I,
L_BUTXT TYPE BUTXT.
DATA: LV_COUNT TYPE I, "计数器
LV_PAGE TYPE I, "当前页码
LV_ALL TYPE I, "总页码
LV_BLANK TYPE I. "空白行项目数
* SELECT SINGLE BUTXT
* FROM T001
* INTO L_BUTXT
* WHERE BUKRS = P_BUKRS.
L_LINE = LINES( GT_EKKO ).
LOOP AT GT_EKKO INTO LW_EKKO.
LV_COUNT = 1. "计数器
LV_PAGE = 0. "页码
* LW_PRINT-BUTXT = L_BUTXT.
LW_OUTPUT-EBELN = LW_EKKO-EBELN.
LW_OUTPUT-BUKRS = LW_EKKO-BUKRS.
LW_OUTPUT-WAERS = LW_EKKO-WAERS.
LW_OUTPUT-LLIEF = LW_EKKO-LLIEF.
* LW_PRINT-CUR_PAGE = SY-TABIX.
* LW_PRINT-PAGES = L_LINE.
LOOP AT GT_EKPO INTO LW_EKPO WHERE EBELN = LW_EKKO-EBELN.
MOVE-CORRESPONDING LW_EKPO TO LW_ITEM.
APPEND LW_ITEM TO LT_ITEM.
CLEAR:
LW_EKPO,
LW_ITEM.
IF LV_COUNT EQ 6.
LV_PAGE = LV_PAGE + 1.
* LW_PRINT-pages = lv_page.
LW_OUTPUT-ITEM = LT_ITEM.
APPEND LW_OUTPUT TO GT_OUTPUT.
LV_COUNT = 0.
CLEAR: LT_ITEM,
LW_OUTPUT-ITEM.
ENDIF.
LV_COUNT = LV_COUNT + 1.
ENDLOOP.
IF LV_COUNT NE 1.
"添加空白行项目
LV_COUNT = LV_COUNT - 1.
IF LV_COUNT < 6. "一页7个行项目,不足7行,添加空白行
LV_BLANK = 6 - LV_COUNT.
DO LV_BLANK TIMES.
CLEAR: LW_ITEM.
APPEND LW_ITEM TO LT_ITEM.
ENDDO.
ENDIF.
* lv_page = lv_page + 1. "当前页码
* LW_PRINT-pages = lv_page.
LW_OUTPUT-ITEM = LT_ITEM.
APPEND LW_OUTPUT TO GT_OUTPUT.
CLEAR:
LW_OUTPUT,
LT_ITEM.
ENDIF.
CLEAR:
LW_OUTPUT,
LW_EKKO.
ENDLOOP.
"计算总页码
"降序排列的页码,binary search读到的就是最大页码,即为总页码
* SORT gt_input BY rsnum pages DESCENDING.
* LOOP AT gt_input INTO gs_input.
*
* READ TABLE gt_input INTO ls_input WITH KEY rsnum = gs_input-rsnum BINARY SEARCH.
* gs_input-all_pg = ls_input-pages.
* MODIFY gt_input FROM gs_input TRANSPORTING all_pg.
* CLEAR: gs_input,
* ls_input.
* ENDLOOP.
ENDFORM. " FRM_EDIT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_PRINT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_DIS_DATA .
****Smartforms控制以及属性
DATA: LV_FM_NAME TYPE RS38L_FNAM,
LS_CONTROL_PARAMETERS TYPE SSFCTRLOP,
LS_OUTPUT_OPTIONS TYPE SSFCOMPOP,
LS_JOBINFO TYPE SSFCRESCL.
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME‘
EXPORTING
FORMNAME = ‘Z_SSX_TEST_PO_03‘
IMPORTING
FM_NAME = LV_FM_NAME
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3.
LS_OUTPUT_OPTIONS-TDDEST = ‘LP01‘. "OutputDevice
LS_OUTPUT_OPTIONS-TDIMMED = ‘X‘. "立即打印
LS_OUTPUT_OPTIONS-TDCOPIES = ‘1‘. "副本数,1
LS_OUTPUT_OPTIONS-TDNOPRINT = ‘ ‘.
LS_OUTPUT_OPTIONS-TDDELETE = ‘‘. "输出后删除
LS_CONTROL_PARAMETERS-NO_DIALOG = ‘‘.
LS_CONTROL_PARAMETERS-DEVICE = ‘PRINTER‘.
LS_CONTROL_PARAMETERS-PREVIEW = ‘X‘.
LS_CONTROL_PARAMETERS-LANGU = ‘1‘.
CALL FUNCTION LV_FM_NAME
EXPORTING
CONTROL_PARAMETERS = LS_CONTROL_PARAMETERS
OUTPUT_OPTIONS = LS_OUTPUT_OPTIONS
USER_SETTINGS = ‘‘
IMPORTING
JOB_OUTPUT_INFO = LS_JOBINFO
TABLES
GT_OUTPUT = GT_OUTPUT.
ENDFORM. " FRM_PRINT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_SHOW_ALV_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SHOW_ALV_DATA .
DATA:
LW_FIELDCAT LIKE LINE OF GT_FIELDCAT.
GW_LAYOUT-COLWIDTH_OPTIMIZE = ‘X‘.
GW_LAYOUT-ZEBRA = ‘X‘.
* LW_FIELDCAT-FIELDNAME = ‘EBELN‘.
* LW_FIELDCAT-SELTEXT_L = ‘凭证号‘.
* LW_FIELDCAT-SELTEXT_M = ‘‘.
* LW_FIELDCAT-SELTEXT_S = ‘‘.
*
* APPEND LW_FIELDCAT TO GT_FIELDCAT.
*
* LW_FIELDCAT-FIELDNAME = ‘BUKRS‘.
* LW_FIELDCAT-SELTEXT_L = ‘公司代码‘.
* LW_FIELDCAT-SELTEXT_M = ‘‘.
* LW_FIELDCAT-SELTEXT_S = ‘‘.
*
* APPEND LW_FIELDCAT TO GT_FIELDCAT.
*
* LW_FIELDCAT-FIELDNAME = ‘WAERS‘.
* LW_FIELDCAT-SELTEXT_L = ‘货币码‘.
* LW_FIELDCAT-SELTEXT_M = ‘‘.
* LW_FIELDCAT-SELTEXT_S = ‘‘.
*
* APPEND LW_FIELDCAT TO GT_FIELDCAT.
*
* LW_FIELDCAT-FIELDNAME = ‘LLIEF‘.
* LW_FIELDCAT-SELTEXT_L = ‘商品供应商‘.
* LW_FIELDCAT-SELTEXT_M = ‘‘.
* LW_FIELDCAT-SELTEXT_S = ‘‘.
*
* APPEND LW_FIELDCAT TO GT_FIELDCAT.
FIELDCATSET ‘EBELN‘ ‘采购凭证号‘.
FIELDCATSET ‘BUKRS‘ ‘公司代码‘.
FIELDCATSET ‘WAERS ‘ ‘货币码‘.
FIELDCATSET ‘LLIEF‘ ‘商品供应商‘.
MYREPID = SY-REPID.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY‘
EXPORTING
I_CALLBACK_PROGRAM = MYREPID
IS_LAYOUT = GW_LAYOUT
IT_FIELDCAT = GT_FIELDCAT
I_CALLBACK_USER_COMMAND = ‘ALV_USER_COMMAND‘
TABLES
T_OUTTAB = GT_EKKO
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " FRM_SHOW_ALV_DATA
*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
FORM ALV_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
IF R_UCOMM = ‘&IC1‘.
PERFORM PRINT USING RS_SELFIELD.
ENDIF.
ENDFORM. "ALV_USER_COMMAND
*&---------------------------------------------------------------------*
*& Form PRINT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_RS_SELFIELD text
*----------------------------------------------------------------------*
FORM PRINT USING RS_SELFIELD TYPE SLIS_SELFIELD.
DATA:
LW_EKKO TYPE TY_EKKO.
READ TABLE GT_EKKO INTO LW_EKKO INDEX RS_SELFIELD-TABINDEX .
SELECT EBELN
MATNR
MENGE
MEINS
PEINH
FROM EKPO
INTO CORRESPONDING FIELDS OF TABLE GT_EKPO
WHERE EBELN = LW_EKKO-EBELN.
PERFORM FRM_EDIT_DATA.
PERFORM FRM_DIS_DATA.
ENDFORM. " PRINT
一个简单的alv双击行实现smartforms打印,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/ssx-bg/p/3755210.html