BDC to update price
in VK11.
Here
is an example of update price on price condition in VK11.
This
can be also achieved by calling BAPI which is safer to use instead of BDC but
here we will use BDC recording given by functional guy.
SAMPLE CODE :
REPORT zbdc_vk11
NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS: truxs, slis.
TYPES: BEGIN OF ty_final,
vkorg TYPE komg-vkorg, " SALES ORG.
vtweg TYPE komg-vtweg, " Distribution Channel
extwg TYPE komg-extwg, " External Material Group
ph1 TYPE komg-prodh1,
ph2 TYPE komg-prodh2,
ph4 TYPE komg-prodh4,
werks TYPE komg-werks, " PLANT
kbetr(15) TYPE c, " CONDITION AMOUNT
konwa TYPE konp-konwa, " UNIT
kpein(15) TYPE c, " PRICING PER UNIT
kmein TYPE konp-kmein, " CONDITION UNIT
datab(10) TYPE c, " VALID FROM
datbi(10) TYPE c, " END DATE
END OF ty_final.
TYPES : BEGIN OF ty_output,
extwg TYPE komg-extwg, " External Material Group
werks TYPE komg-werks, " PLANT
desc(40) TYPE c,
END OF ty_output.
DATA : it_final TYPE STANDARD TABLE OF ty_final,
wa_final TYPE ty_final,
it_output TYPE STANDARD TABLE OF ty_output,
wa_output TYPE ty_output.
DATA: it_type TYPE truxs_t_text_data,
opt TYPE ctu_params,
lv_opt LIKE ctu_params.
DATA : wa_fieldcat TYPE slis_fieldcat_alv, "Field catalog work area
it_fieldcat TYPE slis_t_fieldcat_alv. "field catalog internal table
DATA: lv_date(10) TYPE c, lv_date2(10) TYPE c.
DATA: date(2) TYPE c,
month(2) TYPE c,
year(4) TYPE c,
str TYPE string.
DATA: it_bdcdata TYPE TABLE OF bdcdata,
wa_bdcdata TYPE bdcdata,
ctu TYPE ctu_params,
t_values TYPE vrm_values,
w_values TYPE vrm_value.
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA: wa_return TYPE bdcmsgcoll.
DATA: tcode TYPE tcode VALUE 'VK11'.
INITIALIZATION.
PERFORM initialization.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS : p_file TYPE rlgrap-filename ,"DEFAULT 'C:\Users\abapsu\Desktop\PRICE.XLSX',
p_mode(1) AS LISTBOX VISIBLE LENGTH 20 DEFAULT 'E'.
* P_DEFSIZE LIKE CTU_PARAMS-DEFSIZE DEFAULT 'X'.
SELECTION-SCREEN : END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_mode.
PERFORM dismode.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM f4_file.
START-OF-SELECTION.
PERFORM file_upload.
PERFORM upload_data.
PERFORM disp.
*&---------------------------------------------------------------------*
*& Form FILE_UPLOAD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM file_upload .
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
i_line_header = 'X'
i_tab_raw_data = it_type
i_filename = p_file
TABLES
i_tab_converted_data = it_final[]
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE 'TABLE IS INITIAL' TYPE 'E'.
ELSE.
ctu-dismode = p_mode. "DISPLAY MODE.
ctu-updmode = 'L'. "UPDATE MODE.
* CTU-NOBINPT = 'X'.
ctu-defsize = 'X'. "DEFAULT SIZE.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM upload_data .
LOOP AT it_final INTO wa_final.
PERFORM bdc_dynpro USING 'SAPMV13A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV13A-KSCHL'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ANTA'.
PERFORM bdc_field USING 'RV13A-KSCHL'
'ZSTO'.
PERFORM bdc_dynpro USING 'SAPLV14A' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV130-SELKZ(10)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=WEIT'.
PERFORM bdc_field USING 'RV130-SELKZ(01)'
''.
PERFORM bdc_field USING 'RV130-SELKZ(10)'
'X'.
PERFORM bdc_dynpro USING 'SAPMV13A' '1729'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RV13A-DATBI(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'.
PERFORM bdc_field USING 'KOMG-VKORG'
wa_final-vkorg. "'GLIN'.
PERFORM bdc_field USING 'KOMG-VTWEG'
wa_final-vtweg. "'IC'.
PERFORM bdc_field USING 'KOMG-EXTWG(01)'
wa_final-extwg. " 'V02002'.
PERFORM bdc_field USING 'KOMG-PRODH1(01)'
wa_final-ph1. " 'DV'.
PERFORM bdc_field USING 'KOMG-PRODH2(01)'
wa_final-ph2. "'FB'.
PERFORM bdc_field USING 'KOMG-PRODH4(01)'
wa_final-ph4. "'FE'.
PERFORM bdc_field USING 'KOMG-WERKS(01)'
wa_final-werks. "'2300'.
PERFORM bdc_field USING 'KONP-KBETR(01)'
wa_final-kbetr. "'367.00'.
PERFORM bdc_field USING 'KONP-KONWA(01)'
wa_final-konwa. "'INR'.
PERFORM bdc_field USING 'KONP-KPEIN(01)'
wa_final-kpein. "' 1'.
PERFORM bdc_field USING 'KONP-KMEIN(01)'
wa_final-kmein. "'M2'.
PERFORM bdc_field USING 'RV13A-DATAB(01)'
wa_final-datab. "'01.01.2021'.
PERFORM bdc_field USING 'RV13A-DATBI(01)'
wa_final-datbi.
REFRESH: messtab[].
CALL TRANSACTION tcode USING it_bdcdata OPTIONS FROM ctu MESSAGES
INTO messtab .
REFRESH : it_bdcdata[].
DATA : msg_txt(150) TYPE c.
LOOP AT messtab INTO wa_return.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_return-msgid
lang = sy-langu
no = wa_return-msgnr
v1 = wa_return-msgv1
v2 = wa_return-msgv2
v3 = wa_return-msgv3
v4 = wa_return-msgv4
IMPORTING
msg = msg_txt
EXCEPTIONS
not_found = 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.
IF messtab-msgtyp EQ 'E'.
wa_output-extwg = wa_final-extwg.
wa_output-werks = wa_final-werks.
wa_output-desc = msg_txt.
ELSEIF messtab-msgtyp EQ 'S'.
wa_output-extwg = wa_final-extwg.
wa_output-werks = wa_final-werks.
wa_output-desc = msg_txt.
ELSEIF messtab-msgtyp EQ 'W'.
wa_output-extwg = wa_final-extwg.
wa_output-werks = wa_final-werks.
wa_output-desc = msg_txt.
ELSE.
wa_output-extwg = wa_final-extwg.
wa_output-werks = wa_final-werks.
wa_output-desc = msg_txt.
ENDIF.
APPEND wa_output to it_output.
CLEAR: msg_txt, wa_output.
ENDLOOP.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form INITIALIZATION
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM initialization .
w_values-key = 'A'.
w_values-text = 'FOREGROUND'.
APPEND w_values TO t_values.
CLEAR w_values.
w_values-key = 'N'.
w_values-text = 'BACKGROUND'.
APPEND w_values TO t_values.
CLEAR w_values.
w_values-key = 'E'.
w_values-text = 'ONLY ERRORS'.
APPEND w_values TO t_values.
CLEAR w_values.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISMODE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM dismode .
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'P_MODE'
values = t_values.
ENDFORM.
FORM f4_file .
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
IMPORTING
file_name = p_file.
ENDFORM.
FORM disp .
wa_fieldcat-fieldname = 'EXTWG'.
wa_fieldcat-seltext_m = 'Ext. Material Group'.
wa_fieldcat-tabname = 'T_OUTPUT'.
wa_fieldcat-outputlen = 15.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'WERKS'.
wa_fieldcat-seltext_m = 'PLANT'.
wa_fieldcat-tabname = 'T_OUTPUT'.
wa_fieldcat-outputlen = 15.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'DESC'.
wa_fieldcat-seltext_m = 'Status'.
wa_fieldcat-tabname = 'T_OUTPUT'.
wa_fieldcat-outputlen = 40.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
it_fieldcat = it_fieldcat
TABLES
t_outtab = it_output[].
IF sy-subrc <> 0.
MESSAGE 'ALV List Can not be generated!!!' TYPE 'E'.
ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* START NEW SCREEN *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR wa_bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.
*----------------------------------------------------------------------*
* INSERT FIELD *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
CLEAR wa_bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.
No comments:
Post a Comment