Einer Datenbanktabelle (transparenten Tabelle) kann ein Berechtigungsgruppe zugeordnet werden. Wenn eine neue Berechtigungsgruppe angelegt werden soll, kann dies über die Transaktion SE54 "Generierung Tabellensicht" durchgeführt werden. Auf dem Einstiegsbild wird über den Radio Button "Berechtigungsgruppe" ausgewählt. Durch den Button "Anlegen/Ändern" gelangt man in den Pflege-Dialog zum Anlegen von Berechtigungsgruppen für Tabellen.
Siehe auch: SAP Dokumentation "Berechtigungsgruppen pflegen"
Wednesday, December 13, 2017
Monday, December 4, 2017
Thursday, May 18, 2017
Using HTML in Dynpro an react on user interactions
The report needs dynpro 2000 with a custom container 'CC' for the HTML control.
REPORT zjso_html_in_dynpro_event.
CLASS lcl_html DEFINITION.
PUBLIC SECTION.
CLASS-DATA: mo_cc TYPE REF TO cl_gui_custom_container.
CLASS-DATA: mo_html TYPE REF TO cl_gui_html_viewer.
CLASS-METHODS: pbo, user_command, leave_screen.
CLASS-METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.
ENDCLASS.
START-OF-SELECTION.
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
SET PF-STATUS '2000'.
SET TITLEBAR '2000'.
lcl_html=>pbo( ).
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
lcl_html=>user_command( ).
ENDMODULE.
CLASS lcl_html IMPLEMENTATION.
METHOD pbo.
DATA lv_url TYPE text1024.
DATA lt_html TYPE STANDARD TABLE OF text1024 WITH DEFAULT KEY.
DATA lt_event TYPE cntl_simple_events.
CHECK mo_cc IS NOT BOUND.
lt_html = VALUE #(
( |<!DOCTYPE html><head>| )
( | <meta charset="utf-8">| )
( | <title>HTML in Dynpro</title>| )
( | <style>| )
( ' body { font-family:segoe ui, arial, helvetica; }' )
( | </style>| )
( |<script>| )
( |function onClick(source) \{| )
( | window.location.href = 'SAPEVENT:'+source.innerHTML;| )
( |\}| )
( |</script>| )
( |</head>| )
( |<body>| )
( | <p>Hello, world!</p>| )
( | <a href="SAPEVENT:Hyperlink">Request SAP AS</a>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ef0000">red</div>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ffdd00">yellow</div>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#00ee00">green</div>| )
( |</body></html>| )
).
mo_cc = NEW #( 'CC' ).
mo_html = NEW #( mo_cc ).
" setup event handler for SAPEVENT from HTML control
INSERT VALUE #( eventid = mo_html->m_id_sapevent appl_event = abap_true ) INTO TABLE lt_event.
mo_html->set_registered_events( lt_event ).
SET HANDLER on_sapevent FOR mo_html.
" populate HTML control with HTML page
mo_html->load_data(
IMPORTING assigned_url = lv_url
CHANGING data_table = lt_html
).
mo_html->show_url( lv_url ).
ENDMETHOD.
METHOD user_command.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT'. leave_screen( ). LEAVE TO SCREEN 0.
WHEN 'BACK' OR 'EXIT'. leave_screen( ). LEAVE PROGRAM.
ENDCASE.
ENDMETHOD.
METHOD leave_screen.
IF mo_cc IS BOUND.
mo_cc->free( ).
ENDIF.
ENDMETHOD.
METHOD on_sapevent.
MESSAGE |onClick = { action }| TYPE 'I'.
" check contents of { postdata } and { query_table } in debugger
ENDMETHOD.
ENDCLASS.
REPORT zjso_html_in_dynpro_event.
CLASS lcl_html DEFINITION.
PUBLIC SECTION.
CLASS-DATA: mo_cc TYPE REF TO cl_gui_custom_container.
CLASS-DATA: mo_html TYPE REF TO cl_gui_html_viewer.
CLASS-METHODS: pbo, user_command, leave_screen.
CLASS-METHODS on_sapevent FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.
ENDCLASS.
START-OF-SELECTION.
CALL SCREEN 2000.
*&---------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&---------------------------------------------------------------------*
MODULE status_2000 OUTPUT.
SET PF-STATUS '2000'.
SET TITLEBAR '2000'.
lcl_html=>pbo( ).
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
lcl_html=>user_command( ).
ENDMODULE.
CLASS lcl_html IMPLEMENTATION.
METHOD pbo.
DATA lv_url TYPE text1024.
DATA lt_html TYPE STANDARD TABLE OF text1024 WITH DEFAULT KEY.
DATA lt_event TYPE cntl_simple_events.
CHECK mo_cc IS NOT BOUND.
lt_html = VALUE #(
( |<!DOCTYPE html><head>| )
( | <meta charset="utf-8">| )
( | <title>HTML in Dynpro</title>| )
( | <style>| )
( ' body { font-family:segoe ui, arial, helvetica; }' )
( | </style>| )
( |<script>| )
( |function onClick(source) \{| )
( | window.location.href = 'SAPEVENT:'+source.innerHTML;| )
( |\}| )
( |</script>| )
( |</head>| )
( |<body>| )
( | <p>Hello, world!</p>| )
( | <a href="SAPEVENT:Hyperlink">Request SAP AS</a>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ef0000">red</div>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#ffdd00">yellow</div>| )
( | <div onclick="onClick(this)" style="width: 120px; height: 120px; margin: 8px; background-color:#00ee00">green</div>| )
( |</body></html>| )
).
mo_cc = NEW #( 'CC' ).
mo_html = NEW #( mo_cc ).
" setup event handler for SAPEVENT from HTML control
INSERT VALUE #( eventid = mo_html->m_id_sapevent appl_event = abap_true ) INTO TABLE lt_event.
mo_html->set_registered_events( lt_event ).
SET HANDLER on_sapevent FOR mo_html.
" populate HTML control with HTML page
mo_html->load_data(
IMPORTING assigned_url = lv_url
CHANGING data_table = lt_html
).
mo_html->show_url( lv_url ).
ENDMETHOD.
METHOD user_command.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT'. leave_screen( ). LEAVE TO SCREEN 0.
WHEN 'BACK' OR 'EXIT'. leave_screen( ). LEAVE PROGRAM.
ENDCASE.
ENDMETHOD.
METHOD leave_screen.
IF mo_cc IS BOUND.
mo_cc->free( ).
ENDIF.
ENDMETHOD.
METHOD on_sapevent.
MESSAGE |onClick = { action }| TYPE 'I'.
" check contents of { postdata } and { query_table } in debugger
ENDMETHOD.
ENDCLASS.
Tuesday, May 9, 2017
Update IDoc Status
DATA ls_edi_ds TYPE edi_ds.
CLEAR es_edidc.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'
EXPORTING
document_number = iv_docnum
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_foreign_lock = 1
document_not_exist = 2
document_number_invalid = 3
document_is_already_open = 4
OTHERS = 5.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
ls_edi_ds = VALUE #(
docnum = iv_docnum
status = iv_status
uname = sy-uname
logdat = sy-datum
logtim = sy-uzeit
).
CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
EXPORTING
document_number = iv_docnum
idoc_status = ls_edi_ds
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_number_invalid = 1
other_fields_invalid = 2
status_invalid = 3
OTHERS = 4.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'
EXPORTING
document_number = iv_docnum
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_not_open = 1
failure_in_db_write = 2
parameter_error = 3
status_set_missing = 4
OTHERS = 5.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
CLEAR es_edidc.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'
EXPORTING
document_number = iv_docnum
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_foreign_lock = 1
document_not_exist = 2
document_number_invalid = 3
document_is_already_open = 4
OTHERS = 5.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
ls_edi_ds = VALUE #(
docnum = iv_docnum
status = iv_status
uname = sy-uname
logdat = sy-datum
logtim = sy-uzeit
).
CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
EXPORTING
document_number = iv_docnum
idoc_status = ls_edi_ds
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_number_invalid = 1
other_fields_invalid = 2
status_invalid = 3
OTHERS = 4.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'
EXPORTING
document_number = iv_docnum
IMPORTING
idoc_control = es_edidc
EXCEPTIONS
document_not_open = 1
failure_in_db_write = 2
parameter_error = 3
status_set_missing = 4
OTHERS = 5.
IF sy-subrc <> 0.
CLEAR es_edidc.
RETURN.
ENDIF.
Monday, March 27, 2017
SAP Tables for Status Handling (in ABAP)
Some important tables concerning status:
JEST Individual Object Status
JCDS Change Documents for System/User Statuses (Table JEST)
JSTO Status object information
TJ02 System Status
TJ02T System status texts
TJ20T Texts for Status Profiles
TJ30T Texts for User Status
JEST Individual Object Status
JCDS Change Documents for System/User Statuses (Table JEST)
JSTO Status object information
TJ02 System Status
TJ02T System status texts
TJ20T Texts for Status Profiles
TJ30T Texts for User Status
Tuesday, February 14, 2017
Wednesday, January 25, 2017
Sending emails from ABAP / E-Mail mit ABAP versenden
* https://wiki.scn.sap.com/wiki/display/Snippets/Sending+mail+with+attachment+using+Object+Oriented+Approach
report zjso_send_email.
class lcl_email definition final.
public section.
class-methods send
importing
iv_subject type so_obj_des
it_message_body type bcsy_text
it_attachment type rmps_t_post_content optional
iv_sender_email type adr6-smtp_addr
it_recipient type uiyt_iusr
raising cx_send_req_bcs cx_document_bcs cx_address_bcs.
endclass.
start-of-selection.
try.
lcl_email=>send(
iv_subject = 'Betreff der E-Mail'(001)
it_message_body = value #(
( line = 'Hallo,'(002) )
( line = ' diese E-Mail wurde aus einem SAP-System verschickt.'(003) )
( line = '' )
( line = 'Mit freundlichen Grüßen'(004) )
)
iv_sender_email = 'marvin.maybe@p1zz4.com'
it_recipient = value #(
mandt = sy-mandt
( email = 'michael.laender@deutsch.de' )
( email = 'ablink@usa.com' )
)
).
write / 'E-Mail erfolgreich versendet'(005).
catch cx_send_req_bcs cx_document_bcs cx_address_bcs into data(go_x).
write / go_x->get_text( ).
endtry.
class lcl_email implementation.
method send.
data lo_send_request type ref to cl_bcs.
data lo_document type ref to cl_document_bcs.
data lo_sender type ref to if_sender_bcs.
data lv_attachment_subject type so_obj_des.
data lo_recipient type ref to if_recipient_bcs.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_message_body
i_subject = iv_subject
).
loop at it_attachment into data(ls_attachment).
lv_attachment_subject = ls_attachment-subject.
lo_document->add_attachment(
i_attachment_type = ls_attachment-objtp
i_attachment_subject = lv_attachment_subject
i_att_content_hex = ls_attachment-cont_hex
).
endloop.
lo_send_request->set_document( lo_document ).
lo_sender = cl_cam_address_bcs=>create_internet_address( iv_sender_email ).
lo_send_request->set_sender( lo_sender ).
loop at it_recipient into data(ls_recipient) where email is not initial.
lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_recipient-email ).
lo_send_request->add_recipient( exporting
i_recipient = lo_recipient
i_express = 'X'
).
endloop.
lo_send_request->send( abap_true ).
endmethod.
endclass.
Check transaction SOST after sending an email.
report zjso_send_email.
class lcl_email definition final.
public section.
class-methods send
importing
iv_subject type so_obj_des
it_message_body type bcsy_text
it_attachment type rmps_t_post_content optional
iv_sender_email type adr6-smtp_addr
it_recipient type uiyt_iusr
raising cx_send_req_bcs cx_document_bcs cx_address_bcs.
endclass.
start-of-selection.
try.
lcl_email=>send(
iv_subject = 'Betreff der E-Mail'(001)
it_message_body = value #(
( line = 'Hallo,'(002) )
( line = ' diese E-Mail wurde aus einem SAP-System verschickt.'(003) )
( line = '' )
( line = 'Mit freundlichen Grüßen'(004) )
)
iv_sender_email = 'marvin.maybe@p1zz4.com'
it_recipient = value #(
mandt = sy-mandt
( email = 'michael.laender@deutsch.de' )
( email = 'ablink@usa.com' )
)
).
write / 'E-Mail erfolgreich versendet'(005).
catch cx_send_req_bcs cx_document_bcs cx_address_bcs into data(go_x).
write / go_x->get_text( ).
endtry.
class lcl_email implementation.
method send.
data lo_send_request type ref to cl_bcs.
data lo_document type ref to cl_document_bcs.
data lo_sender type ref to if_sender_bcs.
data lv_attachment_subject type so_obj_des.
data lo_recipient type ref to if_recipient_bcs.
lo_send_request = cl_bcs=>create_persistent( ).
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_message_body
i_subject = iv_subject
).
loop at it_attachment into data(ls_attachment).
lv_attachment_subject = ls_attachment-subject.
lo_document->add_attachment(
i_attachment_type = ls_attachment-objtp
i_attachment_subject = lv_attachment_subject
i_att_content_hex = ls_attachment-cont_hex
).
endloop.
lo_send_request->set_document( lo_document ).
lo_sender = cl_cam_address_bcs=>create_internet_address( iv_sender_email ).
lo_send_request->set_sender( lo_sender ).
loop at it_recipient into data(ls_recipient) where email is not initial.
lo_recipient = cl_cam_address_bcs=>create_internet_address( ls_recipient-email ).
lo_send_request->add_recipient( exporting
i_recipient = lo_recipient
i_express = 'X'
).
endloop.
lo_send_request->send( abap_true ).
endmethod.
endclass.
Check transaction SOST after sending an email.
Thursday, December 22, 2016
concerning iDOCs
Transactions
| WE05 | IDOC Liste |
| WE09 | IDOC(Nach IDOCS über Inhalte bzw. Felder suchen) |
| WE20 | Partnevereinbarungen(Verb. Zwischen Belegen und IDOC Generiereung) |
| BD87 | Nachverarbeitung von IDOCS |
| WE19 | Anlage und Verarbeitung von Testidocs(Als Vorlage bestehendes IDOC) |
| WEDI | Überblick |
| WE60 | Dokumention Idoc Struktur |
Tables
| TBDBE | BAPI-ALE Interface for Inbound Processing Function modules to process inbound, per message type |
Function Modules
| BAPI_IDOC_INPUT1 | Inbound BAPI IDoc: Individual Processing |
Friday, December 9, 2016
function module to get list of application servers
call function 'TH_SERVER_LIST'
tables
list = lt_server
exceptions
no_server_list = 1
others = 2.
tables
list = lt_server
exceptions
no_server_list = 1
others = 2.
check with abap which jobs are running
select single jobname
from tbtco
into lv_jobname
where
jobname like lv_jobname_pat and
status = 'R'.
from tbtco
into lv_jobname
where
jobname like lv_jobname_pat and
status = 'R'.
create and start background jobs from abap
data lv_job_was_released type abap_bool.
data lv_ret type i.
data lv_stepcount type btcstepcnt.
call function 'JOB_OPEN'
exporting
jobname = lv_jobname
importing
jobcount = lv_jobcount
changing
ret = lv_ret
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc <> 0.
" ...
return.
endif.
* submit (mo_run->ms_run-client_report)
* using selection-set mv_variant
* user sy-uname via job mv_jobname number mv_jobcount
* and return.
* Starting the report with submit, SM37 will display a
* temporary variant 0.. insteat of the created variant
call function 'JOB_SUBMIT'
exporting
authcknam = sy-uname
jobcount = lv_jobcount
jobname = lv_jobname
report = lv_client_report
variant = lv_variant
importing
step_number = lv_stepcount
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.
" ...
return.
endif.
call function 'JOB_CLOSE'
exporting
jobcount = lv_jobcount
jobname = lv_jobname
targetsystem = lv_server
strtimmed = 'X' " start immediately
importing
job_was_released = lv_job_was_released
changing
ret = lv_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.
" ...
return.
endif.
data lv_ret type i.
data lv_stepcount type btcstepcnt.
call function 'JOB_OPEN'
exporting
jobname = lv_jobname
importing
jobcount = lv_jobcount
changing
ret = lv_ret
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc <> 0.
" ...
return.
endif.
* submit (mo_run->ms_run-client_report)
* using selection-set mv_variant
* user sy-uname via job mv_jobname number mv_jobcount
* and return.
* Starting the report with submit, SM37 will display a
* temporary variant 0.. insteat of the created variant
call function 'JOB_SUBMIT'
exporting
authcknam = sy-uname
jobcount = lv_jobcount
jobname = lv_jobname
report = lv_client_report
variant = lv_variant
importing
step_number = lv_stepcount
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.
" ...
return.
endif.
call function 'JOB_CLOSE'
exporting
jobcount = lv_jobcount
jobname = lv_jobname
targetsystem = lv_server
strtimmed = 'X' " start immediately
importing
job_was_released = lv_job_was_released
changing
ret = lv_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.
" ...
return.
endif.
save report variants for jobs
data ls_varid type varid.
data ls_varit type varit.
data lt_varit type standard table of varit with empty key.
ls_varid-mandt = sy-mandt. " Mandant
ls_varid-report = lv_client_report.
ls_varid-variant = lv_variant.
ls_varid-flag1 = ''.
ls_varid-flag2 = ''.
ls_varid-transport = ''.
ls_varid-environmnt = 'B'. " Batch
ls_varid-protected = ''.
ls_varid-secu = ''. " Berechtigungsgruppe
ls_varid-version = ''. " Versionsnummer der Variante
ls_varid-ename = sy-uname.
ls_varid-edat = sy-datum. "
ls_varid-etime = sy-uzeit. "
ls_varid-aename = sy-uname.
ls_varid-aedat = sy-datum.
ls_varid-aetime = sy-uzeit.
ls_varid-mlangu = sy-langu.
ls_varid-xflag1 = ''.
ls_varid-xflag2 = ''.
ls_varit-mandt = sy-mandt.
ls_varit-langu = sy-langu.
ls_varit-report = lv_client_report.
ls_varit-variant = lv_variant.
ls_varit-vtext = |My Variant { sy-datum date = iso } | ??
|{ sy-uzeit time = iso }|.
insert ls_varit into table lt_varit.
call function 'RS_CREATE_VARIANT'
exporting
curr_report = lv_client_report
curr_variant = lv_variant
vari_desc = ls_varid
tables
vari_contents = lt_rsparam
vari_text = lt_varit
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.
if sy-subrc = 0.
commit work.
else.
" s...
endif.
data ls_varit type varit.
data lt_varit type standard table of varit with empty key.
ls_varid-mandt = sy-mandt. " Mandant
ls_varid-report = lv_client_report.
ls_varid-variant = lv_variant.
ls_varid-flag1 = ''.
ls_varid-flag2 = ''.
ls_varid-transport = ''.
ls_varid-environmnt = 'B'. " Batch
ls_varid-protected = ''.
ls_varid-secu = ''. " Berechtigungsgruppe
ls_varid-version = ''. " Versionsnummer der Variante
ls_varid-ename = sy-uname.
ls_varid-edat = sy-datum. "
ls_varid-etime = sy-uzeit. "
ls_varid-aename = sy-uname.
ls_varid-aedat = sy-datum.
ls_varid-aetime = sy-uzeit.
ls_varid-mlangu = sy-langu.
ls_varid-xflag1 = ''.
ls_varid-xflag2 = ''.
ls_varit-mandt = sy-mandt.
ls_varit-langu = sy-langu.
ls_varit-report = lv_client_report.
ls_varit-variant = lv_variant.
ls_varit-vtext = |My Variant { sy-datum date = iso } | ??
|{ sy-uzeit time = iso }|.
insert ls_varit into table lt_varit.
call function 'RS_CREATE_VARIANT'
exporting
curr_report = lv_client_report
curr_variant = lv_variant
vari_desc = ls_varid
tables
vari_contents = lt_rsparam
vari_text = lt_varit
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.
if sy-subrc = 0.
commit work.
else.
" s...
endif.
Monday, November 28, 2016
Convert internal table to CSV
report zjso_itab_to_csv.
types gtt_string type standard table of string with empty key.
class lcl_conv definition.
public section.
class-methods conv importing it_input type any table returning value(et_csv) type gtt_string.
class-methods struct_to_csv_row importing is_row type any returning value(rv_csv) type string.
class-methods struct_shorttext_to_csv_row importing is_row type any returning value(rv_csv) type string.
class-methods convert_any_to_string importing iv_any type any returning value(rv_string) type string.
class-methods esc importing iv_string type string returning value(rv_string) type string.
endclass.
start-of-selection.
select * from t001w into table @data(gt_t001w).
cl_demo_output=>display_data( lcl_conv=>conv( gt_t001w ) ).
class lcl_conv implementation.
method conv.
field-symbols <ls_row> type any.
loop at it_input assigning <ls_row>.
if sy-tabix = 1.
insert struct_shorttext_to_csv_row( <ls_row> ) into table et_csv.
endif.
insert struct_to_csv_row( <ls_row> ) into table et_csv.
endloop.
endmethod.
method struct_to_csv_row.
data lv_component_count type i.
data lv_datatype type c. "#EC NEEDED
data lv_i type i.
data lv_conv_string type string.
field-symbols <lv_component> type any.
clear rv_csv.
describe field is_row type lv_datatype components lv_component_count.
lv_i = 1.
do lv_component_count times.
assign component lv_i of structure is_row to <lv_component>.
lv_conv_string = convert_any_to_string( <lv_component> ).
if lv_i = 1.
rv_csv = lv_conv_string.
else.
rv_csv = |{ rv_csv };{ lv_conv_string }|.
endif.
add 1 to lv_i.
enddo.
endmethod.
method struct_shorttext_to_csv_row.
data lo_sdesc type ref to cl_abap_structdescr.
data lt_ddic_field type ddfields.
data ls_ddic_field type dfies.
data lv_tabix type sytabix.
data lv_shorttext type string.
clear rv_csv.
lo_sdesc = cast #( cl_abap_structdescr=>describe_by_data( is_row ) ).
lt_ddic_field = lo_sdesc->get_ddic_field_list( ).
loop at lt_ddic_field into ls_ddic_field.
lv_tabix = sy-tabix.
lv_shorttext = esc( conv #( ls_ddic_field-fieldtext ) ).
if lv_tabix = 1.
rv_csv = lv_shorttext.
else.
rv_csv = |{ rv_csv };{ lv_shorttext }|.
endif.
endloop.
endmethod.
method convert_any_to_string.
data lv_type type c.
data lv_d type d.
data lv_t type t.
clear rv_string.
describe field iv_any type lv_type.
case lv_type.
when 'D'. " Date
lv_d = iv_any.
rv_string = |{ lv_d date = user }|.
when 'T'. " time
lv_t = iv_any.
rv_string = |{ lv_t time = user }|.
when others.
rv_string = iv_any.
endcase.
rv_string = esc( rv_string ).
endmethod.
method esc.
if iv_string cs ';'.
rv_string = |'{ rv_string }'|.
else.
rv_string = iv_string.
endif.
endmethod.
endclass.
types gtt_string type standard table of string with empty key.
class lcl_conv definition.
public section.
class-methods conv importing it_input type any table returning value(et_csv) type gtt_string.
class-methods struct_to_csv_row importing is_row type any returning value(rv_csv) type string.
class-methods struct_shorttext_to_csv_row importing is_row type any returning value(rv_csv) type string.
class-methods convert_any_to_string importing iv_any type any returning value(rv_string) type string.
class-methods esc importing iv_string type string returning value(rv_string) type string.
endclass.
start-of-selection.
select * from t001w into table @data(gt_t001w).
cl_demo_output=>display_data( lcl_conv=>conv( gt_t001w ) ).
class lcl_conv implementation.
method conv.
field-symbols <ls_row> type any.
loop at it_input assigning <ls_row>.
if sy-tabix = 1.
insert struct_shorttext_to_csv_row( <ls_row> ) into table et_csv.
endif.
insert struct_to_csv_row( <ls_row> ) into table et_csv.
endloop.
endmethod.
method struct_to_csv_row.
data lv_component_count type i.
data lv_datatype type c. "#EC NEEDED
data lv_i type i.
data lv_conv_string type string.
field-symbols <lv_component> type any.
clear rv_csv.
describe field is_row type lv_datatype components lv_component_count.
lv_i = 1.
do lv_component_count times.
assign component lv_i of structure is_row to <lv_component>.
lv_conv_string = convert_any_to_string( <lv_component> ).
if lv_i = 1.
rv_csv = lv_conv_string.
else.
rv_csv = |{ rv_csv };{ lv_conv_string }|.
endif.
add 1 to lv_i.
enddo.
endmethod.
method struct_shorttext_to_csv_row.
data lo_sdesc type ref to cl_abap_structdescr.
data lt_ddic_field type ddfields.
data ls_ddic_field type dfies.
data lv_tabix type sytabix.
data lv_shorttext type string.
clear rv_csv.
lo_sdesc = cast #( cl_abap_structdescr=>describe_by_data( is_row ) ).
lt_ddic_field = lo_sdesc->get_ddic_field_list( ).
loop at lt_ddic_field into ls_ddic_field.
lv_tabix = sy-tabix.
lv_shorttext = esc( conv #( ls_ddic_field-fieldtext ) ).
if lv_tabix = 1.
rv_csv = lv_shorttext.
else.
rv_csv = |{ rv_csv };{ lv_shorttext }|.
endif.
endloop.
endmethod.
method convert_any_to_string.
data lv_type type c.
data lv_d type d.
data lv_t type t.
clear rv_string.
describe field iv_any type lv_type.
case lv_type.
when 'D'. " Date
lv_d = iv_any.
rv_string = |{ lv_d date = user }|.
when 'T'. " time
lv_t = iv_any.
rv_string = |{ lv_t time = user }|.
when others.
rv_string = iv_any.
endcase.
rv_string = esc( rv_string ).
endmethod.
method esc.
if iv_string cs ';'.
rv_string = |'{ rv_string }'|.
else.
rv_string = iv_string.
endif.
endmethod.
endclass.
Monday, October 31, 2016
Schedule duration on factory calendar in ERP
form schedule
using
iv_start_date type d
iv_factorty_calendar type wfcid
iv_length type i
changing ev_end_date type d.
data lv_factory_date type facdate.
clear ev_end_date.
call function 'DATE_CONVERT_TO_FACTORYDATE'
exporting
date = iv_start_date
factory_calendar_id = iv_factorty_calendar
importing
factorydate = lv_factory_date
exceptions
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
others = 7.
if sy-subrc <> 0.
write / 'Exception'.
ev_end_date = iv_start_date + iv_length.
return.
endif.
add iv_length to lv_factory_date.
call function 'FACTORYDATE_CONVERT_TO_DATE'
exporting
factorydate = lv_factory_date
factory_calendar_id = iv_factorty_calendar
importing
date = ev_end_date
exceptions
calendar_buffer_not_loadable = 1
factorydate_after_range = 2
factorydate_before_range = 3
factorydate_invalid = 4
factory_calendar_id_missing = 5
factory_calendar_not_found = 6
others = 7.
if sy-subrc <> 0.
write / 'Exception'.
ev_end_date = iv_start_date + iv_length.
endif.
endform.
using
iv_start_date type d
iv_factorty_calendar type wfcid
iv_length type i
changing ev_end_date type d.
data lv_factory_date type facdate.
clear ev_end_date.
call function 'DATE_CONVERT_TO_FACTORYDATE'
exporting
date = iv_start_date
factory_calendar_id = iv_factorty_calendar
importing
factorydate = lv_factory_date
exceptions
calendar_buffer_not_loadable = 1
correct_option_invalid = 2
date_after_range = 3
date_before_range = 4
date_invalid = 5
factory_calendar_not_found = 6
others = 7.
if sy-subrc <> 0.
write / 'Exception'.
ev_end_date = iv_start_date + iv_length.
return.
endif.
add iv_length to lv_factory_date.
call function 'FACTORYDATE_CONVERT_TO_DATE'
exporting
factorydate = lv_factory_date
factory_calendar_id = iv_factorty_calendar
importing
date = ev_end_date
exceptions
calendar_buffer_not_loadable = 1
factorydate_after_range = 2
factorydate_before_range = 3
factorydate_invalid = 4
factory_calendar_id_missing = 5
factory_calendar_not_found = 6
others = 7.
if sy-subrc <> 0.
write / 'Exception'.
ev_end_date = iv_start_date + iv_length.
endif.
endform.
Friday, October 28, 2016
Selection Screen with Maximum Selection (UP TO ... ROWS) MXSEL
constants gc_max_rows type tbmaxsel value '100000'.
constants gc_default_rows type tbmaxsel value '200'.
parameter p_mxsel type tbmaxsel obligatory default gc_default_rows.
initialization.
select single tbmaxsel from rseumod into p_mxsel
where uname = sy-uname.
perform trim_mxsel.
at selection-screen on p_mxsel.
perform trim_mxsel.
start-of-selection.
p_mxsel = p_mxsel + 1.
select * from ...
into corresponding fields of table gt_my
up to p_mxsel rows
where
...
if gt_my is initial.
message s429(mo). " no data found
return.
endif.
if lines( gt_my ) = p_mxsel.
delete gt_my index p_mxsel.
message s016(es) with p_mxsel. " result cut off
endif.
p_mxsel = p_mxsel - 1.
form trim_mxsel.
if p_mxsel > gc_max_rows. p_mxsel = gc_max_rows. endif.
if p_mxsel < 1. p_mxsel = gc_default_rows. endif.
endform.
Wednesday, October 26, 2016
RFC call function destination with standard exceptions
data lv_exception_message type text255.
call function 'REMOTE_FUNCTION'
destination iv_rfc_destination
[...]
exceptions
system_failure = 1 message lv_exception_message
communication_failure = 2 message lv_exception_message
others = 3.
Datatype string is not supported.
call function 'REMOTE_FUNCTION'
destination iv_rfc_destination
[...]
exceptions
system_failure = 1 message lv_exception_message
communication_failure = 2 message lv_exception_message
others = 3.
Datatype string is not supported.
Friday, October 21, 2016
Creating Background Jobs in SAP with ABAP
Starting Jobs
call function 'JOB_OPEN'exporting
jobname = mv_jobname
importing
jobcount = mv_jobcount
changing
ret = lv_ret
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc <> 0.
" log
return.
endif.
* submit (mo_run->ms_run-client_report)
* using selection-set mv_variant
* user sy-uname via job mv_jobname number mv_jobcount
* and return.
* Using the variant above, SM37 will create a temporary
* Variante ..001 but not the previously created variant
call function 'JOB_SUBMIT'
exporting
authcknam = sy-uname
jobcount = mv_jobcount
jobname = mv_jobname
report = mo_run->ms_run-client_report
variant = mv_variant
importing
step_number = lv_stepcount
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.
" log
return.
endif.
call function 'JOB_CLOSE'
exporting
jobcount = mv_jobcount
jobname = mv_jobname
targetsystem = iv_server
strtimmed = 'X' " start immediately
importing
job_was_released = lv_job_was_released
changing
ret = lv_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.
" log
return.
endif.
Creating Variants
data ls_varid type varid.ls_varid-mandt = sy-mandt. " Mandant
ls_varid-report = mo_run->ms_run-client_report.
ls_varid-variant = mv_variant.
ls_varid-flag1 = ''. " CHAR01-Datenelement fuer SYST
ls_varid-flag2 = ''. " CHAR01-Datenelement fuer SYST
ls_varid-transport = ''.
ls_varid-environmnt = 'B'. " Umgebung (B = nur Batch)
ls_varid-protected = ''.
ls_varid-secu = ''. " Berechtigungsgruppe
ls_varid-version = ''. " Versionsnummer der Variante
ls_varid-ename = sy-uname. " Benutzername
ls_varid-edat = sy-datum. " DATE (8-stelig) fuer SYST
ls_varid-etime = sy-uzeit. " TIME-Datenelement fuer SYST
ls_varid-aename = sy-uname. " Benutzername
ls_varid-aedat = sy-datum. " DATE (8-stelig) fuer SYST
ls_varid-aetime = sy-uzeit. " TIME-Datenelement fuer SYST
ls_varid-mlangu = sy-langu. " Sprachenschlüssel
ls_varid-xflag1 = ''. " Flag für Variantenkatalog
ls_varid-xflag2 = ''. " Flag für Variantenkatalog
" Varianten Text
data ls_varit type varit.
data lt_varit type standard table of varit.
ls_varit-mandt = sy-mandt.
ls_varit-langu = sy-langu.
ls_varit-report = mo_run->ms_run-client_report.
ls_varit-variant = mv_variant.
ls_varit-vtext = |{ sy-datum date = iso }|
append ls_varit to lt_varit.
* Save Variante for Job
call function 'RS_CREATE_VARIANT'
exporting
curr_report = mv_client_report
curr_variant = mv_variant
vari_desc = ls_varid
tables
vari_contents = mt_rsparam
vari_text = lt_varit
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.
if sy-subrc = 0.
commit work.
else.
" log
clear mv_variant.
endif.
Subscribe to:
Posts (Atom)
Working with the session Id // ID für den Modus
Sometimes it can be helpful to know the id of the current session CALL FUNCTION 'TH_GET_CONTEXT_ID' IMPORTING cont...
-
Sometimes the backend doesn't return the selected rows of an SALV. For my case get_metadata( ) was the solution: go_salv-> get_met...
-
GUIDs or UUIDs can be created with the class cl_system_uuid . try . data (lv_uuid) = cl_system_uuid => if_system_uuid_static...
-
AA PR-AUF(E) Prozessauftrag (eröffnet) AB PR-AUF(F) Prozessauftrag (freigegeben) AC FE...