cancel
Showing results for 
Search instead for 
Did you mean: 

Can BAPI_ASSORTMENT_MAINTAINDATA change data?

former_member797394
Participant
0 Kudos
672

Hello everyone,

I have written a program that adds assortment module (LOCNR) to an existing assortment (FILIA). It works fine. However, now I need to change the date value_to (DATBI) to todays date, in order to make this assortment module (LOCNR) invalid, means out-of-date. Can I do this with the help of this BAPI? If yes, then how, because I have tried to do this on my own, but the date is not changed. Here is the piece of my code, where I try to change the date value:

wa_assortmentusers-valid_from = ls_info-datab.
SELECT SINGLE datbi INTO wa_assortmentusers-valid_to FROM wrsz 
WHERE asort EQ wa_assortmentusers-assortment
AND locnr EQ wa_assortmentusers-customer_site.
IF sy-subrc EQ 0.
wa_assortmentusers-valid_to = ls_info-datbi.
ELSE.
wa_assortmentusers-valid_to = ls_info-datbi.
ENDIF.
wa_assortmentusersx-valid_from = 'X'.
wa_assortmentusersx-valid_to = 'X'.


Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

former_member797394
Participant
0 Kudos
LOOP AT mt_info INTO ls_info.
TRANSLATE ls_info-asort TO UPPER CASE.
SELECT SINGLE name1 INTO ls_info-name1 FROM wrst WHERE asort EQ ls_info-asort.
wa_assortment-assortment = ls_info-asort.
SELECT SINGLE sotyp INTO wa_assortment-astmt_cat FROM wrs1 WHERE asort EQ wa_assortment-assortment.
wa_assortmentx-astmt_cat = 'X'.
wa_assortmentx-assortment = 'X'.
wa_assortmentusers-assortment = ls_info-asort.
wa_assortmentusers-customer_site = ls_info-locnr.
SELECT SINGLE lfdnr INTO wa_assortmentusers-seqnumber FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment
AND locnr EQ wa_assortmentusers-customer_site
AND datbi GT sy-datum.
IF sy-subrc NE 0.
SELECT MAX( lfdnr ) INTO wa_assortmentusers-seqnumber FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment.
IF sy-subrc EQ 0.
wa_assortmentusers-seqnumber = wa_assortmentusers-seqnumber + loop_num.
ELSEIF sy-subrc NE 0.
wa_assortmentusers-seqnumber = loop_num.
ENDIF.
ENDIF.
wa_assortmentusers-salesorg = '1100'.
wa_assortmentusers-distr_chan = '10'.
wa_assortmentusers-division = '01'.
wa_assortmentusers-astmtuserc = 'A'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = ls_info-datab
IMPORTING
date_internal = ls_info-datab.
wa_assortmentusers-valid_from = ls_info-datab.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = ls_info-datbi
IMPORTING
date_internal = ls_info-datbi
SELECT locnr INTO wa_wrsz-locnr FROM wrsz WHERE asort EQ wa_assortment-assortment
AND datbi GT sy-datum.
APPEND wa_wrsz TO it_wrsz.
SORT it_wrsz.
CLEAR wa_wrsz.
ENDSELECT.
LOOP AT it_wrsz INTO wa_wrsz.
date_cy = date_cy + 1.
IF wa_wrsz-locnr EQ wa_assortmentusers-customer_site.
EXIT.
ENDIF.
ENDLOOP.
CONDENSE date_cy NO-GAPS.
CONCATENATE 'MARK_040(' date_cy ')' INTO ld_mark.
CONCATENATE 'V_WRSZ-LOCNR(' date_cy ')' INTO ld_cursor.
CLEAR date_cy.
CLEAR it_wrsz.
CLEAR wa_wrsz.
SELECT SINGLE datbi INTO wa_assortmentusers-valid_to FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment
AND locnr EQ wa_assortmentusers-customer_site
AND datbi GE sy-datum.
IF sy-subrc EQ 0.
IF ls_info-datbi LT wa_assortmentusers-valid_to.
wa_assortmentusers-valid_to = ls_info-datbi.
wa_description-function = '003'.
wa_description-assortment = ls_info-asort.
wa_descriptionx-function = 'X'.
wa_descriptionx-assortment = 'X'.
cycle = 1.
PERFORM fill_bdcdata USING ls_info.
run_mode = 'E'.
CALL TRANSACTION 'WSOA2'
USING bdcdata MODE run_mode UPDATE 'S' MESSAGES INTO lt_msg.
ENDIF.
ELSE.
wa_assortmentusers-valid_to = ls_info-datbi.
ENDIF.
wa_assortmentusersx-assortment = 'X'.
wa_assortmentusersx-seqnumber = 'X'.
wa_assortmentusersx-customer_site = 'X'.
wa_assortmentusersx-salesorg = 'X'.
wa_assortmentusersx-distr_chan = 'X'.
wa_assortmentusersx-division = 'X'.
wa_assortmentusersx-astmtuserc = 'X'.
wa_assortmentusersx-valid_from = 'X'.
wa_assortmentusersx-valid_to = 'X'.
APPEND wa_assortmentusers TO it_assortmentusers.
APPEND wa_assortmentusersx TO it_assortmentusersx.
APPEND wa_description TO it_description.
APPEND wa_descriptionx TO it_descriptionx.
loop_num = loop_num + 1.
CLEAR wa_assortmentusers.
CLEAR wa_assortmentusersx.
ENDLOOP.
CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA'
EXPORTING
assortment = wa_assortment
assortmentx = wa_assortmentx
IMPORTING
return = ld_return
TABLES
description = it_description
descriptionx = it_descriptionx
assortmentusers = it_assortmentusers
assortmentusersx = it_assortmentusersx.
IF cycle EQ 1.
LOOP AT it_assortmentusers INTO wa_assortmentusers.
WRITE: ld_return-message,
wa_assortmentusers-customer_site, 'Удален из куба', wa_assortmentusers-assortment,
/.
ENDLOOP.
ELSE.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
LOOP AT it_assortmentusers INTO wa_assortmentusers.
WRITE: ld_return-message,
wa_assortmentusers-customer_site, 'Добавлен в куб', wa_assortmentusers-assortment,
/.
ENDLOOP.
ENDIF.
ENDIF.
FORM fill_bdcdata USING is_info   TYPE zmm_kub.
REFRESH bdcdata.
* 1st screen.
PERFORM bdc_dynpro USING 'WRFM_WSO6' '0001'.
PERFORM bdc_field USING 'BDC_CURSOR' 'V_WRS1-ASORT'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'V_WRS1-ASORT' is_info-asort.
* 2nd screen.
PERFORM bdc_dynpro USING 'WRFM_WSO6' '0010'.
PERFORM bdc_field USING 'BDC_CURSOR' 'V_WRS1-NAME1'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ASORT_TAB_FC4'.
PERFORM bdc_field USING 'V_WRS1-NAME1' is_info-name1.
PERFORM bdc_field USING 'V_WRS1-STATU' '1'.
PERFORM bdc_field USING 'V_WRS1-VKORG' '1100'.
PERFORM bdc_field USING 'V_WRS1-VTWEG' '10'.
PERFORM bdc_field USING 'V_WRS1-KZLIK' 'X'.
PERFORM bdc_field USING 'V_WRS1-LAYPR' 'X'.
* 3rd screen.
PERFORM bdc_dynpro USING 'WRFM_WSO6' '0010'.
PERFORM bdc_field USING 'BDC_OKCODE' '/EDEL'.
PERFORM bdc_field USING 'V_WRS1-NAME1' is_info-name1.
PERFORM bdc_field USING 'BDC_CURSOR' ld_cursor.
PERFORM bdc_field USING ld_mark 'X'.
CLEAR ld_mark.
* 4th screen.
PERFORM bdc_dynpro USING 'WRFM_WSO6' '0010'.
PERFORM bdc_field USING 'BDC_OKCODE' '=XSI'.
PERFORM bdc_field USING 'V_WRS1-NAME1' is_info-name1.
PERFORM bdc_field USING 'BDC_CURSOR' ld_cursor.
CLEAR ld_cursor.
ENDFORM.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
CONDENSE bdcdata-fval.
* REPLACE FIRST OCCURRENCE OF '.' in bdcdata-fval WITH ','.
APPEND bdcdata.
ENDFORM.

Answers (1)

Answers (1)

venkateswaran_k
Active Contributor
0 Kudos

Hi

You can use the same BAPI

The table BAPIE1WRST-FUNCTION = assign 003 code to this field

003 = is to delete

004 = is to change

You can see the domain of this data item BAPIE1WRST-FUNCTION

Use - structure BAPIE1WRST-FUNCTION to be passed with 003 for delete 

CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA' "Maintenance of Assortments
  EXPORTING
    assortment =                " bapie1wrs1
    assortmentx =               " bapie1wrs1x
  IMPORTING
    return =                    " bapiret2
* TABLES
*   materialgroup =             " bapie1wrs6
*   materialgroupx =            " bapie1wrs6x
*   description =               " bapie1wrst     <====== pass the code 003
*   descriptionx =              " bapie1wrstx
*   assortmentusers =           " bapie1wrsz
*   assortmentusersx =          " bapie1wrszx
    .  "  BAPI_ASSORTMENT_MAINTAINDATA<br>

Regards,

Venkat

venkateswaran_k
Active Contributor

Hi khasanyusupkhujaev

Are you able to change / delete the existing data using this BAPI

As per documentation, this BAPI is used for create/change/delete as well.

former_member797394
Participant
0 Kudos

Hello venkateswaran.k,

I have not tried yet. I will let you know as soon as I will have any positive or negative results. Kindly ask you to keep in touch.

Thank you, much appreciated.

former_member797394
Participant
0 Kudos

venkateswaran.k,

Should it look something like this? I have made bold the lines that you should pay attantion. I am checking there, if the date in the table is grater than the date I want to send via my excel file. If yes, then give description value 003 and descriptionx X. That did not work for me, unfortanetely. Am I doing something wrong?

Data:
it_description TYPE STANDARD TABLE OF bapie1wrst,
wa_description LIKE LINE OF it_description,
it_descriptionx TYPE STANDARD TABLE OF bapie1wrstx,
wa_descriptionx LIKE LINE OF it_descriptionx.
LOOP AT mt_info INTO ls_info.
TRANSLATE ls_info-asort TO UPPER CASE.
wa_assortment-assortment = ls_info-asort.
wa_assortmentx-assortment = 'X'.
wa_assortmentusers-assortment = ls_info-asort.
wa_assortmentusers-customer_site = ls_info-locnr.
SELECT SINGLE lfdnr INTO wa_assortmentusers-seqnumber FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment
AND locnr EQ wa_assortmentusers-customer_site
AND datbi GT sy-datum.
IF sy-subrc NE 0.
SELECT MAX( lfdnr ) INTO wa_assortmentusers-seqnumber FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment.
IF sy-subrc EQ 0.
wa_assortmentusers-seqnumber = wa_assortmentusers-seqnumber + loop_num.
ELSEIF sy-subrc NE 0.
wa_assortmentusers-seqnumber = loop_num.
ENDIF.
ENDIF.
wa_assortmentusers-salesorg = '1100'.
wa_assortmentusers-distr_chan = '10'.
wa_assortmentusers-division = '01'.
wa_assortmentusers-astmtuserc = 'A'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = ls_info-datab
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = ls_info-datab
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
wa_assortmentusers-valid_from = ls_info-datab.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = ls_info-datbi
* ACCEPT_INITIAL_DATE =
IMPORTING
date_internal = ls_info-datbi
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
.
SELECT SINGLE datbi INTO wa_assortmentusers-valid_to FROM wrsz
WHERE asort EQ wa_assortmentusers-assortment
AND locnr EQ wa_assortmentusers-customer_site
AND datbi GE sy-datum.
IF sy-subrc EQ 0.
IF ls_info-datbi LT wa_assortmentusers-valid_to.
wa_description-function = 003.
wa_description-assortment = ls_info-asort.
wa_descriptionx-function = 'X'.
wa_descriptionx-assortment = 'X'.
wa_assortmentusers-valid_to = ls_info-datbi.
wa_description-assortment = ls_info-asort.
wa_descriptionx-function = 'X'.
wa_descriptionx-assortment = 'X'.
wa_assortmentusers-valid_to = ls_info-datbi.
ENDIF.
ELSE.
wa_assortmentusers-valid_to = ls_info-datbi.
ENDIF.
wa_assortmentusersx-assortment = 'X'.
wa_assortmentusersx-seqnumber = 'X'.
wa_assortmentusersx-customer_site = 'X'.
wa_assortmentusersx-salesorg = 'X'.
wa_assortmentusersx-distr_chan = 'X'.
wa_assortmentusersx-division = 'X'.
wa_assortmentusersx-astmtuserc = 'X'.
wa_assortmentusersx-valid_from = 'X'.
wa_assortmentusersx-valid_to = 'X'.
APPEND wa_assortmentusers TO it_assortmentusers.
APPEND wa_assortmentusersx TO it_assortmentusersx.
APPEND wa_description TO it_description.
APPEND wa_descriptionx TO it_descriptionx.
APPEND wa_descriptionx TO it_descriptionx.
loop_num = loop_num + 1.
CLEAR wa_assortmentusers.
CLEAR wa_assortmentusersx.
ENDLOOP.
CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA'
EXPORTING
assortment = wa_assortment
assortmentx = wa_assortmentx
IMPORTING
return = ld_return
TABLES
* MATERIALGROUP =
* MATERIALGROUPX =
description = it_description
descriptionx = it_descriptionx
descriptionx = it_descriptionx
assortmentusers = it_assortmentusers
assortmentusersx = it_assortmentusersx.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
LOOP AT it_assortmentusers INTO wa_assortmentusers.
WRITE: ld_return-message,
wa_assortmentusers-customer_site, 'Добавлен в куб', wa_assortmentusers-assortment,
/.
ENDLOOP.
ENDIF.
venkateswaran_k
Active Contributor
0 Kudos

Yes, the description table is the key to change or delete

but i see two lines in descriptionx in BAPI

Is that typo error or actual

former_member797394
Participant
0 Kudos

venkateswaran.k,

this is a typo, in my program everything is written without duplications, i don't know why there is a typo here.

But still, this one did not work for me. 😞

venkateswaran_k
Active Contributor
0 Kudos

Hi

Just to confirm this BAPI works for the change/delete - please check as below

1. First remove the If condition and pass the function code 003 or 004 and see it has impact.

Just for your information - 003 - is for delete 004 - is for Change

2. Secondly in your if condition you stated LT ( Less than ). What if it is Less than or Equal to LE - Please handle this scenario also.

Regards,

Venkat

former_member797394
Participant
0 Kudos

venkateswaran.k,

I have managed to solve this issue with another way, finally. Thank you for your time and effort!

venkateswaran_k
Active Contributor

What was that.. Curious to know.

former_member797394
Participant
0 Kudos

venkateswaran.k,

I have used BAPI for creation and BDC for deletion.

I will post my code in a new comment, just in case.

That was full of fun.

Leave your feedback to my code, if something is wrong or If I should add something more.