Get Open Sales Order

引用:翱翔云天

This report is used to get the open sales order, just for a refer.


REPORT /SIE/CHN_SD_SDI_OPEN_QTY .

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

*& Macro declaration *

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

DEFINE SET_ALV_FIELDCAT.

CLEAR LS_FIELDCAT.

LS_FIELDCAT-FIELDNAME = &1. "Field name

LS_FIELDCAT-TABNAME = &2. "Reference table name

LS_FIELDCAT-COL_POS = &3. "Column position

LS_FIELDCAT-OUTPUTLEN = &4. "Output length

LS_FIELDCAT-SELTEXT_L = &5. "Select text long length

LS_FIELDCAT-DDICTXT = 'L'. "Using select text type

APPEND LS_FIELDCAT TO IT_FIELDCAT.

END-OF-DEFINITION.

TABLES: VBAK,VBAP,VBFA.

TYPE-POOLS SLIS.

*ALC used fieldcatelog internal table

DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.

*Structure and internal table for sales open Qty

DATA:

BEGIN OF R_SQ,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

SQ(20),

GQ(20),

OQ(20),

END OF R_SQ,

IT_SQ LIKE TABLE OF R_SQ.

*Structure and table for billing open Qty

DATA BEGIN OF R_BQ.

DATA VBELN LIKE VBAP-VBELN.

DATA POSNR LIKE VBAP-POSNR.

INCLUDE STRUCTURE FPLT.

DATA END OF R_BQ.

DATA IT_BQ LIKE TABLE OF R_BQ.

*Selection screen

SELECTION-SCREEN BEGIN OF BLOCK B1

WITH FRAME TITLE TEXT-B01.

SELECTION-SCREEN BEGIN OF LINE.

PARAMETER RAD1 RADIOBUTTON GROUP R1 USER-COMMAND F1.

SELECTION-SCREEN COMMENT 3(20) TEXT-R01 FOR FIELD RAD1.

PARAMETER RAD2 RADIOBUTTON GROUP R1.

SELECTION-SCREEN COMMENT 40(20) TEXT-R02 FOR FIELD RAD2.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK B1.

SELECT-OPTIONS:

S_VKORG FOR VBAK-VKORG,

S_VTWEG FOR VBAK-VTWEG,

S_SPART FOR VBAK-SPART,

S_KUNNR FOR VBAK-KUNNR,

S_ERDAT FOR VBAK-ERDAT,

S_AUART FOR VBAK-AUART,

S_PSTYV FOR VBAP-PSTYV,

S_ABGRU FOR VBAP-ABGRU,

S_WBS FOR VBAP-PS_PSP_PNR,

S_MATNR FOR VBAP-MATNR,

S_VBELV FOR VBFA-VBELV,

S_VBTYP FOR VBFA-VBTYP_N.

*Initialize program

INITIALIZATION.

RAD1 = 'X'.

*Change output according to screen selection

AT SELECTION-SCREEN OUTPUT.

PERFORM MODIF_SCREEN.

*Check authority

AT SELECTION-SCREEN.

PERFORM AUTH_CHECK.

START-OF-SELECTION.

IF RAD1 IS INITIAL.

* Get billing Qty

PERFORM GET_DATA_BQ.

* Show billing Qty

PERFORM OUTPUT_BQ.

ELSE.

* Get Sales Open Qty

PERFORM GET_DATA_SQ.

* Show Sales Open Qty

PERFORM OUTPUT_SQ.

ENDIF.

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

*& Form modif_screen

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

* text

*----------------------------------------------------------------------*

FORM MODIF_SCREEN.

IF RAD1 IS INITIAL.

LOOP AT SCREEN.

IF SCREEN-NAME CS 'VBELV' OR

SCREEN-NAME CS 'VBTYP'.

SCREEN-ACTIVE = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. " modif_screen

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

*& Form AUTH_CHECK

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

* text

*----------------------------------------------------------------------*

FORM AUTH_CHECK.

* Check whether the User has the Transaction Code Authorization

AUTHORITY-CHECK OBJECT 'S_TCODE'

ID 'TCD' FIELD 'VA03'.

IF SY-SUBRC <> 0.

MESSAGE E043(/SIE/CHN_ALL).

ENDIF.

ENDFORM. " AUTH_CHECK

 

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

*& Form GET_DATA_BQ

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

* text

*----------------------------------------------------------------------*

FORM GET_DATA_BQ.

* With inner join get billing plan

* VBAK--VBAP--VBKD--FPLT

SELECT A~VBELN B~POSNR D~AFDAT D~TETXT D~MLBEZ D~FPROZ

D~FAKWR D~WAERS D~FAKSP D~FAREG D~FKSAF D~ZTERM

D~FPTTP D~FKARV D~KURRF D~MLSTN D~FPFIX

FROM VBAK AS A INNER JOIN VBAP AS B ON B~VBELN = A~VBELN

INNER JOIN VBKD AS C ON C~VBELN = B~VBELN AND C~POSNR = B~POSNR

INNER JOIN FPLT AS D ON D~FPLNR = C~FPLNR

INTO CORRESPONDING FIELDS OF TABLE IT_BQ

WHERE A~VKORG IN S_VKORG

AND A~VTWEG IN S_VTWEG

AND A~SPART IN S_SPART

AND A~KUNNR IN S_KUNNR

AND A~ERDAT IN S_ERDAT

AND A~AUART IN S_AUART

AND B~PSTYV IN S_PSTYV

AND B~ABGRU IN S_ABGRU

AND B~PS_PSP_PNR IN S_WBS

AND B~MATNR IN S_MATNR

AND D~FKSAF <> 'C'.

IF SY-SUBRC <> 0.

MESSAGE S033(/SIE/CHN_ALL)

WITH 'No data exists!'.

ENDIF.

ENDFORM. " GET_DATA_BQ

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

*& Form GET_DATA_SQ

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

* text

*----------------------------------------------------------------------*

FORM GET_DATA_SQ.

* Local data

DATA:

BEGIN OF LR_SQ,

VBELN LIKE VBAP-VBELN,

POSNR LIKE VBAP-POSNR,

RFMNG LIKE VBFA-RFMNG,

KWMENG LIKE VBAP-KWMENG,

OQ LIKE VBAP-KWMENG,

VRKME LIKE VBAP-VRKME,

END OF LR_SQ.

DATA: LIT_SQ LIKE TABLE OF LR_SQ,

LLR_SQ LIKE LR_SQ.

DATA: L_QTY LIKE VBFA-RFMNG.

* Get sales open Qty

* VBAK--VBAP--VBFA

SELECT A~VBELN B~POSNR B~KWMENG B~VRKME C~RFMNG

FROM VBAK AS A INNER JOIN VBAP AS B ON B~VBELN = A~VBELN

INNER JOIN VBFA AS C ON C~POSNV = B~POSNR AND C~VBELV = B~VBELN

INTO CORRESPONDING FIELDS OF TABLE LIT_SQ

WHERE A~VKORG IN S_VKORG

AND A~VTWEG IN S_VTWEG

AND A~SPART IN S_SPART

AND A~KUNNR IN S_KUNNR

AND A~ERDAT IN S_ERDAT

AND A~AUART IN S_AUART

AND B~PSTYV IN S_PSTYV

AND B~ABGRU IN S_ABGRU

AND B~PS_PSP_PNR IN S_WBS

AND B~MATNR IN S_MATNR

AND C~VBTYP_N IN S_VBTYP.

IF SY-SUBRC <> 0.

MESSAGE S033(/SIE/CHN_ALL) WITH 'No data exists!'.

ENDIF.

* GI Qty summary

SORT LIT_SQ BY VBELN POSNR.

LOOP AT LIT_SQ INTO LR_SQ.

LLR_SQ = LR_SQ.

L_QTY = LLR_SQ-RFMNG + L_QTY.

AT END OF POSNR.

LLR_SQ-OQ = LLR_SQ-KWMENG - L_QTY.

WRITE:

L_QTY TO R_SQ-GQ UNIT LLR_SQ-VRKME,

LLR_SQ-KWMENG TO R_SQ-SQ UNIT LLR_SQ-VRKME,

LLR_SQ-OQ TO R_SQ-OQ UNIT LLR_SQ-VRKME.

R_SQ-VBELN = LLR_SQ-VBELN.

R_SQ-POSNR = LLR_SQ-POSNR.

APPEND R_SQ TO IT_SQ.

CLEAR: LLR_SQ,LR_SQ,L_QTY.

ENDAT.

ENDLOOP.

ENDFORM. " GET_DATA_SQ

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

*& Form OUTPUT_SQ

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

* text

*----------------------------------------------------------------------*

FORM OUTPUT_SQ.

* Define ALV fieldcat structure

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

* Add data to field catelog

SET_ALV_FIELDCAT:

'VBELN' 'IT_BQ' '1' '12' TEXT-A01,

'POSNR' 'IT_BQ' '2' '10' TEXT-A02,

'SQ' 'IT_BQ' '3' '22' TEXT-A03,

'GQ' 'IT_BQ' '4' '22' TEXT-A04,

'OQ' 'IT_BQ' '5' '20' TEXT-A05.

* Call function to show result

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT

I_SAVE = 'A'

TABLES

T_OUTTAB = IT_SQ.

ENDFORM. " OUTPUT_SQ

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

*& Form OUTPUT_BQ

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

* text

*----------------------------------------------------------------------*

FORM OUTPUT_BQ.

* Define ALV fieldcat structure

DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

* Add data to field catelog

SET_ALV_FIELDCAT:

'VBELN' 'IT_SQ' '1' '12' TEXT-A01,

'POSNR' 'IT_SQ' '2' '10' TEXT-A02,

'AFDAT' 'IT_SQ' '3' '12' TEXT-B03,

'TETXT' 'IT_SQ' '4' '10' TEXT-B04,

'MLBEZ' 'IT_SQ' '5' '10' TEXT-B05,

'FPROZ' 'IT_SQ' '6' '12' TEXT-B06,

'FAKWR' 'IT_SQ' '7' '22' TEXT-B07,

'WAERS' 'IT_SQ' '8' '10' TEXT-B08,

'FAKSP' 'IT_SQ' '9' '10' TEXT-B09,

'FAREG' 'IT_SQ' '10' '10' TEXT-B10,

'FKSAF' 'IT_SQ' '11' '10' TEXT-B11,

'ZTERM' 'IT_SQ' '12' '10' TEXT-B12,

'FPTTP' 'IT_SQ' '13' '10' TEXT-B13,

'FKARV' 'IT_SQ' '14' '10' TEXT-B14,

'KURRF' 'IT_SQ' '15' '20' TEXT-B15 ,

'MLSTN' 'IT_SQ' '16' '20' TEXT-B16,

'FPFIX' 'IT_SQ' '17' '10' TEXT-B17.

* Call function to show result

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT = IT_FIELDCAT

I_SAVE = 'A'

TABLES

T_OUTTAB = IT_BQ.

ENDFORM. " OUTPUT_BQ

你可能感兴趣的:(order)