cancel
Showing results for 
Search instead for 
Did you mean: 

Sample code for BAPI_PRICES_CONDITIONS

Former Member
0 Kudos
23,173

Hi guys!

Anyone, have a sample code of using the FM BAPI_PRICES_CONDITIONS??

regards

Martín.

Accepted Solutions (1)

Accepted Solutions (1)

ferry_lianto
Active Contributor

Hi Martin,

Please check this sample code from other thread.

wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.

APPEND wtable1 TO table1.


wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.


APPEND wtable2 TO table2.



wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.

APPEND wtable3 TO table3.


CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

loop at table6 into ret.

write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.

endloop.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.

APPEND wtable1 TO table1.


wtable2-operation = '009'.
wtable2-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.

APPEND wtable1 TO table1.


wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.


APPEND wtable2 TO table2.



wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.

APPEND wtable3 TO table3.


CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

loop at table6 into ret.

write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.

endloop.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.


APPEND wtable2 TO table2.



wtable3-operation = '009'.
wtable3-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.

APPEND wtable1 TO table1.


wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.


APPEND wtable2 TO table2.



wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.

APPEND wtable3 TO table3.


CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

loop at table6 into ret.

write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.

endloop.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.

APPEND wtable3 TO table3.


CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

loop at table6 into ret.

write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.

endloop.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.

Also there are other options:

- from LSMW the report RV14BTCI

- batch input to transaction XK15

- using FM modules RV_CONDITION* (e.g. _copy and _save)

Hope this will help.

Regards,

Ferry Lianto

Former Member
0 Kudos

Thank you Ferry!!!

Answers (6)

Answers (6)

0 Kudos

Hey Guys,

have a look at this link as well.

It explains how to use BAPI bapi_prices_conditions in detail.

https://blogs.sap.com/2019/07/22/how-to-use-bapi_prices_conditions-to-mass-upload-price-conditions/

vardhan_naik3
Explorer
0 Kudos

I wrote a code that can handle overlaps. This can be helpful.


FORM f_uploadprices .

   CONSTANTS: lcon_tcode  TYPE tcode  VALUE 'ZPRICEUPLOAD',

              lcon_name_sarea_curr  TYPE rvari_vnam VALUE 'SALESAREA_CURR',

              lcon_name_uom TYPE rvari_vnam VALUE 'UOM',

              lcon_value1_default TYPE tvarv_val VALUE 'DEFAULT',

              lcon_value1_other   TYPE tvarv_val VALUE 'OTHER',

              lcon_operation_009  TYPE msgfn VALUE '009',

              lcon_operation_004  TYPE msgfn VALUE '004',

              lcon_operation_003  TYPE msgfn VALUE '003',

              lcon_table_no_900   TYPE kotabnr VALUE '900',

              lcon_table_no_923   TYPE kotabnr VALUE '923',

              lcon_applicatio_v   TYPE kappl   VALUE 'V',

              lcon_cond_type_j3ap TYPE kschl   VALUE 'J3AP',

              lcon_scale_type_c   TYPE stfkz   VALUE 'C',

              lcon_calc_type_c    TYPE krech   VALUE 'C',

              lcon_valid_to       TYPE kodatbi VALUE '99991231',

              lcon_cond_usage_a   TYPE kvewe VALUE 'A',

              lcon_knumh_i        TYPE knumh VALUE '$000000001',

              lcon_knumh_test        TYPE knumh VALUE 'TESTMODE',

              lcon_cond_count_i   TYPE kopos VALUE '01'.

   TYPES: BEGIN OF t_zparams_sarea_curr,

           vkorg TYPE vkorg,

           vtweg TYPE vtweg,

           spart TYPE spart,

           waerk TYPE waerk,

          END OF t_zparams_sarea_curr,

          BEGIN OF t_zparams_uom,

           kmein TYPE kvmei,

           kpein(5) TYPE c, "kpein,

          END OF t_zparams_uom,

          BEGIN OF t_varkey_a900_header,

             vkorg TYPE vkorg,

             vtweg  TYPE vtweg,

             spart  TYPE spart,

             pltyp  TYPE pltyp,

             waerk  TYPE waerk,

             matnr  TYPE matnr,

          END OF t_varkey_a900_header,

*         BEGIN OF t_varkey_a900_item,

*            VKORG type VKORG,

*            VTWEG  type VTWEG,

*            SPART  type SPART,

*            PLTYP  type PLTYP,

*            WAERK  type WAERK,

*            MATNR  type MATNR,

*         END OF t_varkey_a900_item,

          BEGIN OF t_varkey_a923_header,

             vkorg TYPE vkorg,

             vtweg  TYPE vtweg,

             spart  TYPE spart,

            kunnr  TYPE kunnr_v,

             pltyp  TYPE pltyp,

             waerk  TYPE waerk,

             matnr  TYPE matnr,

          END OF t_varkey_a923_header,

*         BEGIN OF t_varkey_a923_item,

*            VKORG type VKORG,

*            VTWEG  type VTWEG,

*            SPART  type SPART,

*            KUNNR  type KUNNR_V,

*            PLTYP  type PLTYP,

*            WAERK  type WAERK,

*            MATNR  type MATNR,

*         END OF t_varkey_a923_item,

          BEGIN OF t_tvko,

            vkorg TYPE vkorg,

          END OF t_tvko,

          BEGIN OF t_tvtw,

            vtweg TYPE vtweg,

          END OF t_tvtw,

          BEGIN OF t_tspa,

            spart TYPE spart,

          END OF t_tspa,

          BEGIN OF t_tvta,

            vkorg TYPE vkorg,

            vtweg TYPE vtweg,

            spart TYPE spart,

          END OF t_tvta,

          BEGIN OF t_mara,

            matnr TYPE matnr,

          END OF t_mara,

          BEGIN OF t_mvke,

            matnr TYPE matnr,

            vkorg TYPE vkorg,

            vtweg TYPE vtweg,

          END OF t_mvke,

          BEGIN OF t_t006,

            msehi TYPE  msehi,

          END OF t_t006,

          BEGIN OF t_tcurc,

             waers TYPE waers_curc,

          END OF t_tcurc,

          BEGIN OF t_kna1,

            kunnr TYPE kunnr,

          END OF t_kna1,

          BEGIN OF t_knvv,

            kunnr TYPE kunnr,

            vkorg TYPE vkorg,

            vtweg TYPE vtweg,

            spart TYPE spart,

          END OF t_knvv,

          BEGIN OF t_a9xx,

            knumh    TYPE knumh,

            datab    TYPE datab,

            datbi    TYPE datbi,

            kbetr    TYPE  kbetr_kond,

            loevm_ko  TYPE loevm_ko,

          END OF t_a9xx.

   DATA: lt_bapicondct TYPE STANDARD TABLE OF bapicondct,

         lt_bapicondhd TYPE STANDARD TABLE OF bapicondhd,

         lt_bapicondit TYPE STANDARD TABLE OF bapicondit,

         lt_bapicondqs TYPE STANDARD TABLE OF bapicondqs,

         lt_bapicondvs TYPE STANDARD TABLE OF bapicondvs,

         lt_a9xx       TYPE STANDARD TABLE OF t_a9xx,

         lv_tabix      like sy-tabix,

         lv_knumh      TYPE knumh,

         lv_same_recfound TYPE c,

         lt_a9xx_deleted       TYPE STANDARD TABLE OF t_a9xx,

*        ls_a9xx       TYPE t_a9xx,

         lte_bapiret2  TYPE STANDARD TABLE OF bapiret2,

         lte_bapiknumhs  TYPE STANDARD TABLE OF bapiknumhs,

         lte_mem_initial TYPE STANDARD TABLE OF cnd_mem_initial,

         ls_bapicondct TYPE bapicondct,

         ls_bapicondhd TYPE bapicondhd,

         ls_bapicondit TYPE bapicondit,

         ls_bapicondqs TYPE bapicondqs,

         ls_bapicondvs TYPE bapicondvs,

         lse_bapiret2  TYPE bapiret2,

         lse_bapiknumhs        TYPE bapiknumhs,

         lse_mem_initial       TYPE cnd_mem_initial,

         lt_zsd_pricelist TYPE STANDARD TABLE OF zsd_pricelist,

*        lt_zparams_uom        TYPE STANDARD TABLE OF zparams,

*        ls_zparams_value1_uom TYPE tvarv_val,

*        ls_zparams_uom        TYPE t_zparams_uom,

         ls_varkey_a900_header TYPE t_varkey_a900_header,

*        ls_varkey_a900_item   type t_varkey_a900_item,

         ls_varkey_a923_header TYPE t_varkey_a923_header,

*        ls_varkey_a923_item   type t_varkey_a900_item,

         ls_varkey_header(100) TYPE c,

         ls_varkey_item(100)   TYPE c,

         lt_tvko TYPE STANDARD TABLE OF t_tvko,

         lt_tvtw TYPE STANDARD TABLE OF t_tvtw,

         lt_tspa TYPE STANDARD TABLE OF t_tspa,

         lt_tvta TYPE STANDARD TABLE OF t_tvta,

         lt_mara TYPE STANDARD TABLE OF t_mara,

         lt_mvke TYPE STANDARD TABLE OF t_mvke,

         lt_t006 TYPE STANDARD TABLE OF t_t006,

         lt_tcurc TYPE STANDARD TABLE OF t_tcurc,

         lt_kna1  TYPE STANDARD TABLE OF t_kna1,

         lt_knvv  TYPE STANDARD TABLE OF t_knvv,

         lt_upload_j3ap_kunnr TYPE STANDARD TABLE OF t_upload_j3ap.

   FIELD-SYMBOLS: <fs_lt_bapicondct> LIKE LINE OF lt_bapicondct,

                  <fs_lt_bapicondhd> LIKE LINE OF lt_bapicondhd ,

                  <fs_lt_bapicondit> LIKE LINE OF lt_bapicondit ,

                  <fs_lt_bapicondqs> LIKE LINE OF lt_bapicondqs ,

                  <fs_lt_bapicondvs> LIKE LINE OF lt_bapicondvs ,

                  <fs_lte_bapiret2>  LIKE LINE OF lte_bapiret2  ,

                  <fs_lte_bapiknumhs> LIKE LINE OF lte_bapiknumhs ,

                  <fs_lte_mem_initial> LIKE LINE OF lte_mem_initial,

                  <fs_lt_zsd_pricelist> LIKE LINE OF lt_zsd_pricelist,

*                 <fs_lt_zparams_sarea_curr> LIKE LINE OF lt_zparams_sarea_curr,

*                 <fs_lt_zparams_uom>  LIKE LINE OF lt_zparams_uom,

                  <fs_lt_tvko> LIKE LINE OF lt_tvko ,

                  <fs_lt_a9xx> LIKE LINE OF lt_a9xx,

                  <fs_lt_a9xx_deleted> LIKE LINE OF lt_a9xx_deleted,

                  <fs_lt_tvtw> LIKE LINE OF lt_tvtw,

                  <fs_lt_tspa> LIKE LINE OF lt_tspa,

                  <fs_lt_tvta> LIKE LINE OF lt_tvta,

                  <fs_lt_mara> LIKE LINE OF lt_mara,

                  <fs_lt_mvke> LIKE LINE OF lt_mvke,

                  <fs_lt_t006> LIKE LINE OF lt_t006,

                  <fs_lt_tcurc> LIKE LINE OF lt_tcurc,

                  <fs_lt_kna1> LIKE LINE OF lt_kna1,

                  <fs_lt_knvv> LIKE LINE OF lt_knvv.

   REFRESH: gt_output_j3ap[].

   SELECT * FROM zsd_pricelist

         INTO TABLE lt_zsd_pricelist.

*  SELECT * FROM zparams

*        INTO TABLE lt_zparams_uom

*        WHERE tcode = lcon_tcode AND

*              name  = lcon_name_uom.

*  IF p_uomd = abap_true.

*    ls_zparams_value1_uom  = lcon_value1_default.

*  ELSEIF p_uomo = abap_true.

*    ls_zparams_value1_uom = lcon_value1_other.

*  ENDIF.

*  CLEAR: ls_zparams_uom.

*  LOOP AT lt_zparams_uom ASSIGNING <fs_lt_zparams_uom>

*      WHERE value1 = ls_zparams_value1_uom.

*

*    MOVE <fs_lt_zparams_uom>-value2 TO ls_zparams_uom.

*  ENDLOOP.

   SELECT msehi FROM t006

          INTO TABLE lt_t006

          WHERE msehi = p_kmein. "ls_zparams_uom+0(3).

   IF lt_zsd_pricelist[] IS NOT INITIAL.

     SELECT vkorg FROM tvko

            INTO TABLE lt_tvko

            FOR ALL ENTRIES IN lt_zsd_pricelist

            WHERE vkorg = lt_zsd_pricelist-vkorg.

     SORT lt_tvko BY vkorg.

     DELETE ADJACENT DUPLICATES FROM lt_tvko COMPARING vkorg.

     SELECT vtweg FROM tvtw

             INTO TABLE lt_tvtw

             FOR ALL ENTRIES IN lt_zsd_pricelist

             WHERE vtweg = lt_zsd_pricelist-vtweg.

     SORT lt_tvtw BY vtweg.

     DELETE ADJACENT DUPLICATES FROM lt_tvtw COMPARING vtweg.

     SELECT spart FROM tspa

             INTO TABLE lt_tspa

             FOR ALL ENTRIES IN lt_zsd_pricelist

             WHERE spart = lt_zsd_pricelist-spart.

     SORT lt_tspa BY spart.

     DELETE ADJACENT DUPLICATES FROM lt_tspa COMPARING spart.

     SELECT vkorg

            vtweg

            spart FROM tvta INTO TABLE lt_tvta

            FOR ALL ENTRIES IN lt_zsd_pricelist

            WHERE vkorg = lt_zsd_pricelist-vkorg AND

                  vtweg = lt_zsd_pricelist-vtweg AND

                  spart = lt_zsd_pricelist-spart.

     SORT lt_tvta BY vkorg vtweg spart.

     DELETE ADJACENT DUPLICATES FROM lt_tvta

            COMPARING vkorg vtweg spart.

     SELECT waers FROM tcurc

             INTO TABLE lt_tcurc

             FOR ALL ENTRIES IN lt_zsd_pricelist

             WHERE waers = lt_zsd_pricelist-waerk.

     SORT lt_tcurc BY waers.

     DELETE ADJACENT DUPLICATES FROM lt_tcurc

            COMPARING waers.

   ENDIF.

   IF gt_upload_j3ap[] IS NOT INITIAL.

     SELECT matnr FROM mara

            APPENDING TABLE lt_mara

            PACKAGE SIZE 3000

            FOR ALL ENTRIES IN gt_upload_j3ap

            WHERE matnr = gt_upload_j3ap-matnr.

     ENDSELECT.

     SORT lt_mara BY matnr.

     DELETE ADJACENT DUPLICATES FROM lt_mara

          COMPARING matnr.

     lt_upload_j3ap_kunnr[] = gt_upload_j3ap[].

     DELETE lt_upload_j3ap_kunnr WHERE kunnr IS INITIAL.

     IF lt_upload_j3ap_kunnr[] IS NOT INITIAL.

       SELECT kunnr FROM kna1

              APPENDING TABLE lt_kna1

              PACKAGE SIZE 3000

              FOR ALL ENTRIES IN lt_upload_j3ap_kunnr

              WHERE kunnr = lt_upload_j3ap_kunnr-kunnr.

       ENDSELECT.

       SORT lt_kna1 BY kunnr.

       DELETE ADJACENT DUPLICATES FROM lt_kna1

       COMPARING kunnr.

     ENDIF.

     LOOP AT lt_tvta ASSIGNING <fs_lt_tvta>.

       AT NEW vtweg.

         IF gt_upload_j3ap[] IS NOT INITIAL.

           SELECT matnr

                  vkorg

                  vtweg  FROM mvke

                APPENDING TABLE lt_mvke

                PACKAGE SIZE 3000

                FOR ALL ENTRIES IN gt_upload_j3ap

                WHERE matnr = gt_upload_j3ap-matnr AND

                      vkorg = <fs_lt_tvta>-vkorg AND

                      vtweg = <fs_lt_tvta>-vtweg.

           ENDSELECT.

         ENDIF.

       ENDAT.

       IF lt_upload_j3ap_kunnr[] IS NOT INITIAL.

         SELECT kunnr

                vkorg

                vtweg

                spart FROM knvv

              APPENDING TABLE lt_knvv

              PACKAGE SIZE 3000

              FOR ALL ENTRIES IN lt_upload_j3ap_kunnr

              WHERE kunnr = lt_upload_j3ap_kunnr-kunnr AND

                    vkorg = <fs_lt_tvta>-vkorg AND

                    vtweg = <fs_lt_tvta>-vtweg AND

                    spart = <fs_lt_tvta>-spart.

         ENDSELECT.

       ENDIF.

     ENDLOOP.

   ENDIF.

   LOOP AT gt_upload_j3ap ASSIGNING <fs_gt_upload_j3ap>.

     gs_output_j3ap-kunnr = <fs_gt_upload_j3ap>-kunnr.

     gs_output_j3ap-matnr = <fs_gt_upload_j3ap>-matnr.

     gs_output_j3ap-pltyp = <fs_gt_upload_j3ap>-pltyp.

     gs_output_j3ap-kwert = <fs_gt_upload_j3ap>-kwert.

     gs_output_j3ap-datab = <fs_gt_upload_j3ap>-datab.

     gs_output_j3ap-kpein = p_kpein.

     gs_output_j3ap-kmein = p_kmein.

*    ls_zparams_value2_sarea_curr = <fs_gt_upload_j3ap>-pltyp.

     CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'

       EXPORTING

         date                      = <fs_gt_upload_j3ap>-datab

       EXCEPTIONS

         plausibility_check_failed = 1

         OTHERS                    = 2.

     IF sy-subrc IS NOT INITIAL.

       gs_output_j3ap-icon     = icon_cancel.

       gs_output_j3ap-icontext = 'Invalid date'.

       APPEND gs_output_j3ap TO gt_output_j3ap.

       CHECK 1 = 2.

     ELSE.

     ENDIF.

     LOOP AT lt_zsd_pricelist ASSIGNING <fs_lt_zsd_pricelist>

          WHERE pltyp = <fs_gt_upload_j3ap>-pltyp.

       CLEAR: gs_output_j3ap.

       REFRESH: lt_bapicondct[],

                lt_bapicondhd[],

                lt_bapicondit[],

                lt_bapicondqs[],

                lt_bapicondvs[],

                lte_bapiret2[],

                lte_bapiknumhs[],

                lte_mem_initial[].

       CLEAR:   ls_bapicondct,

                ls_bapicondhd,

                ls_bapicondit,

                ls_bapicondqs,

                ls_bapicondvs,

                lse_bapiret2,

                lse_bapiknumhs,

                lse_mem_initial,

                ls_varkey_header,

                ls_varkey_item,

                ls_varkey_a900_header,

*               ls_varkey_a900_item,

                ls_varkey_a923_header.

*               ls_varkey_a923_item.

       gs_output_j3ap-vkorg = <fs_lt_zsd_pricelist>-vkorg.

       gs_output_j3ap-vtweg = <fs_lt_zsd_pricelist>-vtweg.

       gs_output_j3ap-spart = <fs_lt_zsd_pricelist>-spart.

       gs_output_j3ap-kunnr = <fs_gt_upload_j3ap>-kunnr.

       gs_output_j3ap-matnr = <fs_gt_upload_j3ap>-matnr.

       gs_output_j3ap-pltyp = <fs_gt_upload_j3ap>-pltyp.

       gs_output_j3ap-kwert = <fs_gt_upload_j3ap>-kwert.

       gs_output_j3ap-waerk = <fs_lt_zsd_pricelist>-waerk.

       gs_output_j3ap-datab = <fs_gt_upload_j3ap>-datab.

       gs_output_j3ap-kpein = p_kpein.

       gs_output_j3ap-kmein = p_kmein.

       READ TABLE lt_tvko ASSIGNING <fs_lt_tvko>

            WITH KEY vkorg = gs_output_j3ap-vkorg.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Sales organization'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_tvtw ASSIGNING <fs_lt_tvtw>

            WITH KEY vtweg = gs_output_j3ap-vtweg.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Distribution channel'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_tspa ASSIGNING <fs_lt_tspa>

           WITH KEY spart = gs_output_j3ap-spart.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Division'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_tvta ASSIGNING <fs_lt_tvta>

           WITH KEY  vkorg = gs_output_j3ap-vkorg

                     vtweg = gs_output_j3ap-vtweg

                     spart = gs_output_j3ap-spart.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Sales Area'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_t006 ASSIGNING <fs_lt_t006>

           WITH KEY   msehi = gs_output_j3ap-kmein.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Condition Unit'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_tcurc ASSIGNING <fs_lt_tcurc>

           WITH KEY waers = gs_output_j3ap-waerk.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Currency'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       READ TABLE lt_mara ASSIGNING <fs_lt_mara>

            WITH KEY matnr = gs_output_j3ap-matnr.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Incorrect Material'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       IF gs_output_j3ap-kunnr IS NOT INITIAL.

         READ TABLE lt_kna1 ASSIGNING <fs_lt_kna1>

             WITH KEY kunnr = gs_output_j3ap-kunnr.

         IF sy-subrc IS NOT INITIAL.

           gs_output_j3ap-icon = icon_cancel.

           gs_output_j3ap-icontext = 'Incorrect Customer'.

           APPEND gs_output_j3ap TO gt_output_j3ap.

           CHECK 1 = 2.

         ENDIF.

       ENDIF.

       READ TABLE lt_mvke ASSIGNING <fs_lt_mvke>

           WITH KEY matnr = gs_output_j3ap-matnr

                    vkorg = gs_output_j3ap-vkorg

                    vtweg = gs_output_j3ap-vtweg.

       IF sy-subrc IS NOT INITIAL.

         gs_output_j3ap-icon = icon_cancel.

         gs_output_j3ap-icontext = 'Material is not extended to Sales Area'.

         APPEND gs_output_j3ap TO gt_output_j3ap.

         CHECK 1 = 2.

       ENDIF.

       IF gs_output_j3ap-kunnr IS NOT INITIAL.

         READ TABLE lt_knvv ASSIGNING <fs_lt_knvv>

             WITH KEY kunnr = gs_output_j3ap-kunnr

                      vkorg = gs_output_j3ap-vkorg

                      vtweg = gs_output_j3ap-vtweg

                      spart = gs_output_j3ap-spart.

         IF sy-subrc IS NOT INITIAL.

           gs_output_j3ap-icon = icon_cancel.

           gs_output_j3ap-icontext = 'Customer is not extended to Sales Area'.

           APPEND gs_output_j3ap TO gt_output_j3ap.

           CHECK 1 = 2.

         ENDIF.

       ENDIF.

       ls_bapicondct-operation       = lcon_operation_009.

       ls_bapicondct-cond_usage      = lcon_cond_usage_a .

       IF p_a900 = abap_true.

*        refresh lt_a900[].

*        if sy-subrc is NOT INITIAL.

*        endif.

         ls_bapicondct-table_no      = lcon_table_no_900.

         ls_varkey_a900_header-vkorg = <fs_lt_zsd_pricelist>-vkorg.

         ls_varkey_a900_header-vtweg = <fs_lt_zsd_pricelist>-vtweg.

         ls_varkey_a900_header-spart = <fs_lt_zsd_pricelist>-spart.

         ls_varkey_a900_header-pltyp = <fs_gt_upload_j3ap>-pltyp.

         ls_varkey_a900_header-matnr = <fs_gt_upload_j3ap>-matnr.

         ls_varkey_a900_header-waerk = <fs_lt_zsd_pricelist>-waerk.

         ls_varkey_header            = ls_varkey_a900_header.

       ELSEIF p_a923 = abap_true.

*        select single knumh from a923 INTO ls_bapicondct-cond_no

*            where kappl = lcon_applicatio_v and

*                  kschl = lcon_cond_type_j3ap and

*                  vkorg = <fs_lt_zsd_pricelist>-vkorg and

*                  vtweg = <fs_lt_zsd_pricelist>-vtweg and

*                  spart = <fs_lt_zsd_pricelist>-spart and

*                  pltyp = <fs_gt_upload_j3ap>-pltyp   and

*                  kunnr = <fs_gt_upload_j3ap>-kunnr   and

*                  waerk = <fs_lt_zsd_pricelist>-waerk and

*                  DATBI GE <fs_gt_upload_j3ap>-datab and

*                  datab LE <fs_gt_upload_j3ap>-datab.

*        if sy-subrc is NOT INITIAL.

*        endif.

         ls_bapicondct-table_no      = lcon_table_no_923.

         ls_varkey_a923_header-vkorg = <fs_lt_zsd_pricelist>-vkorg.

         ls_varkey_a923_header-vtweg = <fs_lt_zsd_pricelist>-vtweg.

         ls_varkey_a923_header-spart = <fs_lt_zsd_pricelist>-spart.

         ls_varkey_a923_header-pltyp = <fs_gt_upload_j3ap>-pltyp.

         ls_varkey_a923_header-kunnr = <fs_gt_upload_j3ap>-kunnr.

         ls_varkey_a923_header-matnr = <fs_gt_upload_j3ap>-matnr.

         ls_varkey_a923_header-waerk = <fs_lt_zsd_pricelist>-waerk.

         ls_varkey_header            = ls_varkey_a923_header.

       ENDIF.

       IF p_test IS INITIAL.

         ls_bapicondct-cond_no         = lcon_knumh_i .

       ELSE.

         ls_bapicondct-cond_no         = lcon_knumh_test.

       ENDIF.

       CLEAR: lv_knumh,

              lv_same_recfound.

       lv_knumh = ls_bapicondct-cond_no .

       ls_bapicondct-applicatio      = lcon_applicatio_v .

       ls_bapicondct-cond_type       = lcon_cond_type_j3ap.

       ls_bapicondct-varkey          = ls_varkey_header.

       ls_bapicondct-valid_to        = lcon_valid_to.

*      ls_bapicondct-agree_cond

       ls_bapicondct-valid_from      = <fs_gt_upload_j3ap>-datab.

*      ls_bapicondct-vadat

       APPEND ls_bapicondct TO lt_bapicondct.

       REFRESH: lt_a9xx[],

                lt_a9xx_deleted[].

       IF p_a900 = abap_true.

         SELECT  a900~knumh

                        a900~datab

                        a900~datbi

                        konp~kbetr

                        konp~loevm_ko

                        FROM a900

                        INNER JOIN konp

                        ON a900~knumh = konp~knumh

                        INTO TABLE lt_a9xx

             WHERE a900~kappl = lcon_applicatio_v AND

                   a900~kschl = lcon_cond_type_j3ap AND

                   a900~vkorg = <fs_lt_zsd_pricelist>-vkorg AND

                   a900~vtweg = <fs_lt_zsd_pricelist>-vtweg AND

                   a900~spart = <fs_lt_zsd_pricelist>-spart AND

                   a900~pltyp = <fs_gt_upload_j3ap>-pltyp   AND

                   a900~waerk = <fs_lt_zsd_pricelist>-waerk AND

                   a900~matnr = <fs_gt_upload_j3ap>-matnr AND

                   a900~datbi LE lcon_valid_to  AND

                   a900~datbi GE <fs_gt_upload_j3ap>-datab AND

                   a900~datab LE <fs_gt_upload_j3ap>-datab ." and

*                  konp~LOEVM_KO = space.

         SELECT  a900~knumh

                        a900~datab

                        a900~datbi

                        konp~kbetr

                        konp~loevm_ko

                        FROM a900

                        INNER JOIN konp

                        ON a900~knumh = konp~knumh

                        INTO TABLE lt_a9xx_deleted

             WHERE a900~kappl = lcon_applicatio_v AND

                   a900~kschl = lcon_cond_type_j3ap AND

                   a900~vkorg = <fs_lt_zsd_pricelist>-vkorg AND

                   a900~vtweg = <fs_lt_zsd_pricelist>-vtweg AND

                   a900~spart = <fs_lt_zsd_pricelist>-spart AND

                   a900~pltyp = <fs_gt_upload_j3ap>-pltyp   AND

                   a900~waerk = <fs_lt_zsd_pricelist>-waerk AND

                   a900~matnr = <fs_gt_upload_j3ap>-matnr AND

                   a900~datbi LT lcon_valid_to  AND

                   a900~datab GE <fs_gt_upload_j3ap>-datab ."and

*                  konp~LOEVM_KO = space.

       ELSE.

         SELECT         a923~knumh

                        a923~datab

                        a923~datbi

                        konp~kbetr

                        konp~loevm_ko

                        FROM a923

                        INNER JOIN konp

                        ON a923~knumh = konp~knumh

                        INTO TABLE lt_a9xx

             WHERE a923~kappl = lcon_applicatio_v AND

                   a923~kschl = lcon_cond_type_j3ap AND

                   a923~vkorg = <fs_lt_zsd_pricelist>-vkorg AND

                   a923~vtweg = <fs_lt_zsd_pricelist>-vtweg AND

                   a923~spart = <fs_lt_zsd_pricelist>-spart AND

                   a923~kunnr = <fs_gt_upload_j3ap>-kunnr   AND

                   a923~pltyp = <fs_gt_upload_j3ap>-pltyp   AND

                   a923~waerk = <fs_lt_zsd_pricelist>-waerk AND

                   a923~matnr = <fs_gt_upload_j3ap>-matnr AND

                   a923~datbi LE lcon_valid_to  AND

                   a923~datbi GE <fs_gt_upload_j3ap>-datab AND

                   a923~datab LE <fs_gt_upload_j3ap>-datab ." and

*                  konp~LOEVM_KO = space.

         SELECT         a923~knumh

                        a923~datab

                        a923~datbi

                        konp~kbetr

                        konp~loevm_ko

                        FROM a923

                        INNER JOIN konp

                        ON a923~knumh = konp~knumh

                        INTO TABLE lt_a9xx_deleted

             WHERE a923~kappl = lcon_applicatio_v AND

                   a923~kschl = lcon_cond_type_j3ap AND

                   a923~vkorg = <fs_lt_zsd_pricelist>-vkorg AND

                   a923~vtweg = <fs_lt_zsd_pricelist>-vtweg AND

                   a923~spart = <fs_lt_zsd_pricelist>-spart AND

                   a923~kunnr = <fs_gt_upload_j3ap>-kunnr   AND

                   a923~pltyp = <fs_gt_upload_j3ap>-pltyp   AND

                   a923~waerk = <fs_lt_zsd_pricelist>-waerk AND

                   a923~matnr = <fs_gt_upload_j3ap>-matnr AND

                   a923~datbi LT lcon_valid_to AND

                   a923~datab GE <fs_gt_upload_j3ap>-datab." and

*                  konp~LOEVM_KO = space.

       ENDIF.

       LOOP AT lt_a9xx ASSIGNING <fs_lt_a9xx>.

          lv_tabix = sy-tabix.

          READ TABLE lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>

               with key knumh = <fs_lt_a9xx>-knumh.

         if sy-subrc is INITIAL.

           delete lt_a9xx index lv_tabix.

           continue.

         endif.

         ls_bapicondct-cond_no    = <fs_lt_a9xx>-knumh.

         ls_bapicondct-operation  = lcon_operation_004.

         ls_bapicondct-valid_from = <fs_lt_a9xx>-datab.

         ls_bapicondct-valid_to   = <fs_lt_a9xx>-datbi .

         LOOP AT lt_bapicondct ASSIGNING <fs_lt_bapicondct>

             WHERE valid_from = ls_bapicondct-valid_from AND

                   valid_to   = lcon_valid_to AND

                   ( cond_no = lcon_knumh_i OR

                     cond_no = lcon_knumh_test ) .

           <fs_lt_bapicondct>-cond_no = ls_bapicondct-cond_no.

           lv_knumh = <fs_lt_bapicondct>-cond_no.

           lv_same_recfound = abap_true.

           EXIT.

         ENDLOOP.

         IF sy-subrc IS NOT INITIAL.

           <fs_lt_a9xx>-datbi       = <fs_gt_upload_j3ap>-datab - 1.

           ls_bapicondct-valid_to   = <fs_lt_a9xx>-datbi .

           APPEND ls_bapicondct TO lt_bapicondct.

         ENDIF.

       ENDLOOP.

       IF p_del IS INITIAL.

         DELETE lt_a9xx_deleted WHERE loevm_ko NE space.

       ENDIF.

       LOOP AT lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>.

         ls_bapicondct-cond_no    = <fs_lt_a9xx_deleted>-knumh.

         ls_bapicondct-operation  = lcon_operation_003.

         ls_bapicondct-valid_from = <fs_lt_a9xx_deleted>-datab.

         ls_bapicondct-valid_to   = <fs_lt_a9xx_deleted>-datbi.

         APPEND ls_bapicondct TO lt_bapicondct.

       ENDLOOP.

       ls_bapicondhd-operation      = lcon_operation_009.

       IF p_test IS INITIAL.

         ls_bapicondhd-cond_no        = lcon_knumh_i .

       ELSE.

         ls_bapicondhd-cond_no        = lcon_knumh_test .

       ENDIF.

       ls_bapicondhd-created_by     = sy-uname.

       ls_bapicondhd-creat_date     = sy-datum.

       ls_bapicondhd-cond_usage     = lcon_cond_usage_a .

       ls_bapicondhd-table_no       = ls_bapicondct-table_no.

       ls_bapicondhd-applicatio     = lcon_applicatio_v .

       ls_bapicondhd-cond_type      = lcon_cond_type_j3ap.

       ls_bapicondhd-varkey         = ls_varkey_header.

       ls_bapicondhd-valid_from     = <fs_gt_upload_j3ap>-datab.

       ls_bapicondhd-valid_to       = lcon_valid_to.

       APPEND ls_bapicondhd TO lt_bapicondhd.

       LOOP AT lt_a9xx ASSIGNING <fs_lt_a9xx>.

         ls_bapicondhd-cond_no    = <fs_lt_a9xx>-knumh.

         ls_bapicondhd-operation  = lcon_operation_004.

         ls_bapicondhd-valid_from = <fs_lt_a9xx>-datab.

         ls_bapicondhd-valid_to   = <fs_lt_a9xx>-datbi.

         LOOP AT lt_bapicondhd ASSIGNING <fs_lt_bapicondhd>

             WHERE valid_from = ls_bapicondhd-valid_from AND

                   valid_to   = lcon_valid_to AND

                   ( cond_no = lcon_knumh_i OR

                     cond_no = lcon_knumh_test ) .

           <fs_lt_bapicondhd>-cond_no = ls_bapicondhd-cond_no.

           EXIT.

         ENDLOOP.

         IF sy-subrc IS NOT INITIAL.

           APPEND ls_bapicondhd TO lt_bapicondhd.

         ENDIF.

       ENDLOOP.

       LOOP AT lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>.

         ls_bapicondhd-cond_no    = <fs_lt_a9xx_deleted>-knumh.

         ls_bapicondhd-operation  = lcon_operation_003.

         ls_bapicondhd-valid_from = <fs_lt_a9xx_deleted>-datab.

         ls_bapicondhd-valid_to   = <fs_lt_a9xx_deleted>-datbi.

         APPEND ls_bapicondhd TO lt_bapicondhd.

       ENDLOOP.

       ls_bapicondit-operation    = lcon_operation_009.

*      sd_doc

*      itm_number

       IF p_test IS INITIAL.

         ls_bapicondit-cond_no      = lcon_knumh_i .

       ELSE.

         ls_bapicondit-cond_no      = lcon_knumh_test .

       ENDIF.

       ls_bapicondit-cond_count   = lcon_cond_count_i .

       ls_bapicondit-applicatio   = lcon_applicatio_v .

       ls_bapicondit-cond_type    = lcon_cond_type_j3ap.

*      text_no

       ls_bapicondit-scaletype    = lcon_scale_type_c.

*      scalebasin

*      scale_qty

*      unitmeasur

*      measur_iso

*      scale_val

*      currenckey

*      curren_iso

       ls_bapicondit-calctypcon  = lcon_calc_type_c.

       ls_bapicondit-cond_value  = <fs_gt_upload_j3ap>-kwert.

       ls_bapicondit-condcurr    = <fs_lt_zsd_pricelist>-waerk.

*       ls_bapicondit-cond_iso

       ls_bapicondit-cond_p_unt  = p_kpein.

       ls_bapicondit-cond_unit   = p_kmein.

*      conunitiso

*      pricelevel

*      numconvert

*      denominato

*      base_uom

*      baseqtyiso

*      lowerlimit

*      upperlimit

*      plcondval

*      cum_value

*      cumm_accr

*      currency

*      curr_iso

*      condcurren

*      isocurrenc

*      plan_basis

*      rate_unit

*      exclusion

*      customer

*      vendor_no

*      tax_code

*      indidelete

*      conditidx

*      matlsettl

*      accruals

*      reb_retroa

*      statofagre

*      promot_no

*      sales_deal

*      salesquote

*      add_val_dy

*      fix_val_dy

*      pmnttrms

*      numborders

*      minconbava

*      maxconbava

*      maxconval

*      incr_scale

*      pricscale

*      relprcg

*      promotion

*      rebagreemt

*      withtaxcod

*      contract

*      contractno

*      flow_type

*      indimatmai

*      status

*      umsabst

*      matlsettl_external

*      matlsettl_guid

*      matlsettl_version

       APPEND ls_bapicondit TO lt_bapicondit.

       LOOP AT lt_a9xx  ASSIGNING <fs_lt_a9xx>.

         ls_bapicondit-cond_no    = <fs_lt_a9xx>-knumh.

         ls_bapicondit-operation  = lcon_operation_003.

         ls_bapicondit-cond_value = <fs_lt_a9xx>-kbetr.

         IF lv_same_recfound = abap_true.

           LOOP AT lt_bapicondit ASSIGNING <fs_lt_bapicondit>

               WHERE cond_no = lcon_knumh_i OR

                     cond_no = lcon_knumh_test.

             <fs_lt_bapicondit>-cond_no = ls_bapicondit-cond_no.

             EXIT.

           ENDLOOP.

           IF sy-subrc IS NOT INITIAL.

             APPEND ls_bapicondit TO lt_bapicondit.

           ENDIF.

         ELSE.

           APPEND ls_bapicondit TO lt_bapicondit.

         ENDIF.

       ENDLOOP.

       LOOP AT lt_a9xx_deleted  ASSIGNING <fs_lt_a9xx_deleted>.

         ls_bapicondit-cond_no    = <fs_lt_a9xx_deleted>-knumh.

         ls_bapicondit-operation  = lcon_operation_003.

         ls_bapicondit-cond_value = <fs_lt_a9xx_deleted>-kbetr.

         APPEND ls_bapicondit TO lt_bapicondit.

       ENDLOOP.

       CALL FUNCTION 'BAPI_PRICES_CONDITIONS'

         EXPORTING

*         PI_INITIALMODE       = ' '

*         PI_BLOCKNUMBER       =

           pi_physical_deletion = p_del

         TABLES

           ti_bapicondct        = lt_bapicondct

           ti_bapicondhd        = lt_bapicondhd

           ti_bapicondit        = lt_bapicondit

           ti_bapicondqs        = lt_bapicondqs

           ti_bapicondvs        = lt_bapicondvs

           to_bapiret2          = lte_bapiret2

           to_bapiknumhs        = lte_bapiknumhs

           to_mem_initial       = lte_mem_initial

         EXCEPTIONS

           update_error         = 1

           OTHERS               = 2.

       IF sy-subrc <> 0.

* Implement suitable error handling here

       ENDIF.

       LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>

           WHERE type = 'E'.

         IF p_shwmod IS INITIAL.

           CHECK <fs_lte_bapiret2>-message_v1 = lv_knumh OR

                <fs_lte_bapiret2>-message_v3  = 'I'.

         ENDIF.

         gs_output_j3ap-icon      = icon_cancel.

*        IF p_test IS INITIAL.

*          CASE <fs_lte_bapiret2>-message_v3 .

*            WHEN 'I'.

*              gs_output_j3ap-icon_m = icon_create.

*              gs_output_j3ap-datbi  = lcon_valid_to.

*            WHEN 'U'.

*              READ TABLE lt_a9xx ASSIGNING <fs_lt_a9xx>

*                   WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

*              IF sy-subrc IS INITIAL.

*                gs_output_j3ap-kwert = <fs_lt_a9xx>-kbetr.

*                gs_output_j3ap-datbi = <fs_gt_upload_j3ap>-datab - 1.

*              ENDIF.

*              gs_output_j3ap-icon_m = icon_change.

*            WHEN 'D'.

*              READ TABLE lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>

*                   WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

*              IF sy-subrc IS INITIAL.

*                gs_output_j3ap-kwert = <fs_lt_a9xx_deleted>-kbetr.

*                gs_output_j3ap-datbi = <fs_lt_a9xx_deleted>-datbi.

*              ENDIF.

*              gs_output_j3ap-icon_m = icon_delete.

*            WHEN OTHERS.

*          ENDCASE.

*        ENDIF.

         gs_output_j3ap-icontext  = <fs_lte_bapiret2>-message.

         APPEND gs_output_j3ap TO gt_output_j3ap.

       ENDLOOP.

       IF sy-subrc IS NOT INITIAL.

         LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>

             WHERE type = 'W'.

           IF p_shwmod IS INITIAL.

             CHECK <fs_lte_bapiret2>-message_v1 = lv_knumh OR

                  <fs_lte_bapiret2>-message_v3  = 'I'.

           ENDIF.

           gs_output_j3ap-icon      = icon_okay.

             IF <fs_lte_bapiret2>-message_v3  'I' OR

                <fs_lte_bapiret2>-message_v1 = lcon_knumh_test.

               gs_output_j3ap-icon_m = icon_create.

               gs_output_j3ap-kwert  = <fs_gt_upload_j3ap>-kwert.

               gs_output_j3ap-datab  = <fs_gt_upload_j3ap>-datab.

               gs_output_j3ap-datbi  = lcon_valid_to.

             ELSEIF <fs_lte_bapiret2>-message_v3  = 'U'.

               READ TABLE lt_a9xx ASSIGNING <fs_lt_a9xx>

                    WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

               IF sy-subrc IS INITIAL.

                 gs_output_j3ap-kwert = <fs_lt_a9xx>-kbetr.

                 gs_output_j3ap-datab = <fs_lt_a9xx>-datab .

                 gs_output_j3ap-datbi = <fs_lt_a9xx>-datbi .

               ENDIF.

               gs_output_j3ap-icon_m = icon_change.

             ELSEIF <fs_lte_bapiret2>-message_v3  = 'D'.

               READ TABLE lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>

                    WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

               IF sy-subrc IS INITIAL.

                 gs_output_j3ap-kwert = <fs_lt_a9xx_deleted>-kbetr.

                 gs_output_j3ap-datab = <fs_lt_a9xx_deleted>-datab.

                 gs_output_j3ap-datbi = <fs_lt_a9xx_deleted>-datbi.

               ENDIF.

               gs_output_j3ap-icon_m = icon_delete.

             ENDIF.

             IF p_test IS NOT INITIAL.

               CLEAR gs_output_j3ap-icon_m.

             ENDIF.

           gs_output_j3ap-icontext  = <fs_lte_bapiret2>-message.

           APPEND gs_output_j3ap TO gt_output_j3ap.

         ENDLOOP.

         IF sy-subrc IS NOT INITIAL.

           LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>

             WHERE type = 'S'.

             IF p_shwmod IS INITIAL.

               CHECK <fs_lte_bapiret2>-message_v1 = lv_knumh OR

                     <fs_lte_bapiret2>-message_v3  = 'I'.

             ENDIF.

             gs_output_j3ap-icon      = icon_okay.

             IF <fs_lte_bapiret2>-message_v3  'I' OR

                <fs_lte_bapiret2>-message_v1 = lcon_knumh_test.

               gs_output_j3ap-icon_m = icon_create.

               gs_output_j3ap-kwert  = <fs_gt_upload_j3ap>-kwert.

               gs_output_j3ap-datab  = <fs_gt_upload_j3ap>-datab.

               gs_output_j3ap-datbi  = lcon_valid_to.

             ELSEIF <fs_lte_bapiret2>-message_v3  = 'U'.

               READ TABLE lt_a9xx ASSIGNING <fs_lt_a9xx>

                    WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

               IF sy-subrc IS INITIAL.

                 gs_output_j3ap-kwert = <fs_lt_a9xx>-kbetr.

                 gs_output_j3ap-datab = <fs_lt_a9xx>-datab .

                 gs_output_j3ap-datbi = <fs_lt_a9xx>-datbi .

               ENDIF.

               gs_output_j3ap-icon_m = icon_change.

             ELSEIF <fs_lte_bapiret2>-message_v3  = 'D'.

               READ TABLE lt_a9xx_deleted ASSIGNING <fs_lt_a9xx_deleted>

                    WITH KEY knumh = <fs_lte_bapiret2>-message_v1.

               IF sy-subrc IS INITIAL.

                 gs_output_j3ap-kwert = <fs_lt_a9xx_deleted>-kbetr.

                 gs_output_j3ap-datab = <fs_lt_a9xx_deleted>-datab.

                 gs_output_j3ap-datbi = <fs_lt_a9xx_deleted>-datbi.

               ENDIF.

               gs_output_j3ap-icon_m = icon_delete.

             ENDIF.

             IF p_test IS NOT INITIAL.

               CLEAR gs_output_j3ap-icon_m.

             ENDIF.

             gs_output_j3ap-icontext  = <fs_lte_bapiret2>-message.

             APPEND gs_output_j3ap TO gt_output_j3ap.

           ENDLOOP.

         ENDIF.

       ENDIF.

     ENDLOOP.

     IF sy-subrc IS NOT INITIAL.

       gs_output_j3ap-icon  = icon_cancel.

       gs_output_j3ap-icontext  = 'Incorrect pricelist'.

       APPEND gs_output_j3ap TO gt_output_j3ap.

     ENDIF.

   ENDLOOP.

   IF p_test IS NOT INITIAL.

     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

*     IMPORTING

*       RETURN        =

               .

   ELSE.

     LOOP AT gt_output_j3ap ASSIGNING <fs_gt_output_j3ap>

          WHERE icon = icon_cancel.

       EXIT.

     ENDLOOP.

     IF sy-subrc IS INITIAL.

       CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

*     IMPORTING

*       RETURN        =

               .

     ELSE.

       CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

   EXPORTING

      wait = 'X'

*IMPORTING

*return = ret

   .

     ENDIF.

   ENDIF.

ENDFORM.                    " F_UPLOADPRICES

jim_donahue
Explorer
0 Kudos

Vijay asked what my requirement was.

I have a custom RF transaction which prompts for shipping info such as pro number, carrier, weight and freight. All are working well except for the freight cost which I need to store in the delivery pricing condition type 'ZKF2'. If it already exists it should replace the contents, otherwise, it should add it.

Thank you.

Former Member
0 Kudos

Hi All,

I have a requirement that I need to assign freight cost to the pricing condition ZPFR in a delivery document. If the freight cost is already available then I need to modify the freight cost based on the requirement.

Can you please suggest me any function modules or BAPI that will be fullfill above requirement.

Thank you.

Regards

Satish

Former Member
0 Kudos

Hi,

create condition records in the same way as with transaction VK11

thank!

Former Member
0 Kudos

<b>

Former Member
0 Kudos

This BAPI looks like a work-in-progress. The description is in German, there is no documentation, it is not used anywhere and on top of all, it is not a RFC enabled FM. Are you sure this is the right BAPI?

former_member188685
Active Contributor
0 Kudos

hi,

what is your requirement.......?

Regards

vijay