Ble Abap Codes:: Reusa
Ble Abap Codes:: Reusa
INDEX
1. To show alternate colors in rows in alv display.
2. TO put x in fieldx for all the entered values of field
3. Choosing presentation server path on selection screen
4. choosing application (unix) server.
5. Perform used to upload the file from the presentation server.
6. Perform used to upload the file from the application server.
7. Downloading the datas to application server
8. Downloading the datas to presentation server
9. For creating dynamic table and using them
10. Good String processing code
11. Idoc programming
12. bdc programming for updating material
13. Give user the status information during execution of program
14. Program to open excel and values get feeded automatically realtime or can be feeded in background jobs
15. Pop up programming
16. Wait time program
17. at line selection event
18. simple bdc program thru excel with good error handling
19. Important tables of SAP
20. To find the creation/modification data of document at unix server
21. Code to compare contents of two internal table
22. schedule jobs programmatically
23. Coding using define & end define.
24. This include allows you to display one or more ALV tables by simply using a local class. Block mode is
supported so you can display several tables on same screen.
25. User exit for invoices - RV60AFZZ
26. Program to download file to application server and then send mail to user to download it in presentation server
27. Program which create job and specify more details
28. Program to convert spool to pdf
29. Subroutine to prevent time out error
To show alternate colors in rows in alv display.
DATA: l_color(1) TYPE c.
l_color = '0'.
LOOP AT it_result INTO wa_result.
IF l_color = '0'.
wa_result-rowcolor = 'C400'.
l_color = 'X'.
ELSE.
wa_result-rowcolor = 'C500'.
l_color = '0'.
ENDIF.
wa_layout-info_fieldname = 'ROWCOLOR'.
wa_layout-box_fieldname = 'C_ROW'.
Good commands :
(1)
(2)
AT SELECTION-SCREEN ON VALUE-REQUEST FOR outfile.
PARAMETERS: outfile(60) TYPE c MODIF ID md2 DEFAULT
'/usr/sap/trans/data/seedfile.txt'
LOWER CASE.
FORM open_folder .
DATA: l_it_file TYPE STANDARD TABLE OF sdokpath,
l_wa_file TYPE sdokpath,
l_folder TYPE c.
IF sy-subrc EQ 0.
READ TABLE l_it_file INTO l_wa_file INDEX 1.
IF sy-subrc EQ 0.
po_fnm = l_wa_file-pathname.
ENDIF.
ENDIF.
PERFORM open_file.
form open_file .
CALL FUNCTION 'F4_DXFILENAME_4_DYNP'
EXPORTING
* DYNPFIELD_FILETYPE =
dynpfield_filename = 'OUTFILE'
dyname = sy-repid
dynumb = sy-dynnr
filetype = 'P'
location = 'A'
server = ''
.
FORM upload .
MOVE p_file TO w_path.
CLEAR wa_material.
LOOP AT it_material INTO wa_material.
select * from mara where
matnr = wa_material-matnr.
IF sy-subrc = 0.
wa_material-ean11 = mara-ean11.
MODIFY it_material FROM wa_material.
ENDIF.
CLEAR wa_material.
endselect.
ENDLOOP.
FORM upload_apps .
DATA: l_line TYPE string,
l_matnr LIKE mara-matnr.
DO.
CLEAR: l_line,
l_matnr.
READ DATASET p_file1 INTO l_line.
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_matnr = l_line.
CLEAR wa_material.
LOOP AT it_material INTO wa_material.
select * from mara where
matnr = wa_material-matnr.
IF sy-subrc = 0.
wa_material-ean11 = mara-ean11.
MODIFY it_material FROM wa_material.
ENDIF.
CLEAR wa_material.
endselect.
ENDLOOP.
LOOP AT it_output.
TRANSFER it_output TO p_outfil.
IF sy-subrc NE 0.
it_status-matnr = it_output(12).
it_status-status = text-013.
it_status-message = text-008.
APPEND it_status.
ENDIF.
ENDLOOP.
CLOSE DATASET p_outfil.
IF sy-subrc NE 0.
MESSAGE ID 'FB' TYPE 'E' NUMBER '002'
WITH p_outfil.
ELSE.
MESSAGE ID 'FB' TYPE 'I' NUMBER '001'
WITH p_outfil.
ENDIF.
form download_pc .
CLEAR w_file.
w_file = p_desfil.
For creating dynamic table and using them : whole running program
*&---------------------------------------------------------------------*
*& Report Z_T401212 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT Z_T401212 .
type-pools: slis.
type-pools : abap.
lv_check = lv_string(1).
extract first name
Regards,
Michael
Date format
write sy-datum to w_cdate YYMMDD.
Defining range :
Idoc programming :
Program to create idoc, if all configurations are already done. ( purchase order )
check the below sample code for triggering the idoc..The same thing u can do for ur
requirement..slect all then data from ur custom table and finally call the FM
"MASTER_IDOC_DISTRIBUTE".
&---------------------------------------------------------------------
*& Report ZZ_Program_To_Create_Idoc
&---------------------------------------------------------------------
report zz_program_to_create_idoc .
tables: ekko,ekpo.
selection-screen skip 3.
selection-screen begin of block b1 with frame title titl.
selection-screen skip.
select-options s_ebeln for ekko-ebeln.
selection-screen skip.
selection-screen end of block b1.
start-of-selection.
select ebelp
matnr
menge
meins
netpr
from ekpo
into table i_ekpo
where ebeln in s_ebeln.
control_record-mestyp = messagetyp.
control_record-rcvprt = 'LS'.
control_record-idoctp = idoc_name.
control_record-rcvprn = '0MART800'.
loop at i_ekko.
header_segment_data-ebeln = i_ekko-ebeln.
header_segment_data-aedat = i_ekko-aedat.
header_segment_data-bukrs = i_ekko-bukrs.
header_segment_data-bsart = i_ekko-bsart.
header_segment_data-lifnr = i_ekko-lifnr.
i_data-segnam = header_segment_name.
i_data-sdata = header_segment_data.
append i_data.
select ebelp
matnr
menge
meins
netpr
from ekpo
into table i_ekpo
where ebeln = i_ekko-ebeln.
loop at i_ekpo.
item_segment_data-ebelp = i_ekpo-ebelp.
item_segment_data-matnr = i_ekpo-matnr.
item_segment_data-menge = i_ekpo-menge.
item_segment_data-meins = i_ekpo-meins.
item_segment_data-netpr = i_ekpo-netpr.
i_data-segnam = item_segment_name.
i_data-sdata = item_segment_data.
append i_data.
endloop.
clear i_ekpo.
refresh i_ekpo.
endloop.
* OBJ_TYPE = ''
* CHNUM = ''
tables
communication_idoc_control = i_communication
master_idoc_data = i_data
exceptions
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
others = 5
.
if sy-subrc 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
loop at i_communication.
write: 'IDOC GENERATED', i_communication-docnum.
endloop.
commit work.
endif.
initialization.
titl = 'ENTER THE PURCHASE ORDER NUMBER'.
cheers,
Hema.
FORM fill_it_bdcdata .
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'RMMG1-MATNR'
wa_final-matnr.
MOVE wa_final-matnr1 TO wa_result-mat_no.
Program to open excel and values get feeded automatically realtime or can be
feeded in background jobs.
INCLUDE OLE2INCL.
* handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
H_MAPL TYPE OLE2_OBJECT, " list of workbooks
H_MAP TYPE OLE2_OBJECT, " workbook
H_ZL TYPE OLE2_OBJECT, " cell
H_F TYPE OLE2_OBJECT. " font
* start Excel
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
PERFORM ERR_HDL.
Pop up programming
* Warn user about over-selecting...
DESCRIBE TABLE ZVEXT_ORDERS LINES READ_COUNT.
IF READ_COUNT GT 500.
WRITE READ_COUNT TO TEMP_TEXT LEFT-JUSTIFIED.
CONCATENATE 'You have selected' TEMP_TEXT 'orders...'
INTO TEMP_TEXT SEPARATED BY SPACE.
CALL FUNCTION 'POPUP_TO_DECIDE'
EXPORTING
DEFAULTOPTION = '2'
TEXTLINE1 = TEMP_TEXT
TEXTLINE2 = '(processing may be slow)'
TEXTLINE3 = 'Are you sure you want to continue?'
TEXT_OPTION1 = 'Continue'
TEXT_OPTION2 = 'Cancel'
ICON_TEXT_OPTION1 = 'ICON_CHECKED'
ICON_TEXT_OPTION2 = 'ICON_CANCEL'
TITEL = 'Are you sure?'
* START_COLUMN = 25
* START_ROW =6
CANCEL_DISPLAY =''
IMPORTING
ANSWER = TEMP_ANSWER.
IF TEMP_ANSWER = 2.
STOP.
ENDIF.
ENDIF.
REPORT ZPAUSE.
parameters: p_sec type i.
data: new_time like sy-uzeit.
get time.
new_time = sy-uzeit + p_sec.
while sy-uzeit < new_time.
get time.
endwhile.
*----------------------------------------------------------------------*
* MODIFICATION HISTORY *
*----------------------------------------------------------------------*
*Ver|DATE |PGMR |TRANSPORT |DESCRIPTION OF CHANGES *
*No | | | | *
* ---------------------------------------------------------------------*
*001|18-MAR-2008|T401212 |CL1K972236 |Initial *
*----------------------------------------------------------------------*
REPORT zf_fb09
NO STANDARD PAGE HEADING
LINE-COUNT 65 LINE-SIZE 150.
PARAMETERS:
p_file LIKE rlgrap-filename OBLIGATORY.
START-OF-SELECTION.
PERFORM fb09_transaction.
PERFORM write_error_message.
*&---------------------------------------------------------------------*
*& Form bdc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fb09_transaction .
CLEAR it_fb09.
LOOP AT it_fb09.
PERFORM fill_it_bdcdata.
CALL TRANSACTION 'FB09' USING it_bdcdata MODE c_mod UPDATE c_mod1
MESSAGES INTO it_messages.
IF sy-subrc EQ 0.
ADD 1 TO bdc_suc_count.
*it_result-status = 'SUCCESS'.
*it_result-belnr = it_fb09-belnr.
*append it_result.
ELSE.
ADD 1 TO bdc_err_count.
PERFORM error_messages.
ENDIF.
ADD 1 TO bdc_count.
CLEAR it_fb09.
ENDLOOP.
CLEAR t100.
SELECT SINGLE * FROM t100 WHERE sprsl = it_messages-msgspra
AND arbgb = it_messages-msgid
AND msgnr = it_messages-msgnr.
IF sy-subrc EQ 0.
CLEAR lv_string.
lv_string = t100-text.
IF lv_string CS '&1'.
REPLACE '&1' WITH it_messages-msgv1 INTO lv_string.
"Variable part of a message
REPLACE '&2' WITH it_messages-msgv2 INTO lv_string.
REPLACE '&3' WITH it_messages-msgv3 INTO lv_string.
REPLACE '&4' WITH it_messages-msgv4 INTO lv_string.
ELSE.
REPLACE '&' WITH it_messages-msgv1 INTO lv_string.
REPLACE '&' WITH it_messages-msgv2 INTO lv_string.
REPLACE '&' WITH it_messages-msgv3 INTO lv_string.
REPLACE '&' WITH it_messages-msgv4 INTO lv_string.
ENDIF.
CONDENSE lv_string.
CONCATENATE it_messages-msgtyp lv_string INTO lv_string
SEPARATED BY space.
ELSE.
lv_string = it_messages.
ENDIF.
CLEAR it_messages.
ENDLOOP.
it_result-belnr = it_fb09.
it_result-status = 'FAILED'.
it_result-message = lv_string.
APPEND it_result.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FILL_IT_BDCDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_it_bdcdata .
REFRESH it_bdcdata.
PERFORM bdc_dynpro USING 'SAPMF05L' '0102'.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0701 text
* -->P_0702 text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING program LIKE bdcdata-program
dynpro LIKE bdcdata-dynpro.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
CLEAR it_bdcdata.
PERFORM process_excel.
*&---------------------------------------------------------------------
*& Form PROCESS
*&---------------------------------------------------------------------
*text
*----------------------------------------------------------------------
*
*--> p1 text
*<-- p2 text
*----------------------------------------------------------------------
FORM process_excel .
LOOP AT it_excel.
CASE it_excel-col.
WHEN '001'.
it_fb09-belnr = it_excel-value.
WHEN '002'.
it_fb09-bukrs = it_excel-value.
WHEN '003'.
it_fb09-gjahr = it_excel-value.
WHEN '004'.
it_fb09-buzei = it_excel-value.
WHEN '005'.
it_fb09-zterm = it_excel-value.
WHEN '006'.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = it_excel-value
IMPORTING
date_internal = it_excel-value
EXCEPTIONS
date_external_is_invalid = 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.
DATA : lv_date TYPE dats.
lv_date = it_excel-value.
*IT_FB09-ZFBDT = lv_date.
WRITE lv_date TO it_fb09-zfbdt MM/DD/YYYY.
ENDCASE.
AT END OF row.
APPEND it_fb09.
CLEAR it_fb09.
ENDAT.
CLEAR it_excel.
ENDLOOP.
*&---------------------------------------------------------------------*
*& Form open_folder
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM open_folder .
IF sy-subrc EQ 0.
READ TABLE l_it_file INTO l_wa_file INDEX 1.
IF sy-subrc EQ 0.
p_file = l_wa_file-pathname.
ENDIF.
ENDIF.
DATA: timezone_sec(5) TYPE p, " seconds local time is later than GMT
timezone_name(7) TYPE c.
searchpoints-dirname = DIR_NAME.
searchpoints-sp_name = FILE_NAME.
* get in directory
IF SY-SUBRC <> 0.
WRITE: / 'C_DIR_READ_NEXT', 'SUBRC', SY-SUBRC.
EXIT.
ENDIF.
PERFORM P6_TO_DATE_TIME(RSTR0400) USING file-mtime
timezone_sec
file-mod_time
file-mod_date.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
DEFINE get_price_cond.
call function 'RV_PRICE_PRINT_REFRESH'
tables
tkomv = &2.
[edit]
Version
V2 with block mode.
[edit]
Code
*&---------------------------------------------------------------------*
*& Include Z_TABLE_DISPLAY
*&---------------------------------------------------------------------*
* VERSION 2
*
* Code from François Henrotte (EPONA Solutions)
* http://www.eponasolutions.com
* Belgium
* Please keep reference !
*********************************************************************
* HOW TO
*
* Display an ALV grid :
* CALL METHOD lcl_table_display=>display_grid( 'tabname' ).
*
* Display a hierarchical list with header and detail :
* CALL METHOD lcl_table_display=>display_hier( in_header = 'table1'
* in_detail = 'table2' ).
*
* Display a block list with two tables :
* CALL METHOD lcl_table_display=>set_block_mode( 'X' ).
* CALL METHOD lcl_table_display=>display_grid( 'table1' ).
* CALL METHOD lcl_table_display=>display_grid( 'table2' ).
* CALL METHOD lcl_table_display=>end_block_list( ).
*
* You never have to deal with field catalog of tables !!
*
* What if field catalog has to be changed anyway ?
*
* ob_table = lcl_table_display=>create_table( 'tabname' ).
* CALL METHOD ob_table->set_alv_fieldtext( in_field = field
* in_ftext = 'text' ).
* CALL METHOD lcl_table_display=>display_grid( 'tabname' ).
*********************************************************************
*----------------------------------------------------------------------*
* LCL_TABLE_DISPLAY DEFINITION
*----------------------------------------------------------------------*
class lcl_table_display definition.
public section.
create_table
importing
in_tabname type tabname
returning
value(out_table) type ref to lcl_table_display
exceptions
create_error,
get_existing_table
importing
in_tabname type any optional
in_repid type any optional
in_struc type any optional
returning
value(out_table) type ref to lcl_table_display
exceptions
no_parameter
not_found,
refresh_objects.
protected section.
private section.
methods: init_block_list,
fill_fieldcat importing repid type repid
struc type tabname
changing fcat type slis_t_fieldcat_alv
exceptions no_definition,
get_definition importing repid type repid
struc type tabname
changing abap type rsfb_source,
recursive_definition importing repid type repid
changing abap type rsfb_source,
map_structure importing source type any
changing destin type any,
get_default_variant changing out_variant type disvariant.
*----------------------------------------------------------------------*
* LCL_TABLE_DISPLAY IMPLEMENTATION
*----------------------------------------------------------------------*
class lcl_table_display implementation.
***
* Display table in ALV list
***
method display_list.
data: l_object type ref to lcl_table_display,
l_tabname type tabname,
l_found type c.
l_tabname = in_tabname.
loop at gt_table_obj into l_object.
if l_object->g_table = l_tabname.
l_found = 'X'.
exit.
endif.
endloop.
if l_found is initial.
l_object = lcl_table_display=>create_table( l_tabname ).
if g_block_mode is initial.
l_object->g_table_type = 4.
else.
l_object->g_table_type = 2.
endif.
call method l_object->set_all_events.
endif.
call method l_object->output_list.
endmethod. "display_list
***
* Display table in ALV grid
***
method display_grid.
data: l_object type ref to lcl_table_display,
l_tabname type tabname,
l_found type c.
l_tabname = in_tabname.
loop at gt_table_obj into l_object.
if l_object->g_table = l_tabname.
l_found = 'X'.
exit.
endif.
endloop.
if l_found is initial.
l_object = lcl_table_display=>create_table( l_tabname ).
if g_block_mode is initial.
l_object->g_table_type = 4.
else.
l_object->g_table_type = 2.
endif.
call method l_object->set_all_events.
endif.
if g_block_mode is initial.
call method l_object->output_grid.
else.
call method l_object->output_list.
endif.
endmethod. "display_grid
***
* Display tables in ALV hierarchy
***
method display_hier.
data: l_tabnam1 type tabname,
l_tabnam2 type tabname,
lt_fcat1 type slis_t_fieldcat_alv,
lt_fcat2 type slis_t_fieldcat_alv,
ls_fcat1 type slis_fieldcat_alv,
ls_fcat2 type slis_fieldcat_alv.
l_tabnam1 = in_header.
l_tabnam2 = in_detail.
call method lcl_table_display=>get_existing_table
exporting
in_tabname = l_tabnam1
receiving
out_table = g_header_table
exceptions
not_found = 1.
if sy-subrc ne 0.
g_header_table = lcl_table_display=>create_table( l_tabnam1 ).
if g_block_mode is initial.
g_header_table->g_table_type = 1.
else.
g_header_table->g_table_type = 3.
endif.
call method g_header_table->set_all_events.
endif.
call method lcl_table_display=>get_existing_table
exporting
in_tabname = l_tabnam2
receiving
out_table = g_detail_table
exceptions
not_found = 1.
if sy-subrc ne 0.
g_detail_table = lcl_table_display=>create_table( l_tabnam2 ).
endif.
out_table = l_object.
endmethod. "create_table
***
* Get existing table
***
method get_existing_table.
data: l_object type ref to lcl_table_display,
l_tabname type tabname,
l_repid type repid,
l_struc type tabname,
l_found type c.
l_tabname = in_tabname.
l_repid = in_repid.
l_struc = in_struc.
if l_tabname is initial.
if l_repid is initial and
l_struc is initial.
raise no_parameter.
else.
* Get last existing table with same definition
loop at gt_table_obj into l_object.
if l_object->g_repid = l_repid and
l_object->g_struc = l_struc.
l_found = 'X'.
exit.
endif.
endloop.
endif.
else.
* Get last existing table with same name
loop at gt_table_obj into l_object.
if l_object->g_table = l_tabname.
l_found = 'X'.
exit.
endif.
endloop.
endif.
if l_found is initial.
raise not_found.
else.
out_table = l_object.
endif.
endmethod. "get_existing_table
***
* Create table display
***
method constructor.
data: l_object type ref to lcl_table_display.
* Set attributes
me->g_repid = l_repid.
me->g_struc = l_struc.
me->g_table = l_struc.
replace 'TY' with 'WT' into me->g_table.
* Field catalog
call method lcl_table_display=>get_existing_table
exporting
in_repid = l_repid
in_struc = l_struc
receiving
out_table = l_object
exceptions
not_found = 1.
if sy-subrc = 0.
me->gt_fcat = l_object->get_alv_fieldcat( ).
call method set_table_name
exporting
in_tabname = me->g_table.
else.
call method fill_fieldcat
exporting
repid = l_repid
struc = l_struc
changing
fcat = me->gt_fcat.
if me->gt_fcat is initial.
raise empty_fieldcat.
endif.
endif.
if g_block_mode is initial.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = g_header_table->g_repid
is_layout = g_header_table->gs_layo
it_fieldcat = lt_fcat
it_sort = lt_sort
i_save = 'U'
is_variant = ls_vari
it_events = g_header_table->gt_evnt
i_tabname_header = g_header_table->g_table
i_tabname_item = g_detail_table->g_table
is_keyinfo = ls_keyi
is_print = g_header_table->gs_prin
tables
t_outtab_header = <head>
t_outtab_item = <deta>
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
raise display_error.
endif.
call method refresh_objects.
else.
call function 'REUSE_ALV_BLOCK_LIST_HS_APPEND'
exporting
is_layout = g_header_table->gs_layo
it_fieldcat = lt_fcat
is_keyinfo = ls_keyi
i_header_tabname = g_header_table->g_table
i_item_tabname = g_detail_table->g_table
it_events = g_header_table->gt_evnt
it_sort = lt_sort
i_text = g_block_text
tables
t_outtab_header = <head>
t_outtab_item = <deta>
exceptions
program_error = 1
maximum_of_appends_reached = 2
others = 3.
if sy-subrc <> 0.
raise display_error.
endif.
endif.
endmethod. "output_hierarchy
***
* Init block list
***
method init_block_list.
data: ls_evnt1 type slis_alv_event,
ls_evnt2 type slis_alv_event.
free: me->gt_defin.
if me->gt_defin is initial.
raise no_definition.
endif.
* Retrieve tokens
scan abap-source abap
tokens into lt_token
statements into lt_state.
l_field = in_field.
if in_noout is supplied.
l_noout = in_noout.
else.
l_noout = 'X'.
endif.
if in_tech is supplied.
l_tech = in_tech.
endif.
l_field = in_field.
if in_edit is supplied.
l_edit = in_edit.
else.
l_edit = 'X'.
endif.
l_field = in_field.
loop at me->gt_fcat into ls_fcat
where fieldname = l_field.
ls_fcat-seltext_m = in_ftext.
ls_fcat-ddictxt = 'M'.
modify gt_fcat from ls_fcat transporting seltext_m ddictxt.
endloop.
endmethod. "set_alv_fieldtext
***
* Set field sum
***
method set_alv_fieldsum.
data: l_field type fieldname,
l_dosum type c,
ls_fcat type slis_fieldcat_alv.
l_field = in_field.
if in_dosum is supplied.
l_dosum = in_dosum.
else.
l_dosum = 'X'.
endif.
l_field = in_field.
read table me->gt_fcat into ls_fcat
with key fieldname = l_field.
if sy-subrc = 0.
l_tabix = sy-tabix.
else.
exit.
endif.
if in_desc is supplied.
l_desc = in_desc.
endif.
if in_group is supplied.
l_group = in_group.
else.
l_group = '*'.
endif.
if in_subtot is supplied.
l_subtot = in_subtot.
else.
l_subtot = 'X'.
endif.
ls_sort-spos = l_index.
ls_sort-fieldname = in_field.
ls_sort-tabname = me->g_table.
if l_desc is initial.
ls_sort-up = 'X'.
else.
ls_sort-down = 'X'.
endif.
ls_sort-group = l_group.
ls_sort-subtot = l_subtot.
if in_key is supplied.
l_key = in_key.
else.
l_key = 'X'.
endif.
loop at me->gt_fcat into ls_fcat from 1 to in_level.
ls_fcat-key = l_key.
modify gt_fcat from ls_fcat transporting key.
endloop.
endmethod. "set_alv_keys
***
* Add event
***
method set_alv_event.
data: ls_evnt type slis_alv_event.
endmethod. "set_all_events
***
* Map fields from incoming structure into attribute
***
method map_structure.
data: ob_desc type ref to cl_abap_structdescr,
ls_compo type abap_compdescr.
out_variant-report = me->g_repid.
out_variant-handle = me->g_variant_level.
out_variant-username = sy-uname.
call function 'REUSE_ALV_VARIANT_DEFAULT_GET'
exporting
i_save = 'U'
changing
cs_variant = out_variant
exceptions
others = 0.
endmethod. "get_default_variant
endclass. "lcl_table_display IMPLEMENTATION
[edit]
Links
l_title = sy-repid.
FUNCTION Zsend_report_mail.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_UNAME) TYPE SYUNAME DEFAULT SY-UNAME
*" REFERENCE(I_TITLE) TYPE SO_OBJ_DES
*" TABLES
*" IT_TEXT_DATA
*" EXCEPTIONS
*" INVALID_USER
*" MAIL_SEND_ERROR
*" OPEN_FILE
*" FILE_GET_NAME
*"----------------------------------------------------------------------
* save file
OPEN DATASET l_filename FOR OUTPUT IN TEXT MODE.
IF sy-subrc NE 0.
RAISE open_file.
ENDIF.
LOOP AT it_text_data. " into l_text_data.
TRANSFER it_text_data TO l_filename.
ENDLOOP.
CLOSE DATASET l_filename.
* mail parameters
REFRESH lt_object_parb.
CLEAR lt_object_parb.
lt_object_parb-name = 'FUNCTION'. " mail identifier
lt_object_parb-value = 'FILE_DOWNLOAD'. " mail identifier
APPEND lt_object_parb.
lt_object_parb-name = 'FILENAME'.
lt_object_parb-value = l_filename.
APPEND lt_object_parb.
ENDFUNCTION.
========================================================
===================
FUNCTION zmail_download.
*"----------------------------------------------------------------------
*"*"Local interface:
*" TABLES
*" MSGDIAL STRUCTURE SOPARBI1
*"----------------------------------------------------------------------
* This function is called in a SAP mail to download a file from the
* application server file system.
* Function ZSEND_REPORT_MAIL is used to save report result
* on application server file system and to send SAP mail to user.
* Based on UK COM solution by Damian Norton.
* read parameters
LOOP AT msgdial INTO ls_msgdial.
CASE ls_msgdial-name.
WHEN 'FUNCTION'.
l_operation = ls_msgdial-value.
WHEN 'FILENAME'.
l_filename = ls_msgdial-value.
WHEN OTHERS.
MESSAGE e368(00) WITH 'Invalid parameter' ls_msgdial-name.
ENDCASE. " ls_msgdial-name
ENDLOOP. " msgdial
IF l_operation = 'FILE_DOWNLOAD'.
* check, whether file exists on presentation server
REFRESH lt_text_data.
OPEN DATASET l_filename FOR INPUT IN TEXT MODE.
IF sy-subrc = 0.
DO.
READ DATASET l_filename INTO lt_text_data-line.
IF sy-subrc = 0.
APPEND lt_text_data.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET l_filename.
* request filename on presentation server - or GUI_DOWNLOAD??
CALL FUNCTION 'DOWNLOAD'
TABLES
data_tab = lt_text_data
EXCEPTIONS
invalid_filesize = 1
invalid_table_width = 2
invalid_type = 3
no_batch = 4
unknown_error = 5
gui_refuse_filetransfer = 6
customer_error = 7
OTHERS = 8.
IF sy-subrc NE 0.
MESSAGE e688(00) WITH 'File download error' sy-subrc.
ENDIF.
ELSE.
MESSAGE e398(00) WITH 'File open error' l_filename.
ENDIF. " sy-subrc = 0 (OPEN DATASET)
ENDIF. " l_operation = 'FILE_DOWNLOAD'
ENDFUNCTION.
REPORT ZT401212.
*DATA : BEGDATE TYPE DATUM VALUE '20091001'.
*data : lr_value1 type ztsdmp_result,
* lr_uname type ztsdmp_result with header line,
* wa_value1 TYPE zlsdmp_result.
*
*
*SELECT VALUE1 AS low FROM ZENHDATA
*INTO CORRESPONDING FIELDS OF TABLE lr_value1
*WHERE ZENH = 'E000000198'
*AND active EQ 'X'.
*clear wa_value1.
*
*LOOP AT lr_value1 INTO wa_value1.
*
* lr_uname-sign = 'I'. lr_uname-option = 'EQ'. lr_uname-low = wa_va
lue1-low.
* append lr_uname.
*ENDLOOP.
*IF sy-uname IN lr_uname.
*BEGDATE(4) = BEGDATE(4) - 1.
*ENDIF.
data : wa_control_rec type EDIDC,
lv_pathname type EDI_PATH-PTHNAM.
wa_control_rec-docnum = '0000000000767117'.
wa_control_rec-mandt = sy-mandt.
CALL FUNCTION 'EDI_PATH_NAME_OUT'
EXPORTING
PORT = 'ZCROP'
CONTROLREC = wa_control_rec
IMPORTING
PATHNAME = lv_pathname.
data : i_sel1 TYPE TABLE OF rsparams,
wa_sel type rsparams.
wa_sel-selname = 'HOST'. "Parameter P_object
wa_sel-kind = 'P'. "Parameter
wa_sel-low = '168.246.56.45'.
append wa_sel to i_sel1.
wa_sel-selname = 'USER'. "Parameter P_object
wa_sel-kind = 'P'. "Parameter
wa_sel-low = 'anonymous'.
append wa_sel to i_sel1.
wa_sel-selname = 'PASSWD'. "Parameter P_object
wa_sel-kind = 'P'. "Parameter
wa_sel-low = 'anonymous'.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'.
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
If sy-sysid eq 'MSP'.
wa_sel-low = 'cd seedsftp/ShipNoticeIDOCs'.
ELSEIF SY-SYSID EQ 'DEV' OR SY-SYSID EQ 'TRI'.
wa_sel-low = 'cd seedsftp/ShipNoticeIDOCs_test'.
endif.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'. "Parameter
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
wa_sel-low = 'append[]'.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'. "Parameter
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
CONCATENATE lv_pathname(22) '[' into wa_sel-low.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'. "Parameter
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
CONCATENATE lv_pathname+22(40) '[' into wa_sel-low.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'. "Parameter
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
move '[]' to wa_sel-low.
append wa_sel to i_sel1.
wa_sel-selname = 'CMDS'. "Parameter P_object
wa_sel-kind = 'S'. "Parameter
wa_sel-sign = 'I'.
wa_sel-option = 'EQ'.
concatenate 'shipment_idoc-' lv_pathname+40(21) '.dat' into wa_s
el-low.
append wa_sel to i_sel1.
data : lv_count LIKE tbtcjob-jobcount.
CALL FUNCTION 'JOB_OPEN'
EXPORTING
* DELANFREP = ' '
* JOBGROUP = ' '
JOBNAME = 'zftpcall_ship_notice'
SDLSTRTDT = sy-datum
SDLSTRTTM = sy-uzeit
* JOBCLASS =
IMPORTING
JOBCOUNT = lv_count
* CHANGING
* RET =
* EXCEPTIONS
* CANT_CREATE_JOB = 1
* INVALID_JOB_DATA = 2
* JOBNAME_MISSING = 3
* OTHERS = 4
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*submit zftpcall_ship_notice to sap-spool without spool dynpro
*with selection-table i_sel1 user 'ZNAFTA' VIA JOB 'zftpcall_ship_noti
ce' number lv_count
*with operatingsystem ''
*and return.
data : ls_varid LIKE varid,
lit_vari_text LIKE varit OCCURS 0 WITH HEADER LINE.
CLEAR lit_vari_text.
lit_vari_text-langu = sy-langu.
lit_vari_text-report = 'ZFTPCALL'.
lit_vari_text-variant = 'ship_notice'.
lit_vari_text-vtext = 'ship notice variant'.
APPEND lit_vari_text.
*.check variant
DATA: rc LIKE sy-subrc.
CALL FUNCTION 'RS_VARIANT_EXISTS'
EXPORTING
report = 'ZFTPCALL'
variant = 'ship_notice'
IMPORTING
r_c = rc
EXCEPTIONS
not_authorized = 01
no_report = 02
report_not_existent = 03
report_not_supplied = 04.
IF sy-subrc <> 0.
rc = 8.
ENDIF.
if rc = 0.
CLEAR ls_varid.
ls_varid-report = 'ZFTPCALL'.
ls_varid-variant = 'ship_notice'.
* ls_varid-transport = 'F'.
* ls_varid-environmnt = 'A'.
* ADD 1 TO ls_varid-version .
ls_varid-ename = sy-uname.
ls_varid-edat = sy-datum.
ls_varid-etime = sy-uzeit.
ls_varid-mlangu = sy-langu.
ADD 1 TO ls_varid-version.
CALL FUNCTION 'RS_CHANGE_CREATED_VARIANT'
EXPORTING
curr_report = 'ZFTPCALL'
curr_variant = 'ship_notice'
vari_desc = ls_varid
ONLY_CONTENTS = 'Y'
TABLES
vari_contents = i_sel1
vari_text = lit_vari_text
EXCEPTIONS
illegal_report_or_variant = 01
illegal_variantname = 02
not_authorized = 03
not_executed = 04
report_not_existent = 05
report_not_supplied = 06
variant_doesnt_exist = 07
variant_locked = 08
selections_no_match = 09.
COMMIT WORK.
else.
CALL FUNCTION 'RS_CREATE_VARIANT'
EXPORTING
CURR_REPORT = 'ZFTPCALL'
CURR_VARIANT = 'ship_notice'
VARI_DESC = ls_varid
TABLES
VARI_CONTENTS = i_sel1
VARI_TEXT = lit_vari_text
* VSCREENS =
* EXCEPTIONS
* ILLEGAL_REPORT_OR_VARIANT = 1
* ILLEGAL_VARIANTNAME = 2
* NOT_AUTHORIZED = 3
* NOT_EXECUTED = 4
* REPORT_NOT_EXISTENT = 5
* REPORT_NOT_SUPPLIED = 6
* VARIANT_EXISTS = 7
* VARIANT_LOCKED = 8
* OTHERS = 9
.
endif.
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 'JOB_SUBMIT'
EXPORTING
* ARCPARAMS =
AUTHCKNAM = 'ZBTCNAFTA'
* COMMANDNAME = ' '
* OPERATINGSYSTEM = 'chwsxd34_DEV_00'
* EXTPGM_NAME = ' '
* EXTPGM_PARAM = ' '
* EXTPGM_SET_TRACE_ON = ' '
* EXTPGM_STDERR_IN_JOBLOG = 'X'
* EXTPGM_STDOUT_IN_JOBLOG = 'X'
* EXTPGM_SYSTEM = 'chwsxd34_DEV_00'
* EXTPGM_RFCDEST = 'chwsxd34_DEV_00'
* EXTPGM_WAIT_FOR_TERMINATION = 'X'
JOBCOUNT = lv_count
JOBNAME = 'zftpcall_ship_notice'
LANGUAGE = sy-langu
* PRIPARAMS = ' '
REPORT = 'ZFTPCALL'
VARIANT = 'ship_notice'
* IMPORTING
* STEP_NUMBER =
* EXCEPTIONS
* BAD_PRIPARAMS = 1
* BAD_XPGFLAGS = 2
* INVALID_JOBDATA = 3
* JOBNAME_MISSING = 4
* JOB_NOTEX = 5
* JOB_SUBMIT_FAILED = 6
* LOCK_FAILED = 7
* PROGRAM_MISSING = 8
* PROG_ABAP_AND_EXTPG_SET = 9
* OTHERS = 10
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
data : target_server like BTCTGTSRVR-SRVNAME.
if sy-sysid eq 'MSP'.
target_server = 'sapmspci_MSP_00'.
elseif sy-sysid eq 'TRI'.
target_server = 'saptria1_TRI_01'.
elseif sy-sysid eq 'DEV'.
target_server = 'chwsxd34_DEV_00'.
endif.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
* AT_OPMODE = ' '
* AT_OPMODE_PERIODIC = ' '
* CALENDAR_ID = ' '
* EVENT_ID = ' '
* EVENT_PARAM = ' '
* EVENT_PERIODIC = ' '
JOBCOUNT = lv_count
JOBNAME = 'zftpcall_ship_notice'
* LASTSTRTDT = NO_DATE
* LASTSTRTTM = NO_TIME
* PRDDAYS = 0
* PRDHOURS = 0
* PRDMINS = 0
* PRDMONTHS = 0
* PRDWEEKS = 0
* PREDJOB_CHECKSTAT = ' '
* PRED_JOBCOUNT = ' '
* PRED_JOBNAME = ' '
SDLSTRTDT = SY-DATUM
SDLSTRTTM = SY-UZEIT
* STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS
STRTIMMED = 'X'
TARGETSYSTEM = 'X'
* START_ON_WORKDAY_NOT_BEFORE = SY-DATUM
* START_ON_WORKDAY_NR = 0
* WORKDAY_COUNT_DIRECTION = 0
* RECIPIENT_OBJ =
TARGETSERVER = target_server
* DONT_RELEASE = ' '
* TARGETGROUP = ' '
* DIRECT_START =
* IMPORTING
* JOB_WAS_RELEASED =
* CHANGING
* RET =
* EXCEPTIONS
* CANT_START_IMMEDIATE = 1
* INVALID_STARTDATE = 2
* JOBNAME_MISSING = 3
* JOB_CLOSE_FAILED = 4
* JOB_NOSTEPS = 5
* JOB_NOTEX = 6
* LOCK_FAILED = 7
* INVALID_TARGET = 8
* OTHERS = 9
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
select single * from tsp01 where rqident = spoolno.
if sy-subrc <> 0.
WRITE: / 'Spoolauftrag existiert nicht'(003)
COLOR COL_negative.
exit.
endif.
client = tsp01-rqclient.
name = tsp01-rqo1name.
CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
EXPORTING
AUTHORITY = 'SP01'
CLIENT = client
NAME = name
PART = 1
IMPORTING
* CHARCO =
* CREATER =
* CREDATE =
* DELDATE =
* MAX_CREDATE =
* MAX_DELDATE =
* NON_UNIQ =
* NOOF_PARTS =
* RECTYP =
* SIZE =
* STOTYP =
TYPE = type
OBJTYPE = objtype
EXCEPTIONS
FB_ERROR = 1
FB_RSTS_OTHER = 2
NO_OBJECT = 3
NO_PERMISSION = 4.
if objtype(3) = 'OTF'.
is_otf = 'X'.
else.
is_otf = space.
endif.
if is_otf = 'X'.
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = spoolno
NO_DIALOG = ' '
* DST_DEVICE =
* PDF_DESTINATION =
IMPORTING
PDF_BYTECOUNT = numbytes
PDF_SPOOLID = pdfspoolid
* OTF_PAGECOUNT =
BTC_JOBNAME = jobname
BTC_JOBCOUNT = jobcount
TABLES
PDF = pdf
EXCEPTIONS
ERR_NO_OTF_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DSTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
case sy-subrc.
when 0.
WRITE: / 'Funktion CONVERT_OTFSPOOLJOB_2_PDF erfolgreich'(001)
COLOR COL_POSITIVE.
when 1.
WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)
COLOR COL_negative.
exit.
when 2.
WRITE: / 'Spoolauftrag existiert nicht'(003)
COLOR COL_negative.
exit.
when 3.
WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)
COLOR COL_negative.
exit.
when others.
WRITE: / 'Fehler bei Funktion CONVERT_OTFSPOOLJOB_2_PDF'(005)
COLOR COL_negative.
exit.
endcase.
else.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
SRC_SPOOLID = spoolno
NO_DIALOG = ' '
* DST_DEVICE =
* PDF_DESTINATION =
IMPORTING
PDF_BYTECOUNT = numbytes
PDF_SPOOLID = pdfspoolid
* LIST_PAGECOUNT =
BTC_JOBNAME = jobname
BTC_JOBCOUNT = jobcount
TABLES
PDF = pdf
EXCEPTIONS
ERR_NO_ABAP_SPOOLJOB = 1
ERR_NO_SPOOLJOB = 2
ERR_NO_PERMISSION = 3
ERR_CONV_NOT_POSSIBLE = 4
ERR_BAD_DESTDEVICE = 5
USER_CANCELLED = 6
ERR_SPOOLERROR = 7
ERR_TEMSEERROR = 8
ERR_BTCJOB_OPEN_FAILED = 9
ERR_BTCJOB_SUBMIT_FAILED = 10
ERR_BTCJOB_CLOSE_FAILED = 11.
case sy-subrc.
when 0.
WRITE: / 'Funktion CONVERT_ABAPSPOOLJOB_2_PDF erfolgreich'(006
)
COLOR COL_POSITIVE.
when 1.
WRITE: / 'Kein OTF- und kein ABAP-Spoolauftrag'(002)
COLOR COL_negative.
exit.
when 2.
WRITE: / 'Spoolauftrag existiert nicht'(003)
COLOR COL_negative.
exit.
when 3.
WRITE: / 'Keine Berechtigung zum Lesen Spoolauftrag'(004)
COLOR COL_negative.
exit.
when others.
WRITE: / 'Fehler bei Funktion CONVERT_ABAPSPOOLJOB_2_PDF'(007)
COLOR COL_negative.
exit.
endcase.
endif.
*************** download PDF file ***********
check download = 'X'.
if not ( jobname is initial ).
WRITE: / 'Konvertierung per Hintergrundjob'(008)
COLOR COL_normal,
jobname, jobcount.
exit.
endif.
perform download_w_ext(RSTXPDFT) tables pdf
using p_file
'.pdf'
'BIN'
numbytes
cancel.
if cancel = space.
WRITE: / NUMBYTES, 'Bytes heruntergeladen in Datei'(009), P_FILE
.
endif.