Skip to Content
0
Former Member
Dec 19, 2012 at 05:45 AM

Display negative values for schedule line types

60 Views

Hi Experts,

I have created a report using 3 tables VBAK,VBAP,VBEP which is giving correct diplay uptill now.

Now the user requirement is to show WMENG as negative where ETENR is 1. How to achieve this as I have tried but am kind of stuck here. Appending is the code for your reference.

Please guide me in the right direction.

Thanx in advance

DATA : WA_VBAK TYPE VBAK,
WA_VBAP TYPE VBAP,
WA_VBEP TYPE VBEP,
IT_VBAK TYPE STANDARD TABLE OF VBAK,
IT_VBAP TYPE STANDARD TABLE OF VBAP,
IT_VBEP TYPE STANDARD TABLE OF VBEP,
WA_FCAT TYPE SLIS_FIELDCAT_ALV,
IT_FCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV,
AMOUNT TYPE I,
L_COUNT TYPE CHAR2.

DATA: BEGIN OF WA_FINAL,
* amount TYPE amount,
VBELN TYPE VBELN,
ERDAT TYPE ERDAT,
ERNAM TYPE ERNAM,
POSNR TYPE POSNR,
MATNR TYPE MATNR,
MATKL TYPE MATKL,
ETENR TYPE ETENR,
ETTYP TYPE ETTYP,
WMENG TYPE WMENG,
END OF WA_FINAL.

DATA: IT_FINAL LIKE TABLE OF WA_FINAL.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS :
* MATERIAL FOR VBAP-MATNR,
DOC_NUM FOR VBEP-VBELN.
* NAME FOR VBAK-ERNAM.


SELECTION-SCREEN END OF BLOCK B1.

START-OF-SELECTION.

PERFORM GET_DATA.

PERFORM DISPLAY_ALV.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*



FORM GET_DATA .

BREAK-POINT.

SELECT * FROM VBAK INTO TABLE IT_VBAK WHERE VBELN IN DOC_NUM.

SELECT * FROM VBAP INTO TABLE IT_VBAP WHERE VBELN IN DOC_NUM.

SELECT * FROM VBEP INTO TABLE IT_VBEP FOR ALL ENTRIES IN IT_VBAK WHERE VBELN = IT_VBAK-VBELN.

SELECT * FROM VBEP INTO TABLE IT_VBEP FOR ALL ENTRIES IN IT_VBAP WHERE VBELN = IT_VBAP-VBELN.

SORT IT_VBEP BY VBELN DESCENDING.

amount = wa_vbep-wmeng.

LOOP AT IT_VBEP INTO WA_VBEP.
WA_FINAL-VBELN = WA_VBEP-VBELN.
WA_FINAL-ETENR = WA_VBEP-ETENR.
WA_FINAL-ETTYP = WA_VBEP-ETTYP.
WA_FINAL-WMENG = WA_VBEP-WMENG.
* WA_FINAL-AMOUNT = WA_VBEP-amount.


CLEAR: WA_VBAK, WA_VBAP.
* CLEAR WA_VBAP.

READ TABLE IT_VBAK INTO WA_VBAK WITH KEY VBELN = WA_VBEP-VBELN BINARY SEARCH.
READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN = WA_VBEP-VBELN BINARY SEARCH.

IF SY-SUBRC = 0. "RC=return code


WA_FINAL-ERDAT = WA_VBAK-ERDAT.
WA_FINAL-ERNAM = WA_VBAK-ERNAM.
WA_FINAL-POSNR = WA_VBAP-POSNR.
WA_FINAL-MATNR = WA_VBAP-MATNR.
WA_FINAL-MATKL = WA_VBAP-MATKL.

ENDIF.

IF WA_VBEP-ETENR = 1.

AMOUNT = WA_VBEP-WMENG * -1.

ENDIF.

APPEND WA_FINAL TO IT_FINAL.

CLEAR: WA_FINAL, WA_VBAK, WA_VBAP, WA_VBEP.
ENDLOOP.



ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_ALV .

IF IT_FINAL[] IS NOT INITIAL.
CLEAR: WA_FCAT, L_COUNT. REFRESH IT_FCAT.

WA_FCAT-FIELDNAME = 'VBELN'.
WA_FCAT-TABNAME = 'VBAK'.
WA_FCAT-SELTEXT_L = 'Document Number'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ERDAT'.
WA_FCAT-TABNAME = 'VBAK'.
WA_FCAT-SELTEXT_L = 'Creation Date'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ERNAM'.
WA_FCAT-TABNAME = 'VBAK'.
WA_FCAT-SELTEXT_L = 'Created By'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'POSNR'.
WA_FCAT-TABNAME = 'VBAP'.
WA_FCAT-SELTEXT_L = 'Document Item'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MATNR'.
WA_FCAT-TABNAME = 'VBAP'.
WA_FCAT-SELTEXT_L = 'Material Number'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'MATKL'.
WA_FCAT-TABNAME = 'VBAP'.
WA_FCAT-SELTEXT_L = 'Material Group'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ETENR'.
WA_FCAT-TABNAME = 'VBEP'.
WA_FCAT-SELTEXT_L = 'Schedule Line Number'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'Amount'.
WA_FCAT-TABNAME = 'wa_final'.
WA_FCAT-SELTEXT_L = 'Amount'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'ETTYP'.
WA_FCAT-TABNAME = 'VBEP'.
WA_FCAT-SELTEXT_L = 'Schedule Line Catagory'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = 'WMENG'.
WA_FCAT-TABNAME = 'VBEP'.
WA_FCAT-SELTEXT_L = 'Order Quantity'.
WA_FCAT-COL_POS = L_COUNT + 1.
APPEND WA_FCAT TO IT_FCAT.



CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = IT_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
* IF SY-SUBRC <> 0.
** Implement suitable error handling here
* ENDIF.
* CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
ENDIF.

ENDFORM. " DISPLAY_ALV