I created the following table in SAP:
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.
I created the following table in SAP:
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.
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.
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).
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.