Вы находитесь на странице: 1из 7

*&---------------------------------------------------------------------*

*& Report Z_OPENSALE


*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_OPENSALE.
FIELD-SYMBOLS: <GFS_LINE>,<GFS_LINE1>,
<GFS_DYN_TABLE> TYPE STANDARD TABLE,
<FS1>.
DATA : GT_DYN_FCAT1 TYPE SLIS_T_FIELDCAT_ALV .
DATA : T_VBAP_H2 TYPE TABLE OF VBAPVB,
W_VBAP_H2 TYPE VBAPVB.
DATA : T_VBAP_H TYPE TABLE OF VBAPVB,
W_VBAP_H TYPE VBAPVB.
DATA : GT_DYN_TABLE TYPE REF TO DATA,
GW_LINE TYPE REF TO DATA,
GW_LINE1 TYPE REF TO DATA,
GW_DYN_FCAT TYPE LVC_S_FCAT,
GT_DYN_FCAT TYPE LVC_T_FCAT.
DATA : T_VBAP_H3 TYPE TABLE OF VBAPVB,
W_VBAP_H3 TYPE VBAPVB,
W_VBAP_H31 TYPE VBAPVB.
DATA : G_VBELN TYPE VBELN.
DATA : FNAME TYPE STRING.
DATA : GV_POS TYPE I.
DATA : IT_HEAD TYPE SLIS_T_LISTHEADER,
WA_HEAD TYPE SLIS_LISTHEADER.
DATA T_EVENTS TYPE SLIS_T_EVENT.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001 .
SELECT-OPTIONS: S_VBELN FOR G_VBELN OBLIGATORY.
SELECTION-SCREEN : END OF BLOCK B1 .
SELECT *
FROM VBAP
INTO TABLE T_VBAP_H
WHERE VBELN IN S_VBELN
AND PSTYV IN ('AMIL','ZTAP','ASNG')
AND ABGRU = ' '.
SELECT *
FROM VBAP
INTO TABLE T_VBAP_H3
WHERE VBELN IN S_VBELN
AND PSTYV NOT IN ('AMIL','ZTAP','ASNG').
* AND ABGRU <> ' '.
PERFORM GET_VBEP. "Schedule Line Items
GV_POS = GV_POS + 1.
GW_DYN_FCAT-FIELDNAME = 'VBELN'.
GW_DYN_FCAT-OUTPUTLEN = 18.
GW_DYN_FCAT-TABNAME = 'T_VBAP_H3'.
GW_DYN_FCAT-COLTEXT = 'Sale Order'.
GW_DYN_FCAT-COL_POS = GV_POS.
GW_DYN_FCAT-KEY = 'X'.
GW_DYN_FCAT-KEY_SEL = 'X'.
APPEND GW_DYN_FCAT TO GT_DYN_FCAT.
CLEAR GW_DYN_FCAT.
GV_POS = GV_POS + 1.
GW_DYN_FCAT-FIELDNAME = 'MATNR'.
GW_DYN_FCAT-OUTPUTLEN = 18.
GW_DYN_FCAT-TABNAME = 'T_VBBE3'.
GW_DYN_FCAT-COLTEXT = 'MATERIAL'.
GW_DYN_FCAT-COL_POS = GV_POS.
GW_DYN_FCAT-KEY = 'X'.
GW_DYN_FCAT-KEY_SEL = 'X'.
APPEND GW_DYN_FCAT TO GT_DYN_FCAT.
CLEAR GW_DYN_FCAT.
GV_POS = GV_POS + 1.
GW_DYN_FCAT-FIELDNAME = 'KWMENG'.
GW_DYN_FCAT-OUTPUTLEN = 18.
GW_DYN_FCAT-TABNAME = 'T_VBBE3'.
GW_DYN_FCAT-COLTEXT = 'BAL'.
GW_DYN_FCAT-COL_POS = GV_POS.
GW_DYN_FCAT-KEY = 'X'.
GW_DYN_FCAT-KEY_SEL = 'X'.
APPEND GW_DYN_FCAT TO GT_DYN_FCAT.
CLEAR GW_DYN_FCAT.
SORT T_VBAP_H3 BY MATNR.
LOOP AT T_VBAP_H3 INTO W_VBAP_H3.
GV_POS = GV_POS + 1.
* CONCATENATE W_VBAP_H3-MATNR INTO FNAME.
FNAME = W_VBAP_H3-MATNR.
READ TABLE GT_DYN_FCAT INTO GW_DYN_FCAT WITH KEY FIELDNAME = W_VBAP_H3-MATNR.
IF SY-SUBRC NE 0.
GW_DYN_FCAT-FIELDNAME = W_VBAP_H3-MATNR.
GW_DYN_FCAT-TABNAME = 'T_VBAP_H3'.
GW_DYN_FCAT-COLTEXT = W_VBAP_H3-MATNR+14(4).
GW_DYN_FCAT-OUTPUTLEN = 10.
GW_DYN_FCAT-COL_POS = GV_POS.
GW_DYN_FCAT-DATATYPE = 'DEC'.
GW_DYN_FCAT-DECIMALS = '0'.
* GW_DYN_FCAT-DO_SUM = 'X'.
APPEND GW_DYN_FCAT TO GT_DYN_FCAT.
ENDIF.
CLEAR GW_DYN_FCAT.
ENDLOOP.
** Create a dynamic internal table with this structure.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
I_STYLE_TABLE = 'X'
IT_FIELDCATALOG = GT_DYN_FCAT
IMPORTING
EP_TABLE = GT_DYN_TABLE
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
IF SY-SUBRC EQ 0.
* Assign the new table to field symbol
ASSIGN GT_DYN_TABLE->* TO <GFS_DYN_TABLE>.
* Create dynamic work area for the dynamic table
CREATE DATA GW_LINE LIKE LINE OF <GFS_DYN_TABLE>.
CREATE DATA GW_LINE1 LIKE LINE OF <GFS_DYN_TABLE>.
ASSIGN GW_LINE->* TO <GFS_LINE>.
ASSIGN GW_LINE1->* TO <GFS_LINE1>.
ENDIF.
* Populate the dynamic table
SORT T_VBAP_H2 BY VBELN POSNR MATNR.
LOOP AT T_VBAP_H2 INTO W_VBAP_H2.
* Avoid duplicate entries for key field PART.
READ TABLE <GFS_DYN_TABLE> INTO <GFS_LINE1> WITH KEY ('MATNR') = W_VBAP_H2-MAT
NR ('VBELN') = W_VBAP_H2-VBELN.
IF SY-SUBRC = 0.
CONTINUE.
ENDIF.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = W_VBAP_H2-VBELN.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = W_VBAP_H2-MATNR.
UNASSIGN <FS1>.
ASSIGN COMPONENT 'KWMENG' OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = W_VBAP_H2-KWMENG.
UNASSIGN <FS1>.
LOOP AT GT_DYN_FCAT INTO GW_DYN_FCAT.
IF GW_DYN_FCAT-FIELDNAME = 'MATNR' OR GW_DYN_FCAT-FIELDNAME = 'VBELN' OR
GW_DYN_FCAT-FIELDNAME = 'KWMENG' .
CONTINUE.
ENDIF.
LOOP AT T_VBAP_H3 INTO W_VBAP_H31 WHERE VBELN = W_VBAP_H2-VBELN AND UEPOS
= W_VBAP_H2-POSNR AND MATNR = GW_DYN_FCAT-FIELDNAME.
IF SY-SUBRC = 0 .
ASSIGN COMPONENT GW_DYN_FCAT-FIELDNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
<FS1> = W_VBAP_H31-KWMENG.
UNASSIGN <FS1>.
ENDIF.
CLEAR : W_VBAP_H31.
ENDLOOP.
ENDLOOP.
APPEND <GFS_LINE> TO <GFS_DYN_TABLE>.
CLEAR: <GFS_LINE>.
CLEAR: W_VBAP_H3, W_VBAP_H31.
ENDLOOP.
LOOP AT <GFS_DYN_TABLE> INTO <GFS_LINE>.
LOOP AT GT_DYN_FCAT INTO GW_DYN_FCAT.
ASSIGN COMPONENT GW_DYN_FCAT-FIELDNAME OF STRUCTURE <GFS_LINE> TO <FS1>.
ENDLOOP.
ENDLOOP.
**DATA: T_FD TYPE TYPE STANDARD TABLE .
*
CALL FUNCTION 'LVC_TRANSFER_TO_SLIS'
EXPORTING
IT_FIELDCAT_LVC = GT_DYN_FCAT
* IT_SORT_LVC =
* IT_FILTER_LVC =
* IS_LAYOUT_LVC =
IMPORTING
ET_FIELDCAT_ALV = GT_DYN_FCAT1
* ET_SORT_ALV =
* ET_FILTER_ALV =
* ES_LAYOUT_ALV =
* TABLES
* IT_DATA = T_FD
* EXCEPTIONS
* IT_DATA_MISSING = 1
* IT_FIELDCAT_LVC_MISSING = 2
* OTHERS = 3
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
I_CALLBACK_TOP_OF_PAGE = 'TOP'
IT_EVENTS = T_EVENTS
IT_FIELDCAT = GT_DYN_FCAT1
I_DEFAULT = 'X'
I_SAVE = 'A'
TABLES
T_OUTTAB = <GFS_DYN_TABLE>.
FORM TOP.
REFRESH : IT_HEAD.
WA_HEAD-TYP = 'H'.
WA_HEAD-INFO = 'SORT WISE '.
APPEND WA_HEAD TO IT_HEAD.
CLEAR WA_HEAD.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_HEAD.
ENDFORM. "TOP
"TOP
*&---------------------------------------------------------------------*
*& Form GET_VBEP
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_VBEP .
IF T_VBAP_H IS NOT INITIAL.
SELECT VBELN
POSNR
ETENR
EDATU
WMENG
BMENG
VRKME
LMENG
FROM VBEP
INTO TABLE T_VBEP
FOR ALL ENTRIES IN T_VBAP_H
WHERE VBELN = T_VBAP_H-VBELN
AND POSNR = T_VBAP_H-POSNR.
SELECT *
FROM VBEP
INTO TABLE T_VBEP6
FOR ALL ENTRIES IN T_VBAP_H
WHERE VBELN = T_VBAP_H-VBELN
AND POSNR = T_VBAP_H-POSNR.
ENDIF.
SORT T_VBAP_H2 BY VBELN.
******************************************
LOOP AT T_VBAP_H2 INTO W_VBAP_H2.
LOOP AT T_VBUP INTO W_VBUP WHERE VBELN = W_VBAP_H2-VBELN AND POSNR = W_VBAP_
H2-POSNR.
APPEND W_VBUP TO T_VBUP2.
ENDLOOP.
LOOP AT T_VBFA INTO W_VBFA WHERE VBELV = W_VBAP_H2-VBELN AND POSNV = W_VBAP_
H2-POSNR.
APPEND W_VBFA TO T_VBFA2.
ENDLOOP.
LOOP AT T_VBEP6 INTO W_VBEP6 WHERE VBELN = W_VBAP_H2-VBELN AND POSNR = W_VBA
P_H2-POSNR.
APPEND W_VBEP6 TO T_VBEP7.
ENDLOOP.
APPEND W_VBAP_H2 TO T_VBAP_H3.
******************************************
CALL FUNCTION 'RV_SCHEDULE_CHECK_DELIVERIES'
EXPORTING
FBELEG = W_VBAP_H2-VBELN
FPOSNR = W_VBAP_H2-POSNR
TABLES
FVBFA = T_VBFA2
FVBUP = T_VBUP2
FXVBEP = T_VBEP7
FVBAP = T_VBAP_H3.
APPEND LINES OF T_VBEP7 TO T_VBEP8.
REFRESH: T_VBFA2,
T_VBUP2,
T_VBEP7,
T_VBAP_H3.
ENDLOOP.
DELETE T_VBEP8 WHERE VSMNG = ' '.
FIELD-SYMBOLS: <W_VBEP> TYPE TY_VBEP.
LOOP AT T_VBEP ASSIGNING <W_VBEP>.
READ TABLE T_VBAK INTO W_VBAK WITH KEY VBELN = <W_VBEP>-VBELN.
IF SY-SUBRC = 0.
READ TABLE T_KONV INTO W_KONV WITH KEY KNUMV = W_VBAK-KNUMV.
IF SY-SUBRC = 0.
<W_VBEP>-KBETR = W_KONV-KBETR.
ENDIF.
endif.
READ TABLE T_VBEP8 INTO W_VBEP8 WITH KEY VBELN = <W_VBEP>-VBELN POSNR = <W_V
BEP>-POSNR ETENR = <W_VBEP>-ETENR.
IF SY-SUBRC = 0.
<W_VBEP>-WMENG = <W_VBEP>-WMENG - W_VBEP8-VSMNG.
ENDIF.
CLEAR <W_VBEP>-REMARK.
REFRESH TLINE[].
DATA: L_NAME TYPE THEAD-TDNAME.
CONCATENATE <W_VBEP>-VBELN <W_VBEP>-POSNR INTO L_NAME.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
ID = 'TRAD'
LANGUAGE = 'E'
NAME = L_NAME "'YHC2010CHAH01T90KG100010'
OBJECT = 'VBBP'
TABLES
LINES = TLINE
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT TLINE.
CONCATENATE <W_VBEP>-REMARK TLINE-TDLINE INTO <W_VBEP>-REMARK.
ENDLOOP.
REFRESH TLINE.
CLEAR TLINE.
REPLACE ALL OCCURRENCES OF '<(>&<)>' IN <W_VBEP>-REMARK WITH '&'.
ENDLOOP.
DELETE T_VBEP WHERE WMENG IS INITIAL.
ENDFORM. " GET_VBEP