cancel
Showing results for 
Search instead for 
Did you mean: 

Function module for assortment change WSOA2

former_member797394
Participant
0 Kudos
821

Hello everyone,

My requirement in function module is to call transaction code WSOA2 in order to add stores(WRSZ-LOCNR) to existing assortments(WRS1-ASORT).

This is my first time I am asking for FM, that is why a more clear answer would be appreciated. However, it is not neccessary.

I hope my question is clear.

Accepted Solutions (1)

Accepted Solutions (1)

venkateswaran_k
Active Contributor

Hi

You may try with the BAPI - BAPI_ASSORTMENT_MAINTAINDATA . Open the bapi SE37 - the FM documentation may help you further

CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA' "Maintenance of Assortments
  EXPORTING
    assortment =                " bapie1wrs1
    assortmentx =               " bapie1wrs1x
  IMPORTING
    return =                    " bapiret2
* TABLES
*   materialgroup =             " bapie1wrs6
*   materialgroupx =            " bapie1wrs6x
*   description =               " bapie1wrst
*   descriptionx =              " bapie1wrstx
*   assortmentusers =           " bapie1wrsz
*   assortmentusersx =          " bapie1wrszx
former_member797394
Participant
0 Kudos

Thank you vey much. I have a question. What is the difference between assortment and assortmentx. What should I write here?

venkateswaran_k
Active Contributor
0 Kudos

Hi

Sorry for delay,

In X table - you have to mark the items you mentioned in assortment table, - mark them with X in assortmentX table. If you do not mention then that item will mot be updated

former_member797394
Participant
0 Kudos

venkateswaran.k

Am I doing everything correctly? If yes, then program does not write my entries and not even giving any errors.

DATA:
ld_return TYPE bapiret2,
it_assortmentusers TYPE STANDARD TABLE OF bapie1wrsz, "TABLES PARAM
wa_assortmentusers LIKE LINE OF it_assortmentusers,
it_assortmentusersx TYPE STANDARD TABLE OF bapie1wrszx, "TABLES PARAM
wa_assortmentusersx LIKE LINE OF it_assortmentusersx,
ld_assortment TYPE bapie1wrs1,
wa_assortment LIKE ld_assortment,
ld_assortmentx TYPE bapie1wrs1x,
wa_assortmentx LIKE ld_assortmentx.
LOOP AT mt_info INTO ls_info.
wa_assortment-assortment = ls_info-asort.
wa_assortmentx-assortment = 'X'.
wa_assortmentusers-seqnumber = '5'.
wa_assortmentusers-customer_site = ls_info-locnr.
wa_assortmentusers-salesorg = ls_info-vkorg.
wa_assortmentusers-distr_chan = ls_info-vtweg.
wa_assortmentusersx-seqnumber = 'X'.
wa_assortmentusersx-customer_site = 'X'.
wa_assortmentusersx-salesorg = 'X'.
wa_assortmentusersx-distr_chan = 'X'.
APPEND wa_assortmentusers TO it_assortmentusers.
APPEND wa_assortmentusersx TO it_assortmentusersx.
ENDLOOP.
CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA'
EXPORTING
assortment = wa_assortment
assortmentx = wa_assortmentx
IMPORTING
return = ld_return
TABLES
* MATERIALGROUP =
* MATERIALGROUPX =
* DESCRIPTION =
* DESCRIPTIONX =
assortmentusers = it_assortmentusers
assortmentusersx = it_assortmentusersx.
WRITE: ld_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
venkateswaran_k
Active Contributor
0 Kudos

Hi

Did you debug and check the table - ld_return

What is expected and what it is nod updated. Can you please share.

former_member797394
Participant
0 Kudos

venkateswaran.k

Yes, I have debuged. In ld-return, there is nothing written. My programm should append new markets to an assortment. So, I am passing assortment(ASORT), market(LOCNR) and two more fields. Everything seems to be written to internal tables,but nothing is written to the tables. What may be the reason for this? And what should I share, for better understanding?

venkateswaran_k
Active Contributor
0 Kudos

I am not fully aware of the functionality. However, can you please pass the values for ( for both asoortment and assortment uers)

VALID_FROM

VALID_TO

ASTMT_CAT

former_member797394
Participant
0 Kudos

I tried this, but unfortunately this didnt work

Answers (1)

Answers (1)

former_member797394
Participant
0 Kudos

Here is the full code:

REPORT zmm_kub_upl.
INCLUDE zbc_bal_log.
DATA:
ld_return TYPE bapiret2,
it_assortmentusers TYPE STANDARD TABLE OF bapie1wrsz, "TABLES PARAM
wa_assortmentusers LIKE LINE OF it_assortmentusers,
it_assortmentusersx TYPE STANDARD TABLE OF bapie1wrszx, "TABLES PARAM
wa_assortmentusersx LIKE LINE OF it_assortmentusersx,
ld_assortment TYPE bapie1wrs1,
wa_assortment LIKE ld_assortment,
ld_assortmentx TYPE bapie1wrs1x,
wa_assortmentx LIKE ld_assortmentx.
PARAMETERS:
p_file TYPE localfile OBLIGATORY.
CLASS lcl_report DEFINITION DEFERRED.
TYPES: BEGIN OF gts_struct,
sheet TYPE i,
name TYPE tabname,
END OF gts_struct.
DATA: go_report TYPE REF TO lcl_report.
DATA: bdcdata TYPE TABLE OF bdcdata WITH HEADER LINE.
CLASS lcl_excel_uploader DEFINITION.
PUBLIC SECTION.
DATA: header_rows_count TYPE i.
DATA: max_rows TYPE i.
DATA: filename TYPE localfile.
DATA: mt_struct TYPE TABLE OF gts_struct.
METHODS:
constructor.
METHODS:
upload IMPORTING iv_sheet TYPE i
CHANGING ct_data TYPE ANY TABLE.
PRIVATE SECTION.
DATA: lv_tot_components TYPE i.
METHODS:
do_upload
IMPORTING
iv_begin TYPE i
iv_end TYPE i
iv_sheet TYPE i
EXPORTING
rv_empty TYPE flag
CHANGING
ct_data TYPE STANDARD TABLE.
ENDCLASS.
CLASS lcl_excel_uploader IMPLEMENTATION.
METHOD constructor.
max_rows = 9999.
DATA: ls_struct TYPE gts_struct.
ls_struct-sheet = 1.
ls_struct-name = 'ZMM_KUB'.
APPEND ls_struct TO mt_struct.
ENDMETHOD.
METHOD upload.
DATA: lo_struct TYPE REF TO cl_abap_structdescr,
lo_table TYPE REF TO cl_abap_tabledescr,
lt_comp TYPE cl_abap_structdescr=>component_table.
    lo_table ?= cl_abap_structdescr=>describe_by_data( ct_data ).
lo_struct ?= lo_table->get_table_line_type( ).
lt_comp = lo_struct->get_components( ).
lv_tot_components = lines( lt_comp ).
DATA: lv_empty TYPE flag,
lv_begin TYPE i,
lv_end TYPE i.
lv_begin = header_rows_count + 1.
lv_end = max_rows.
WHILE lv_empty IS INITIAL.
do_upload(
EXPORTING
iv_begin = lv_begin
iv_end = lv_end
iv_sheet = iv_sheet
IMPORTING
rv_empty = lv_empty
CHANGING
ct_data = ct_data
).
lv_begin = lv_end + 1.
lv_end = lv_begin + max_rows.
ENDWHILE.
ENDMETHOD.
METHOD do_upload.
DATA: li_exceldata TYPE STANDARD TABLE OF zalsmex_tabline.
DATA: ls_exceldata LIKE LINE OF li_exceldata.
DATA: lv_tot_rows TYPE i.
DATA: lv_packet TYPE i.
DATA: lt_dfies TYPE TABLE OF dfies.
DATA: ls_struct TYPE gts_struct.
FIELD-SYMBOLS: <struc> TYPE any,
<field> TYPE any.
* Upload this packet
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE1'
EXPORTING
filename = filename
i_begin_col = 1
i_begin_row = iv_begin
i_end_col = lv_tot_components
i_end_row = iv_end
i_sheet = iv_sheet
TABLES
intern = li_exceldata
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
rv_empty = 'X'.
EXIT.
ENDIF.
* No rows uploaded, exit
IF li_exceldata IS INITIAL.
rv_empty = 'X'.
EXIT.
ENDIF.
* Проверка запятых
DATA lr_structdescr TYPE REF TO cl_abap_structdescr.
DATA l_component TYPE abap_compdescr .
READ TABLE mt_struct INTO ls_struct WITH KEY sheet = iv_sheet.
IF sy-subrc EQ 0.
lr_structdescr ?= cl_abap_typedescr=>describe_by_name( ls_struct-name ).
ENDIF.
* Move from Row, Col to Flat Structure
LOOP AT li_exceldata INTO ls_exceldata.
* Append new row
AT NEW row.
APPEND INITIAL LINE TO ct_data ASSIGNING <struc>.
ENDAT.
READ TABLE lr_structdescr->components INTO l_component INDEX ls_exceldata-col.
IF l_component-type_kind = 'P'.
REPLACE ALL OCCURRENCES OF ',' IN ls_exceldata-value WITH '.'.
ENDIF.
* component and its value
ASSIGN COMPONENT ls_exceldata-col OF STRUCTURE <struc> TO <field>.
IF sy-subrc EQ 0.
<field> = ls_exceldata-value.
ENDIF.
* add the row count
AT END OF row.
IF <struc> IS NOT INITIAL.
lv_tot_rows = lv_tot_rows + 1.
ENDIF.
ENDAT.
ENDLOOP.
* packet has more rows than uploaded rows,
* no more packet left. Thus exit
lv_packet = iv_end - iv_begin.
IF lv_tot_rows LT lv_packet.
rv_empty = 'X'.
ENDIF.
ENDMETHOD. "do_upload
ENDCLASS.
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
CONSTANTS: mc_object TYPE bal_s_log-object VALUE 'ZMM',
mc_subobject TYPE bal_s_log-subobject VALUE 'ZMM_INFO_UPL'.
DATA: mt_info TYPE TABLE OF zmm_kub,
mo_log TYPE REF TO lcl_bal_log.
METHODS:
constructor,
file_f4,
load_file,
post_data,
* create_condition IMPORTING is_info TYPE zmm_inforec,
* check,
add_sy_message
.
ENDCLASS.
CLASS lcl_report IMPLEMENTATION.
METHOD file_f4.
DATA: lv_directory TYPE string,
lt_filetable TYPE filetable,
ls_filetable TYPE LINE OF filetable,
lv_rc TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
* window_title =
* default_extension =
* default_filename =
file_filter = 'Excel files (*.xls, *.xlsx)|*.xls; *.xlsx'
* with_encoding =
* initial_directory = 'C:\'
* multiselection =
CHANGING
file_table = lt_filetable
rc = lv_rc
* user_action =
* file_encoding =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc EQ 0.
READ TABLE lt_filetable INTO ls_filetable INDEX 1.
p_file = ls_filetable-filename.
ELSE.
ENDIF.
ENDMETHOD.
METHOD load_file.
DATA: lo_uploader TYPE REF TO lcl_excel_uploader.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = 'Загрузка файла...'.
CREATE OBJECT mo_log
EXPORTING
extnumber = ''
object = mc_object
subobject = mc_subobject.
CREATE OBJECT lo_uploader.
lo_uploader->max_rows = 65000.
lo_uploader->filename = p_file.
* lo_uploader->filename = 'C:\Users\kh.yusupkhujayev\Desktop\kip.xlsx'.
lo_uploader->header_rows_count = 2.
lo_uploader->upload( EXPORTING iv_sheet = 1 CHANGING ct_data = mt_info ).
ENDMETHOD.
METHOD post_data.
DATA: lt_msg TYPE TABLE OF bdcmsgcoll,
ls_msg LIKE LINE OF lt_msg,
ls_info LIKE LINE OF mt_info,
lv_dummy,
la_new TYPE abap_bool,
lv_new TYPE abap_bool,
lv_chn TYPE abap_bool.
DATA run_mode TYPE c.
LOOP AT mt_info INTO ls_info.
wa_assortment-assortment = ls_info-asort.
wa_assortment-astmt_cat = 'C'.
wa_assortmentx-assortment = 'X'.
wa_assortmentx-astmt_cat = 'X'.
wa_assortmentusers-seqnumber = '5'.
wa_assortmentusers-customer_site = ls_info-locnr.
wa_assortmentusers-salesorg = ls_info-vkorg.
wa_assortmentusers-distr_chan = ls_info-vtweg.
wa_assortmentusers-valid_from = ls_info-datab.
wa_assortmentusers-valid_from = ls_info-datbi.
* wa_assortmentusers-astmtuserc = 'C'.
wa_assortmentusersx-seqnumber = 'X'.
wa_assortmentusersx-customer_site = 'X'.
wa_assortmentusersx-salesorg = 'X'.
wa_assortmentusersx-distr_chan = 'X'.
wa_assortmentusersx-valid_from = 'X'.
wa_assortmentusersx-valid_from = 'X'.
* wa_assortmentusersx-astmtuserc = 'X'.
APPEND wa_assortmentusers TO it_assortmentusers.
APPEND wa_assortmentusersx TO it_assortmentusersx.
ENDLOOP.
CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA'
EXPORTING
assortment = wa_assortment
assortmentx = wa_assortmentx
IMPORTING
return = ld_return
TABLES
* MATERIALGROUP =
* MATERIALGROUPX =
* DESCRIPTION =
* DESCRIPTIONX =
assortmentusers = it_assortmentusers
assortmentusersx = it_assortmentusersx.
WRITE:/
ld_return-type,
ld_return-id,
ld_return-number,
ld_return-message.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDMETHOD.
METHOD constructor.
ENDMETHOD.
ENDCLASS.
INITIALIZATION.
CREATE OBJECT go_report.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
go_report->file_f4( ).
START-OF-SELECTION.
go_report->load_file( ).
go_report->post_data( ).
venkateswaran_k
Active Contributor
0 Kudos

Yes, Just a random try..

Put the Commit statement just immidiate after the BAPI.

Write statement after the commit.

former_member797394
Participant
0 Kudos

venkateswaran.k

 CALL FUNCTION 'BAPI_ASSORTMENT_MAINTAINDATA'
EXPORTING
assortment = wa_assortment
assortmentx = wa_assortmentx
IMPORTING
return = ld_return
TABLES
* MATERIALGROUP =
* MATERIALGROUPX =
* DESCRIPTION =
* DESCRIPTIONX =
assortmentusers = it_assortmentusers
assortmentusersx = it_assortmentusersx.
IF sy-subrc EQ 0.
COMMIT WORK AND WAIT.
ENDIF.

If you mean like this, than, it still does not work. Is there any option I can know what is going wrong with ld_return. There should be something wrong, so my program does not work.

former_member797394
Participant
0 Kudos

venkateswaran.k

I found out that in WRSZ table, data is inserting, but because it is not writing assortment, my program does not work correctly.

former_member797394
Participant
0 Kudos

venkateswaran.k

Issue solved, finally.

Thank you for your support.

venkateswaran_k
Active Contributor
0 Kudos

Curious to know - what was the issue that was hidden for long time

former_member797394
Participant
0 Kudos

venkateswaran.k

Hello,

the mistake was that I needed assortment both for assortment and assortment user, it should look like this:

wa_assortment-assortment          = ls_info-asort.
wa_assortmentx-assortment = 'X'.
wa_assortmentusers-assortment = ls_info-asort.
wa_assortmentusersx-assortment = 'X'.
former_member797394
Participant
0 Kudos

venkateswaran.k

However, another issue seems to pop up. Can I also change the value of data with the help of this BAPI? Now I need to change the DATBI (Valid To) of an existing assortment in order to delete it. So, first task is done, which was to enter data. Now, I need to delete data. Can I do this with the help of this BAPI?

venkateswaran_k
Active Contributor

hmm. I need to research on that.

You may close this thread and open a new thread - so that It will be useful for those who are searching for solution on same issue