12-29-2013 12:17 PM
Note for Moderator ( This is not practice question and I have done enough search before posting this, The first table represents PO and second one its Line Items. If we have to close PO than we need to check delivery completed indicator whether all of them has status closed or not). Secondly I am not abap developer and need logical help in writing End routine in BW. Please do not remove this post.
Hi experts,
I have one internal table with empty column E
Table 1
A C D E
1001 John MMM
2001 Tom PPP
I have another internal table that has value x in column E
Table 2
A B E
1001 10 x
1001 20 0
1001 30 x
2001 20 x
2001 30 x
My Requirement is to match key column A of table2 with table1and put value 1 in column E of table 1 in case all the values in column E of Table 2 are x otherwise put 0.
final output of table 1 should be
A C D E
1001 John MMM 0
2001 Tom PPP 1
Please suggest, any suggestion will be highly appreciated.
regards,
rayan
12-29-2013 2:30 PM
Hi Rayan,
PFB the code.
sort table1 by A.
sort table2 by A.
loop at table1 into wa_table1.
read table table2 into wa_table2
with key A = wa_table1-A
E = 0 binary search.
if sy-subrc eq 0.
wa_table1-E = 0.
else.
wa_table1-E = 1.
endif.
modify table1 from wa_table1 index sy-tabix.
endloop.
Regards,
Jai
12-29-2013 12:25 PM
DATA : e_check.
LOOP AT itab1 INTO wa_itab1.
e_check = 'X'.
LOOP AT itab2 INTO wa_itab2 WHERE a = wa_itab1-a.
IF wa_itab2-e = ' '.
CLEAR e_check.
ENDIF.
CLEAR wa_itab2.
ENDLOOP.
IF e_check = 'X'.
wa_itab1-e = '1'.
ELSE.
wa_itab1-e = '0'.
ENDIF.
MODIFY itab1 FROM wa_itab1.
CLEAR wa_itab1.
ENDLOOP.
12-29-2013 12:28 PM
Loop at itab1
Lv_tabix = sy-tabix
loop at itab2 where field1 = itab1-field1 and fielde ne 'X'.
Exit.
Endloop.
If sy-subrc eq 0
Itab1-fielde = 0
Else.
Itba1-fielde = 1
endif
modify itab1 index lv_tabix transporting fielde
endloop.
12-29-2013 2:30 PM
Hi Rayan,
PFB the code.
sort table1 by A.
sort table2 by A.
loop at table1 into wa_table1.
read table table2 into wa_table2
with key A = wa_table1-A
E = 0 binary search.
if sy-subrc eq 0.
wa_table1-E = 0.
else.
wa_table1-E = 1.
endif.
modify table1 from wa_table1 index sy-tabix.
endloop.
Regards,
Jai
12-30-2013 1:52 PM
Hi there,
The proposal made by Jai is the best over here according to me with just some slight modifications:
- Use fields symbols instead of work headers and remove that ugly MODIFY statement.
- No need to populate wa_table2 since you only check if the record exists or not (instead use the option "transporting no fields".
I guess this can be important if the code is relevant to BW (meaning probably huge tables...)
Cheers,
Manu.
01-05-2014 12:41 PM
Hi,
Manu is right, i have to load millions in BW and the code I tried earlier is taking very long time to execute, I have tried the code mentioned by JAI but output is different. Can you please check below code and suggest if I am doing any thing wrong there. Below code always put 1 even if one indicator is x and other is null.
TYPES: BEGIN OF T_POSTAT,
PONUM TYPE /BIC/AZPUR_SUM00-/BIC/ZPO_NUM,
POLNUM TYPE /BIC/AZPUR_SUM00-/BIC/ZPO_INUM,
PODIN TYPE /BIC/AZPUR_SUM00-/BIC/ZPO_DIN,
END OF T_POSTAT.
DATA: ITAB_POSTAT TYPE STANDARD TABLE OF T_POSTAT WITH HEADER LINE.
DATA: WA_POSTAT LIKE LINE OF ITAB_POSTAT.
DATA: ITAB_TARGET TYPE STANDARD TABLE OF _TY_S_TG_1.
DATA: WA_TARGET LIKE LINE OF ITAB_TARGET.
DATA : ICOUNT TYPE RSARECORD.
IF RESULT_PACKAGE IS NOT INITIAL.
ICOUNT = 1.
REFRESH ITAB_POSTAT.
SELECT /BIC/ZPO_NUM /BIC/ZPO_INUM /BIC/ZPO_DIN
FROM /BIC/AZPUR_SUM00 INTO TABLE ITAB_POSTAT FOR ALL ENTRIES
IN RESULT_PACKAGE WHERE /BIC/ZPO_NUM =
RESULT_PACKAGE-/BIC/ZPO_NUM AND
/BIC/ZPO_INUM = RESULT_PACKAGE-/BIC/ZPO_INUM .
SORT RESULT_PACKAGE DESCENDING BY /BIC/ZPO_NUM /BIC/ZPO_INUM
/BIC/ZPR_REQ DF_PREQITM.
SORT ITAB_POSTAT DESCENDING BY PONUM POLNUM.
DELETE ADJACENT DUPLICATES FROM RESULT_PACKAGE COMPARING
/BIC/ZPO_NUM /BIC/ZPO_INUM /BIC/ZPR_REQ DF_PREQITM.
LOOP AT RESULT_PACKAGE into WA_TARGET.
READ TABLE ITAB_POSTAT INTO WA_POSTAT with key PONUM =
WA_TARGET-/BIC/ZPO_NUM PODIN = '' binary search.
if sy-subrc eq 0.
WA_TARGET-/BIC/ZIO_OPEN = 0.
else.
WA_TARGET-/BIC/ZIO_OPEN = 1.
ENDIF.
CLEAR WA_POSTAT.
modify RESULT_PACKAGE from WA_TARGET index sy-tabix.
ICOUNT = ICOUNT + 1.
ENDLOOP.
ENDIF.
regards,
Rayan
01-05-2014 1:14 PM
Hi Rayan,
READ TABLE ITAB_POSTAT INTO WA_POSTAT with key PONUM =
WA_TARGET-/BIC/ZPO_NUM PODIN = '' binary search.
must be failing.Try to sort the table with same fields that you are using in read statement and just try to debug how the read table statement is behaving
Thanks
Bala Duvvuri
01-05-2014 5:57 PM
Hi Rayan,
Bala is right, for using binary search u should sort thr internal table with the keys you are using in the with key clause of your read statement. In your case PONUM & PODIN should be used in the sort statement instead of PONUM POLNUM.
Regards,
Jai
01-06-2014 7:28 AM
Hi Ryan,
Please refer below code , i hope it will help for you.
DATA : flag.
LOOP AT itab1 INTO wa_itab1.
LOOP AT itab2 INTO wa_itab2 WHERE field_e = wa_itab1-field_e.
IF wa_itab2-field_e ne ' '.
flag = 'X'.
ENDIF.
CLEAR wa_itab2.
ENDLOOP.
IF flag = 'X'.
wa_itab1-field_e = '1'.
ELSE.
wa_itab1-field_e = '0'.
ENDIF.
MODIFY itab1 FROM wa_itab1 transporting field_e.
CLEAR wa_itab1.
ENDLOOP.
Regards,
Thangam.P