‎2013 Dec 26 6:20 AM
Hi,
I am extracting data for BW, I have one structure that has fields lets say
EBELN
EBELP
NETWR
NETPR
ELIKZ
PO STATUS
I have condition which will check if EKPO~ELIKZ is true for all PO ITEM of PO then it has to put 1 in PO Status field (Custom field). I am trying below logic but thinks doesn't seems working.
DATA ITAB_PO TYPE TABLE OF ZPO_DETAILS.
DATA WA_PO TYPE ZPO_DETAILS.
TYPES: BEGIN OF T_OPENPO,
PONUM TYPE EKPO-EBELN,
POINUM TYPE EKPO-EBELP,
OPENPO TYPE EKPO-ELIKZ,
END OF T_OPENPO.
DATA TAB_OPENPO TYPE TABLE OF T_OPENPO.
DATA WA_OPENPO TYPE T_OPENPO.
SELECT EKPO~EBELN EKPO~EBLEP EKPO~NETWR EKPO~NETPR EKPO~ELIKZ FROM EKPO
INTO TABLE ITAB_POO
WHERE -----
LOOP AT ITAB_PO INTO WA_PO.
IF WA_PO-EBELN <> 0.
SELECT EKPO~EBELN EKPO~EBELP EKPO~ELIKZ from EKPO INTO WA_OPENPO where EKPO~EBELN = WA_PO-EBELN.
ENDIF.
ENDLOOP.
I am not abaper so plz advice how to achieve this
Thanks,
Rayan
‎2013 Dec 26 6:37 AM
Do as mentioned below Assumping ZPO_DETAILS as all fields
DATA ITAB_PO TYPE TABLE OF ZPO_DETAILS.
field-symbols <WA_PO> TYPE ZPO_DETAILS.
SELECT EKPO~EBELN EKPO~EBLEP EKPO~NETWR EKPO~NETPR EKPO~ELIKZ FROM EKPO
INTO TABLE ITAB_POO
WHERE -----
LOOP AT ITAB_PO assigning <WA_PO>.
IF <WA_PO>-ELIKZ eq 'X'
<WA_PO>-PO_STATUs = '1'.
ENDIF.
ENDLOOP.
‎2013 Dec 26 6:26 AM
Hi Rayan,
Firstly What are you trying to achieve is not clearly mentioned in your query. And writing SELECT Query in a loop is not recommended.
Can you make it little bit clear.
Thanks & Regards,
Vijay
‎2013 Dec 26 6:34 AM
Hi Vijay,
Thanks for Reply, actually I am not abaper so trying different options. My requirement is to fecth data into table and than return it with one custom field PO Status. If all line items of that PO are closed than we have to consider it close and put 1 in PO status field. I have not written entire select just want some logic to achieve this.
regards,
rayan
‎2013 Dec 26 6:34 AM
can't understand your logic correctly,
you are using same table to fetch the values twice , why ?? you can use single select statement where you can select all the required values with the conditions.
then you can access the values from internal table into structure or work area by looping it.
Regards,
sivaganesh
‎2013 Dec 26 6:37 AM
Do as mentioned below Assumping ZPO_DETAILS as all fields
DATA ITAB_PO TYPE TABLE OF ZPO_DETAILS.
field-symbols <WA_PO> TYPE ZPO_DETAILS.
SELECT EKPO~EBELN EKPO~EBLEP EKPO~NETWR EKPO~NETPR EKPO~ELIKZ FROM EKPO
INTO TABLE ITAB_POO
WHERE -----
LOOP AT ITAB_PO assigning <WA_PO>.
IF <WA_PO>-ELIKZ eq 'X'
<WA_PO>-PO_STATUs = '1'.
ENDIF.
ENDLOOP.
‎2013 Dec 26 6:45 AM
Hi Rayan,
let me conclude my understanding about your requirement.
if the databse table record of EKPO contains true in ELIKZ field then yo have mark the PO_status as 1.
I am assuming that ZPO_DETAILS is having below fields in it.
EBELN
EBELP
NETWR
NETPR
ELIKZ
PO_STATUS
you can write as below.
data: lt_podet type standard table of zpo_details,
lwa_podet type zpo_details.
select ebeln ebelp netwr netpr elikz
into corresponding fields of lt_podet
where ebeln = <inpute condition>.
loop at lt_podet into lwa_podet where elikz is not initial.
lwa_po_status = 1.
modify lt_podet from lwa_podet.
endloop.
let us know if you face any issues with this.
Thanks,
Bhaskar
‎2013 Dec 26 6:59 AM
Hi,
Thanks, I am applying above code in my logic. Just want to confirm few things, does it checks if all the Line Item of PO are closed only than it puts 1 in PO status. i.e. Lets say PO has 2 line items closed but one is not closed in that case it should not put 1 in status. Does it alter the main internal table ZPO_DETAILS and add this PO status or the above code is enough to do it.
regards,
‎2013 Dec 26 7:16 AM
Hi Rayan,
in above you didnot mentioned about thischeck.
let me help you with this, i have a PO with 2 line items. so if all the line items for the PO should be closed to put the PO_STATUS as 1.
if this is correct. then you have to modify the code as below.
after fetching data into internal table.
check for the non-closed items in your table and delete them from internal table.
make another internal table lt_podet_dup.
LOOP AT LT_PODET INTO LWA_PODET WHERE ELIKZ IS INITIAL.
APPEND LWA_PODET INTO LT_PODET_DUP.
ENDLOOP.
SORT LT_PODET_DUP BY EBELN.
DELETE ADJACENT DUPLICATES FROM LT_PODET_DUP COMPARING EBELN.
loop at lt_podet into lwa_podet where elikz is not initial.
READ TABLE LT_PODET_DUP WITH KEY EBELN = LWA_PODET-EBELN.
IF SY-SUBRC <> 0.
lwa_po_status = 1.
modify lt_podet from lwa_podet.
ENDIF.
endloop.