Selection Screen Logic in Ibargam
Selection Screen Logic in Ibargam
Selection Screen Logic in Ibargam
*&---------------------------------------------------------------------*
*& Form LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM layout.
wa_layout-edit = 'X'.
ENDFORM. "LAYOUT
*&---------------------------------------------------------------------*
*& Form FREE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM free.
IF c_alv IS NOT INITIAL.
CALL METHOD c_alv->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
FREE c_alv.
ENDIF.
ENDIF.
IF c_container IS NOT INITIAL.
CALL METHOD c_container->free
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
FREE c_container.
ENDIF.
ENDIF.
ENDFORM. "FREE
*&---------------------------------------------------------------------*
*& Form DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM display.
*Creating object of container.
CREATE OBJECT c_container
EXPORTING
container_name = 'CONTAINER'.
*Creating object of alv
CREATE OBJECT c_alv
EXPORTING
i_parent = c_container.
* Fieldcatalog.
PERFORM alv_fieldcat.
PERFORM exclude.
CLEAR wa_output.
IF flag = 1.
DO 20 TIMES.
APPEND wa_output TO it_output.
ENDDO.
CLEAR flag.
ENDIF.
CALL METHOD c_alv->set_table_for_first_display
EXPORTING
is_layout = wa_layout
it_toolbar_excluding = it_exclude
CHANGING
it_outtab = it_output
it_fieldcatalog = it_fieldcat.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_f4 FOR c_alv.
CLEAR: gs_f4, git_f4[].
gs_f4-fieldname = 'MATNR'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'VKORG'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'VTWEG'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'WERKS'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'DISMM'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
* CLEAR: gs_f4.
* gs_f4-fieldname = 'PERKZ'. "Characteristics Profile
* gs_f4-register = 'X'.
* gs_f4-getbefore = 'X'.
* INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'BWSCL'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CLEAR: gs_f4.
gs_f4-fieldname = 'MTVFP'. "Characteristics Profile
gs_f4-register = 'X'.
gs_f4-getbefore = 'X'.
INSERT gs_f4 INTO TABLE git_f4.
CALL METHOD c_alv->register_f4_for_fields
EXPORTING
it_f4 = git_f4[].
ENDFORM. "DISPLAY
*&---------------------------------------------------------------------*
*& Form ALV_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM alv_fieldcat.
CLEAR wa_fieldcat.
REFRESH it_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'MATNR'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Article No.'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-outputlen = 20.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 2.
wa_fieldcat-fieldname = 'VKORG'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Sales Org.'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 8.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 3.
wa_fieldcat-fieldname = 'VTWEG'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Dist Channel'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 8.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 4.
wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Site'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 6.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 5.
wa_fieldcat-fieldname = 'DISMM'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Rp Type'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 5.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 6.
wa_fieldcat-fieldname = 'SOBST'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Target Stock'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 7.
wa_fieldcat-fieldname = 'PRMOD'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Forecast Model'.
* wa_fieldcat-DFIELDNAME = 'PRMOD'.
wa_fieldcat-ref_field = 'PRMOD'.
wa_fieldcat-ref_table = 'MPOP'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 8.
wa_fieldcat-fieldname = 'PERKZ'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Period Indicator'.
wa_fieldcat-ref_field = 'PERKZ'.
wa_fieldcat-ref_table = 'MPOP'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 9.
wa_fieldcat-fieldname = 'BWSCL'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Supply Source'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-row_pos = 1.
wa_fieldcat-col_pos = 10.
wa_fieldcat-fieldname = 'MTVFP'.
wa_fieldcat-tabname = 'IT_OUTPUT'.
wa_fieldcat-coltext = 'Availability Check'.
wa_fieldcat-f4availabl = 'X'.
wa_fieldcat-outputlen = 10.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " ALV_FIELDCAT
*&---------------------------------------------------------------------*
*& Form call_screen
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM call_screen .
CALL SCREEN 100.
ENDFORM. " call_screen
*&---------------------------------------------------------------------*
*& Form UPLOAD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload .
DATA: p_file TYPE rlgrap-filename.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = sy-repid
dynpro_number = sy-dynnr
* FIELD_NAME = ' '
* STATIC = ' '
* MASK = ' '
CHANGING
file_name = p_file
* EXCEPTIONS
* MASK_TOO_LONG = 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.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_line_header = 'X'
i_tab_raw_data = i_tab
i_filename = p_file
TABLES
i_tab_converted_data = it_output
EXCEPTIONS
conversion_failed = 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.
PERFORM remove_blank_lines.
ENDFORM. " UPLOAD
*&---------------------------------------------------------------------*
*& Form save
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM update.
DATA: wa_headdata LIKE bapie1mathead.
DATA: bapi_return LIKE bapireturn1.
DATA: it_plantdata TYPE STANDARD TABLE OF bapie1marcrt,
wa_plantdata TYPE bapie1marcrt,
it_plantdatax TYPE STANDARD TABLE OF bapie1marcrtx,
wa_plantdatax TYPE bapie1marcrtx.
DATA: it_forecast TYPE STANDARD TABLE OF bapie1mpoprt,
wa_forecast TYPE bapie1mpoprt,
it_forecastx TYPE STANDARD TABLE OF bapie1mpoprtx,
wa_forecastx TYPE bapie1mpoprtx.
DATA: it_salesdata TYPE STANDARD TABLE OF bapie1mvkert,
wa_salesdata TYPE bapie1mvkert,
it_salesdatax TYPE STANDARD TABLE OF bapie1mvkertx,
wa_salesdatax TYPE bapie1mvkertx.
DATA: msg TYPE string.
DATA: it_msg TYPE esp1_message_tab_type,
wa_msg LIKE LINE OF it_msg.
DATA: lineno TYPE sy-tabix.
DATA: e_msg(50) TYPE c,
s_msg(50) TYPE c.
CLEAR it_msg[].
LOOP AT it_output INTO wa_output.
CLEAR lineno.
lineno = sy-tabix.
CLEAR: wa_headdata, wa_plantdata, wa_plantdatax,
wa_forecast, wa_forecastx, wa_salesdata,
wa_salesdatax.
REFRESH: it_plantdata,it_plantdatax,it_forecast,
it_forecastx,it_salesdata,it_salesdatax.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_output-matnr
IMPORTING
output = wa_output-matnr.
wa_headdata-material = wa_output-matnr.
wa_headdata-logst_view = 'X'.
wa_plantdata-material = wa_output-matnr.
wa_plantdata-plant = wa_output-werks.
IF wa_output-dismm IS NOT INITIAL.
wa_plantdata-mrp_type = wa_output-dismm.
ENDIF.
IF wa_output-sobst IS NOT INITIAL.
wa_plantdata-target_stock = wa_output-sobst.
ENDIF.
IF wa_output-perkz IS NOT INITIAL.
wa_plantdata-period_ind = wa_output-perkz.
ENDIF.
IF wa_output-bwscl IS NOT INITIAL.
wa_plantdata-sup_source = wa_output-bwscl.
ENDIF.
IF wa_output-mtvfp IS NOT INITIAL.
wa_plantdata-availcheck = wa_output-mtvfp.
ENDIF.
APPEND wa_plantdata TO it_plantdata.
wa_plantdatax-material = wa_output-matnr.
wa_plantdatax-plant = wa_output-werks.
IF wa_output-dismm IS NOT INITIAL.
wa_plantdatax-mrp_type = 'X'.
ENDIF.
IF wa_output-sobst IS NOT INITIAL.
wa_plantdatax-target_stock = 'X'.
ENDIF.
IF wa_output-perkz IS NOT INITIAL.
wa_plantdatax-period_ind = 'X'.
ENDIF.
IF wa_output-bwscl IS NOT INITIAL.
wa_plantdatax-sup_source = 'X'.
ENDIF.
IF wa_output-mtvfp IS NOT INITIAL.
wa_plantdatax-availcheck = 'X'.
ENDIF.
APPEND wa_plantdatax TO it_plantdatax.
IF wa_output-prmod IS NOT INITIAL.
wa_forecast-material = wa_output-matnr.
wa_forecast-plant = wa_output-werks..
wa_forecast-fore_model = wa_output-prmod.
APPEND wa_forecast TO it_forecast.
wa_forecastx-material = wa_output-matnr.
wa_forecastx-plant = wa_output-werks.
wa_forecastx-fore_model = 'X'.
APPEND wa_forecastx TO it_forecastx.
ENDIF.
wa_salesdata-material = wa_output-matnr.
wa_salesdata-sales_org = wa_output-vkorg.
wa_salesdata-distr_chan = wa_output-vtweg.
APPEND wa_salesdata TO it_salesdata.
wa_salesdatax-material = wa_output-matnr.
wa_salesdatax-sales_org = wa_output-vkorg.
wa_salesdatax-distr_chan = wa_output-vtweg.
APPEND wa_salesdatax TO it_salesdatax.
gv_error = 'X'.
c_subrc = 'X'.
IF c_subrc EQ 'X'.
t_subrc = 'X'.
ENDIF.
CONCATENATE 'Line No.: ' i_tabix
INTO lv_line1 SEPARATED BY space.
lv_line2 = ' Site is invalid Use F4 for Help'.
MESSAGE e000(su) WITH lv_line1 lv_line2 .
EXIT.
ENDIF.
ENDFORM. " werks_validation
*&---------------------------------------------------------------------*
*& Form duplicacy_check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM duplicacy_check .
DATA: index TYPE sy-index,
index1 TYPE sy-index.
DATA: count TYPE i.
DESCRIBE TABLE it_output LINES count.
IF count IS INITIAL.
MESSAGE e000(su) WITH 'Enter article first'.
ENDIF.
WHILE index1 <= count.
index = sy-index .
index1 = sy-index + 1.
READ TABLE it_output INTO wa_output INDEX index.
IF wa_output-matnr IS NOT INITIAL and count > 1.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_output-matnr
IMPORTING
output = wa_output-matnr.
READ TABLE it_output INTO wa_output1 INDEX index1.
IF wa_output1-matnr IS NOT INITIAL.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_output1-matnr
IMPORTING
output = wa_output1-matnr.
IF wa_output-matnr = wa_output1-matnr.
MESSAGE e000(su) WITH 'article no' wa_output1-matnr 'repeated'.
ENDIF.
CLEAR: wa_output,wa_output1.
ENDIF.
ENDIF.
ENDWHILE.
ENDFORM. " duplicacy_check
*&---------------------------------------------------------------------*
*& Form test
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
*FORM test .
* DATA: BEGIN OF it_upd OCCURS 0,
* tabname(30) TYPE c,
* fieldname(30) TYPE c,
* END OF it_upd.
* DATA: BRET TYPE STANDARD TABLE OF BAPIRET2.
* DATA: wa_upd LIKE LINE OF it_upd.
* DATA: it_wrpl TYPE STANDARD TABLE OF wrpl,
* wa_wrpl TYPE wrpl.
*
* wa_upd-tabname = 'WRPL'.
* wa_UPD-fieldname = 'SOBST'.
* APPEND wa_upd TO it_upd.
* LOOP AT IT_OUTPUT INTO WA_OUTPUT.
*
* WA_WRPL-SOBST = WA_OUTPUT-SOBST.
*APPEND WA_WRPL TO IT_WRPL.
* CALL FUNCTION 'MATERIAL_UPDATE_LOGISTIC_DATA'
* TABLES
* it_upd_field_names = it_upd
** IT_NEW_MARC_DATA =
* it_new_wrpl_data = IT_WRPL
** IT_NEW_MPOP_DATA =
** IT_SITE_KEYS =
* ot_messages = BRET.
** OT_PROCESSED_MARC_DATA =
** OT_PROCESSED_WRPL_DATA =
** OT_PROCESSED_MPOP_DATA =
** EXCEPTIONS
** WRONG_INPUT_DATA = 1
** WRONG_REFERENCE_HANDLING = 2
** LOCK_PROBLEMS = 3
** FOREIGN_KEY_CHECK_ERROR = 4
** SPECIAL_CHECK_ERROR = 5
** OTHERS = 6
* .
* IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
* ENDIF.
* ENDLOOP.
*ENDFORM. " test