cancel
Showing results for 
Search instead for 
Did you mean: 

Unfirming PPDS planned orders

Former Member
0 Kudos


Hello

I was trying to check if there is any standard transaction available to unfirm already firmed planned orders(firmed manually or by system)

I know we can do this via /SAPAPO/RRP4 or /SAPAPO?RRP3 but the requirement is to execute in background mode for list of parts and expecation is all the firmed planned orders for the given part numbers are unfirmed in one single go

In /SAP/CDPSB0 I tried using function - Unfirm Objects with planning object as Orders and gave part number against production number in the selection

but some how system is not able to recognize the orders and it is not performing any action

Please let me know if i'm missing something in CDPSB0 and also let me know if there is standard trnasaction with which I can achieve my requirement

Thanks

Vijai

Accepted Solutions (1)

Accepted Solutions (1)

mwallace
Participant
0 Kudos

Hello Vijai

Are you sending to order to ECC?  If so you can use MD19.

Thanks

Michael

Former Member
0 Kudos

Hi Michael

Thanks for the reply..it partially meets my requirement

Yes orders are sent to ECC,. but again via MD19 we can only do it the foreground

I'm looking for a transaction with which we can set it up as a background job, we want to unfirm orders just before MRP job is run in APO..please let me know if we have any transaction in APO or ECC

Thanks

Vijai

mwallace
Participant
0 Kudos

Hello Vijai

There isn't a standard program in ECC and once the orders are sent to ECC they can't be modified in APO.

You can use use BAPI_PLANNEDORDER_CHANGE and BAPI_TRANSACTION_COMMIT to create a z program.

The point of unfirmed orders is that they can be changed so normally the firmed orders would just be deleted and new created to replace them.

Regards

Michael

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello All

Thanks for your valuable inputs, we found a workaround to address this requirement

instead of unfirming the firmed planned order, there is standard program available to delete firmed orders and you have options to select order category too..

Program - /SAPAPO/DELETE_PP_ORDER

Our intention was to unfirm,so that the subsequent MRP run will reexplode based on current demand situation and create new planned orders , so this program has met our requirement

Just wanted to share it here

0 Kudos

Hi Vijai.

It is not recommended to use /SAPAPO/DELETE_PP_ORDER in productive environments. For example, because it cannot generate planning file entries if you do change planning, and it cannot trigger automatic planning if planning procedure is set up for that as well. It is mostly used to clean up system during implementation phase rather than being a planning tool.

I'd recommend using the BAPI/heuristic as suggested by Thiago, or deleting them via Receipts View, if necessary.

It may also be a good idea to check why planned orders are being firmed earlier than necessary/requested.

Regards,

Tiago

Former Member
0 Kudos

Hi Tiago

Thanks for sharing this information and sorrry for coming back late

we are planning to use this program for parts belonging to one

production planner (MRP controller in ECC terms) and followed by

regenerative MRP for those parts,

In that way still it would meet our requirement ,so just want to confirm if that should be ok else we are missing something else with this program and that should be conisdered before

using it in production environment

Appreciate your help and looking forward for your reply / guidance

Thanks

Vijai

Former Member
0 Kudos

Hello Tiago

Not sure if you got a chance to check my reply, can you please check and give your opinion

Thanks

Vijai

Former Member
0 Kudos

Hello Viajai,

we used this program in the productive environment for one customer, but we use it to delete planned orders that it is the past.

For the MRP purpose we prefer to use the developed heuristic to unfirm the planned orders and purchase requisitions before the MRP run.

We prefer to use the heuristic to keep the planned orders and for MRP just create/delete what is necessary.

Former Member
0 Kudos

Hello Tiago

Appreciate your reply !

From long term perspective We will look into developing heurestic but for short term solution this program seem to be meeting our requirement

As mentioned above -we are planning to use this program for parts belonging to one

production planner (MRP controller in ECC terms) and followed by

regenerative MRP for those parts, so really the planing file entry part is not a concern as regen will still plan for those parts and we dont have automatic planing turned on , so I'm thinking we should be ok

I was looking for a confirmation from Tiago Furlanneto as he brought up the point and there is a note out there in market place that mention the same

Thanks

Vijai

ramesh_mahankali
Active Participant
0 Kudos

Hi,

For anyone looking to FIRM/UNFIRM planned orders you can use the function module  /SAPAPO/RRP_ORDER_SET_FIRMED. You can use this FM in a custom program to FIRM/UNFIRM planned orders.

Thanks,

Ramesh

former_member189901
Contributor
0 Kudos

Hii Vijai,

An order is PP-firmed if any of the following are true:

  • The order is inside the PTF
  • The order is output firmed/input Firmed
  • The order is date fixed

How to Un-firm those firmed orders

  • The order is inside the PTF- Impossible to unfirm, as long as the order is in Time fence
  • The order is output firmed/input Firmed-  Manually have to  uncheck the Output firmed tick to unfirm those orders..
  • The order is date fixed- Run Unfirm object through background jobs to un-firm the orders or else do it from Dsboard

Regards

Debashis

Former Member
0 Kudos

Hi Debashis

I understand when the orders get firmed indicator

My requirement is to avoid the manual or foreground option and do it via background method

Please let me know if we have any standard transaction with which I can meet this requirement

Thanks

Vijai

former_member189901
Contributor
0 Kudos

Hii Vijai,

You can run background job UNFIRM Object through /sapapo/cdpsbo for firmed order which are date fixed only...

Regards

Debashis

Former Member
0 Kudos

Hi Vijai,

from what I know there is no standard transaction that you can do this in background.

I had the same requirement for a client and we develop a heuristic so we can run using //CDPSB0.

For this development we use the BAPI_MOSRVAPS_SAVEMULTI3 for inhouse production and the BAPI_POSRVAPS_SAVEMULTI3 for the external procurement.

I found one version of the development code, but I don't remenber if it is the final one.

I put it below, maybe it can help you.

Best Regards

Thiago

FUNCTION XXXXXXXX.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     REFERENCE(I_HEUR_SETTINGS) TYPE  /SAPAPO/HEUR_SETTINGS

*"     VALUE(I_SIMVERID) TYPE  /SAPAPO/VRSIOID

*"     VALUE(I_SIMSESSID) TYPE  /SAPAPO/OM_SIMSESSION

*"     REFERENCE(I_DIALOG_FLG) TYPE  C DEFAULT SPACE

*"     REFERENCE(I_OBJECT_KEYS) TYPE  /SAPAPO/HEUR_OBJECT_KEYS

*"  EXPORTING

*"     REFERENCE(E_CHANGED_OBJECTS) TYPE  /SAPAPO/HEUR_CHANGED_OBJECTS

*"     REFERENCE(E_OBJECT_KEYS) TYPE  /SAPAPO/HEUR_OBJECT_KEYS

*"  EXCEPTIONS

*"      NOT_QUALIFIED

*"      NO_INPUT_OBJECTS

*"      FAILED

*"----------------------------------------------------------------------

   DATA:   li_pegid        TYPE          /sapapo/pegid_tab,

           li_pegkey       TYPE          /sapapo/pegkey_tab,

           lw_pegkey       TYPE          /sapapo/pegkey_tab,

           lw_pegid        TYPE          /sapapo/pegid,

           lw_loc          TYPE          ty_loc,

           li_loc          TYPE TABLE OF ty_loc,

           li_mat_aux      TYPE TABLE OF ty_matmap,

           li_loc_aux      TYPE TABLE OF ty_loc,

           lw_matloc       TYPE          ty_matloc,

           lw_matmap       TYPE          ty_matmap,

           li_matloc       TYPE TABLE OF ty_matloc,

           li_matmap       TYPE TABLE OF ty_matmap,

           li_prodloc      TYPE TABLE OF bapi_prodloc_key,

           lw_prodloc      TYPE          bapi_prodloc_key,

           lw_prodloc_aux1 TYPE          bapi_prodloc_key,

           lt_prodloc_aux1 TYPE TABLE OF bapi_prodloc_key,

           lt_product      TYPE TABLE OF bapiproductrange,

           lw_product      TYPE          bapiproductrange,

           lt_location     TYPE TABLE OF bapilocrange,

           lw_location     TYPE          bapilocrange,

           lt_receipts     TYPE TABLE OF bapi10502poouto,

           lw_receipts     TYPE          bapi10502poouto,

           lw_prodloc_aux  TYPE          bapi_prodloc_key,

           lt_poouti       TYPE TABLE OF bapi10502poouti,

           lw_poouti       TYPE          bapi10502poouti,

           lt_pooutix      TYPE TABLE OF bapi10502pooutix,

           lw_pooutix      TYPE          bapi10502pooutix,

           lt_return       TYPE TABLE OF bapiret2,

           li_order_head   TYPE TABLE OF bapi10503ordheadout,

           lw_order_head   TYPE          bapi10503ordheadout,

           li_modes        TYPE TABLE OF bapi10503ordmodeout,

           li_return       TYPE TABLE OF bapiret2,

           li_activities   TYPE TABLE OF bapi10503ordactout,

           lv_tabix        TYPE          i,

           li_order        TYPE TABLE OF bapi10503ordheadin,

           lw_order        TYPE          bapi10503ordheadin,

           li_order_x      TYPE TABLE OF bapi10503ordheadinx,

           lw_order_x      TYPE          bapi10503ordheadinx,

           lt_locno        TYPE TABLE OF /sapapo/locno,

           lv_simverid     TYPE          bapigenfields-vrsioex.

   FIELD-SYMBOLS<fs_pegkey>     TYPE /sapapo/pegkey,

                   <fs_matloc>     TYPE ty_matloc,

                   <fs_matmap>     TYPE ty_matmap,

                   <fs_mat_aux>    TYPE ty_matmap,

                   <fs_loc>        TYPE ty_loc,

                   <fs_activities> TYPE bapi10503ordactout,

                   <fs_prodloc>    TYPE bapi_prodloc_key.

   DATA: lt_fix        TYPE TABLE OF ztlb_screen_1001,

         lw_fix        TYPE          ztlb_screen_1001,

         lv_tzone      TYPE          tznzone,

         lv_start_time TYPE          bapi10004rsflds-start_t,

         lv_end_time   TYPE          bapi10004rsflds-end_t,

         lv_start      TYPE          sy-datum,

         lv_end        TYPE          sy-datum,

         lv_no_def_ord TYPE /sapapo/rrp_no_default_order,

         lv_check      TYPE flag.

*  SELECT SINGLE vrsioex

*    FROM  /sapapo/apo01

*    INTO lv_simverid

*    WHERE  vrsioid  = i_simverid.

   SELECT SINGLE vrsioex

                 rrp_no_def_order

           INTO (lv_simverid,

                 lv_no_def_ord)

           FROM  /sapapo/apo01

           WHERE vrsioid  = i_simverid.

   IF lv_no_def_ord IS INITIAL.

     CLEAR lv_check.

   ELSE.

     lv_check = 'X'.

   ENDIF.

   SELECT *

     FROM ztlb_screen_1001

     INTO TABLE lt_fix.

   IF lt_fix IS NOT INITIAL.

     READ TABLE lt_fix INTO lw_fix WITH KEY e_name = i_heur_settings-heur_id.

     IF sy-subrc IS INITIAL.

       IF lw_fix-e_fix IS INITIAL.

         LOOP AT i_object_keys-pegid_tab INTO lw_pegid.

           APPEND lw_pegid TO li_pegid.

         ENDLOOP.

*=========================================================*

* Change simsessid

*=========================================================*

         IF NOT i_simsessid IS INITIAL.

           CALL FUNCTION '/SAPAPO/TSIM_SIMULATION_DELETE'

             EXPORTING

               iv_simsessid    = i_simsessid

               iv_simversid    = i_simverid

             EXCEPTIONS

               deleting_failed = 1

               OTHERS          = 2.

           IF sy-subrc NE 0.

             RAISE failed.

           ENDIF.

           CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_SET'

             EXPORTING

               iv_simsession = space.

         ENDIF.

* Get Pegging Area Information

*=========================================================*

         CALL FUNCTION '/SAPAPO/DM_PEGID_GET_PEGKEY'

           EXPORTING

             it_pegid  = li_pegid

           IMPORTING

             et_pegkey = li_pegkey.

* Fill intern tables

*=========================================================*

         LOOP AT li_pegkey ASSIGNING <fs_pegkey>.

           lw_loc-locid = <fs_pegkey>-locid.

           APPEND lw_loc TO li_loc_aux.

           lw_matmap-matid = <fs_pegkey>-matid.

           APPEND lw_matmap TO li_mat_aux.

           lw_matloc-matid = <fs_pegkey>-matid.

           lw_matloc-locid = <fs_pegkey>-locid.

           APPEND lw_matloc TO li_matloc.

         ENDLOOP.

* Delete duplicates

*=========================================================*

         SORT li_loc_aux BY locid.

         DELETE ADJACENT DUPLICATES FROM li_loc_aux COMPARING locid.

         SORT li_mat_aux BY matid.

* Select Locations

*=========================================================*

         IF NOT li_loc_aux[] IS INITIAL.

           SELECT locid loctype locno

                  INTO TABLE li_loc

                  FROM /sapapo/loc

                  FOR ALL ENTRIES IN li_loc_aux

                  WHERE locid = li_loc_aux-locid.

         ENDIF.

* Select Products

*=========================================================*

         IF NOT li_mat_aux[] IS INITIAL.

           SELECT ext_matnr matid logsys

                  INTO TABLE li_matmap

                  FROM /sapapo/matmap

                  FOR ALL ENTRIES IN li_mat_aux

                  WHERE matid = li_mat_aux-matid.

         ENDIF.

* Delete duplicates comparing Logical system

*=========================================================*

         REFRESH li_mat_aux.

         li_mat_aux[] = li_matmap[].

         SORT li_mat_aux BY logsys.

         DELETE ADJACENT DUPLICATES FROM li_mat_aux COMPARING logsys.

* Include Logical System into intern table

*=========================================================*

         LOOP AT li_matloc ASSIGNING <fs_matloc>.

           READ TABLE li_matmap ASSIGNING <fs_matmap>

                                WITH KEY matid = <fs_matloc>-matid.

           <fs_matloc>-logsys = <fs_matmap>-logsys.

           MODIFY li_matloc FROM <fs_matloc>.

         ENDLOOP.

* Delete duplicates

*=========================================================*

         SORT li_matloc.

* Get orders

*=========================================================*

         LOOP AT li_mat_aux ASSIGNING <fs_mat_aux>.

           REFRESH li_prodloc.

           LOOP AT  li_matloc ASSIGNING <fs_matloc>

                              WHERE logsys = <fs_mat_aux>-logsys.

* Read Location

*=========================================================*

             READ TABLE li_loc ASSIGNING <fs_loc>

             WITH KEY locid = <fs_matloc>-locid.

* Read Products

*=========================================================*

             READ TABLE li_matmap ASSIGNING <fs_matmap>

             WITH KEY matid = <fs_matloc>-matid.

* Fill intern table

*=========================================================*

             lw_prodloc-product  = <fs_matmap>-ext_matnr.

             lw_prodloc-location = <fs_loc>-locno.

             lw_prodloc-loctype  = <fs_loc>-loctype.

             APPEND lw_prodloc TO li_prodloc.

           ENDLOOP.

         ENDLOOP.

         CLEAR: lw_prodloc.

         APPEND LINES OF li_prodloc TO lt_prodloc_aux1.

         DELETE ADJACENT DUPLICATES FROM lt_prodloc_aux1 COMPARING product.

         LOOP AT lt_prodloc_aux1 INTO lw_prodloc_aux1.

           CLEAR: lt_product, lw_product, lt_location, lw_location.

*Move dados que serao lidos pela bapi POSRVAPS_GETLIST3

           MOVE: 'I' TO lw_product-sign,

                 'EQ' TO lw_product-option,

                 lw_prodloc_aux1-product  TO lw_product-low. "<fs_mat_aux>-ext_matnr TO lw_product-low.

           APPEND lw_product TO lt_product.

*Move dados que serao lidos pela bapi POSRVAPS_GETLIST3

           LOOP AT li_loc INTO <fs_loc>.

             MOVE: 'I' TO lw_location-sign,

                   'EQ' TO lw_location-option,

                   <fs_loc>-locno TO lw_location-low.

             APPEND lw_location TO lt_location.

           ENDLOOP.

            lv_start_time = i_object_keys-start_planhorizon.

           lv_end_time   = i_object_keys-end_planhorizon.

           CALL FUNCTION 'BAPI_POSRVAPS_GETLIST3'

             EXPORTING

               logical_system     = <fs_mat_aux>-logsys

               start_time         = lv_start_time

               end_time           = lv_end_time

               plng_version       = lv_simverid

             TABLES

               product_selection  = lt_product

               location_selection = lt_location

               receipts           = lt_receipts.

*Tabela que recebeu as ordens de transferencia

           IF lt_receipts IS NOT INITIAL.

*Le as ordens de transferencia

             LOOP AT lt_receipts INTO lw_receipts.

*Move os dados para tabela que sera passada para BAPI POSRVAPS_SAVEMULTI3

               MOVE: lw_receipts-ordid         TO lw_poouti-ordid,

                     lw_receipts-order_number  TO lw_poouti-order_number,

                     lw_receipts-item_number   TO lw_poouti-item_number,

                     lw_receipts-sched_line    TO lw_poouti-sched_line,

                     lw_receipts-proc_type     TO lw_poouti-proc_type,

                     ' '                       TO lw_poouti-fixed.

               APPEND lw_poouti TO lt_poouti.

               MOVE: lw_receipts-ordid         TO lw_pooutix-ordid,

                     lw_receipts-order_number  TO lw_pooutix-order_number,

                     lw_receipts-item_number   TO lw_pooutix-item_number,

                     lw_receipts-sched_line    TO lw_pooutix-sched_line,

                     c_x                       TO lw_pooutix-fixed.

               APPEND lw_pooutix TO lt_pooutix.

             ENDLOOP.

* Change Orders

*=========================================================*

             CALL FUNCTION 'BAPI_POSRVAPS_SAVEMULTI3'

               EXPORTING

                 logical_system        = <fs_mat_aux>-logsys

                 order_type            = '1'

                 ext_number_assignment = ' '

                 commit_control        = 'E'

                 plng_version          = lv_simverid

                 event_control         = '1'

               TABLES

                 receipts              = lt_poouti

                 receipts_x            = lt_pooutix

                 return                = lt_return.

             CLEAR: lt_poouti, lt_pooutix, lt_return.

             REFRESH: lt_poouti, lt_pooutix, lt_return.

           ENDIF.

         ENDLOOP.

* Get orders for selected products

*=========================================================*

         IF NOT li_prodloc[] IS INITIAL.

           lv_start_time = i_object_keys-start_planhorizon.

           lv_end_time   = i_object_keys-end_planhorizon.

*          break exaleixo.

           CALL FUNCTION 'BAPI_MOSRVAPS_GETLIST2'

             EXPORTING

               logical_system        = <fs_mat_aux>-logsys

               start_time            = lv_start_time

               end_time              = lv_end_time

               plng_version          = lv_simverid

             TABLES

               product_location_keys = li_prodloc

               order_heads           = li_order_head

               return                = li_return.

*            activities            = li_activities.

           IF li_order_head IS NOT INITIAL.

             LOOP AT li_order_head INTO lw_order_head.

*            READ TABLE li_activities ASSIGNING <fs_activities>

*            WITH KEY ordid = lw_order_head-ordid

*                 acttype = 'P'.

*

*            CHECK sy-subrc EQ 0.

               lw_order-ordid = lw_order_head-ordid.

               lw_order-order_number = lw_order_head-order_number.

               lw_order-output_fixed = ' '.

               lw_order-master_atpcat = 'AI'.

               APPEND lw_order TO li_order.

               CLEAR lv_tabix.

               lw_order_x-ordid        = lw_order_head-ordid.

               lw_order_x-order_number = lw_order_head-order_number.

               lw_order_x-output_fixed = c_x.

               lw_order_x-master_atpcat = c_x.

               APPEND lw_order_x TO li_order_x.

               CALL FUNCTION 'BAPI_MOSRVAPS_SAVEMULTI3'

                 EXPORTING

                   logical_system         = <fs_mat_aux>-logsys

                   order_type             = '6'

                   ext_number_assignment  = ' '

                   commit_control         = 'E'

                   plng_version           = lv_simverid

                   check_source_existence = lv_check

                   event_control          = '1'

                 TABLES

                   order_head             = li_order

                   order_head_x           = li_order_x

                   return                 = li_return.

               CLEAR: li_return, li_order, li_order_x.

               REFRESH: li_return, li_order, li_order_x.

             ENDLOOP.

           ENDIF.

         ENDIF.

       ELSE.

         LOOP AT i_object_keys-pegid_tab INTO lw_pegid.

           APPEND lw_pegid TO li_pegid.

         ENDLOOP.

*=========================================================*

* Change simsessid

*=========================================================*

         IF NOT i_simsessid IS INITIAL.

           CALL FUNCTION '/SAPAPO/TSIM_SIMULATION_DELETE'

             EXPORTING

               iv_simsessid    = i_simsessid

               iv_simversid    = i_simverid

             EXCEPTIONS

               deleting_failed = 1

               OTHERS          = 2.

           IF sy-subrc NE 0.

             RAISE failed.

           ENDIF.

           CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_SET'

             EXPORTING

               iv_simsession = space.

         ENDIF.

* Get Pegging Area Information

*=========================================================*

         CALL FUNCTION '/SAPAPO/DM_PEGID_GET_PEGKEY'

           EXPORTING

             it_pegid  = li_pegid

           IMPORTING

             et_pegkey = li_pegkey.

* Fill intern tables

*=========================================================*

         LOOP AT li_pegkey ASSIGNING <fs_pegkey>.

           lw_loc-locid = <fs_pegkey>-locid.

           APPEND lw_loc TO li_loc_aux.

           lw_matmap-matid = <fs_pegkey>-matid.

           APPEND lw_matmap TO li_mat_aux.

           lw_matloc-matid = <fs_pegkey>-matid.

           lw_matloc-locid = <fs_pegkey>-locid.

           APPEND lw_matloc TO li_matloc.

         ENDLOOP.

* Delete duplicates

*=========================================================*

         SORT li_loc_aux BY locid.

         DELETE ADJACENT DUPLICATES FROM li_loc_aux COMPARING locid.

         SORT li_mat_aux BY matid.

* Select Locations

*=========================================================*

         IF NOT li_loc_aux[] IS INITIAL.

           SELECT locid loctype locno

                  INTO TABLE li_loc

                  FROM /sapapo/loc

                  FOR ALL ENTRIES IN li_loc_aux

                  WHERE locid = li_loc_aux-locid.

         ENDIF.

* Select Products

*=========================================================*

         IF NOT li_mat_aux[] IS INITIAL.

           SELECT ext_matnr matid logsys

                  INTO TABLE li_matmap

                  FROM /sapapo/matmap

                  FOR ALL ENTRIES IN li_mat_aux

                  WHERE matid = li_mat_aux-matid.

         ENDIF.

* Delete duplicates comparing Logical system

*=========================================================*

         REFRESH li_mat_aux.

         li_mat_aux[] = li_matmap[].

         SORT li_mat_aux BY logsys.

         DELETE ADJACENT DUPLICATES FROM li_mat_aux COMPARING logsys.

* Include Logical System into intern table

*=========================================================*

         LOOP AT li_matloc ASSIGNING <fs_matloc>.

           READ TABLE li_matmap ASSIGNING <fs_matmap>

                                WITH KEY matid = <fs_matloc>-matid.

           <fs_matloc>-logsys = <fs_matmap>-logsys.

           MODIFY li_matloc FROM <fs_matloc>.

         ENDLOOP.

* Delete duplicates

*=========================================================*

         SORT li_matloc.

* Get orders

*=========================================================*

         LOOP AT li_mat_aux ASSIGNING <fs_mat_aux>.

           REFRESH li_prodloc.

           LOOP AT  li_matloc ASSIGNING <fs_matloc>

                              WHERE logsys = <fs_mat_aux>-logsys.

* Read Location

*=========================================================*

             READ TABLE li_loc ASSIGNING <fs_loc>

             WITH KEY locid = <fs_matloc>-locid.

* Read Products

*=========================================================*

             READ TABLE li_matmap ASSIGNING <fs_matmap>

             WITH KEY matid = <fs_matloc>-matid.

* Fill intern table

*=========================================================*

             lw_prodloc-product  = <fs_matmap>-ext_matnr.

             lw_prodloc-location = <fs_loc>-locno.

             lw_prodloc-loctype  = <fs_loc>-loctype.

             APPEND lw_prodloc TO li_prodloc.

           ENDLOOP.

         ENDLOOP.

         CLEAR: lw_prodloc.

         APPEND LINES OF li_prodloc TO lt_prodloc_aux1.

         DELETE ADJACENT DUPLICATES FROM lt_prodloc_aux1 COMPARING product.

         LOOP AT lt_prodloc_aux1 INTO lw_prodloc_aux1.

           CLEAR: lt_product, lw_product, lt_location, lw_location.

*Move dados que serao lidos pela bapi POSRVAPS_GETLIST3

           MOVE: 'I' TO lw_product-sign,

                 'EQ' TO lw_product-option,

                 lw_prodloc_aux1-product  TO lw_product-low. "<fs_mat_aux>-ext_matnr TO lw_product-low.

           APPEND lw_product TO lt_product.

*Move dados que serao lidos pela bapi POSRVAPS_GETLIST3

           LOOP AT li_loc INTO <fs_loc>.

             MOVE: 'I' TO lw_location-sign,

                   'EQ' TO lw_location-option,

                   <fs_loc>-locno TO lw_location-low.

             APPEND lw_location TO lt_location.

           ENDLOOP.

            lv_start_time = i_object_keys-start_planhorizon.

           lv_end_time   = i_object_keys-end_planhorizon.

           CALL FUNCTION 'BAPI_POSRVAPS_GETLIST3'

             EXPORTING

               logical_system     = <fs_mat_aux>-logsys

               start_time         = lv_start_time

               end_time           = lv_end_time

               plng_version       = lv_simverid

             TABLES

               product_selection  = lt_product

               location_selection = lt_location

               receipts           = lt_receipts.

*Tabela que recebeu as ordens de transferencia

           IF lt_receipts IS NOT INITIAL.

*Le as ordens de transferencia

             LOOP AT lt_receipts INTO lw_receipts.

*Move os dados para tabela que sera passada para BAPI POSRVAPS_SAVEMULTI3

               MOVE: lw_receipts-ordid         TO lw_poouti-ordid,

                     lw_receipts-order_number  TO lw_poouti-order_number,

                     lw_receipts-item_number   TO lw_poouti-item_number,

                     lw_receipts-sched_line    TO lw_poouti-sched_line,

                     lw_receipts-proc_type     TO lw_poouti-proc_type,

                     c_x                       TO lw_poouti-fixed.

               APPEND lw_poouti TO lt_poouti.

               MOVE: lw_receipts-ordid         TO lw_pooutix-ordid,

                     lw_receipts-order_number  TO lw_pooutix-order_number,

                     lw_receipts-item_number   TO lw_pooutix-item_number,

                     lw_receipts-sched_line    TO lw_pooutix-sched_line,

                     c_x                       TO lw_pooutix-fixed.

               APPEND lw_pooutix TO lt_pooutix.

             ENDLOOP.

* Change Orders

*=========================================================*

             CALL FUNCTION 'BAPI_POSRVAPS_SAVEMULTI3'

               EXPORTING

                 logical_system        = <fs_mat_aux>-logsys

                 order_type            = '1'

                 ext_number_assignment = ' '

                 commit_control        = 'E'

                 plng_version          = lv_simverid

                 event_control         = '1'

               TABLES

                 receipts              = lt_poouti

                 receipts_x            = lt_pooutix

                 return                = lt_return.

             CLEAR: lt_poouti, lt_pooutix, lt_return.

             REFRESH: lt_poouti, lt_pooutix, lt_return.

           ENDIF.

         ENDLOOP.

* Get orders for selected products

*=========================================================*

         IF NOT li_prodloc[] IS INITIAL.

           lv_start_time = i_object_keys-start_planhorizon.

           lv_end_time   = i_object_keys-end_planhorizon.

           CALL FUNCTION 'BAPI_MOSRVAPS_GETLIST2'

             EXPORTING

               logical_system        = <fs_mat_aux>-logsys

               start_time            = lv_start_time

               end_time              = lv_end_time

               plng_version          = lv_simverid

             TABLES

               product_location_keys = li_prodloc

               order_heads           = li_order_head

               return                = li_return.

*            activities            = li_activities.

           IF li_order_head IS NOT INITIAL.

             LOOP AT li_order_head INTO lw_order_head.

*            READ TABLE li_activities ASSIGNING <fs_activities>

*            WITH KEY ordid = lw_order_head-ordid

*                 acttype = 'P'.

*

*            CHECK sy-subrc EQ 0.

               lw_order-ordid         = lw_order_head-ordid.

               lw_order-order_number  = lw_order_head-order_number.

               lw_order-output_fixed  = c_x.

               lw_order-master_atpcat = 'AJ'.

               APPEND lw_order TO li_order.

               CLEAR lv_tabix.

               lw_order_x-ordid         = lw_order_head-ordid.

               lw_order_x-order_number  = lw_order_head-order_number.

               lw_order_x-output_fixed  = c_x.

               lw_order_x-master_atpcat = c_x.

               APPEND lw_order_x TO li_order_x.

               CALL FUNCTION 'BAPI_MOSRVAPS_SAVEMULTI3'

                 EXPORTING

                   logical_system         = <fs_mat_aux>-logsys

                   order_type             = '6'

                   ext_number_assignment  = ' '

                   commit_control         = 'E'

                   plng_version           = lv_simverid

                   check_source_existence = lv_check

                   event_control          = '1'

                 TABLES

                   order_head             = li_order

                   order_head_x           = li_order_x

                   return                 = li_return.

               CLEAR: li_return, li_order, li_order_x.

               REFRESH: li_return, li_order, li_order_x.

             ENDLOOP.

           ENDIF.

         ENDIF.

       ENDIF.

     ENDIF.

   ENDIF.

*=========================================================*

* Create Simulation Session

*=========================================================*

   IF NOT i_simsessid IS INITIAL.

     CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_CREATE'

       EXPORTING

         iv_simsession = i_simsessid

         iv_simid      = i_simverid

         iv_cif_mode   = 'X'

       IMPORTING

         ev_simsession = i_simsessid

       EXCEPTIONS

         error_message = 1

         OTHERS        = 2.

     IF sy-subrc NE 0.

       RAISE failed.

     ENDIF.

   ENDIF.

ENDFUNCTION.