Skip to Content

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

PROBLEM

Can anybody solve the problem given below.

I have 3 Internal tables A,B,C by name.Internal tables A and B contain some numbers all in a field.Among them C has no data in it.Here I have 3 requirements.

1.I have to copy the contents of A and B into C.

2.I have to output the numbers which occur repeatedly in C and also I have to output that how many times each number is being repeated.

3.After obtaining the solution for second requirement I have to delete the numbers in Internal table C which are repeatedly occured.

I will award max points to those who have solved it.

Former Member
replied

Hi Sandy,

you seem to be asking a lot of fundamental questions. Perhaps you should start reading the documentation and having a go? Maybe even buy a book or two?

Anyway, here is a quick code sample. I have used the sample table SFLIGHT for this and am comparing the field CONNID.

DATA a TYPE TABLE OF sflight.
DATA b TYPE TABLE OF sflight.
DATA c TYPE TABLE OF sflight.
DATA d TYPE REF TO sflight.
DATA e TYPE REF TO sflight.
DATA cnt TYPE i.

SELECT * FROM sflight INTO TABLE a.
SELECT * FROM sflight INTO TABLE b.

* 1.I have to copy the contents of A and B into C.
INSERT lines of a INTO TABLE c.
INSERT lines of b INTO TABLE c.

*2.I have to output the numbers which occur repeatedly in C and also I have to output that how many times each number is being repeated.
SORT c BY connid.
LOOP AT c REFERENCE INTO d.
  IF e IS NOT BOUND. e = d. ENDIF.
  IF d->connid = e->connid.
    ADD 1 TO cnt.
  ELSE.
    IF cnt > 1.
      WRITE: /, e->connid, cnt.
    ENDIF.
    e = d.
    cnt = 1.
  ENDIF.
ENDLOOP.

*3.After obtaining the solution for second requirement I have to delete the numbers in Internal table C which are repeatedly occured.
DELETE ADJACENT DUPLICATES FROM c COMPARING connid.

Cheers

Graham Robbo

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question