首先,简单说明一下要用到的表类型、类、函数:
表类型
LVC_T_FCAT-(存放自定义列属性的表类型,一般用到的属性有:FIELDNAME、OUTPUTLEN、DATATYPE、INTTYPE、INTLEN、DECIMALS)。
LVC_S_FCAT- (LVC_T_FCAT类型的工作区类型)。
类
CL_ABAP_TABLEDESCR-(内表结构属性操作类,比如可以读取内表的列名称、内表值、内表列属性等等)。
CL_ABAP_STRUCTDESCR-(CL_ABAP_TABLEDESCR的工作区类型)。
函数
CONVERSION_EXIT_CUNIT_OUTPUT-(单位输出转换)。
CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( 内表
):获取CL_ABAP_TABLEDESCR对象。
CL_ABAP_TABLEDESCR对象->GET_TABLE_LINE_TYPE(
):获取CL_ABAP_STRUCTDESCR对象(注意函数括号里面的空格)。
REUSE_ALV_GRID_DISPLAY:ALV显示内表结果。
REUSE_ALV_COMMENTARY_WRITE:ALV抬头信息。
下面是一个开发实例的SAMPLE,根据给出的BOM循环查找BOM下面的所有最底层物料,根据工厂存在的物料价格动态地输出相应的列:
*&---------------------------------------------------------------------*
*& Report ZCOR017
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZCOR017
.
TABLES
:MAST
,STPO
.
TYPE-POOLS
: SLIS
.
*****************************TYPES*****************************************
TYPES
:
BEGIN
OF TY_STPO
,
STLNR
TYPE STPO
-STLNR
,
STLTY
TYPE STPO
-STLTY
,
STLKN
TYPE STPO
-STLKN
,
STPOZ
TYPE STPO
-STPOZ
,
IDNRK
TYPE STPO
-IDNRK
,
END
OF TY_STPO
.
TYPES
:
BEGIN
OF TY_MAST
,
MATNR
TYPE MAST
-MATNR
,
WERKS
TYPE MAST
-WERKS
,
STLAN
TYPE MAST
-STLAN
,
STLNR
TYPE MAST
-STLNR
,
END
OF TY_MAST
.
TYPES
:
BEGIN
OF TY_MAKT
,
MATNR
TYPE MAKT
-MATNR
,
MAKTX
TYPE MAKT
-MAKTX
,
END
OF TY_MAKT
.
TYPES
:
BEGIN
OF TY_MARA
,
MATNR
TYPE MARA
-MATNR
,
MEINS
TYPE MARA
-MEINS
,
END
OF TY_MARA
.
TYPES
:
BEGIN
OF TY_T001K
,
BWKEY
TYPE T001K
-BWKEY
,
END
OF TY_T001K
.
TYPES
:
BEGIN
OF TY_MBEW
,
MATNR
TYPE MBEW
-MATNR
,
BWKEY
TYPE MBEW
-BWKEY
,
STPRS
TYPE MBEW
-STPRS
,
PEINH
TYPE MBEW
-PEINH
,
END
OF TY_MBEW
.
*****************************DATA*****************************************
DATA
:
GT_STPO
TYPE
TABLE
OF TY_STPO
,
GS_STPO
TYPE TY_STPO
,
LT_STPO
TYPE
TABLE
OF TY_STPO
,
LS_STPO
TYPE TY_STPO
,
GT_MAST
TYPE
TABLE
OF TY_MAST
,
GS_MAST
TYPE TY_MAST
,
LT_MAST
TYPE
TABLE
OF TY_MAST
,
LS_MAST
TYPE TY_MAST
,
GT_MAKT
TYPE
TABLE
OF TY_MAKT
,
GS_MAKT
TYPE TY_MAKT
,
GT_MARA
TYPE
TABLE
OF TY_MARA
,
GS_MARA
TYPE TY_MARA
,
GT_T001K
TYPE
TABLE
OF TY_T001K
,
GS_T001K
TYPE TY_T001K
,
GT_MBEW
TYPE
TABLE
OF TY_MBEW
,
GS_MBEW
TYPE TY_MBEW
,
DNY_TAB
TYPE
REF
TO
DATA
,
DNY_LINE
TYPE
REF
TO
DATA
,
IFC
TYPE LVC_T_FCAT
,
XFC
TYPE LVC_S_FCAT
,
GS_LAYOUT
TYPE SLIS_LAYOUT_ALV
,
GT_FIELD
TYPE SLIS_T_FIELDCAT_ALV
,
GS_FIELD
LIKE
LINE
OF GT_FIELD
,
COUNTER
TYPE
I
VALUE
0
,
GV_STC_DESC
TYPE
REF
TO CL_ABAP_STRUCTDESCR
,
GV_TAB_DESC
TYPE
REF
TO CL_ABAP_TABLEDESCR
,
GT_TOP
TYPE SLIS_T_LISTHEADER
,
GS_TOP
TYPE SLIS_LISTHEADER
.
.
******************************DEFINETION****************************************
DEFINE DF_LVC_FCAT
.
XFC
-FIELDNAME
= &1
.
XFC
-DATATYPE
= &2
.
XFC
-INTTYPE
= &3
.
XFC
-INTLEN
= &4
.
XFC
-
DECIMALS
= &5
.
APPEND XFC
TO IFC
.
CLEAR XFC
.
END-OF-DEFINITION
.
DEFINE M_ALV_FIELDCAT
.
GS_FIELD
-FIELDNAME
= &1
.
GS_FIELD
-REPTEXT_DDIC
= &2
.
GS_FIELD
-OUTPUTLEN
= &3
.
GS_FIELD
-
ICON
= &4
.
GS_FIELD
-
EDIT
=
''
.
GS_FIELD
-
CHECKBOX
=
''
.
GS_FIELD
-REF_FIELDNAME
=
''
.
GS_FIELD
-REF_TABNAME
=
''
.
GS_FIELD
-JUST
=
''
.
GS_FIELD
-NO_ZERO
=
''
.
APPEND GS_FIELD
TO GT_FIELD
.
CLEAR GS_FIELD
.
END-OF-DEFINITION
.
******************************FILED-SYMBOLS****************************************
FIELD-SYMBOLS
:
$DNY_TAB> TYPE STANDARD TABLE,"该死的渣浪不支持小于号大于号组合,只能用$来代替了。
$DNY_WA> ,
$DNY_FIELD>,
$FS_TAB> TYPE ABAP_COMPDESCR.
******************************SCREEN****************************************
SELECTION-SCREEN
BEGIN
OF
BLOCK B1
WITH
FRAME
TITLE
TEXT
-
009
.
SELECTION-SCREEN
BEGIN
OF
LINE
.
SELECTION-SCREEN
COMMENT
1
(
51
)
TEXT
-
010
.
SELECTION-SCREEN
END
OF
LINE
.
SELECTION-SCREEN
BEGIN
OF
LINE
.
SELECTION-SCREEN
COMMENT
1
(
50
)
TEXT
-
011
.
SELECTION-SCREEN
END
OF
LINE
.
SELECTION-SCREEN
BEGIN
OF
LINE
.
SELECTION-SCREEN
COMMENT
1
(
60
)
TEXT
-
012
.
SELECTION-SCREEN
END
OF
LINE
.
SELECTION-SCREEN
END
OF
BLOCK B1
.
SELECTION-SCREEN
BEGIN
OF
BLOCK B2
WITH
FRAME
TITLE
TEXT
-
001
.
SELECT-OPTIONS
:
SMATNR
FOR MAST
-MATNR OBLIGATORY
.
PARAMETERS SWERKS
TYPE MAST
-WERKS
.
SELECTION-SCREEN
BEGIN
OF
LINE
.
SELECTION-SCREEN
COMMENT
1
(
10
)
TEXT
-
002
FOR
FIELD R1
.
PARAMETERS R1
RADIOBUTTON
GROUP G1
DEFAULT
'X'
.
SELECTION-SCREEN
COMMENT
14
(
10
)
TEXT
-
003
FOR
FIELD R1
.
PARAMETERS R2
RADIOBUTTON
GROUP G1
.
SELECTION-SCREEN
COMMENT
27
(
10
)
TEXT
-
004
FOR
FIELD R1
.
SELECTION-SCREEN
END
OF
LINE
.
PARAMETERS P1
TYPE T416
-STLAN OBLIGATORY
.
SELECTION-SCREEN
END
OF
BLOCK B2
.
*******************************FLOW***************************************
INITIALIZATION
.
"DO NOTHING.
AT
SELECTION-SCREEN
.
PERFORM CHECK_INPUT
.
START-OF-SELECTION
.
PERFORM RETRIVE_DATA
.
PERFORM PROCESS_DATA
.
END-OF-SELECTION
.
PERFORM PROCESS_OUTPUT
.
*******************************FORM***************************************
*&---------------------------------------------------------------------*
*& Form CHECK_INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CHECK_INPUT
.
"BOM类别为主机BOM,物料输入为6101*或671*,否则提示“主机BOM只允许输入6101*或671*物料”
IF R1
=
'X'
.
LOOP
AT SMATNR
.
IF SMATNR
-LOW
IS
NOT
INITIAL
AND SMATNR
-HIGH
IS
INITIAL
.
IF SMATNR
-LOW+0
(
4
)
NE
'6101'
AND SMATNR
-LOW+0
(
3
)
NE
'671'
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ELSEIF SMATNR
-LOW
IS
NOT
INITIAL
AND SMATNR
-HIGH
IS
NOT
INITIAL
.
IF SMATNR
-LOW+0
(
4
)
EQ
'6101'
AND SMATNR
-HIGH+0
(
4
)
NE
'6101'
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
IF SMATNR
-LOW+0
(
4
)
NE
'6101'
AND SMATNR
-HIGH+0
(
4
)
EQ
'6101'
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
IF SMATNR
-LOW+0
(
3
)
EQ
'671'
AND SMATNR
-HIGH+0
(
3
)
NE
'671'
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
IF SMATNR
-LOW+0
(
3
)
NE
'671'
AND SMATNR
-HIGH+0
(
3
)
EQ
'671'
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ELSE
.
MESSAGE
TEXT
-
005
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ENDLOOP
.
"BOM类别为项目物资,物料输入为672*数据,否则提示“只允许输入672*物料”
ELSEIF R2
=
'X'
.
LOOP
AT SMATNR
.
IF SMATNR
-LOW
IS
NOT
INITIAL
AND SMATNR
-HIGH
IS
INITIAL
.
IF SMATNR
-LOW+0
(
3
)
NE
'672'
.
MESSAGE
TEXT
-
006
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ELSEIF SMATNR
-LOW
IS
NOT
INITIAL
AND SMATNR
-HIGH
IS
NOT
INITIAL
.
IF SMATNR
-LOW+0
(
3
)
NE
'672'
OR SMATNR
-HIGH+0
(
3
)
NE
'672'
.
MESSAGE
TEXT
-
006
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ELSE
.
MESSAGE
TEXT
-
006
TYPE
'E'
.
LEAVE
LIST-PROCESSING
.
ENDIF
.
ENDLOOP
.
ENDIF
.
ENDFORM
.
" CHECK_INPUT
*&---------------------------------------------------------------------*
*& Form RETRIVE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM RETRIVE_DATA
.
"检查BOM存在性
IF SWERKS
IS
NOT
INITIAL
.
SELECT MATNR WERKS STLAN STLNR
FROM MAST
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MAST
WHERE MATNR
IN SMATNR
AND WERKS
EQ SWERKS
AND STLAN
EQ P1
.
ELSE
.
SELECT MATNR WERKS STLAN STLNR
FROM MAST
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MAST
WHERE MATNR
IN SMATNR
AND STLAN
EQ P1
.
ENDIF
.
IF GT_MAST
IS
INITIAL
.
MESSAGE
TEXT
-
007
TYPE
'I'
.
LEAVE
LIST-PROCESSING
.
CALL
SELECTION-SCREEN
1000
.
ENDIF
.
"根据BOM获取子层
SELECT STLNR STLTY STLKN STPOZ IDNRK
FROM STPO
INTO CORRESPONDING
FIELDS
OF
TABLE GT_STPO
FOR
ALL ENTRIES
IN GT_MAST
WHERE STLTY
EQ
'M'
AND STLNR
= GT_MAST
-STLNR
.
PERFORM FOO_BOM
CHANGING GT_STPO
.
"删除重复行
SORT GT_STPO
BY IDNRK
.
DELETE
ADJACENT
DUPLICATES
FROM GT_STPO
COMPARING IDNRK
.
"获取物料描述
SELECT MATNR MAKTX
FROM MAKT
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MAKT
FOR
ALL ENTRIES
IN GT_STPO
WHERE MATNR
= GT_STPO
-IDNRK
.
"获取单位
SELECT MATNR MEINS
FROM MARA
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MARA
FOR
ALL ENTRIES
IN GT_STPO
WHERE MATNR
= GT_STPO
-IDNRK
.
"获取价格
IF R1
=
'X'
.
IF SWERKS
IS
NOT
INITIAL
.
SELECT MATNR BWKEY STPRS PEINH
FROM MBEW
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MBEW
FOR
ALL ENTRIES
IN GT_STPO
WHERE MATNR
= GT_STPO
-IDNRK
AND BWKEY
= SWERKS
.
ELSE
.
SELECT BWKEY
FROM T001K
INTO CORRESPONDING
FIELDS
OF
TABLE GT_T001K
WHERE BWKEY
NOT
IN
(
'6010'
,
'6100'
,
'6540'
,
'6888'
)
AND BWMOD
=
'MY02'
.
LOOP
AT GT_T001K
INTO GS_T001K
.
IF GS_T001K
-BWKEY+3
(
1
)
EQ
'9'
.
DELETE GT_T001K
.
ENDIF
.
ENDLOOP
.
SELECT MATNR BWKEY STPRS PEINH
FROM MBEW
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MBEW
FOR
ALL ENTRIES
IN GT_STPO
WHERE MATNR
= GT_STPO
-IDNRK
.
LOOP
AT GT_MBEW
INTO GS_MBEW
.
READ
TABLE GT_T001K
TRANSPORTING
NO
FIELDS
WITH
KEY BWKEY
= GS_MBEW
-BWKEY
.
IF SY
-SUBRC <>
0
.
DELETE GT_MBEW
.
ENDIF
.
ENDLOOP
.
ENDIF
.
ELSE
.
SELECT MATNR BWKEY STPRS PEINH
FROM MBEW
INTO CORRESPONDING
FIELDS
OF
TABLE GT_MBEW
FOR
ALL ENTRIES
IN GT_STPO
WHERE MATNR
= GT_STPO
-IDNRK
AND BWKEY
=
'6888'
.
ENDIF
.
ENDFORM
.
" RETRIVE_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PROCESS_DATA
.
DF_LVC_FCAT
:
"FIELDNAME DATATYPE INTTYPE INTLEN DECIMALS
'MATNR'
'C'
'C'
18
0
,
"物料
'MAKTX'
'C'
'C'
40
0
,
"物料描述
'MEINS'
'C'
'C'
3
0
,
"基本单位
'CHECK'
'C'
'C'
4
0
,
"价格检查标识
'LMEIN'
'C'
'C'
1
0
.
"本报表价格单位
IF R1
=
'X'
.
IF SWERKS
IS
NOT
INITIAL
.
DF_LVC_FCAT
:
SWERKS
'P'
'P'
11
2
.
"工厂价格
ELSE
.
SORT GT_T001K
.
CLEAR GS_T001K
.
LOOP
AT GT_T001K
INTO GS_T001K
.
DF_LVC_FCAT
:
GS_T001K
-BWKEY
'P'
'P'
11
2
.
"工厂价格
CLEAR GS_T001K
.
ENDLOOP
.
ENDIF
.
ELSE
.
DF_LVC_FCAT
:
'6888'
'P'
'P'
11
2
.
"6888工厂价格
ENDIF
.
CALL
METHOD CL_ALV_TABLE_CREATE
=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG
= IFC
IMPORTING
EP_TABLE
= DNY_TAB
.
ASSIGN DNY_TAB
->*
TO $DNY_TAB>.
CREATE
DATA DNY_LINE
LIKE
LINE
OF $DNY_TAB>.
ASSIGN DNY_LINE
->*
TO $DNY_WA>.
CLEAR GS_STPO
.
LOOP
AT GT_STPO
INTO GS_STPO
.
"物料
ASSIGN
COMPONENT
'MATNR'
OF
STRUCTURE $DNY_WA> TO $DNY_FIELD>.
= GS_STPO
-IDNRK
.
"物料描述
CLEAR GS_MAKT
.
READ
TABLE GT_MAKT
INTO GS_MAKT
WITH
KEY MATNR
= GS_STPO
-IDNRK
.
IF SY
-SUBRC
=
0
.
ASSIGN
COMPONENT
'MAKTX'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
= GS_MAKT
-MAKTX
.
ENDIF
.
"基本单位
CLEAR GS_MARA
.
READ
TABLE GT_MARA
INTO GS_MARA
WITH
KEY MATNR
= GS_STPO
-IDNRK
.
IF SY
-SUBRC
=
0
.
CALL
FUNCTION
'CONVERSION_EXIT_CUNIT_OUTPUT'
EXPORTING
INPUT
= GS_MARA
-MEINS
* LANGUAGE = SY-LANGU
IMPORTING
* LONG_TEXT =
OUTPUT
= GS_MARA
-MEINS
* SHORT_TEXT =
* EXCEPTIONS
* UNIT_NOT_FOUND = 1
* OTHERS = 2
.
IF SY
-SUBRC <>
0
.
* Implement suitable error handling here
ENDIF
.
ASSIGN
COMPONENT
'MEINS'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
= GS_MARA
-MEINS
.
ENDIF
.
"本报表价格单位
ASSIGN
COMPONENT
'LMEIN'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'1'
.
"各工厂价格
IF R1
=
'X'
.
IF SWERKS
IS
INITIAL
.
CLEAR
: GS_MBEW
,GS_T001K
,COUNTER
.
SORT GT_T001K
.
LOOP
AT GT_T001K
INTO GS_T001K
.
ASSIGN
COMPONENT GS_T001K
-BWKEY
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
LOOP
AT GT_MBEW
INTO GS_MBEW
WHERE MATNR
= GS_STPO
-IDNRK
AND BWKEY
= GS_T001K
-BWKEY
.
= GS_MBEW
-STPRS / GS_MBEW
-PEINH
.
IF
NE
0
.
COUNTER
= COUNTER +
1
.
ENDIF
.
ENDLOOP
.
IF SY
-SUBRC <>
0
.
=
0
.
ENDIF
.
ENDLOOP
.
"价格检查标识
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
IF COUNTER
=
LINES
( GT_T001K
)
AND COUNTER
NE
0
.
=
'@5B@'
.
"GREEN
ELSEIF COUNTER
=
0
.
=
'@5C@'
.
"RED
ELSE
.
=
'@5D@'
.
"YELLOW
ENDIF
.
ELSE
.
CLEAR
:GS_MBEW
.
ASSIGN
COMPONENT SWERKS
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
READ
TABLE GT_MBEW
INTO GS_MBEW
WITH
KEY MATNR
= GS_STPO
-IDNRK BWKEY
= SWERKS
.
IF SY
-SUBRC
=
0
.
= GS_MBEW
-STPRS / GS_MBEW
-PEINH
.
"价格检查标识
IF
NE
0
.
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5B@'
.
"GREEN
ELSE
.
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5C@'
.
"RED
ENDIF
.
ELSE
.
=
0
.
"价格检查标识
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5C@'
.
"RED
ENDIF
.
ENDIF
.
ELSE
.
CLEAR
: GS_MBEW
.
ASSIGN
COMPONENT
'6888'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
READ
TABLE GT_MBEW
INTO GS_MBEW
WITH
KEY BWKEY
=
'6888' MATNR
= GS_STPO
-IDNRK
.
IF SY
-SUBRC
=
0
.
= GS_MBEW
-STPRS / GS_MBEW
-PEINH
.
"价格检查标识
IF
NE
0
.
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5B@'
.
"GREEN
ELSE
.
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5C@'
.
"RED
ENDIF
.
ELSE
.
=
0
.
"价格检查标识
ASSIGN
COMPONENT
'CHECK'
OF
STRUCTURE
$
DNY_WA> TO $DNY_FIELD>
.
=
'@5C@'
.
ENDIF
.
ENDIF
.
APPEND $DNY_WA>
TO $DNY_TAB>
.
.
CLEAR GS_STPO
.
ENDLOOP
.
ENDFORM
.
" PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM PROCESS_OUTPUT
.
M_ALV_FIELDCAT
:
"FIELDNAME HEADING OUTPUTLEN ICON
'MATNR'
'物料'
'18'
''
,
'MAKTX'
'物料描述'
'40'
''
,
'MEINS'
'基本单位'
'4'
''
,
'CHECK'
'价格检查标识'
'4'
'X'
,
'LMEIN'
'本报表价格单位'
'4'
''
.
IF R1
=
'X'
.
GV_TAB_DESC ?= CL_ABAP_TYPEDESCR
=>DESCRIBE_BY_DATA
( $DNY_TAB> ).
GV_STC_DESC ?= GV_TAB_DESC
->GET_TABLE_LINE_TYPE
(
)
.
DATA
: LV_STR
TYPE STRING
.
LOOP
AT GV_STC_DESC
->COMPONENTS
ASSIGNING $FS_TAB>.
IF
$
FS_TAB>-NAME EQ 'MATNR'
OR
$
FS_TAB>-NAME EQ 'MAKTX'
OR
$
FS_TAB>-NAME EQ 'MEINS'
OR
$
FS_TAB>-NAME EQ 'CHECK'
OR
$
FS_TAB>-NAME EQ 'LMEIN'.
CONTINUE
.
ENDIF
.
CLEAR LV_STR
.
LV_STR
=
$
FS_TAB>-NAME && '-工厂价格'.
M_ALV_FIELDCAT
:
$
FS_TAB>-NAME LV_STR '15' ''.
ENDLOOP
.
ELSE
.
M_ALV_FIELDCAT
:
'6888'
'6888-工厂价格'
'15'
''
.
ENDIF
.
****************************ALV LAYOUT******************************************
GS_LAYOUT
-COLWIDTH_OPTIMIZE
=
'X'
.
"宽度自动优化
GS_LAYOUT
-ZEBRA
=
'X'
.
"斑马线
**********************TOP OF PAGR************************************************
"Type H is used to display headers i.e. big font
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'H'
.
IF R1
=
'X'
.
GS_TOP
-INFO
=
'投标报价主机BOM价格检查'
.
ELSE
.
GS_TOP
-INFO
=
'投标报价项目物资相关BOM物料检查'
.
ENDIF
.
APPEND GS_TOP
TO GT_TOP
.
"Type S is used to display key and value pairs
IF R1
=
'X'
.
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'S'
.
GS_TOP
-
KEY
=
'红灯:'
.
GS_TOP
-INFO
=
'所有工厂价格为0'
.
APPEND GS_TOP
TO GT_TOP
.
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'S'
.
GS_TOP
-
KEY
=
'黄灯:'
.
GS_TOP
-INFO
=
'一个工厂有价格不为0(排除绿灯条件)'
.
APPEND GS_TOP
TO GT_TOP
.
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'S'
.
GS_TOP
-
KEY
=
'绿灯:'
.
GS_TOP
-INFO
=
'所有工厂价格都不为0'
.
APPEND GS_TOP
TO GT_TOP
.
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'S'
.
GS_TOP
-
KEY
=
'备注:'
.
GS_TOP
-INFO
=
'只对所有主机工厂检查,且价格单位均为1'
.
APPEND GS_TOP
TO GT_TOP
.
ELSE
.
CLEAR GS_TOP
.
GS_TOP
-TYP
=
'S'
.
GS_TOP
-
KEY
=
'备注:'
.
GS_TOP
-INFO
=
'只检查6888工厂物料价格'
.
APPEND GS_TOP
TO GT_TOP
.
ENDIF
.
"Type A is used to display italic font
* CLEAR GS_TOP.
* GS_TOP-TYP = 'A'.
* GS_TOP-INFO = SY-DATUM.
* APPEND GS_TOP TO GT_TOP.
*****************************ALV*****************************************
CALL
FUNCTION
'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM
= SY
-REPID
I_CALLBACK_TOP_OF_PAGE
=
'TOP_OF_PAGE'
IS_LAYOUT
= GS_LAYOUT
IT_FIELDCAT
= GT_FIELD
I_DEFAULT
=
'X'
I_SAVE
=
'A'
TABLES
T_OUTTAB
= $ DNY_TAB>
EXCEPTIONS
PROGRAM_ERROR
=
1
OTHERS
=
2
.
IF SY
-SUBRC <>
0
.
MESSAGE
ID SY
-MSGID
TYPE SY
-MSGTY
NUMBER SY
-MSGNO
WITH SY
-MSGV1 SY
-MSGV2 SY
-MSGV3 SY
-MSGV4
.
ENDIF
.
ENDFORM
.
" PROCESS_OUTPUT
*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
FORM TOP_OF_PAGE
.
CALL
FUNCTION
'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY
= GT_TOP
.
ENDFORM
.
"top_of_page
*&---------------------------------------------------------------------*
*& Form FOO_BOM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GT_STPO text
*----------------------------------------------------------------------*
FORM FOO_BOM
CHANGING P_GT_STPO
LIKE GT_STPO
.
IF P_GT_STPO
IS
INITIAL
.
MESSAGE
TEXT
-
008
TYPE
'I'
.
RETURN
.
ENDIF
.
CLEAR
:
LT_MAST
,
LS_MAST
,
LT_STPO
,
LS_STPO
.
IF SWERKS
IS
NOT
INITIAL
.
SELECT MATNR WERKS STLAN STLNR
FROM MAST
INTO CORRESPONDING
FIELDS
OF
TABLE LT_MAST
FOR
ALL ENTRIES
IN P_GT_STPO
WHERE MATNR
= P_GT_STPO
-IDNRK
AND WERKS
EQ SWERKS
AND STLAN
EQ P1
.
ELSE
.
SELECT MATNR WERKS STLAN STLNR
FROM MAST
INTO CORRESPONDING
FIELDS
OF
TABLE LT_MAST
FOR
ALL ENTRIES
IN P_GT_STPO
WHERE MATNR
= P_GT_STPO
-IDNRK
AND STLAN
EQ P1
.
ENDIF
.
IF LT_MAST
IS
NOT
INITIAL
.
SELECT STLNR STLTY STLKN STPOZ IDNRK
FROM STPO
INTO CORRESPONDING
FIELDS
OF
TABLE LT_STPO
FOR
ALL ENTRIES
IN LT_MAST
WHERE STLTY
EQ
'M'
AND STLNR
= LT_MAST
-STLNR
.
LOOP
AT LT_MAST
INTO LS_MAST
.
DELETE P_GT_STPO
WHERE IDNRK
= LS_MAST
-MATNR
.
ENDLOOP
.
APPEND
LINES
OF LT_STPO
TO P_GT_STPO
.
PERFORM FOO_BOM
CHANGING P_GT_STPO
.
ENDIF
.
ENDFORM
.
" FOO_BOM