Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

PO History Data

Hi Folks,

I have a problem in selecting the PO hitstory data.For a PO there are two bewtp for 0010 and 0020 item.But I am getting only one BEWTP not both.

Moreover at the time of filtering the internal table w.r.t to BEWTP it is not checking for itfinal-bewtp NE 'E'.

Kindly let me know where I am going wrong.

REPORT ZMM .

*Tables.

TABLES : ekbe,

rbkp,

rseg,

bkpf,

bset,

lfa1,

makt.

*Declaration for ALV.

TYPE-POOLS: slis.

DATA : ITFIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.

DATA : ITREPID TYPE SY-REPID.

ITREPID = SY-REPID.

DATA : ITEVENT TYPE SLIS_T_EVENT.

DATA : ITLISTHEADER TYPE SLIS_T_LISTHEADER.

DATA : WALISTHEADER LIKE LINE OF ITLISTHEADER.

DATA : ITLAYOUT TYPE SLIS_LAYOUT_ALV.

DATA : TOP TYPE SLIS_FORMNAME.

DATA : ITSORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.

DATA : ITSORT1 TYPE SLIS_SORTINFO_ALV.

DATA : ITPRINTPARAMS TYPE SLIS_PRINT_ALV.

DATA : ITVARIANT TYPE DISVARIANT.

DATA : DATE1(15) TYPE C,

DATE2(15) TYPE C,

STRING1(65) TYPE C,

TITLE(65) TYPE C,

LFBNR LIKE RSEG-LFBNR,

BEWTP LIKE EKBE-BEWTP.

*Internal table Declarations.

TYPES: BEGIN OF ty_itfinal,

SL_NO TYPE sy-tabix, " FOR SERIAL No.

BELNR TYPE rbkp-belnr, " Material Doc. No.

BUDAT TYPE rbkp-budat, " Posting Date in the Document

LIFNR TYPE rbkp-lifnr, " Vendor Code

XBLNR TYPE rbkp-xblnr, " Supplier Document Number

BLDAT TYPE rbkp-bldat, " Document Date

KURSF TYPE rbkp-kursf, "

BUZEI TYPE rseg-buzei, " miro line item

EBELN TYPE rseg-ebeln, " po no

EBELP TYPE rseg-ebelp, " PO line item

MATNR TYPE rseg-matnr, " part no

BWTAR TYPE rseg-bwtar, " valuation type

MENGE TYPE rseg-menge, " quantity

WRBTR TYPE rseg-wrbtr, " value of goods

SHKZG TYPE rseg-SHKZG, " DEBIT/CREDIT

LFBNR TYPE rseg-lfbnr, "

WRBTR_R TYPE rseg-wrbtr, " Rate

WRBTR_V TYPE rseg-wrbtr, " Value of Goods

BEWTP TYPE ekbe-bewtp, " PO history category

BUDAT1 TYPE ekbe-budat, "

HWSTE_C TYPE bset-hwste, " ED/CVD(Tax Amount in Local Currency)

HWSTE_E TYPE bset-hwste, " E.Cess(Tax Amount in Local Currency)

HWSTE_S TYPE bset-hwste, " Snhe.Cess(Tax Amount in Local Currency)

ACCNO TYPE bkpf-belnr, "

BELNR1 TYPE BKPF-BELNR,

AWKEY TYPE BKPF-AWKEY,

NAME1 TYPE lfa1-name1, " vendor name

MAKTX TYPE makt-maktx, " Material Description

END OF TY_ITFINAL.

DATA: ITFINAL TYPE TY_ITFINAL OCCURS 0 WITH HEADER LINE.

TYPES : BEGIN OF TY_ITAB1,

BELNR LIKE rbkp-belnr, " Material Doc. No.

BUDAT LIKE rbkp-budat, " Posting Date in the Document

LIFNR LIKE rbkp-lifnr, " Vendor Code

XBLNR LIKE rbkp-xblnr, " Supplier Document Number

BLDAT LIKE rbkp-bldat, " Document Date

KURSF LIKE rbkp-kursf, " Ex.Rate

END OF TY_ITAB1.

DATA :ITAB1 TYPE TY_ITAB1 OCCURS 0 WITH HEADER LINE.

TYPES: BEGIN OF TY_ITAB3,

BELNR1 TYPE BKPF-BELNR,

AWKEY TYPE BKPF-AWKEY,

ACCNO TYPE BKPF-BELNR,

HWSTE_X TYPE BSET-HWSTE,

HWSTE_Y TYPE BSET-HWSTE,

HWSTE_Z TYPE BSET-HWSTE,

END OF TY_ITAB3.

DATA:ITAB3 TYPE TY_ITAB3 OCCURS 0 WITH HEADER LINE.

TYPES: BEGIN OF TY_ITAB4,

BELNR1 TYPE BKPF-BELNR,

AWKEY TYPE BKPF-AWKEY,

HWSTE_X TYPE BSET-HWSTE,

HWSTE_Y TYPE BSET-HWSTE,

HWSTE_Z TYPE BSET-HWSTE,

hwste_F TYPE BSET-HWSTE,

END OF TY_ITAB4.

DATA:ITAB4 TYPE TY_ITAB4 OCCURS 0 WITH HEADER LINE.

*Selection Screen

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.

PARAMETERS: P_BUKRS LIKE RBKP-BUKRS OBLIGATORY.

PARAMETERS: P_WERKS LIKE RSEG-WERKS OBLIGATORY.

SELECT-OPTIONS: S_BUDAT FOR RBKP-BUDAT OBLIGATORY.

PARAMETERS : P_GJAHR LIKE RSEG-GJAHR OBLIGATORY.

SELECTION-SCREEN END OF BLOCK block1.

CONCATENATE S_BUDAT-LOW6(2) '.' S_BUDAT-LOW4(2) '.' S_BUDAT-LOW+0(4) INTO DATE1.

CONCATENATE S_BUDAT-HIGH6(2) '.' S_BUDAT-HIGH4(2) '.' S_BUDAT-HIGH+0(4) INTO DATE2.

PERFORM GETDATA.

PERFORM ALV.

&----


*& Form GETDATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM GETDATA.

*Invoice Header

SELECT BELNR

BUDAT

LIFNR

XBLNR

BLDAT

KURSF

FROM RBKP

INTO TABLE ITAB1

WHERE GJAHR = P_GJAHR.

IF SY-SUBRC NE 0.

MESSAGE 'No Data.' TYPE 'S'.

ELSE.

*Filtering the internal table w.r.t to BUDAT.

LOOP AT ITAB1.

IF ITAB1-BUDAT NOT IN S_BUDAT.

DELETE itab1.

ENDIF.

ENDLOOP.

ENDIF.

*Invoice Item.

LOOP AT ITAB1.

MOVE-CORRESPONDING ITAB1 TO ITFINAL.

SELECT BUZEI

EBELN

EBELP

MATNR

BWTAR

MENGE

WRBTR

SHKZG

LFBNR

FROM RSEG INTO CORRESPONDING FIELDS OF ITFINAL

WHERE BELNR = ITAB1-BELNR AND

GJAHR = P_GJAHR.

ENDSELECT.

*Vendor Details.

SELECT name1

FROM lfa1 INTO itfinal-name1

WHERE lifnr = itfinal-lifnr.

ENDSELECT.

*Material Description.

SELECT maktx

FROM makt INTO itfinal-maktx

WHERE matnr = itfinal-matnr.

ENDSELECT.

APPEND ITFINAL.

clear itfinal.

ENDLOOP.

<b>LOOP AT ITFINAL.

SELECT BEWTP

FROM EKBE

INTO BEWTP "CORRESPONDING FIELDS OF ITFINAL

WHERE EBELN = ITFINAL-EBELN AND

EBELP = ITFINAL-EBELP.

MOVE BEWTP TO ITFINAL-BEWTP.</b>

ENDSELECT.

MODIFY ITFINAL.

ENDLOOP.

LOOP AT ITFINAL.

IF ITFINAL-LFBNR IS INITIAL.

SELECT SINGLE BELNR

FROM EKBE INTO (LFBNR)

WHERE EBELN = ITFINAL-EBELN AND

EBELP = ITFINAL-EBELP.

MOVE LFBNR TO ITFINAL-LFBNR.

MODIFY ITFINAL.

ENDIF.

ENDLOOP.

<b>LOOP AT ITFINAL.

IF ITFINAL-SHKZG NE 'S' AND

ITFINAL-BEWTP NE 'E'.

DELETE ITFINAL.

ENDIF.

ENDLOOP.</b>

*Tax Amount.

*Accounting Doc.No.

SELECT BELNR

AWKEY

FROM bkpf INTO TABLE ITAB3

WHERE blart = 'RE' AND

GJAHR = P_GJAHR AND

BUKRS = P_BUKRS AND

BUDAT IN S_BUDAT.

*Excise Duty and Ed.Cess.

clear itab3.

LOOP AT ITAB3.

move-corresponding itab3 to itab4.

SELECT single HWSTE

FROM BSET INTO (ITAB4-hwste_x)

WHERE BELNR = ITab3-BELNR1 AND

GJAHR = P_GJAHR AND

BUKRS = P_BUKRS and

KSCHL = 'JMO1'.

IF ITAB4-HWSTE_X IS INITIAL.

SELECT single HWSTE

FROM BSET INTO (ITab4-HWSTE_X)

WHERE BELNR = ITab3-BELNR1 AND

BUKRS = P_BUKRS AND

GJAHR = P_GJAHR AND

KSCHL = 'JMO2'.

ENDIF.

SELECT SINGLE HWSTE

FROM BSET INTO (ITAB4-HWSTE_Y)

WHERE BELNR = ITAB3-BELNR1 AND

GJAHR = P_GJAHR AND

BUKRS = P_BUKRS AND

KSCHL = 'JEC1'.

IF ITAB4-HWSTE_Y IS INITIAL.

SELECT SINGLE HWSTE

FROM BSET INTO (ITAB4-HWSTE_Y)

WHERE BELNR = ITAB3-BELNR1 AND

GJAHR = P_GJAHR AND

BUKRS = P_BUKRS AND

KSCHL = 'JEC2'.

ENDIF.

ITAB4-HWSTE_Z = ( ITAB4-HWSTE_Y / 3 ) * 2.

ITAB4-HWSTE_F = ITAB4-HWSTE_Y - ITAB4-HWSTE_Z.

APPEND ITAB4.

endloop.

LOOP AT ITAB4.

ITAB4-AWKEY = ITAB4-AWKEY+0(10).

MODIFY ITAB4.

ENDLOOP.

loop at itfinal.

read table itab4 with key awkey = itfinal-belnr.

move itab4-hwste_x to itfinal-hwste_c.

move itab4-hwste_z to itfinal-hwste_e.

move itab4-hwste_f to itfinal-hwste_s.

modify itfinal.

endloop.

*Filtering the Internal Table w.r.t P.O History Category.

LOOP AT itfinal.

  • IF itfinal-bewtp EQ 'E'.

  • DELETE itfinal.

  • ENDIF.

itfinal-wrbtr_v = itfinal-wrbtr * itfinal-kursf.

itfinal-wrbtr_r = itfinal-wrbtr_v / itfinal-menge.

MODIFY itfinal.

ENDLOOP.

ENDFORM. " GETDATA

&----


*& Form ALV

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM alv .

IF itfinal[] IS INITIAL.

MESSAGE 'No Values exist for the Selection.' TYPE 'S'.

STOP.

ENDIF.

LOOP AT itfinal.

itfinal-sl_no = sy-tabix.

MODIFY itfinal.

ENDLOOP.

DEFINE j_fieldcat.

itfieldcat-fieldname = &1.

itfieldcat-col_pos = &2.

itfieldcat-seltext_l = &3.

itfieldcat-do_sum = &4.

itfieldcat-outputlen = &5.

itfieldcat-edit = &6.

append itfieldcat to itfieldcat.

clear itfieldcat.

END-OF-DEFINITION.

j_fieldcat 'SL_NO' '' 'SL. NO' '' 03 ''.

j_fieldcat 'LFBNR' '' 'MATERIAL DOC.No.' '' 10 ''.

j_fieldcat 'BUDAT' '' 'POSTING DATE.' '' 08 ''.

j_fieldcat 'LIFNR' '' 'VENDOR' '' 10 ''.

j_fieldcat 'NAME1' '' 'VENDOR NAME.' '' 35 ''.

j_fieldcat 'XBLNR' '' 'SUPPLIER DOC.No.' ' ' 10 '' .

j_fieldcat 'BLDAT' '' 'ACCOUNTING DOC.DATE' '' 08 ''.

j_fieldcat 'MATNR' '' 'PART No.' '' 18 ''.

j_fieldcat 'MAKTX' '' 'DESCRIPTION' '' 40 '' .

j_fieldcat 'MENGE' '' 'QUANTITY RECEIVED' '' 08 ''.

j_fieldcat 'KURSF' '' 'ECHANGE RATE' '' 13 ''.

j_fieldcat 'WRBTR_R' '' 'RATE' '' 13 ''.

j_fieldcat 'WRBTR_V' '' 'VALUE OF GOODS' '' 13 ''.

j_fieldcat 'HWSTE_C' '' 'ED/CVD' '' 13 ''.

j_fieldcat 'HWSTE_E' '' 'EDU.CESS' '' 13 ''.

j_fieldcat 'HWSTE_S' '' 'S&HE.CESS' '' 13 ''.

j_fieldcat 'BWTAR' '' 'VALUTAION TYPE' '' 10 ''.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = sy-repid

is_layout = itlayout

i_callback_user_command = ' '

i_callback_top_of_page = 'TOP'

it_fieldcat = itfieldcat[]

i_save = 'A'

  • is_variant = ITVARIANT

it_events = itevent[]

  • is_print = ITPRINTPARAMS

it_sort = itsort[]

TABLES

t_outtab = itfinal

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. " ALV

&----


*& Form TOP

&----


  • Top of page for ALV Report

----


FORM top.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = itevent

  • EXCEPTIONS

  • LIST_TYPE_WRONG = 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.

string1 = 'Excise Input Details - IDC/PDC'.

CONCATENATE string1 p_werks date1 'to' date2 INTO title SEPARATED BY space.

walistheader-typ = 'H'.

walistheader-info = title.

APPEND walistheader TO itlistheader.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = itlistheader

  • I_LOGO = ''.

  • I_END_OF_LIST_GRID =

.

  • ENDIF.

CLEAR itlistheader.

  • ENDIF.

ENDFORM. "TOP

K.Kiran.

Tags:
Not what you were looking for? View more on this topic or Ask a question