2010 Jan 20 8:32 AM
Hello,
A production order includes contains components that produced with other production orders that use components produced by another prod order....... so on
This chain may include up to 10 levels.
The task is to populate the record of the lowest level with final prod order number and be able to expand te hierarchy
I probably need to use recursive loop to get into the lowest level
Does ABAP have something specific for recursive processing? Can I call the same FM , method , FORM from itself?
Thanks
2010 Jan 20 10:09 AM
I've not used a function module but I've done the same sort of thing to 'flatten out' the HR org structure just using ordinary loops. The tables mentioned here are all pre-filled custom tables but it should be possible to adapt the method to work with other tables.
* Add the org unit details to the working table which will be used
* to query the next level down.
CLEAR ls_orgs_working.
ls_orgs_working-child = gs_orgs-child.
ls_orgs_working-parent = gs_orgs-parent.
APPEND ls_orgs_working TO lt_orgs_working.
* Now, starting from this org, treewalk down the hierarchy and get
* the people details and totals for each sub org. The HIER_ORG_UNIT
* value for this records must be GS_ORGS-CHILD ie to relate them to
* our starting org unit.
DO.
* If we've reached the bottom of the hierarchy, leave the DO loop.
IF lt_orgs_working IS INITIAL.
EXIT.
ENDIF.
* Otherwise, get all the org units for which the current org unit is
* a parent.
SELECT *
INTO TABLE lt_orgs_temp
FROM zabs_orgs
FOR ALL ENTRIES IN lt_orgs_working
WHERE parent = lt_orgs_working-child.
IF sy-subrc = 0.
CLEAR lt_orgs_working.
LOOP AT lt_orgs_temp INTO ls_orgs_temp.
* Add the totals for the sub org to the GS_ORGS-CHILD totals.
gs_orgs-meeting_sorgs = gs_orgs-meeting_sorgs +
ls_orgs_temp-meeting.
gs_orgs-headcount_sorgs = gs_orgs-headcount_sorgs +
ls_orgs_temp-headcount.
gs_orgs-znew_sorgs = gs_orgs-znew_sorgs +
ls_orgs_temp-znew.
* Add the sub org unit details to the working table so that
* they can be used to query the next level down.
CLEAR ls_orgs_working.
ls_orgs_working-child = ls_orgs_temp-child.
ls_orgs_working-parent = ls_orgs_temp-parent.
APPEND ls_orgs_working TO lt_orgs_working.
ENDLOOP.
ELSE.
CLEAR lt_orgs_working.
ENDIF.
ENDDO.
Hello,
A production order includes contains components that produced with other production orders that use components produced by another prod order....... so on
This chain may include up to 10 levels.
The task is to populate the record of the lowest level with final prod order number and be able to expand te hierarchy
I probably need to use recursive loop to get into the lowest level
Does ABAP have something specific for recursive processing? Can I call the same FM , method , FORM from itself?
Thanks
2010 Jan 20 8:45 AM
Hope you mean about the BOM Matrix Components explosion.
Use a subroutine and call it recursively.
available function modules are
CSAP_MAT_BOM_READ ( from higher level to lower level)
CSEP_MAT_BOM_SELECT_WHERE_USED( From lower to higher)
You can check this link for recursive logic link:[Inverse BOM explosion|https://wiki.sdn.sap.com/wiki/display/Snippets/InverseorReverseBomwithQtyRequired]
2010 Jan 20 9:39 AM
2010 Jan 20 10:09 AM
I've not used a function module but I've done the same sort of thing to 'flatten out' the HR org structure just using ordinary loops. The tables mentioned here are all pre-filled custom tables but it should be possible to adapt the method to work with other tables.
* Add the org unit details to the working table which will be used
* to query the next level down.
CLEAR ls_orgs_working.
ls_orgs_working-child = gs_orgs-child.
ls_orgs_working-parent = gs_orgs-parent.
APPEND ls_orgs_working TO lt_orgs_working.
* Now, starting from this org, treewalk down the hierarchy and get
* the people details and totals for each sub org. The HIER_ORG_UNIT
* value for this records must be GS_ORGS-CHILD ie to relate them to
* our starting org unit.
DO.
* If we've reached the bottom of the hierarchy, leave the DO loop.
IF lt_orgs_working IS INITIAL.
EXIT.
ENDIF.
* Otherwise, get all the org units for which the current org unit is
* a parent.
SELECT *
INTO TABLE lt_orgs_temp
FROM zabs_orgs
FOR ALL ENTRIES IN lt_orgs_working
WHERE parent = lt_orgs_working-child.
IF sy-subrc = 0.
CLEAR lt_orgs_working.
LOOP AT lt_orgs_temp INTO ls_orgs_temp.
* Add the totals for the sub org to the GS_ORGS-CHILD totals.
gs_orgs-meeting_sorgs = gs_orgs-meeting_sorgs +
ls_orgs_temp-meeting.
gs_orgs-headcount_sorgs = gs_orgs-headcount_sorgs +
ls_orgs_temp-headcount.
gs_orgs-znew_sorgs = gs_orgs-znew_sorgs +
ls_orgs_temp-znew.
* Add the sub org unit details to the working table so that
* they can be used to query the next level down.
CLEAR ls_orgs_working.
ls_orgs_working-child = ls_orgs_temp-child.
ls_orgs_working-parent = ls_orgs_temp-parent.
APPEND ls_orgs_working TO lt_orgs_working.
ENDLOOP.
ELSE.
CLEAR lt_orgs_working.
ENDIF.
ENDDO.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |