Handling Messages through Log

data: gt_return type table of bapiret2,
gs_return type bapiret2.

data: g_log_handle type balloghndl,
g_s_log      type bal_s_log.

data: l_s_msg      type bal_s_msg.

data:    g_s_display_profile type bal_s_prof.

clear gs_return.
gs_return-type = ‘E’.
gs_return-id   = ‘ZMSG’.
gs_return-number = ‘000’.
gs_return-message_v1 = ‘error msg part 1’.
gs_return-message_v2 = ‘error msg part 2’.
gs_return-message_v3 = ‘error msg part 3’.
gs_return-message_v4 = ‘error msg part 4’.
append gs_return to gt_return.

if gt_return is not initial.
g_s_log-extnumber = ‘Error log’.

call function ‘BAL_LOG_CREATE’
exporting
i_s_log      = g_s_log
importing
e_log_handle = g_log_handle
exceptions
others       = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

loop at gt_return into gs_return.

clear l_s_msg.

l_s_msg-msgno = gs_return-number.
l_s_msg-msgid = gs_return-id.
l_s_msg-msgty = gs_return-type.
l_s_msg-msgv1 = gs_return-message_v1.
l_s_msg-msgv2 = gs_return-message_v2.
l_s_msg-msgv3 = gs_return-message_v3.
l_s_msg-msgv4 = gs_return-message_v4.

call function ‘BAL_LOG_MSG_ADD’
exporting
i_log_handle = g_log_handle
i_s_msg      = g_s_msg
exceptions
others       = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

endloop.

* get a prepared profile
call function ‘BAL_DSP_PROFILE_POPUP_GET’
importing
e_s_display_profile = g_s_display_profile
exceptions
others              = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

* use grid for display if wanted
g_s_display_profile-use_grid = ‘X’.

* set report to allow saving of variants
g_s_display_profile-disvariant-report = sy-repid.

* when you use also other ALV lists in your report,
* please specify a handle to distinguish between the display
* variants of these different lists, e.g:
g_s_display_profile-disvariant-handle = ‘LOG’.

* call display function module
call function ‘BAL_DSP_LOG_DISPLAY’
exporting
i_s_display_profile = g_s_display_profile
exceptions
others              = 1.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

*Refresh Log

call function ‘BAL_LOG_REFRESH’     exporting
i_log_handle  = g_log_handle
exceptions
log_not_found = 1
others        = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.

List box on selection screen

Example for list box on selection screen (example for ALV display variant).

 

type-pools: vrm, slis.

parameters: p_vari type slis_vari.

at selection-screen output.

data: param type vrm_id,
values     type vrm_values,
value like line of values.

data: lt_ltdx  type table of ltdx,
lt_ltdxt type table of ltdxt,
ls_ltdx  type ltdx,
ls_ltdxt type ltdxt.

select * from ltdxt
into table lt_ltdxt
where report = sy-repid.

if sy-subrc = 0.

param = ‘P_VARI’.

loop at lt_ltdxt into ls_ltdxt.
clear value.
value-key = ls_ltdxt-variant.
value-text = ls_ltdxt-variant.
append value to values.
endloop.

call function ‘VRM_SET_VALUES’
exporting
id     = param
values = values.

endif.

Useful utility function modules

J_4I_NOTES_TICKLER_MAIN

K_ABC_LIST_POPUP

POPUP_TO_CONFIRM_WITH_MESSAGE

Simple ALV Grid

Simple ALV Grid display using CL_SALV_TABLE, is shown below. GT_OUTPUT_TABLE is an internal table whose structure is from data dictionary.

data: lo_alv type ref to cl_salv_table,
lo_cols_tab type ref to cl_salv_columns_table,
lo_selections type ref to cl_salv_selections,
lo_layout  type ref to cl_salv_layout,
ls_key    type salv_s_layout_key,
lx_msg type ref to cx_salv_msg.

try.
cl_salv_table=>factory(
importing
r_salv_table = lo_alv
changing
t_table = gt_su_head ).

catch cx_salv_msg into lx_msg.
endtry.

lo_alv->set_screen_status(
pfstatus = ‘STANDARD_FULLSCREEN’
report   = ‘SAPLSLVC_FULLSCREEN’
set_functions = lo_alv->c_functions_all ).

lo_cols_tab = lo_alv->get_columns( ).
lo_cols_tab->set_optimize(‘X’).

lo_selections = lo_alv->get_selections( ).
lo_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ).

lo_layout = lo_alv->get_layout( ).
ls_key-report = sy-repid.
lo_layout->set_key( ls_key ).
lo_layout->set_save_restriction( if_salv_c_layout=>restrict_none ).

lo_alv->display( ).

Useful Transaction Codes

SAP1 – Menu transaction for all SAP standard reports

Convert time from one time-zone to another

data: l_timestamp type tzonref-tstamps.

call function ‘IB_CONVERT_INTO_TIMESTAMP’
  exporting
    i_datlo     = lv_date
    i_timlo     = lv_time
    i_tzone     = ‘EST’
  importing
    e_timestamp = l_timestamp.
if sy-subrc = 0 and l_timestamp is not initial.
  call function ‘IB_CONVERT_FROM_TIMESTAMP’
    exporting
      i_timestamp = l_timestamp
      i_tzone     = ‘PST’
    importing
      e_datlo     = lv_date
      e_timlo     = lv_time.
endif.

 

SAP Printing , Spool

Spool requests are stored in temporary sequential files called Temse. When the file size reaches its maximum limit, spool overflow occurs and nothing can be printed from SAP.

Transactions: SM21 and ST22 show spool overflow errors like spool_internal_error, spool overflow

To troubleshoot, go to Transaction SPAD, on the menu Administration->Clean-up spool. We can delete requests that are already printed and or based on minimum spool request age in days.

Alternatively:

1. The standard report RSPO0041 can be executed through SE38 to clean up the spool

2.  The standard report RSPO0043 can be executed through SE38 to check the consistency of spool/temse and re-organizes the spool.

Reference: Basis Blog

Program to Copy/Delete file on Unix Server

data : unixcom like rlgrap-filename.

data: begin of itab occurs 0,
line(400),
end of itab.

data: lines type i.

*———————————————————————-

start-of-selection.
refresh itab.

“cp /dir/file1 /dir2/file2
“the above command will copy the file1 of dir1 to file2 of dir2.

“rm /dir/fiel1
“the above command will remove the file1 from directory dir.

unixcom = ‘cp /dir/file1 /dir/file2’.

"if you want to use the rm
unixcom = 'rm /dir/file1 '.
call 'SYSTEM' id 'COMMAND' field unixcom
id 'TAB' field itab[].

"if any error or any thing you get in the itab
"just check the itab once after the finishing

AL11 File utilities

Program:

CACS_FILE_COPY – Copying a File from Application to Presentation Server and Vice Versa

Function modules:

ARCHIVFILE_CLIENT_TO_SERVER – Copy file from presentation to app server

ARCHIVFILE_SERVER_TO_CLIENT – Copy file from app server to presentation

 

Also following SAP standard programs are available.

RPCIFU01
Display File

RPCIFU03
Download Unix File to PC

RPCIFU04
Upload PC File to Unix File

Function module to get fixed values from domain

DATA: lv_dname TYPE dcobjdef-name,
lt_dd07v TYPE TABLE OF dd07v,
ls_dd07v TYPE dd07v.

lv_dname = ‘RBSTAT’.
CALL FUNCTION ‘DDIF_DOMA_GET’
EXPORTING
name          = lv_dname
langu         = sy-langu
TABLES
dd07v_tab     = lt_dd07v
EXCEPTIONS
illegal_input = 1
OTHERS        = 2.