2014 Apr 09 4:15 PM
Hi All,
Below are the records in my internal table it_glt0.
racct drcrk hslvt
0000120000 H | 853.47-
0000120000 S | 0.00
0000120001 S | 0.00
0000120001 H | 0.00
0000120007 S | 0.00
0000120007 H | 0.00
0000120080 S | 0.00
0000120080 H | 564258.37-
for each account no, I have debit and credit values. If both the Debit and credit values are zero, then I have to delete that multiple record.
Below should be my final internal table.
racct drcrk hslvt
0000120000 H | 853.47-
0000120000 S | 0.00
0000120080 S | 0.00
0000120080 H | 564258.37-
How to acheive this functionality. Please help.
Thanks,
Haritha
Hi All,
Below are the records in my internal table it_glt0.
racct drcrk hslvt
0000120000 H | 853.47-
0000120000 S | 0.00
0000120001 S | 0.00
0000120001 H | 0.00
0000120007 S | 0.00
0000120007 H | 0.00
0000120080 S | 0.00
0000120080 H | 564258.37-
for each account no, I have debit and credit values. If both the Debit and credit values are zero, then I have to delete that multiple record.
Below should be my final internal table.
racct drcrk hslvt
0000120000 H | 853.47-
0000120000 S | 0.00
0000120080 S | 0.00
0000120080 H | 564258.37-
How to acheive this functionality. Please help.
Thanks,
Haritha
2014 Apr 09 4:22 PM
Hi Haritha,
You can try this
DELETE ADJACENT DUPLICATES FROM it_glt0 COMPARING racct hslvt
Best Regards.
2014 Apr 09 4:29 PM
Hi,
I tried this already. I am getting the below.
racct drcrk hslvt
|0000120000 |H | 853.47-
|0000120000 |S | 0.00
|0000120001 |H | 0.00
|0000120007 |H | 0.00
|0000120080 |H | 564258.37-
|0000120080 |S | 0.00
Below should be my final internal table.
racct drcrk hslvt
0000120000 H | 853.47-
0000120000 S | 0.00
0000120080 S | 0.00
0000120080 H | 564258.37-
Thanks,
Haritha
2014 Apr 09 4:48 PM
Hi,
Why you don't try to delete first all the entries that are zero?
The result would be:
0000120000 H | 853.47-
0000120080 H | 564258.37-
After that, you would have to add entries (0.0) for each entry that has a value. For that you should check if there is a "H" entry, you would have to insert a "S" entry with 0.0
0000120000 H | 853.47-
| 0000120000 | S | | | 0.00 |
0000120080 H | 564258.37-
| 0000120080 | S | | | 0.00 |
Best Regards
2014 Apr 09 5:10 PM
Hi Haritha,
Please follow the below steps.
Option 1.
Sort your internal table it_glt0.
Loop at it_glto.
use at end of <racct>
sum.
end at.
if sum = 0 ,then append these records into a different temp table which you do not append into your final internal table.
Option 2:
Sort your internal table it_glt0.
LOOP AT IT_GLTO INTO WA_GLTO.
I= SY-TABIX.
C= I + 1,
D = I - 1.
READ TABLE IT_GLTO INTO WA1_GLTO INDEX C.
READ TABLE IT_GLTO INTO WA2_GLTO INDEX D.
now compare racct fields for both WA1_GLTO and WA2_GLTO .
if they are the same and also the debit and credit values for both are zeros ,delete both these records using their index numbers,Esle append the ones with not zeros into the final internal table.
Thanks
Sarita
2014 Apr 10 10:08 AM
2014 Apr 09 5:30 PM
hi Haritha,
loop at it_glt0 INTO wa_glt0.
clear : wa_glt0_1
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'H'.
move wa_table1-hslvt to lv_hslvt.
CLEAR wa_glt0_1.
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'S'.
if wa_table1-hslvt = lv_hslvt.
delete it_table WHERE racct = wa_table-racct.
ENDIF.
ENDLOOP.
try this code it will work.
Best regards,
2014 Apr 09 7:53 PM
Good code Nitin But he needs delete the two lines when the two lines have value 0
2014 Apr 10 1:56 AM
Hi Nitin,
The above code will work fine but you must have forgotten to add a check for LV_HSLVT and WA_TABLE1-HSLVT equal to zero.
loop at it_glt0 INTO wa_glt0.
clear : wa_glt0_1
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'H'.
move wa_table1-hslvt to lv_hslvt.
CLEAR wa_glt0_1.
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'S'.
if wa_table1-hslvt eq 0 and lv_hslvt eq 0.
delete it_table WHERE racct = wa_table-racct.
ENDIF.
ENDLOOP.
Now the code will work fine
2014 Apr 09 7:49 PM
Hi Haritha.
Please create a program test and past this code I Did and worked.
*&---------------------------------------------------------------------*
*& Report ZTESTER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztester.
TYPES:BEGIN OF ty_1,
racct(10) TYPE c,
drcrk(1) TYPE c,
hslvt(6) TYPE p DECIMALS 2,
END OF ty_1.
DATA:t_1 TYPE TABLE OF ty_1,
t_auxiliary TYPE TABLE OF ty_1,
w_1 LIKE LINE OF t_1,
w_auxiliary LIKE LINE OF t_1,
v_tabix TYPE sy-tabix,
v_tabix2 TYPE sy-tabix.
w_1-racct = '0000120000'.
w_1-drcrk = 'H'.
w_1-hslvt = '853.47'.
APPEND w_1 TO t_1.
w_1-racct = '0000120000'.
w_1-drcrk = 'S'.
w_1-hslvt = ' 0.00'.
APPEND w_1 TO t_1.
w_1-racct = '0000120001'.
w_1-drcrk = 'H'.
w_1-hslvt = ' 0.00'.
APPEND w_1 TO t_1.
w_1-racct = '0000120001'.
w_1-drcrk = 'S'.
w_1-hslvt = ' 0.00'.
APPEND w_1 TO t_1.
w_1-racct = '0000120007'.
w_1-drcrk = 'S'.
w_1-hslvt = ' 0.00'.
APPEND w_1 TO t_1.
w_1-racct = '0000120007'.
w_1-drcrk = 'H'.
w_1-hslvt = ' 0.00'.
APPEND w_1 TO t_1.
w_1-racct = '0000120080'.
w_1-drcrk = 'H'.
w_1-hslvt = '564258.37'.
APPEND w_1 TO t_1.
w_1-racct = '0000120080'.
w_1-drcrk = 'S'.
w_1-hslvt = '0.00'.
APPEND w_1 TO t_1.
t_auxiliary[] = t_1[].
SORT: t_auxiliary BY racct
drcrk,
t_1 BY racct
drcrk.
LOOP AT t_1 INTO w_1.
v_tabix = sy-tabix.
IF w_1-drcrk = 'H'.
READ TABLE t_auxiliary INTO w_auxiliary WITH KEY racct = w_1-racct
drcrk = 'S' BINARY SEARCH.
v_tabix2 = sy-tabix.
IF sy-subrc = 0.
IF w_1-hslvt = 0 AND w_auxiliary-hslvt = 0.
DELETE t_1 INDEX v_tabix.
DELETE t_1 INDEX v_tabix2.
CONTINUE.
ENDIF.
endif.
ELSEIF w_1-drcrk = 'S'.
READ TABLE t_auxiliary INTO w_auxiliary WITH KEY racct = w_1-racct
drcrk = 'H' BINARY SEARCH.
v_tabix2 = sy-tabix.
IF sy-subrc = 0.
IF w_1-hslvt = 0 AND w_auxiliary-hslvt = 0.
DELETE t_1 INDEX v_tabix.
DELETE t_1 INDEX v_tabix2.
CONTINUE.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
check sy-subrc = 0.
2014 Apr 09 9:40 PM
Here is what you can do,
Hope this helps.
-Amit.
2014 Apr 10 1:47 AM
Hi Haritha,
We can achieve this in couple of steps.
Now you will get the required data into your final internal table IT_FINAL.
Please ask me if any future clarifications required.
2014 Apr 10 5:21 AM
Please check whether the below code will be useful for you.
1) Copy it_glt0 to another internal table.
2) Declare a flag lv_flag
3) Sort it_glt0 based on racct and drcrk.
4) Loop the internal table. If at any point there is a value in hslvt, capture it in the flag.
5) Check whether the flag contains a value. If not delete the new internal table for the corresponding racct.
6) Its pre assumed that drcrk always contains a S or H.
DATA lv_flag.
IT_GLT0_COPY = IT_GLT0.
SORT it_glt0 BY RACCT DRCRK.
LOOP AT it_glt0 INTO WA_glt0.
IF WA_GLT0-HSLVT IS NOT INITIAL.
LV_FLAG = 'X'.
ENDIF.
AT END OF RACCT.
IF LV_FLAG ne 'X'.
DELETE it_glt0_copy WHERE racct = WA_glt0-racct.
ENDIF.
CLEAR lv_flag.
ENDAT.
ENDLOOP.
2014 Apr 10 5:34 AM
Hi ,
try this below code :
loop at it_glt0 INTO wa_glt0.
clear : wa_glt0_1
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'H'.
and move to other internal table...
CLEAR wa_glt0_1.
READ TABLE it_glt0 INTO wa_glt0_1 WITH KEY racct = wa_table-racct drcrk = 'S'.
here put the conditon for both values are equal to ZERO.
delete the data from internal table.
ENDIF.
ENDLOOP.
2014 Apr 10 6:06 AM
Hi,
Two pass solution:
FORM test_04 .
TYPES: BEGIN OF tp_data_1 .
TYPES: racct TYPE racct ,
shkzg TYPE shkzg ,
hslvt TYPE hslvt .
TYPES: END OF tp_data_1 .
DATA: it_data_1 TYPE TABLE OF tp_data_1 .
DATA: st_data_1 LIKE LINE OF it_data_1 .
st_data_1-racct = '0000120000'.
st_data_1-shkzg = 'H'.
st_data_1-hslvt = '853.47'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120000'.
st_data_1-shkzg = 'S'.
st_data_1-hslvt = ' 0.00'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120001'.
st_data_1-shkzg = 'H'.
st_data_1-hslvt = ' 0.00'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120001'.
st_data_1-shkzg = 'S'.
st_data_1-hslvt = '0.00'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120007'.
st_data_1-shkzg = 'S'.
st_data_1-hslvt = '0.00'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120007'.
st_data_1-shkzg = 'H'.
st_data_1-hslvt = '0.00'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120080'.
st_data_1-shkzg = 'H'.
st_data_1-hslvt = '564258.37'.
APPEND st_data_1 TO it_data_1.
st_data_1-racct = '0000120080'.
st_data_1-shkzg = 'S'.
st_data_1-hslvt = '0.00'.
APPEND st_data_1 TO it_data_1.
TYPES: BEGIN OF tp_sums_1 .
TYPES: racct TYPE racct ,
counter TYPE integer .
TYPES: END OF tp_sums_1 .
DATA: it_sums_1 TYPE TABLE OF tp_sums_1 .
DATA: st_sums_1 LIKE LINE OF it_sums_1 .
FIELD-SYMBOLS: <st_data_1> LIKE LINE OF it_data_1 .
LOOP AT it_data_1 ASSIGNING <st_data_1> .
st_sums_1-racct = <st_data_1>-racct .
IF <st_data_1>-hslvt NE 0 .
st_sums_1-counter = 1 .
ELSE .
st_sums_1-counter = 0 .
ENDIF .
COLLECT st_sums_1 INTO it_sums_1 .
ENDLOOP.
DELETE it_sums_1 WHERE counter EQ 0 .
SORT it_sums_1 BY racct .
LOOP AT it_data_1 ASSIGNING <st_data_1> .
READ TABLE it_sums_1 TRANSPORTING NO FIELDS
WITH KEY
racct = <st_data_1>-racct .
IF sy-subrc NE 0 .
DELETE it_data_1 .
ENDIF .
ENDLOOP .
BREAK-POINT .
ENDFORM . "test_04
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |