Skip to Content

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

doubt in extraction zrfc

hi,

I want to give some aedat range in mjy input parameters

or useful conditions i want to pass but that should be optional.

anyway i am going to pass pur org (EKORG) as a input parameters..

other that plz guide me to do some thing

............

*"----


""Local interface:

*" IMPORTING

*" VALUE(I_EKORG) TYPE EKKO-EKORG OPTIONAL

*" VALUE(I_LIFNR) TYPE LFA1-LIFNR OPTIONAL

*" TABLES

*" LT_EKKO STRUCTURE ZPO_DATA_47 OPTIONAL

*" LT_EKPO STRUCTURE ZPO_ITEM_47 OPTIONAL

*" LT_EKET STRUCTURE ZPO_EKET_47 OPTIONAL

*" LT_ADRC STRUCTURE ZPO_ADRC_47 OPTIONAL

*" LT_EKKN STRUCTURE ZPO_EKKN_47 OPTIONAL

*" LT_EKBE STRUCTURE ZPO_EKBE_47 OPTIONAL

*" EXCEPTIONS

*" INVALID_PO

*" NOT_ORACLE_PO

*"----


  • Types declaration for PO history

TYPES : BEGIN OF ty_s_ekbe,

ebeln TYPE ekko-ebeln,

ebelp TYPE ekpo-ebelp,

menge TYPE ekpo-menge,

vgabe TYPE vgabe,

qty TYPE ekpo-menge,

END OF ty_s_ekbe.

data : it_ekbe type standard table of ty_s_ekbe.

  • Types declaration of Address data

TYPES: BEGIN OF ty_s_adrc,

adrnr TYPE ekko-adrnr,

END OF ty_s_adrc.

  • Tables

DATA: lt_tline_read TYPE STANDARD TABLE OF tline,

gt_adrc TYPE STANDARD TABLE OF ty_s_adrc,

gt_ekbe TYPE STANDARD TABLE OF ty_s_ekbe.

  • Local structures

DATA: ls_ekko TYPE zpo_data_47,

ls_ekpo TYPE zpo_item_47,

ls_adrc TYPE zpo_adrc_47,

ls_ekkn TYPE zpo_ekkn_47,

ls_tline TYPE tline,

ls_ekbe TYPE ty_s_ekbe.

  • Local variables

DATA: lv_adrnr TYPE adrnr,

lv_id TYPE thead-tdname,

lv_str TYPE stxh.

Data l_rec type I value 10000.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = i_lifnr

IMPORTING

OUTPUT = i_lifnr

.

*if not i_ekorg is INITIAL and not i_lifnr is INITIAL.

  • Select Purchasing Document Header data

  • ELSE.

SELECT ebeln

bukrs

bsart

lifnr

zterm

ekorg

ekgrp

waers

bedat

wkurs

inco1

inco2

  • ltex1

adrnr

FROM ekko

INTO TABLE lt_ekko package size l_rec

where ekorg = i_ekorg and lifnr eq i_lifnr and

bsart in ('OR1', 'OR2').

*and ekorg = i_ekorg

  • and lifnr eq i_lifnr.

*

    • up to 5 rows

  • WHERE

    • bsart = 'OR2'.

*

  • bsart in ('OR1', 'OR2').

  • ENDIF.

  • Check if the given Purchase order number is valid or not

IF lt_ekko[] IS INITIAL.

  • raise and error message if the purchase order number is invalid

RAISE invalid_po.

ELSE.

  • Select Scheduling Agreement Schedule Lines data

SELECT ebeln

ebelp

eindt

slfdt

FROM eket

INTO TABLE lt_eket

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln.

  • Select item data for the purchase order

SELECT ebeln

ebelp

txz01

matnr

werks

lgort

matkl

idnlf

menge

meins

bprme

bpumz

bpumn

umrez

umren

netpr

peinh

mahnz

mahn1

mahn2

mahn3

uebtk

elikz

erekz

knttp

wepos

weunb

repos

webre

kzabs

labnr

plifz

mhdrz

FROM ekpo

INTO TABLE lt_ekpo

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln.

  • Fetch the address number for the vendor

SELECT adrnr FROM ekko

INTO TABLE gt_adrc

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln.

  • get the address details of the vendor using the address number

SELECT addrnumber

name1

city1

city2

post_code1

street

country

region

FROM adrc

INTO TABLE lt_adrc

FOR ALL ENTRIES IN gt_adrc

WHERE addrnumber = gt_adrc-adrnr.

  • Get Account Assignment in Purchasing Document data

SELECT ebeln

ebelp

sakto

gsber

kostl

wempf

ablad

prctr

mwskz

FROM ekkn

INTO TABLE lt_ekkn

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln.

  • Get the quantity and transaction type values from PO history details

  • table

SELECT ebeln

ebelp

vgabe

menge

  • sum(menge)

FROM ekbe

INTO corresponding fields of TABLE gt_ekbe

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln.

  • Populate the headar and item texts

  • Header text

LOOP AT lt_ekko INTO ls_ekko.

CLEAR lv_id.

lv_id = ls_ekko-ebeln.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = 'F01'

language = sy-langu

name = lv_id

object = 'EKKO'

TABLES

lines = lt_tline_read

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.

READ TABLE lt_tline_read INTO ls_tline INDEX 1.

ls_ekko-ltex1 = ls_tline-tdline.

CLEAR : ls_tline,

lv_id.

MODIFY lt_ekko FROM ls_ekko.

REFRESH lt_tline_read.

ENDIF.

  • item text

CLEAR lv_id.

lv_id = ls_ekko-ebeln.

CALL FUNCTION 'READ_TEXT'

EXPORTING

client = sy-mandt

id = 'F01'

language = sy-langu

name = lv_id

object = 'EKPO'

TABLES

lines = lt_tline_read

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.

READ TABLE lt_tline_read INTO ls_tline INDEX 1.

ls_adrc-ltex1 = ls_tline-tdline.

CLEAR : ls_tline,

lv_id.

MODIFY lt_adrc FROM ls_adrc.

REFRESH lt_tline_read.

ENDIF.

ENDLOOP.

    • check the condition whether to send the data or not.

LOOP AT gt_ekbe INTO ls_ekbe.

ls_ekbe-qty = ls_ekbe-qty + ls_ekbe-menge.

READ TABLE lt_ekpo INTO ls_ekpo WITH KEY ebeln = ls_ekbe-ebeln

ebelp = ls_ekbe-ebelp.

IF sy-subrc = 0.

  • 3-way match for GRs and IRs on PO:

  • Scenario 1: No GR or IR

IF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-wepos IS INITIAL AND

ls_ekpo-repos IS INITIAL.

ls_ekpo-menge = ls_ekpo-menge.

*Scenario 2: Number of GRs and IRs match GRs=IRs

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-wepos EQ ls_ekpo-repos .

ls_ekpo-menge = ls_ekpo-menge.

ls_ekpo-wepos = ls_ekpo-wepos.

  • Scenario 3: No IRs

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-wepos IS NOT INITIAL AND

ls_ekpo-repos IS INITIAL.

ls_ekpo-menge = ls_ekpo-menge.

ls_ekpo-wepos = ls_ekpo-wepos.

  • Scenario 4: More GRs than IRs GRs >IRs

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-wepos GT ls_ekpo-repos .

ls_ekpo-menge = ls_ekpo-menge.

ls_ekpo-wepos = ls_ekpo-wepos.

ls_ekpo-repos = ls_ekpo-repos .

  • Scenario 5: No of POs,GRs and IRs match POs=GRs=IRs

ELSEIF ls_ekpo-menge EQ ls_ekpo-wepos AND

ls_ekpo-menge EQ ls_ekpo-repos.

ls_ekpo-menge = 0.

ls_ekpo-wepos = 0.

  • Scenario 6: No of IRs greater than GRs IRs>GRs

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-repos GT ls_ekpo-wepos .

ls_ekpo-menge = ls_ekpo-menge.

  • Material PO line with a 2 way-match

  • Scenario 1: No IR

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-repos IS INITIAL.

ls_ekpo-menge = ls_ekpo-menge.

  • Scenario 2: Has IR

ELSEIF ls_ekpo-menge IS NOT INITIAL AND

ls_ekpo-repos IS NOT INITIAL.

ls_ekpo-menge = ls_ekpo-menge.

ENDIF.

  • Condition to filter the PO's

IF ( ls_ekbe-vgabe = '1' AND ls_ekpo-menge NE ls_ekbe-qty ) OR

( ls_ekbe-vgabe = '2' AND ls_ekpo-menge NE ls_ekbe-qty ).

APPEND ls_ekbe TO it_ekbe.

MODIFY lt_ekpo FROM ls_ekpo TRANSPORTING menge wepos repos

WHERE ebeln = ls_ekpo-ebeln

AND ebelp = ls_ekpo-ebelp.

CLEAR : ls_ekpo,

ls_ekbe.

ELSE.

DELETE lt_ekko WHERE ebeln = ls_ekbe-ebeln.

DELETE lt_ekpo WHERE ebeln = ls_ekbe-ebeln.

DELETE lt_ekkn WHERE ebeln = ls_ekbe-ebeln.

CLEAR ls_ekbe.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDSELECT.

ENDFUNCTION.

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