1

I created the following table in SAP:

My Table

How can I print only these lines, where the employee has signed in (KOMMEN), but not signed out (GEHEN)?

In this example I want print only the last line.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
doomsweb
  • 51
  • 8
  • If the development is in the early stage or not many things are based on this table I think you should redesign your solution and think in "sessions". Your life will be much easier IMHO. – szako Jun 04 '17 at 16:41
  • its a homework from my university. so its not possibe to change the structure. – doomsweb Jun 04 '17 at 16:51
  • There is a command for conditional loops over tables (`LOOP ... WHERE`). But if this is a DB tab, you could also move the `WHERE` to your `SELECT` –  Jun 04 '17 at 17:58
  • If it is a homework, what have you tried so far? – vwegert Jun 04 '17 at 18:55
  • @vwegert i changed The table structure (Added 2 more columns 1. Sign in, 2. sign in Time, 3. sign out, 4. sign out Time) And then with where-clause (WHERE signout ='') and now i have only The entries who signed in but Not signed out) but my prof. Does Not allow any change on The table structure :/ – doomsweb Jun 05 '17 at 10:11
  • I assume the shown table is sorted somehow as seen on the attached pic. I think it is ordered by person & date & time ascending. Create arrival / leave pairs as per person during looping and process that. – szako Jun 05 '17 at 12:43
  • Have a look at the documentation for the where clause and pay special attention to the EXISTS part. https://help.sap.com/http.svc/rc/abapdocu_750_index_htm/7.50/en-US/abenwhere_logexp.htm – Gert Beukema Jun 05 '17 at 16:15

3 Answers3

0

The output method you use is called ABAP list output. There are many different output methods in ABAP. The list output is only one. The pitty with this list output in your case is, that adding a filter is up to the developer. I.e. there is no default feature of the ABAP list output to filter for certain values. This output method is really kept simple.

Like said in the comments you should change your ABAP code and do the filtering 'manually' in the loop. To give an example:

LOOP AT lt_employees INTO ls_employee
  WHERE komgeh = 'KOMMEN'.
  WRITE: / ls_employee-mandt, 
           ls_employee-id,
           ls_employee-pnr,
           ls_employee-komgeh,
           ls_employee-datum,
           ls_employee-uhrzeit.
ENDLOOP.

Note that there are also other possibilities to filter for the 'KOMMEN'-values in the internal table. You could think of an IF-statement inside the LOOP. Anyways applying a WHERE-clause at the LOOP-statement is one of the most performant ways of filtering an internal table.

In addition, as you did not posted your code, you need to transfer the names I used in the code snippet to your code.

0

Suppose the structure of the table is as simple as on the screen you provided, you can use simple GROUP clause for counting unpaired login (KOMMEN) events:

SELECT PNR
  FROM table
  INTO TABLE @DATA(itab)
 GROUP BY PNR
 HAVING COUNT(*) = 1.

The prerequisite for this solution to work is even number of records if the user ended his session, and odd number if he doesn't (only signed in).

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
0
   SORT lt_data BY datum ASCENDING
                   PNR   ASCENDING
                   K_G   DESCENDING.

    LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<line>) WHERE k_g = 'KOMMEN'.
      lv_tabix = sy-tabix + 1.

      READ TABLE lt_data ASSIGNING FIELD-SYMBOL(<temp>) index lv_tabix.

      IF sy-subrc IS NOT INITIAL
      OR <line>-datum <> <temp>-datum
      OR <line>-pnr   <> <temp>-pnr.
        APPEND <line> TO lt_output.
      ENDIF.
    ENDLOOP.

Then you have all the lines you want in lt_output.

Braunbaer
  • 1
  • 3