data: c_bslash value '\', " Backward slash
c_fslash value '/'. " Forward slash
*----------------------------------------------------------------------*
* Variable declarations *
*----------------------------------------------------------------------*
data: x_data_in(230) type c, " String
v_lines type i, " Total no. of lines
v_err_cnt type i, " Error count
v_msg(250) type c. " Log msg
* Internal table to upload the data
data: begin of it_data_in occurs 0 ,
matnr_old(18), " Old material number
price(16), " Selling price
gcolor(3), " Grid color
gsize(5), " Grid Size
end of it_data_in.
* Internal table with SAP Material Numbers & no grid values
data: begin of it_cond_recs occurs 0 ,
matnr(18), " SAP material number
price(16), " Selling price
end of it_cond_recs.
* Internal table with SAP Material Numbers with grid values
data: begin of it_cond_recsg occurs 0 ,
matnr(18), " SAP material number
price(16), " Selling price
gvalue(8), " Grid value
end of it_cond_recsg.
* Internal table for getting the BDC data
data : begin of it_bdcdata occurs 0.
include structure bdcdata. " Table to hold BDC data
data : end of it_bdcdata.
* Internal table for reading the messages of call transaction
DATA : BEGIN OF It_MESSAGE_TAB OCCURS 0.
INCLUDE STRUCTURE BDCMSGCOLL. "Table to hold messages
DATA : END OF It_MESSAGE_TAB.
* Internal table for Error messages
data: begin of it_error occurs 0,
matnr(18) type n, " Material no.
msg(250), " Log message
end of it_error.
* Internal table to upload the presentation server
data: begin of it_upload occurs 0,
string(230) type c,
end of it_upload.
*----------------------------------------------------------------------
* Selection Screen
*----------------------------------------------------------------------
*----------------------------------------------------------------------*
* Build Logical System Info Block *
*----------------------------------------------------------------------*
selection-screen begin of block b_dsn with frame title text-001.
parameters: p_fname type rlgrap-filename. " File name
parameters: rd_pserv radiobutton group radi default 'X', " Pres. Server
rd_aserv radiobutton group radi. " App. Server
selection-screen end of block b_dsn.
*selection-screen begin of block outputfile with frame title text-002.
*parameters: p_ofile type edi_path-pthnam default '/tmp/log.txt'.
*selection-screen end of block outputfile.
*-----------------------------------------------------------------------
* at Selection-screen
*-----------------------------------------------------------------------
* Check which file is selected
at selection-screen on value-request for p_fname.
* Perform to get the current value of the selection screen
perform get_current_value.
if rd_aserv = 'X'.
message i003 with 'Can not browse unix directories'(003).
else.
* F4 help for presentation server file name
perform get_local_file_name.
endif.
at selection-screen.
* perform to validate file name
perform validate_filename using p_fname.
** perform to validate output file name
* perform validate_filename using p_ofile.
*----------------------------------------------------------------------
* Start of selection
*----------------------------------------------------------------------
start-of-selection.
if not it_data_in[] is initial.
* perform to process data posting
perform process_data_posting.
endif.
*----------------------------------------------------------------------
* End of selection
*----------------------------------------------------------------------
end-of-selection.
if not it_error[] is initial.
write:/'Total no. of errors:', v_err_cnt.
loop at it_error.
write:/ 'Material no :', it_error-matnr,
/ 'Log Msg :', it_error-msg(70).
endloop.
else.
write:'Success'.
endif.
*&---------------------------------------------------------------------*
*& Form ws_upload
*&---------------------------------------------------------------------*
* Subroutine for Uploading file
*----------------------------------------------------------------------*
form ws_upload.
*&---------------------------------------------------------------------*
*& Form load_unix
*&---------------------------------------------------------------------*
* Form to Load Unix File
*----------------------------------------------------------------------*
form load_unix.
open dataset p_fname for input in text mode.
if sy-subrc <> 0.
message i003 with p_fname.
stop.
else.
do.
clear x_data_in.
read dataset p_fname into x_data_in.
case sy-subrc.
when 0.
split x_data_in at '~'
into it_data_in-matnr_old
it_data_in-price
it_data_in-gcolor
it_data_in-gsize.
append it_data_in.
clear it_data_in.
when 4.
exit.
when 8.
message i003 with 'Unable to Read the File'(009) p_fname.
stop.
endcase.
enddo.
close dataset p_fname.
endif.
endform. " load_unix
*&---------------------------------------------------------------------*
*& Form get_current_value
*&---------------------------------------------------------------------*
* Read the screen for radio button
*----------------------------------------------------------------------*
form get_current_value.
* Local internal table for screen fields
data: begin of i_dynpfields occurs 0.
include structure dynpread.
data: end of i_dynpfields.
call function 'DYNP_VALUES_READ'
exporting
dyname = sy-cprog
dynumb = sy-dynnr
tables
dynpfields = i_dynpfields
exceptions
invalid_abapworkarea = 1
invalid_dynprofield = 2
invalid_dynproname = 3
invalid_dynpronummer = 4
invalid_request = 5
no_fielddescription = 6
invalid_parameter = 7
undefind_error = 8
double_conversion = 9
others = 10.
if sy-subrc <> 0.
message i999 with 'Unbale to read the selection screen values'(015).
else.
read table i_dynpfields index 1.
if sy-subrc = 0.
move i_dynpfields-fieldvalue to rd_aserv.
endif.
endif.
endform. " get_current_value
*&---------------------------------------------------------------------*
*& Form get_local_file_name
*&---------------------------------------------------------------------*
* F4 help for presentation server
*----------------------------------------------------------------------*
form get_local_file_name.
* Local variable
data: l_fname like ibipparms-path, " File name
v_repid like sy-repid.
l_fname = p_fname.
v_repid = sy-repid.
*&---------------------------------------------------------------------*
*& Form validate_filename
*&---------------------------------------------------------------------*
* To validate file name
*----------------------------------------------------------------------*
form validate_filename using p_fname type any.
if rd_aserv = 'X'.
* Local variable for file length
data : l_len type i.
l_len = strlen( p_fname ).
if p_fname ca space.
if sy-fdpos < l_len.
message e333 with 'File name should not contain spaces'(004).
endif.
endif.
if p_fname ca c_bslash.
message e333 with 'File name should not contain \'(005).
endif.
if p_fname na c_fslash. " No directory path given
message w333 with 'File will be created in home directory'(006).
endif.
endif.
if p_fname+0(1) = c_fslash and p_fname+1 = space.
message e333 with 'File name should not contain only /'(007).
endif.
endform. " validate_filename
*&---------------------------------------------------------------------*
*& Form process_data_posting
*&---------------------------------------------------------------------*
* To process data posting
*----------------------------------------------------------------------*
FORM process_data_posting.
* perform get SAP Material number
perform get_SAP_materials.
* perform to build BDC Data
perform build_bdc_data.
ENDFORM. " process_data_posting
*&---------------------------------------------------------------------*
*& Form get_SAP_materials
*&---------------------------------------------------------------------*
* To get SAP Material numbers for the old materials
*----------------------------------------------------------------------*
FORM get_SAP_materials.
* Local variable
data: l_gvalue(8), " Grid value
l_matnr(18). " Material no.
sort it_data_in by matnr_old.
loop at it_data_in.
at new matnr_old.
select single matnr from mara into l_matnr
where bismt = it_data_in-matnr_old.
endat.
concatenate it_data_in-gcolor
it_data_in-gsize
into l_gvalue.
if l_gvalue is initial.
it_cond_recs-matnr = l_matnr.
it_cond_recs-price = it_data_in-price.
sort it_cond_recs by matnr.
sort it_cond_recsg by matnr.
ENDFORM. " get_SAP_materials
*&---------------------------------------------------------------------*
*& Form build_bdc_data
*&---------------------------------------------------------------------*
* To build bdc data for J3a4 (Create price & SZ Condition)
*----------------------------------------------------------------------*
FORM build_bdc_data.
if not it_cond_recs[] is initial.
* perform to build BDC Data for J3a4 with out grid values
perform build_bdc_data_no_grid.
endif.
if not it_cond_recsg[] is initial.
* perform to build BDC Data for J3a4 with grid values
perform build_bdc_data_with_grid.
endif.
ENDFORM. " build_bdc_data
*&---------------------------------------------------------------------*
*& Form populate1
*&---------------------------------------------------------------------*
* To populate screen and field information
*----------------------------------------------------------------------*
FORM populate1 USING value(p_a) type any
value(p_b) type any
value(p_c) type any.
*&---------------------------------------------------------------------*
*& Form build_bdc_data_with_grid
*&---------------------------------------------------------------------*
* To build bdc data for J3a4 (Create price & SZ Condition)
* with grid values
*----------------------------------------------------------------------*
FORM build_bdc_data_with_grid.
data: l_gsize(18), " Field name
l_kbetr(15), " Field name
l_cnt type n, " Counter
l_cnt_c(3). " Counter
loop at it_cond_recsg.
at new matnr.
read table it_cond_recsg index sy-tabix.
*&---------------------------------------------------------------------*
*& Form build_bdc_data_no_grid
*&---------------------------------------------------------------------*
* To build bdc data for J3a4 (Create price & SZ Condition)
* with no grid values
*----------------------------------------------------------------------*
FORM build_bdc_data_no_grid.
data: l_matnr(15), " Field name
l_kbetr(15), " Field name
l_cnt type n, " Counter
l_cnt_c(3). " Counter
* To call the transaction J3a4
perform call_transaction.
ENDFORM. " build_bdc_data_no_grid
*&---------------------------------------------------------------------*
*& Form call_transaction
*&---------------------------------------------------------------------*
* To call the transaction J3a4
*----------------------------------------------------------------------*
FORM call_transaction.
* Structure declaration for options
data: x_opt like ctu_params.
x_opt-DISMODE = 'N'. " No Screen Mode
x_opt-UPDMODE = 'S'. " Update mode "Synchronous or Asynchronous
x_opt-DEFSIZE = 'X'. " Sets to the default size of the window
* call the transaction J3a4
CALL TRANSACTION 'J3A4' USING It_BDCDATA
MESSAGES INTO it_MESSAGE_TAB
options from x_opt.
* Perform to read the messages
perform message_format.
* Appending the error records into error table
it_error-matnr = it_cond_recsg-matnr. " Material No.
it_error-msg = v_msg. " Error message
append it_error.
clear it_error.
endif.
REFRESH: It_BDCDATA,
it_message_tab.
CLEAR: It_BDCDATA,
it_message_tab.
ENDFORM. " call_transaction
*&---------------------------------------------------------------------*
*& Form message_format
*&---------------------------------------------------------------------*
* Subroutine to read the messages
*----------------------------------------------------------------------*
FORM message_format.
CLEAR V_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = It_MESSAGE_TAB-MSGID
LANG = 'EN'
NO = It_MESSAGE_TAB-MSGNR
V1 = It_MESSAGE_TAB-MSGV1
V2 = It_MESSAGE_TAB-MSGV2
V3 = It_MESSAGE_TAB-MSGV3
V4 = It_MESSAGE_TAB-MSGV4
IMPORTING
MSG = V_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
V_MSG = SPACE.
ENDIF.
ENDFORM. " message_format
Also there's an interface named RV14BTCI to create condition records.
Look documentation of this report
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.