通过输入Customer Number 取出Custmer 的相关信息..(Table: KNA1 , KNB1 )
REPORT ZZW_GET_CUSTOMER .
***********************************************************************
*
* Author: Lilo.Zhu
*
* Date: 05/12/2006
*
* Keyword: KNAL (General Data In Customer Master)
* REUSE_ALV_FIELDCATALOG_MERGE (Gird and Event)
* CONCATENATE
*
***********************************************************************
*
* Last Modified Data:
*
* Log: 1.GET_CUST_NO lenght=10 e.g: 1031 --> 0000001031
*
*
***********************************************************************
TYPE-POOLS: SLIS.
*----------------------------------------------------------------------
* TABLES
*----------------------------------------------------------------------
TABLES: KNA1, "General Data in Customer Master
KNB1. "Customer Master (Company Code)
*----------------------------------------------------------------------
* INTERNAL TABLE
*----------------------------------------------------------------------
DATA: BEGIN OF LT_ALVTABLE OCCURS 0,
KUNNR LIKE KNA1-KUNNR, "Customer Number
BUKRS LIKE KNB1-BUKRS, "Company Code
NAME1 LIKE KNA1-NAME1, "Name 1
NAME2 LIKE KNA1-NAME2, "Name 2
STRAS LIKE KNA1-STRAS, "House number and street
PSTLZ LIKE KNA1-PSTLZ, "Postal Code
ORT01 LIKE KNA1-ORT01, "City
KTOKD LIKE KNA1-KTOKD, "Customer account group
END OF LT_ALVTABLE.
*-----------------------------------------------------------------------
* DATA-STATEMENTS THAT ARE NECESSARY FOR THE USE OF THE ALV-GRID
*-----------------------------------------------------------------------
DATA: GT_XEVENTS TYPE SLIS_T_EVENT.
DATA: XS_EVENT TYPE SLIS_ALV_EVENT.
DATA: REPID TYPE SY-REPID.
DATA: ZTA_PRINT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA: LO_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: LO_ITABNAME TYPE SLIS_TABNAME.
DATA: LS_VARIANT TYPE DISVARIANT.
*-----------------------------------------------------------------------
* Initialization
*-----------------------------------------------------------------------
INITIALIZATION.
*-----------------------------------------------------------------------
* Parameters and selection / Selection-options
*-----------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK CHARLY
WITH FRAME TITLE TEXT-001.
*PARAMETERS CUST_NO LIKE KNA1-KUNNR.
SELECTION-SCREEN END OF BLOCK CHARLY.
SELECT-OPTIONS CUST_NO FOR KNA1-KUNNR .
*-----------------------------------------------------------------------
* Start Of main programe
*-----------------------------------------------------------------------
START-OF-SELECTION.
PERFORM SELECT_RECORDS.
PERFORM PRINT_ALVLIST.
END-OF-SELECTION.
*-----------------------------------------------------------------------
* Form select_records
*-----------------------------------------------------------------------
FORM SELECT_RECORDS.
* PERFORM GET_CUST_NO.
SELECT * INTO CORRESPONDING FIELDS OF LT_ALVTABLE
FROM KNA1 AS A
INNER JOIN KNB1 AS B
ON A~KUNNR = B~KUNNR
* WHERE A~KUNNR = '0000001031'.
* WHERE A~KUNNR = CUST_NO.
WHERE A~KUNNR IN CUST_NO.
* WRITE: / CUST_NO.
APPEND LT_ALVTABLE.
ENDSELECT.
ENDFORM.
*-----------------------------------------------------------------------
* Form get customer number
*-----------------------------------------------------------------------
FORM GET_CUST_NO.
DATA: LINT_INDEX TYPE I.
DATA: ZERO(1).
LINT_INDEX = 10 - LINT_INDEX.
IF STRLEN( CUST_NO ) < 10.
DO LINT_INDEX TIMES.
CONCATENATE ZERO CUST_NO INTO CUST_NO.
ENDDO.
ENDIF.
ENDFORM.
*-----------------------------------------------------------------------
* Form print_alvlist
*-----------------------------------------------------------------------
FORM PRINT_ALVLIST.
REPID = SY-REPID.
LO_ITABNAME = 'LT_ALVTABLE'.
* Fill the variables of the alv-grid.
PERFORM SET_LAYOUT USING LO_LAYOUT. "Change layout-settings
PERFORM SET_EVENTS USING GT_XEVENTS. "Set the events(top-page etc)
PERFORM FILL_STRUCTURE. "Read the structure of the
"--itab
PERFORM MODIFY_STRUCTURE. "Modify itab's file-properties
* Sort the table
SORT LT_ALVTABLE BY KUNNR.
* Present the table using the ALV-grid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = REPID
IT_FIELDCAT = ZTA_PRINT[]
IS_LAYOUT = LO_LAYOUT
IT_EVENTS = GT_XEVENTS
I_SAVE = 'A'
IS_VARIANT = LS_VARIANT
TABLES
T_OUTTAB = LT_ALVTABLE.
ENDFORM. "print_alvlist
*-----------------------------------------------------------------------
* Form SET_LAYOUT
*-----------------------------------------------------------------------
FORM SET_LAYOUT USING PA_LAYOUT TYPE SLIS_LAYOUT_ALV.
* Minimize the columnwidth
PA_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
* Give the table a striped pattern
PA_LAYOUT-ZEBRA = 'X'.
* Set the text of the line with totals
PA_LAYOUT-TOTALS_TEXT = 'Total:'.
* Set the text of the line with subtotals
PA_LAYOUT-SUBTOTALS_TEXT = 'Subtotal:'.
ENDFORM. "SET_LAYOUT
*-----------------------------------------------------------------------
* Form Set_events
*-----------------------------------------------------------------------
* Appends the values of the events to the events-variable that is
* used by REUSE_ALV_LIST_DISPLAY
*-----------------------------------------------------------------------
FORM SET_EVENTS USING PA_EVENTS TYPE SLIS_T_EVENT.
XS_EVENT-NAME = SLIS_EV_TOP_OF_LIST.
XS_EVENT-FORM = 'XTOP_OF_LIST'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_END_OF_LIST.
XS_EVENT-FORM = 'XEND_OF_LIST'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_TOP_OF_PAGE.
XS_EVENT-FORM = 'XTOP_OF_PAGE'.
APPEND XS_EVENT TO PA_EVENTS.
XS_EVENT-NAME = SLIS_EV_END_OF_PAGE.
XS_EVENT-FORM = 'XEND_OF_PAGE'.
APPEND XS_EVENT TO PA_EVENTS.
ENDFORM. "SET EVENTS
*-----------------------------------------------------------------------
* Form XTOP_OF_LIST
*-----------------------------------------------------------------------
FORM XTOP_OF_LIST.
DATA LO_DATE(8).
CONCATENATE SY-DATUM+6(2) '.'
SY-DATUM+4(2) '.'
SY-DATUM+2(2)
INTO LO_DATE.
WRITE: AT 1 'Report:'(T01), 20 'Reportname'(T02).
WRITE: AT 50 'Date:'(T03),LO_DATE.
NEW-LINE.
WRITE: AT 1 'Customer-Name Report: '(T04),SY-REPID.
WRITE: AT 50 'Page:'(T05), SY-CPAGE.
ENDFORM. "xtop_of_list
*-----------------------------------------------------------------------
* Form XEND_OF_LIST
*-----------------------------------------------------------------------
FORM XEND_OF_LIST.
WRITE: 'Footer of the list'(002).
ENDFORM. "xend_of_list
*-----------------------------------------------------------------------
* Form XTOP_OF_PAGE
*-----------------------------------------------------------------------
FORM XTOP_OF_PAGE.
WRITE: / 'Top of the page.'(003).
*()*Here your selection-criterial can be printed
ENDFORM. "xtop_of_page
*-----------------------------------------------------------------------
* Form XEND_OF_PAGE
*-----------------------------------------------------------------------
FORM XEND_OF_PAGE.
WRITE: / 'End of the page.'(004).
EndForm. "xtop_of_page
*-----------------------------------------------------------------------
* Form FILL_STRUCTURE
*-----------------------------------------------------------------------
FORM FILL_STRUCTURE.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME = REPID
I_INTERNAL_TABNAME = LO_ITABNAME
I_INCLNAME = 'ZZW_GET_CUSTOMER'
CHANGING
CT_FIELDCAT = ZTA_PRINT[].
ENDFORM. "FILL_STRUCTURE
*-----------------------------------------------------------------------
* Form MODIFY_STRUCTURE
*-----------------------------------------------------------------------
* Set the fieldproperties to your wishes
*-----------------------------------------------------------------------
FORM MODIFY_STRUCTURE.
LOOP AT ZTA_PRINT.
CLEAR ZTA_PRINT-KEY.
CASE ZTA_PRINT-FIELDNAME.
WHEN 'KUNNR'. "Customer Name
ZTA_PRINT-COL_POS = 0.
ZTA_PRINT-SELTEXT_S = 'Cstm'(H01).
ZTA_PRINT-SELTEXT_M = 'Customer'(H01).
ZTA_PRINT-SELTEXT_L = 'Customer Number'(H01).
WHEN 'BUKRS'. "Company Code
ZTA_PRINT-COL_POS = 1.
WHEN 'NAME1'. "Name 1
ZTA_PRINT-COL_POS = 2.
WHEN 'NAME2'.
ZTA_PRINT-COL_POS = 3. "NAME 2 (now set to invisible)
ZTA_PRINT-NO_OUT = 'X'.
WHEN 'STRAS'. "House number and street
ZTA_PRINT-COL_POS = 4.
WHEN 'PSTLZ'. "Postcode
ZTA_PRINT-COL_POS = 5.
WHEN 'ORT01'. "City
ZTA_PRINT-COL_POS = 6.
WHEN 'KTOKD'. "Customer Account Group
ZTA_PRINT-COL_POS = 7.
ENDCASE.
MODIFY ZTA_PRINT.
ENDLOOP.
ENDFORM. "MODIFY_STRUCTURE
SELECT-OPTIONS CUST_NO FOR KNA1-KUNNR .
2.Like Table 中要输入的字段方式
PARAMETERS CUST_NO LIKE KNA1-KUNNR.
2.直接输入的方式
SELECTION-SCREEN BEGIN OF BLOCK CHARLY
WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN END OF BLOCK CHARLY.
SELECT-OPTIONS CUST_NO FOR KNA1-KUNNR .
程序效果图: