Skip to Content
avatar image
Former Member

Getting PRTs used in a Routing operation

Hi SAP-Community,

I'm currently developing a custom program which needs to read all PRTs for a given operation in a routing.

I.e. I open CA03, enter my group number, double-click a group counter, select a single operation and click the "PRT" button. Now I see a list of all PRTs for this operation.

I would like to know how to do this in ABAP. (With functional modules, BAPIs, tables, or something similar)

I already learned that the information I want (object type and ID) is stored in the PLFH table if I supply task list type (PLNTY), group (PLNNR), node (PLNKN) and deletion indicator (LOEKZ) <> 'X' - however in some cases this will still return more PRTs than shown in CA03. I assume this is because PLFH also stores history data for all PRTs ever connected to this plan operation - so I might need another join with a table which tells me what entries are still valid. But I don't know which table that might be.

Could you tell me if there is a functional module for this or how my table selects should look like?

Thanks, Dennis

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Mar 10, 2017 at 04:57 PM

    Wohoo, finally figured it out!

    As it turns out, PLFH does indeed store all the information I need, but also historical data. To get only the entries valid at a specific date, you need to select with datuv <= yourDate, and then group by the PRT position counter. In each group you must only keep the most recent entry (indicated by the highest ZAEHL value)

    This subroutine does exactly that:

    **********************************************************************
    ** PLFH doesn't store only active PRTs but much rather a complete-day
    ** based history, depending on change number.
    ** This Subroutine returns those PRTs which would also be shown in CA03.
    **********************************************************************
    FORM get_active_plfh_entries
     USING uv_plnty TYPE plnty
     uv_plnnr TYPE plnnr
     uv_plnkn TYPE plnkn
     uv_datuv TYPE datuv
     CHANGING ct_active_plfhs TYPE plfh_tt.
    
     DATA ls_plfh_line TYPE plfh.
    
     CLEAR ct_active_plfhs.
    
     SELECT * FROM plfh
     INTO TABLE ct_active_plfhs
     WHERE plnty = uv_plnty
     AND plnnr = uv_plnnr
     AND plnkn = uv_plnkn
     AND datuv <= uv_datuv.
    
     " Remove those entries which were replaced by a newer one or have a deletion flag
     LOOP AT ct_active_plfhs INTO ls_plfh_line.
     " Delete entries which are replaced by THIS entry.
     " (i.e. same position counter but lower ZAEHL)
     DELETE ct_active_plfhs
     WHERE plnty = ls_plfh_line-plnty
     AND plnnr = ls_plfh_line-plnnr
     AND pzlfh = ls_plfh_line-pzlfh
     AND zaehl < ls_plfh_line-zaehl.
    
     IF ls_plfh_line-loekz = 'X'.
     " Remove this entry as well since it has a deletion flag
     DELETE ct_active_plfhs WHERE pzlfh = ls_plfh_line-pzlfh.
     ENDIF.
     ENDLOOP.
    ENDFORM.
    
    Add comment
    10|10000 characters needed characters exceeded