Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

changed PO

Former Member
0 Likes
1,275

Hi all,

In the below program have taken Purchase order 3000000535 as an example. It was intially ordered on 20.06.2006. I have changed it on 25.06.2006. When I run below test program with Date 25.06.2006 it is not picking this purchase order number. But if I run with old date when Purchase order was originally created it is taking. i don’t want to capture date on previous date.

To have Purchase order picked up not only from EKKO-AEDAT = Sys Date but also check EKPO-AEDAT = Sys Date and capture all the data.

REPORT ztest_program .

TABLES : ekko,ekpo.

*File Header Record

DATA : lv_record_identifier(3) TYPE c VALUE '100',

lv_sp_id(3) TYPE c VALUE '16',

lv_sp_name(60) TYPE c VALUE 'CLICK',

lv_creation_date(8) TYPE c,

lv_creation_time(6) TYPE c,

lv_file_format(3) TYPE c VALUE 'HELLO',

lv_file_version(3) TYPE c VALUE '1.1'.

*Organization Header Record

DATA : lv_record_identifier1(3) TYPE c VALUE '110',

lv_org_id(4) TYPE c VALUE '1744',

lv_org_name(60) TYPE c VALUE 'HAI'.

*for vrtkz field

DATA : v_vrtkz TYPE c.

DATA : v_knttp(25) TYPE c.

*for conversion to character type

DATA : v_netwr(13) TYPE c,

v_menge(13) TYPE c,

v_vproz(10) TYPE c.

*for record count

DATA : lv_record_count TYPE i.

*for tab delimiter

CONSTANTS : c_tab TYPE x VALUE '09'.

*for total value

DATA : v_total1 TYPE p DECIMALS 2,

v_total(15) TYPE c.

*output string

DATA : output_string1 TYPE string,

output_string2 TYPE string,

output_string3 TYPE string,

output_string4 TYPE string,

output_string5 TYPE string,

output_string6 TYPE string.

*for selection based on creation date and document type

SELECT-OPTIONS : so_aedat FOR ekko-aedat,

so_bsart FOR ekko-bsart.

*File Detail Record

*Purchasing Document Header

DATA : BEGIN OF lt_ekko OCCURS 0,

lv_record_identifier2(3) TYPE c,

lv_org_id1(4) TYPE c,

ebeln LIKE ekko-ebeln, " Purchasing Document Number

aedat LIKE ekko-aedat,

bsart LIKE ekko-bsart, " Purchasing document type

lifnr LIKE ekko-lifnr, " Vendor's account number

zsrm_pcnum LIKE ekko-zsrm_pcnum, " SRM: Procurement card number

bukrs LIKE ekko-bukrs, " Company Code

name1 LIKE lfa1-name1, " Name 1

END OF lt_ekko.

*Purchasing Document Item

DATA : BEGIN OF lt_ekpo OCCURS 0,

ebeln LIKE ekpo-ebeln, " Purchasing Document Number

ebelp LIKE ekpo-ebelp, " Item Number of Purchasing Document

aedat LIKE ekpo-aedat,

vrtkz LIKE ekpo-vrtkz, " Distribution indicator for multiple

" account assignment

afnam LIKE ekpo-afnam, " Name of requisitioner/requester

txz01 LIKE ekpo-txz01, " Short text

netwr LIKE ekpo-netwr, " Net order value in PO currency

menge LIKE ekpo-menge, " Purchase order quantity

knttp LIKE ekpo-knttp, " Account assignment category

mwskz TYPE ekpo-mwskz, " Tax on sales/purchases code

END OF lt_ekpo.

*Account Assignment in Purchasing Document

DATA : BEGIN OF lt_ekkn OCCURS 0,

ebeln LIKE ekkn-ebeln, " Purchasing Document Number

ebelp LIKE ekkn-ebelp, " Item Number of Purchasing Document

zekkn LIKE ekkn-zekkn, " Sequential number of account

" assignment

vproz LIKE ekkn-vproz, " Distribution percentage in the case

" of multiple acct assgt

sakto LIKE ekkn-sakto, " G/L account number

kostl LIKE ekkn-kostl, " Cost Center

ps_psp_pnr LIKE ekkn-ps_psp_pnr, " Work breakdown structure

" element (WBS element)

aufnr LIKE ekkn-aufnr, " Order Number

END OF lt_ekkn.

*Scheduling Agreement Schedule Lines

DATA : BEGIN OF lt_eket OCCURS 0,

ebeln LIKE eket-ebeln, " Purchasing Document Number

ebelp LIKE eket-ebelp, " Item Number of Purchasing Document

eindt LIKE eket-eindt, " Item delivery date

END OF lt_eket.

*DATA: lt_distinct_ekpo LIKE lt_ekpo OCCURS 0 WITH HEADER LINE.

DATA : lt_ekko_temp LIKE lt_ekko OCCURS 0 WITH HEADER LINE.

*Organization Footer Record

DATA : lv_record_identifier3(3) TYPE c VALUE '130',

lv_org_id2(4) TYPE c VALUE '1744',

lv_org_name1(60) TYPE c VALUE 'GNBC-UNIV-1',

lv_detail_record_count(5) TYPE c.

*File Footer Record

DATA : lv_record_identifier4(3) TYPE c VALUE '140',

lv_extract_record_count(5) TYPE c,

lv_file_record_count(5) TYPE c.

*for date and time format

lv_creation_date = sy-datum.

lv_creation_time = sy-uzeit.

*concatenate for File Header Record

CONCATENATE lv_record_identifier

lv_sp_id

lv_sp_name

lv_creation_date

lv_creation_time

lv_file_format

lv_file_version

INTO output_string1

SEPARATED BY c_tab.

WRITE 😕 output_string1.

*concatenate Organization Header Record

CONCATENATE lv_record_identifier1

lv_org_id

lv_org_name

INTO output_string2

SEPARATED BY c_tab.

WRITE 😕 output_string2.

*selection of fields

SELECT a~ebeln

a~bedat

a~bsart

a~zsrm_pcnum

a~lifnr

a~bukrs

b~name1

INTO CORRESPONDING FIELDS OF TABLE lt_ekko

FROM ekko AS a INNER JOIN lfa1 AS b

ON alifnr = blifnr

WHERE ( aaedat IN so_aedat OR aaedat = sy-datum )

AND a~bsart IN so_bsart

AND ( absart = 'ECDP' OR absart = 'ECPO' )

AND a~zsrm_pcnum IS not NULL.

IF NOT lt_ekko[] IS INITIAL.

SELECT ebeln

ebelp

aedat

vrtkz

afnam

txz01

netwr

menge

knttp

mwskz

FROM ekpo

INTO TABLE lt_ekpo

FOR ALL ENTRIES IN lt_ekko

WHERE ebeln = lt_ekko-ebeln

AND ( aedat IN so_aedat OR aedat = sy-datum ).

ENDIF.

IF NOT lt_ekpo[] IS INITIAL.

SELECT ebeln

ebelp

zekkn

vproz

sakto

kostl

ps_psp_pnr

aufnr

FROM ekkn

INTO TABLE lt_ekkn

FOR ALL ENTRIES IN lt_ekpo

WHERE ebeln = lt_ekpo-ebeln

AND ebelp = lt_ekpo-ebelp.

SELECT ebeln

ebelp

eindt

FROM eket

INTO TABLE lt_eket

FOR ALL ENTRIES IN lt_ekpo

WHERE ebeln = lt_ekpo-ebeln

AND ebelp = lt_ekpo-ebelp.

ENDIF.

*LOOP AT lt_ekko.

  • READ TABLE lt_ekpo WITH KEY ebeln = lt_ekko-ebeln.

  • IF sy-subrc = 0.

  • MOVE lt_ekko TO lt_ekko_temp.

  • APPEND lt_ekko_temp.

  • ENDIF.

*ENDLOOP.

*

*FREE lt_ekko.

*MOVE lt_ekko_temp[] TO lt_ekko[].

*FREE lt_ekko_temp.

*for specifying the record length

*describe table lt_ekko LINES record_count.

lv_record_count = sy-dbcnt.

lv_detail_record_count = lv_record_count.

lv_extract_record_count = lv_record_count - 2.

lv_file_record_count = lv_record_count + 4.

*concatenate for File Detail Record

LOOP AT lt_ekko.

CLEAR v_total1.

LOOP AT lt_ekpo WHERE ebeln = lt_ekko-ebeln.

v_total1 = v_total1 + lt_ekpo-netwr.

MOVE v_total1 TO v_total.

SHIFT v_total LEFT DELETING LEADING space.

ENDLOOP.

LOOP AT lt_ekpo WHERE ebeln = lt_ekko-ebeln.

READ TABLE lt_ekkn WITH KEY ebeln = lt_ekpo-ebeln

ebelp = lt_ekpo-ebelp BINARY SEARCH.

READ TABLE lt_eket WITH KEY ebeln = lt_ekpo-ebeln

ebelp = lt_ekpo-ebelp BINARY SEARCH.

*clearing zeros for integer values

CLEAR : v_netwr,v_menge,v_vproz.

v_netwr = lt_ekpo-netwr.

SHIFT v_netwr LEFT DELETING LEADING space.

v_menge = lt_ekpo-menge.

SHIFT v_menge LEFT DELETING LEADING space.

  • for vrtkz field

IF lt_ekpo-vrtkz EQ '1' OR lt_ekpo-vrtkz EQ '2'.

MOVE 'M' TO v_vrtkz.

ELSE.

MOVE 'S' TO v_vrtkz.

ENDIF.

  • for vproz field

IF lt_ekkn-vproz EQ '0.0'.

MOVE '100.0' TO v_vproz.

ELSE.

MOVE lt_ekkn-vproz TO v_vproz.

ENDIF.

SHIFT v_vproz LEFT DELETING LEADING space.

*for knttp value

CASE lt_ekpo-knttp.

WHEN 'K'.

MOVE lt_ekkn-kostl TO v_knttp.

WHEN 'P'.

MOVE lt_ekkn-ps_psp_pnr TO v_knttp.

WHEN 'O'.

MOVE lt_ekkn-aufnr TO v_knttp.

WHEN OTHERS.

MOVE lt_ekpo-knttp TO v_knttp.

ENDCASE.

SHIFT v_knttp LEFT DELETING LEADING space.

CLEAR output_string3.

*output string

lt_ekko-lv_record_identifier2 = '120'.

lt_ekko-lv_org_id1 = '1744'.

CONCATENATE lt_ekko-lv_record_identifier2

lt_ekko-lv_org_id1

v_vrtkz

lt_ekko-ebeln

lt_ekko-lifnr

lt_ekko-name1

v_total

lt_ekko-aedat

lt_ekko-zsrm_pcnum

lt_ekpo-afnam

lt_ekpo-txz01

v_netwr

v_vproz

v_menge

lt_eket-eindt

lt_ekko-bukrs

v_knttp

lt_ekkn-sakto

lt_ekpo-mwskz

INTO output_string3

SEPARATED BY c_tab.

IF v_vrtkz = 'M'.

LOOP AT lt_ekkn WHERE ebeln = lt_ekpo-ebeln

AND ebelp = lt_ekpo-ebelp.

MOVE: lt_ekkn-vproz TO v_vproz.

CASE lt_ekpo-knttp.

WHEN 'K'.

MOVE lt_ekkn-kostl TO v_knttp.

WHEN 'P'.

MOVE lt_ekkn-ps_psp_pnr TO v_knttp.

WHEN 'O'.

MOVE lt_ekkn-aufnr TO v_knttp.

WHEN OTHERS.

MOVE lt_ekpo-knttp TO v_knttp.

ENDCASE.

SHIFT v_vproz LEFT DELETING LEADING space.

CONCATENATE lt_ekko-lv_record_identifier2

lt_ekko-lv_org_id1

v_vrtkz

lt_ekko-ebeln

lt_ekko-lifnr

lt_ekko-name1

v_total

lt_ekko-aedat

lt_ekko-zsrm_pcnum

lt_ekpo-afnam

lt_ekpo-txz01

v_netwr

v_vproz

v_menge

lt_eket-eindt

lt_ekko-bukrs

v_knttp

lt_ekkn-sakto

lt_ekpo-mwskz

INTO output_string6

SEPARATED BY c_tab.

WRITE 😕 output_string6.

ENDLOOP.

ELSE.

WRITE 😕 output_string3.

ENDIF.

ENDLOOP.

ENDLOOP.

*concatenate for Organization Footer Record

CONCATENATE lv_record_identifier3

lv_org_id2

lv_org_name1

lv_detail_record_count

INTO output_string4

SEPARATED BY c_tab.

WRITE 😕 output_string4.

*concatenate for File Footer Record

CONCATENATE lv_record_identifier4

lv_extract_record_count

lv_file_record_count

INTO output_string5

SEPARATED BY c_tab.

WRITE 😕 output_string5.

Message was edited by: vj bb

Message was edited by: vj bb

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,060

You understand that AEDAT will never change, right? This is the creation date of the PO. Once, you create the PO, this field will never change, no matter how many times you change the PO.

Are you saying that you want to pick up the PO when the PO was changed on Sy-DATUM?

Regards,

Rich Heilman

Read only

0 Likes
1,060

Yes Rich..Exactly..

when the PO was changed on Sy-DATUM

Changes are come usually at Line item level.

Purchase order changes are occur at line item level.

There is date field in EKPO table called Changed on. Program should also check all EKPO Change Field which is system date or the date which we pass on selection parameters. Presently Program is looking EKKO creation date.

Make program also check EKPO Change date = Sys date or Selection parameter date, Pick that Purchase order number from EKPO-EBELN and then follow the process which we do it for new PO, Get EKKO data, EKPO and EKKN data.

Message was edited by: vj bb

Read only

0 Likes
1,060

I think you will need to check against tables CDHDR and CDPOS. THese are the Change Document tables. When a purchase order is changed, records get written here.

Regards,

Rich Heilman

Read only

0 Likes
1,060

If the AEDAT is updated when you change a PO line and when it is created, I suppose you can check against it. You can change your first select like this. This will join EKPO and check against the AEDAT in the EKPO table. This will duplicate records, since your are joining, so after, you need to sort and get rid of duplicate records.




SELECT a~ebeln
a~bedat
a~bsart
a~zsrm_pcnum
a~lifnr
a~bukrs
b~name1
INTO CORRESPONDING FIELDS OF TABLE lt_ekko
FROM ekko AS a 
   INNER JOIN lfa1 AS b
      ON a~lifnr = b~lifnr
<b>   inner join ekpo as c
      on a~ebeln = c~ebeln</b>
WHERE ( a~aedat IN so_aedat OR a~aedat = sy-datum )
AND a~bsart IN so_bsart
AND ( a~bsart = 'ECDP' OR a~bsart = 'ECPO' )
AND a~zsrm_pcnum IS not NULL
<b>and ( c~aedat IN so_aedat OR c~aedat = sy-datum ).
  sort lt_ekko ASCENDING by ebeln.
  delete ADJACENT DUPLICATES FROM lt_ekko COMPARING ebeln.</b>

Regards,

Rich Heilman

Read only

0 Likes
1,060

I think u didn't understand...

when I have taken Purchase order 3000000535 as an example. It was intially ordered on 20.06.2006. I have changed it on 25.06.2006. When I run this test program with Date 25.06.2006 it is not picking this purchase order number. But if I run with old date when Purchase order was originally created it is taking. We don’t want to capture date on previous date.

R u clear...

Read only

0 Likes
1,060

So you don't wan to pick it up for 20.06.2006?

REgards,

Rich Heilman

Read only

0 Likes
1,060

yes..i don't want to pick it up on 20.06.2006 but only on 25.06.2006

Message was edited by: vj bb