0

I have a custom z_table containing document id (key), username and two status fields - in progress and completed. My goal is to count how many documents are in progress and completed by the distinct users. I would like to populate the status fields of the internal table of type Z_table with 1s and 0s as follows and then I could use the aggregate functions to count. For displaying the data I am using class cl_salv_table. Below is an example how my table should look like:

- Doc ID-----User-----In progress-----Completed -- 
¦   201   ¦  user1 ¦      1        ¦      1      ¦
--------------------------------------------------
¦   202   ¦  user2 ¦      1        ¦      0      ¦
--------------------------------------------------

How could I fill the fields "In progress" and "Completed" with 1s and 0s based by a condition? The condition I know. Could anybody help me with this please?

Thank you very much!

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48

1 Answers1

1

If I understand the problem well then a simple LOOP and IF condition will solve your problem. If the username in your internal table is already filled in you will simply go through the table and if the username is the same you will fill in the status with the appropriate value.

SELECT *
FROM Z_TABLE
INTO @DATA(itab)
ORDER BY user.      "Sort by user

LOOP AT itab INTO DATA(itab_line).

  "If the user is new, append it to the table
  IF itab_line-user <> last_user.
    APPEND VALUE #( user = itab_line-user
                    in_progress = itab_line-in_progress 
                    completed = itab_line-completed ) TO result_tab

  "If the user is already exists in the table, change the status
  ELSE.
    ASSIGN result_tab[ user = itab_line-user ] TO FIELD-SYMBOL(<itab_line_by_user>).
    <itab_line_by_user>-in_progress = <itab_line_by_user>-in_progress + itab_line-in_progress.
    <itab_line_by_user>-completed = <itab_line_by_user>-completed + itab_line-completed.
  ENDIF.

  "Set the last_user variable
  last_user = itab_line-user.
ENDLOOP.

This is just one possible solution out of many. For example: It is also possible to solve this with the LOOP AT GROUP or REDUCE command.

Kisbandi
  • 71
  • 5