cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Delete and Create new schedule lines in procurement scheduling agreements in SAP APO

YayatiEkbote
Contributor
0 Likes
883

Hello experts,

I have a requirement to delete old schedule lines and create new schedule lines through file. I was working on FM /SAPAPO/DM_PO_CHANGE.

The schedule lines get deleted through the FM when passing the parameter 'Method' = 'D' "D for delete.

But when I map the file parameters to the it_schedule parameter of FM /SAPAPO/DM_PO_CHANGE with 'method' parameter = 'A' (A for Add) to create new schedule lines, I get 'LC_APP_ERROR' (sy-subrc = 3). I am unable to understand what parameters are necessary to be filled in it_schedule internal table to create new schedule lines.

Currently my code looks like below -

<Code>

     LOOP AT lt_file INTO ls_file.

          ls_schedule -method = 'A'. "A for add

          ls_schedule-orderid  = ls_file-orderid. " This gets populated by converting ebeln(scheduling agreement number) to orderid

          ls_schedule-itemno  = ls_file-itemno.

          ls_schedule-schedno = ls_file-schedno.


          CALL FUNCTION '/SAPAPO/DATE_CONVERT_TIMESTAMP'

                 EXPORTING

                   iv_date      = ls_file-avl_date

                   iv_time      = sy-uzeit

                 IMPORTING

                   ev_timestamp = ls_schedule-avail_time.

          CALL FUNCTION '/SAPAPO/DATE_CONVERT_TIMESTAMP'

                 EXPORTING

                   iv_date      = ls_file-ship_date

                   iv_time      = sy-uzeit

                 IMPORTING

                   ev_timestamp = ls_schedule-gi_end_time.

          ls_schedule-to_org_quantity = ls_file-sch_qty.

          ls_schedule-to_ext_fixed     = ls_file-fixed.

          APPEND ls_schedule TO lt_schedule.

     ENDLOOP.

     ls_gen_aprm-simversion = '000'.

CALL FUNCTION '/SAPAPO/DM_PO_CHANGE'

       EXPORTING

         is_gen_params     = ls_gen_parm

         it_schedule       = lt_schedule

       IMPORTING

         et_rc             = lt_rc

         et_sched_failures = lt_schd_fail

       EXCEPTIONS

         lc_connect_failed = 1

         lc_com_error      = 2

         lc_appl_error     = 3

         OTHERS            = 4.

</Code>

I am getting sy-subrc = '3'.

One thing I would like to add here is that

I am using following approach -

/SAPAPO/CMDS_TPSRC_GET - To get BZQID by passing EBELN from file.

/SAPAPO/PWB_BZQID_GET_ORDER - To get ORDERID in structure ES_ORDKEY By passing BZQID received from previous FM & IV_ORDER_TYPE = '16'.

If I pass iv_order_type as '16' (for scheduling agreement) then I get schedule line detials in FM /SAPPO/DM_PO_READ but if I pass iv_order_type as '17' (release plan) then I get release schedule in FM /SAPAPO/DM_PO_READ. ORDERID for type '16' is different than ORDERID for type '17'.

Once I delete schedule lines for order type '16', then I don't get order number for type '16' instead I get only details for order type '17'.

If this is the reason I am unable to add new schedule lines, could anyone please suggest a better approach? How to delete old schedule lines and create new schedule lines using FMs/Class methods?

Regards

Yayati Ekbote

View Entire Topic
YayatiEkbote
Contributor
0 Likes

Hello experts,

I have found a way to create schedule lines.

<Code>

LOOP AT lt_file INTO ls_file.

CALL FUNCTION '/SAPAPO/RRP_SOURCES_GET'

             EXPORTING

               iv_pegid         = lv_pegid                    "found previously using product  & location

               iv_quantity      = ls_file-sch_qty

               iv_reqdat        = ls_file-reqdat

               iv_dialog        = abap_false

               iv_buffer_flg    = abap_true

               iv_order_create  = abap_true

             IMPORTING

               et_source        = lt_source

               et_sources_valid = lt_src_vld

             EXCEPTIONS

               user_canceled    = 1

               not_qualified    = 2

               unknown_error    = 3

               OTHERS           = 4.

READ TABLE lt_src_vld INTO DATA(ls_src_vld) WITH KEY ebeln = ls_file-ebeln

                                                                                          ebelp = ls_file-itmno.

             IF sy-subrc IS INITIAL AND

                ls_src_vld IS NOT INITIAL.

               READ TABLE lt_source INTO DATA(ls_src) WITH KEY trpid = ls_src_vld-trpid.

               IF sy-subrc IS INITIAL AND

                  ls_src IS NOT INITIAL.

CALL FUNCTION '/SAPAPO/RRP_ORDER_CREATE'

       EXPORTING

         iv_pegid       = lv_pegid

         iv_quantity    = ls_file-sch_qty

         iv_scrap       = 0

         iv_rqmtti      = lv_reqtti          "date converted to time stamp

         iv_startti     = lv_strtti            "date converted to time stamp

         iv_firmed      = abap_true

         iv_priority    = 0

         is_source      = ls_src

         iv_application = lv_app

         iv_dialog      = abap_false

       IMPORTING

         ev_ordid       = ls_srec-ordid

         ev_schedid     = ls_srec-schedid

         ev_ordno       = ls_srec-ordno

         ev_position_no = ls_srec-posno

         ev_line_no     = ls_srec-linno

         ev_subrc       = ls_srec-subrc

         ev_actid       = ls_srec-actid

         ev_io_time     = ls_srec-iotim

         ev_ippe_id     = ls_srec-ippeid

         ev_no_inputs   = ls_srec-ipno


APPEND ls_rec TO lt_rec.

CLEAR ls_rec      .

ENDLOOP.

LOOP AT lt_rec INTO ls_rec WHERE subrc NE 0.

lv_fail = abap_true.

ENDLOOP.

IF lv_fail EQ abap_false.

COMMIT WORK.

ENDIF.

</Code>

But even if I do commit work, the newly created schedule lines are not saved to system.

Kindly let me know what I am missing.

I am having a doubt that some how global buffer tables are not getting filled.

If this is the case, can anyone let me know how to do it?

Regards,

Yayati Ekbote

YayatiEkbote
Contributor
0 Likes

Solved. I used methods of class /SAPAPO/CL_TDL_LC_DS_DAO.

Methods used in sequence -

/SCMB/IF_TDL_DAO_GENERAL~INIT

/SCMB/IF_TDL_DELIVERYSCHEDULE~SET

/SCMB/IF_TDL_DAO_GENERAL~SAVE_TO_DB

Thanks!!