Thursday, September 11, 2008

To Delete Selectedrows in ALV Container

CASE sy-ucomm.
WHEN 'EXIT' OR 'CANC'.
LEAVE TO SCREEN 0 .
WHEN 'DEL'.
DATA: t_row_no TYPE lvc_t_roid,
w_row_no TYPE lvc_s_roid.
DATA flag TYPE c.
DATA n TYPE c VALUE '1'.
*=== To Delete the selected rows in the ALV Grid
CALL METHOD grid1->get_selected_rows IMPORTING et_row_no = t_row_no.
IF NOT t_row_no IS INITIAL.
SORT t_row_no BY row_id.
flag = 0.
LOOP AT t_row_no INTO w_row_no.
IF flag = 0.
DELETE it_final_l INDEX w_row_no-row_id.
flag = 1.
ELSEIF flag = 1.
n = w_row_no-row_id - 1.
DELETE it_final_l INDEX n.
ENDIF.
ENDLOOP.
EXPORT it_final_l TO MEMORY ID m_id.
CALL METHOD grid1->refresh_table_display.
ENDIF.
ENDCASE.

Wednesday, August 6, 2008

Popup_Debug(Drag & Drop)

save the below code as .txt format.

[Function]
COMMAND = /H
Title = Debugger
Type = systemcommand

Upload Values to the Table From Flat File

TABLES: /RB04/YT2_URLHLP.
TYPES: g_ty_line(1500) TYPE c.
DATA : g_t_urlhlp LIKE /RB04/YT2_URLHLP OCCURS 0.DATA : g_wa_urlhlp TYPE /RB04/YT2_URLHLP.
DATA : g_t_tot TYPE TABLE OF g_ty_line, g_wa_tot TYPE g_ty_line.
DATA : l_f_row_pos(10), l_f_col_pos(10).

* SELECTION SCREEN ELEMENTS
PARAMETER g_f_name LIKE rlgrap-filename.
* AT SELECTION-SCREEN EVENT
AT SELECTION-SCREEN ON VALUE-REQUEST FOR g_f_name.
PERFORM get_file_name CHANGING g_f_name.
START-OF-SELECTION.
DELETE FROM /RB04/YT2_URLHLP CLIENT SPECIFIED WHERE mandt = sy-mandt.
PERFORM upload_to_itab TABLES g_t_tot USING g_f_name.
IF NOT g_t_tot IS INITIAL.
LOOP AT g_t_tot INTO g_wa_tot.

SPLIT g_wa_tot AT ''
INTO g_wa_urlhlp-mandt
g_wa_urlhlp-NAVID
g_wa_urlhlp-spras
g_wa_urlhlp-URL.
APPEND g_wa_urlhlp TO g_t_urlhlp.
ENDLOOP.

ELSE.
MESSAGE s000(38) WITH 'No data gets uploaded'. ENDIF.
LOOP AT g_t_urlhlp INTO g_wa_urlhlp.

* insert /RB04/YT2_FCATXT FROM TABLE gt_fcatxt.
move-corresponding g_wa_urlhlp to /RB04/YT2_URLHLP. INSERT /RB04/YT2_URLHLP.
MESSAGE s000(38) WITH 'Record uploaded'.
ENDLOOP.

FORM get_file_name CHANGING pf_name.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'RLGRAP-FILENAME'
IMPORTING file_name = pf_name.
ENDFORM. " get_file_name

FORM upload_to_itab TABLES pt_tot STRUCTURE /RB04/YT2_URLHLP USING pf_name. CALL FUNCTION 'WS_UPLOAD'
EXPORTING
filename = pf_name
filetype = 'ASC'
TABLES
data_tab = pt_tot
EXCEPTIONS
conversion_error = 1
file_open_error = 2
file_read_error = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
ENDFORM. " upload_from_loc_to_itab

Wednesday, June 25, 2008

Event Handler/Doubleclick/Hotspot/Select/Deselect all

program zzz_simple_editable_grid.
include .
data grid1 type ref to cl_gui_alv_grid.
data: es_row_no type lvc_s_roid,
ls_row_id type lvc_s_row,
ls_col_id type lvc_s_col,
ls_row type i,
ls_value type c,
ls_col type i,
ls_row_no type lvc_s_roid.
types: row_table type table of lvc_s_roid.
data t_rows type row_table.
data: begin of wa_rows,
row_id type int4,
sub_row_id type int4,
end of wa_rows.
data: t_index type int4.
data: t_size type int4.
*----------------------------------------------------------------------*
* CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler definition .
public section .
methods:
**Hot spot Handler
handle_hotspot_click for event hotspot_click of cl_gui_alv_grid
importing e_row_id e_column_id es_row_no,
**Double Click Handler
handle_double_click for event double_click of cl_gui_alv_grid
importing e_row e_column es_row_no,
** Toolbar handler.
handle_toolbar
for event toolbar of cl_gui_alv_grid
importing e_object e_interactive,
* button press
handle_user_command
for event user_command of cl_gui_alv_grid
importing e_ucomm,
* data changed
handle_data_changed
for event data_changed of cl_gui_alv_grid
importing er_data_changed,
*data changed finished
handle_data_changed_finished
for event data_changed of cl_gui_alv_grid.

endclass. "lcl_event_handler DEFINITION

*----------------------------------------------------------------------*
* CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
class lcl_event_handler implementation.
*Handle Hotspot Click
method handle_hotspot_click .
perform mouse_click
using e_row_id
e_column_id.
call method grid1->get_current_cell
importing
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.

call method grid1->refresh_table_display.
call method grid1->set_current_cell_via_id
exporting
is_column_id = e_column_id
is_row_no = es_row_no.


endmethod. "lcl_event_handler
*Handle Double Click
method handle_double_click.
perform double_click
using e_row
e_column.
call method grid1->get_current_cell
importing
e_row = ls_row
e_value = ls_value
e_col = ls_col
es_row_id = ls_row_id
es_col_id = ls_col_id
es_row_no = es_row_no.
call method grid1->refresh_table_display.
call method grid1->set_current_cell_via_id
exporting
is_column_id = ls_col_id
is_row_no = es_row_no.


endmethod. "handle_double_click
method handle_toolbar.
data: ls_toolbar type stb_button.
* append a separator to normal toolbar
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
* append an icon for your function
clear ls_toolbar.
move 'FUNC' to ls_toolbar-function.
move icon_railway to ls_toolbar-icon.
move 'Your Function' to ls_toolbar-quickinfo.
move 'Your user function' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
* Select All Rows
move 'SELE' to ls_toolbar-function.
move icon_select_all to ls_toolbar-icon.
move 'Select all' to ls_toolbar-quickinfo.
move 'Select entire Grid' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
* Deselect all Rows.
move 'DSEL' to ls_toolbar-function.
move icon_deselect_all to ls_toolbar-icon.
move 'Deselect all' to ls_toolbar-quickinfo.
move 'Deselect entire Grid' to ls_toolbar-text.
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "handle_toolbar
method handle_user_command.
break-point 1.
case e_ucomm.
when 'FUNC'. "Your button
* Perform what you need to do.
when 'SELE'.
perform select_all_rows.
when 'DSEL'.
perform deselect_all_rows.
when others.
endcase.
endmethod. "handle_user_command
method handle_data_changed.
perform data_changed using er_data_changed.
endmethod. "data_changed
method handle_data_changed_finished.
perform data_changed_finished.
endmethod. "data_changed_finished
endclass. "lcl_event_handler IMPLEMENTATION
* Define any structure
types: begin of s_elements,
vbeln type vapma-vbeln,
posnr type vapma-posnr,
matnr type vapma-matnr,
kunnr type vapma-kunnr,
werks type vapma-werks,
vkorg type vapma-vkorg,
vkbur type vapma-vkbur,
status type c,
end of s_elements.
* end of your structure
data:wa_elements type s_elements.
data: ord_nr type vapma-vbeln,
mat_nr type vapma-matnr,
cus_nr type vapma-kunnr.

data lr_rtti_struc type ref to cl_abap_structdescr .
data:
zog like line of lr_rtti_struc->components .
data:
zogt like table of zog,
wa_it_fldcat type lvc_s_fcat,
it_fldcat type lvc_t_fcat ,
dy_line type ref to data,
dy_table type ref to data.

data: dref type ref to data.
field-symbols: type any,
type standard table,
.
data grid_container1 type ref to cl_gui_custom_container .
data grid_container2 type ref to cl_gui_custom_container.
data: g_handler type ref to lcl_event_handler. "handler
data: ok_code type sy-ucomm.
data: struct_grid_lset type lvc_s_layo.
start-of-selection.
*build the field catalog for dynamic table
* First get your data structure into a field symbol
create data dref type s_elements.
assign dref->* to .
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( ).
* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog
zogt[] = lr_rtti_struc->components.
loop at zogt into zog.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
if wa_it_fldcat-fieldname = 'VBELN'.
wa_it_fldcat-hotspot = 'X'.
endif.
append wa_it_fldcat to it_fldcat.
endloop.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.
* Now using the field catalog created above we can
* build a dynamic table
* and populate it
* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = dy_table.

assign dy_table->* to .
create data dy_line like line of .
assign dy_line->* to .
* Now fill our table with data
select vbeln posnr matnr kunnr werks vkorg vkbur
up to 200 rows
from vapma
into corresponding fields of table .
* Call the screen to display the grid
call screen 200.

*&---------------------------------------------------------------------*
*& Form select_all_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form select_all_rows.
describe table lines t_size.
t_index = 1.
while t_index le t_size.
clear wa_rows.
wa_rows-row_id = t_index.
append wa_rows to t_rows.
t_index = t_index + 1.
endwhile.
call method grid1->set_selected_rows
exporting
it_row_no = t_rows.
endform. "select_all_rows

*&---------------------------------------------------------------------*
*& Form deselect_all_rows
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form deselect_all_rows.
describe table lines t_size.
t_index = 1.
refresh t_rows.
clear wa_rows.
wa_rows-row_id = t_index.
append wa_rows to t_rows.
call method grid1->set_selected_rows
exporting
it_row_no = t_rows.
endform. "deselect_all_rows

*&---------------------------------------------------------------------*
*& Form double_click
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_ROW text
* -->E_COLUMN text
*----------------------------------------------------------------------*
form double_click
using e_row type lvc_s_row
e_column type lvc_s_col.
read table index e_row into wa_elements.
case e_column-fieldname.
when 'MATNR'.
mat_nr = wa_elements-matnr.
set parameter id 'MAT' field mat_nr.
call transaction 'MM03' and skip first screen.
when 'KUNNR'.
cus_nr = wa_elements-kunnr.
set parameter id 'KUN' field cus_nr.
call transaction 'XD03' and skip first screen.
when others.
endcase.
wa_elements-status = 'V'.
modify from wa_elements index e_row.
endform. "double_click
*&---------------------------------------------------------------------*
*& Form mouse_click
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->E_ROW text
* -->E_COLUMN_ID text
*----------------------------------------------------------------------*
form mouse_click
using e_row type lvc_s_row
e_column_id type lvc_s_col.
read table index e_row into wa_elements.

ord_nr = wa_elements-vbeln.
set parameter id 'AUN' field ord_nr.
call transaction 'VA03' and skip first screen.
wa_elements-status = 'V'.
modify from wa_elements index e_row.
endform. "mouse_click
*&---------------------------------------------------------------------*
*& Form data_changed
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->ER_DATA_CHANGED text
*----------------------------------------------------------------------*
form data_changed
using er_data_changed.
break-point 1.
endform. "data_changed
*&---------------------------------------------------------------------*
*& Form data_changed_finished
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form data_changed_finished.

break-point 1.
endform. "data_changed_finished

*&---------------------------------------------------------------------*
*& Form instantiate_grid
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->GRID_CONTAINER text
* -->CLASS_OBJECT text
* -->CONTAINER_NAME text
*----------------------------------------------------------------------*
form instantiate_grid
using grid_container type ref to cl_gui_custom_container
class_object type ref to cl_gui_alv_grid
container_name type scrfname.
data: lt_exclude type ui_functions,
ls_exclude type ui_func.

create object grid_container
exporting
container_name = container_name.
create object class_object
exporting
i_parent = grid_container.
struct_grid_lset-sel_mode = 'D'.

ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
append ls_exclude to lt_exclude.
* ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_check.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_refresh.
*APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum.
APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_subtot.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info.
APPEND ls_exclude TO lt_exclude.
*ls_exclude = cl_gui_alv_grid=>mc_fc_sort.
*APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_delete_filter.
APPEND ls_exclude TO lt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_excl_all.
APPEND ls_exclude TO lt_exclude.
*
* struct_grid_lset-edit = 'X'.
create object g_handler.
set handler g_handler->handle_double_click for class_object.
set handler g_handler->handle_hotspot_click for class_object.
set handler g_handler->handle_toolbar for class_object.
set handler g_handler->handle_user_command for class_object.
set handler g_handler->handle_data_changed for class_object.
set handler g_handler->handle_data_changed_finished for class_object.
call method class_object->register_edit_event
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
call method class_object->set_table_for_first_display
exporting
is_layout = struct_grid_lset
it_toolbar_excluding = lt_exclude
changing
it_outtab =
it_fieldcatalog = it_fldcat.
endform. "instantiate_grid

* PBO module
module status_0200 output.
if grid_container1 is initial.
perform instantiate_grid
using grid_container1
grid1
'ALV_CONTAINER'.
endif.

* SET PF-STATUS '001'.
* SET TITLEBAR '000'.
endmodule. "status_0100 OUTPUT
* PAI module
module user_command_0200 input.
case sy-ucomm.
when 'BACK'.
leave program.
when 'EXIT'.
leave program.
when 'RETURN'.
leave program.
when others.
endcase.
endmodule. "user_command_0100 INPUT

Thursday, June 12, 2008

To Remove SY-Ucomm(Ok-Code) in Subscreen

module user_command_103 input.
data: gv_ucomm_0809 like sy-ucomm.
constants: c_ucomm like sy-ucomm value 'P003'.
data: l_f_okcode like sy-ucomm.
perform get_ok_code_bom1 changing l_f_okcode.
case l_f_okcode.
when 'SRC'.
clear sy-ucomm.
*=== select all QC notifs with same VID
select * from qmel into table gt_qmel where
qmart eq c_qc and
qmnum ne viqmel-qmnum and
kfz_ident_nr eq viqmel-kfz_ident_nr.
if sy-subrc = 0.
* call VID display scrn
call screen 809 starting at 8 8 ending at 76 22.
else.
* no same VID exists
message w050(/rb04/yt2_iqis) with text-116.
endif.
* remove customer fcode/ucomm in sapliqs0
* customer fcode is invalid for sap and error arises!!!
field-symbols: .
field_name = '(SAPLIQS0)OK-CODE'.
assign (field_name) to .
= c_ucomm.
* clear g_activetab.
field_name = '(SAPLXQQM)SY-UCOMM'.
assign (field_name) to .
clear .
endcase.
endmodule. " USER_COMMAND_0809


*&---------------------------------------------------------------------*
*& Form get_ok_code_bom1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form get_ok_code_bom1 changing l_okcode.
field-symbols: .
data: field_name(40) type c.
field_name = '(SAPLIQS0)OK-CODE'.
assign (field_name) to .
l_okcode = .
endform. " get_ok_code_bom1

ALV Pop-up With Double Click Functionality

Report ZALV.
*=== class handler for ALV POPUP
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: gt_qmel TYPE TABLE OF qmel,
l_r_qmel TYPE qmel,
g_repid LIKE sy-repid,
gs_layout1 TYPE lvc_s_layo,
gt_fieldcat1 TYPE lvc_t_fcat WITH HEADER LINE,
cont_on_main TYPE scrfname VALUE 'ALV_CONTAINER',
grid2 TYPE REF TO cl_gui_alv_grid,
*=== references to custom container: neccessary to bind ALV Control
custom_container1 TYPE REF TO cl_gui_custom_container,
event_receiver TYPE REF TO lcl_event_receiver.

DATA: l_it_fieldcat TYPE lvc_t_fcat, l_wa_fieldcat TYPE lvc_s_fcat.

*&---------------------------------------------------------------------*
*CLASS lcl_event_receiver for double click
*----------------------------------------------------------------------
*=== class definition to Handle Double click
class lcl_event_receiver definition.
public section. methods:
handle_double_click for event double_click of cl_gui_alv_grid
importing e_row e_column. private section.
endclass.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
class lcl_event_receiver implementation.
method handle_double_click.
data: ls_qmel like line of gt_qmel.
*=== e_row contains the selected row index value
Read table gt_qmel index e_row-index into ls_qmel.
*=== notification which is selectd needs to be displayed
set parameter id 'IQM' field ls_qmel-qmnum.
call transaction 'QM03' and skip first screen .
endmethod. "handle_double_clickendclass.
*&---------------------------------------------------------------------*
*& Module STATUS_0809 OUTPUT
*&---------------------------------------------------------------------*
module status_0809 output.
*== set status set pf-status '0809'.
data: l_text(80) type c. g_repid = sy-repid.
* set the container for ALV if custom_container1 is initial.
create object custom_container1
exporting
container_name = cont_on_main
exceptions
cntl_error = 1 cntl_system_error = 2.
*=== create an instance of alv control
create object grid2 exporting i_parent = custom_container1.
*=== change title
concatenate text-111 ':' viqmel-kfz_ident_nr into l_text.
gs_layout-grid_title = l_text.
*=== adjust field catalog*=== to suppress the output of already displayed key fields of qmel perform field_catalog_103.
call method grid2->set_table_for_first_display
exporting
is_layout = gs_layout
changing
it_fieldcatalog = l_it_fieldcat[]
it_outtab = gt_qmel.
*=== Event for Double click
create object event_receiver.
set handler event_receiver->handle_double_click for grid2.
call method cl_gui_control=>set_focus exporting control = grid2.
call method cl_gui_cfw=>flush.
else.
call method grid2->refresh_table_display.
endif. "IF grid2 IS INITIAL.
endmodule. " STATUS_0809 OUTPUT
*&---------------------------------------------------------------------*
*& Form field_catalog.
*&---------------------------------------------------------------------*
form field_catalog_103.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'QMEL'
changing
ct_fieldcat = l_it_fieldcat[].
perform delete_feildcat_103.
endform. " mask_columns
*&---------------------------------------------------------------------*
*& Form delete_feildcat
*&---------------------------------------------------------------------*
form delete_feildcat_103.
*=== delete fieldcatalog other then the fieldname
delete l_it_fieldcat where ( fieldname ne 'MATNR' and fieldname ne 'SPART' and fieldname ne 'KUNUM' and fieldname ne 'QMNUM' ).
endform. " delete_feildcat

BDC Call Transaction

REPORT zz_mae_bdc NO STANDARD PAGE HEADING LINE-SIZE 255.
TYPE-POOLS truxs.
DATA it_raw TYPE truxs_t_text_data.
DATA: w_textout LIKE t100-text.


*Used to stores error information from CALL TRANSACTION Function Module
DATA: BEGIN OF messtab OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF messtab.

*=== data declaration for internal table
DATA: BEGIN OF it_bdc OCCURS 0,
title_medi LIKE sza1_d0100-title_medi,
name1 LIKE addr1_data-name1,
name2 LIKE addr1_data-name2,
name4 LIKE addr1_data-name4,
sort1 LIKE addr1_data-sort1,
street LIKE addr1_data-street,
post_code1 LIKE addr1_data-post_code1,
city1 LIKE addr1_data-city1,
country LIKE addr1_data-country,
region LIKE addr1_data-region,
po_box LIKE addr1_data-po_box,
post_code2 LIKE addr1_data-post_code2,
langu LIKE addr1_data-langu,
tel_number LIKE sza1_d0100-tel_number,
fax_number LIKE sza1_d0100-fax_number,
smtp_addr LIKE sza1_d0100-smtp_addr,
END OF it_bdc.
DATA: BEGIN OF ty_error,
err_msg(73) TYPE c,
title_medi LIKE sza1_d0100-title_medi,
name1 LIKE addr1_data-name1,
name2 LIKE addr1_data-name2,
name4 LIKE addr1_data-name4,
sort1 LIKE addr1_data-sort1,
street LIKE addr1_data-street,
post_code1 LIKE addr1_data-post_code1,
city1 LIKE addr1_data-city1,
country LIKE addr1_data-country,
region LIKE addr1_data-region,
po_box LIKE addr1_data-po_box,
post_code2 LIKE addr1_data-post_code2,
langu LIKE addr1_data-langu,
tel_number LIKE sza1_d0100-tel_number,
fax_number LIKE sza1_d0100-fax_number,
smtp_addr LIKE sza1_d0100-smtp_addr,
END OF ty_error.


DATA it_final LIKE TABLE OF it_bdc WITH HEADER LINE.
DATA bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: it_error LIKE TABLE OF ty_error WITH HEADER LINE.
*=== selection screen for input
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE tit.
SELECTION-SCREEN SKIP 1.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN: END OF BLOCK b1.
*=== initilization
INITIALIZATION.
MOVE 'FILE NAME' TO tit.
*=== selection screen for F4 help
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.

START-OF-SELECTION.
*=== To convert XLS to SAP
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR = 'X'
* I_LINE_HEADER = 'X'
i_tab_raw_data = it_raw
i_filename = p_file
TABLES
i_tab_converted_data = it_final.
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2


LOOP AT it_final.
PERFORM bdc_dynpro USING 'SAPLSZA1' '0101'.
PERFORM bdc_field USING 'BDC_CURSOR'
'ADDR1_DATA-COUNTRY'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SAVE'.
PERFORM bdc_field USING 'SZA1_D0100-TITLE_MEDI'
it_final-title_medi.
PERFORM bdc_field USING 'ADDR1_DATA-NAME1'
it_final-name1.
PERFORM bdc_field USING 'ADDR1_DATA-NAME2'
it_final-name2.
PERFORM bdc_field USING 'ADDR1_DATA-NAME4'
it_final-name4.
PERFORM bdc_field USING 'ADDR1_DATA-SORT1'
it_final-sort1.
PERFORM bdc_field USING 'ADDR1_DATA-STREET'
it_final-street.
PERFORM bdc_field USING 'ADDR1_DATA-POST_CODE1'
it_final-post_code1.
PERFORM bdc_field USING 'ADDR1_DATA-CITY1'
it_final-city1.
PERFORM bdc_field USING 'ADDR1_DATA-COUNTRY'
it_final-country.
PERFORM bdc_field USING 'ADDR1_DATA-REGION'
it_final-region.
PERFORM bdc_field USING 'ADDR1_DATA-PO_BOX'
it_final-po_box.
PERFORM bdc_field USING 'ADDR1_DATA-POST_CODE2'
it_final-post_code2.
PERFORM bdc_field USING 'ADDR1_DATA-LANGU'
it_final-langu.
PERFORM bdc_field USING 'SZA1_D0100-TEL_NUMBER'
it_final-tel_number.
PERFORM bdc_field USING 'SZA1_D0100-FAX_NUMBER'
it_final-fax_number.
PERFORM bdc_field USING 'SZA1_D0100-SMTP_ADDR'
it_final-smtp_addr.
*call transaction to update customer instalment text
CALL TRANSACTION 'ZZ_MAE_TEST' USING bdcdata MODE 'N' UPDATE 'S'
MESSAGES INTO messtab.
*
IF sy-subrc NE 0.
*Retrieve error messages displayed during BDC update
LOOP AT messtab WHERE msgtyp = 'E'.
*Builds actual message based on info returned from Call transaction
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = messtab-msgid
msgnr = messtab-msgnr
msgv1 = messtab-msgv1
msgv2 = messtab-msgv2
msgv3 = messtab-msgv3
msgv4 = messtab-msgv4
IMPORTING
message_text_output = w_textout.
ENDLOOP.

* Build error table ready for output
it_error-err_msg = w_textout.
it_error-title_medi = it_final-title_medi.
it_error-name1 = it_final-name1.
it_error-name2 = it_final-name2.
it_error-name4 = it_final-name4.
it_error-sort1 = it_final-sort1.
it_error-street = it_final-street.
it_error-post_code1 = it_final-post_code1.
it_error-city1 = it_final-city1.
it_error-country = it_final-country.
it_error-region = it_final-region.
it_error-po_box = it_final-po_box.
it_error-post_code2 = it_final-post_code2.
it_error-langu = it_final-langu.
it_error-tel_number = it_final-tel_number.
it_error-fax_number = it_final-fax_number.
it_error-smtp_addr = it_final-smtp_addr.
APPEND it_error.
CLEAR it_error.
ENDIF.

SELECT SINGLE * FROM adrc
WHERE name1 = it_final-name1
AND name2 = it_final-name2
AND addr_group = 'Z_P1'
AND chckstatus <> 'D'.
IF sy-subrc = 0.
* Partnernummer generieren und im Feld ADRESS_ID speichern
PERFORM gen_adrnr
USING '*Y'
it_final-name1
lc_maint_mode
adrc-addrnumber
CHANGING adrc-address_id.
adrc-address_id = adrc-address_id.
UPDATE adrc.
ENDIF.
* Clear bdc data table
CLEAR: bdcdata.
REFRESH: bdcdata.
ENDLOOP.
*=== download error files in destop
PERFORM download.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM. "bdc_dynpro
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
* if fval <> nodata.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
* endif.
ENDFORM. "bdc_field


*&---------------------------------------------------------------------*
*& Form DOWNLOAD
*&---------------------------------------------------------------------*
FORM download.
DATA l_v_path_name TYPE string.
DATA file_path(5) TYPE c VALUE 'C:\'.
CONCATENATE file_path sy-datum sy-uzeit'.' 'TXT' INTO
l_v_path_name.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_v_path_name
filetype = 'ASC'
TABLES
data_tab = it_error.
ENDFORM.
Powered By Blogger