Friday, May 11, 2012

SAP ABAP Technicals: Make Invisible - Ranges in the select-option

SAP ABAP Technicals: Make Invisible - Ranges in the select-option

Friday, September 24, 2010

Save and Edit in classical report

*----------------------------------------------------------*
* created by : Manikandan
* created date: 28.12.2008
* description : The sample code for editing the clssical report
* and saving after modification successfully. this is an
* example program,so that i didnt use more validations,
* this is to aviod complexicity of the coding .
*----------------------------------------------------------*
REPORT ZEDIT_CLASSICAL_REPORT.

TYPES: BEGIN OF TY_ITAB ,
MATNR LIKE MARA-MATNR,
MEINS LIKE MARA-MEINS,
END OF TY_ITAB .

DATA: ITAB TYPE TABLE OF TY_ITAB WITH HEADER LINE,
WA TYPE TY_ITAB.

DATA: V_MEINS LIKE MARA-MEINS,
V_MEINS1 LIKE MARA-MEINS,
V_MATNR LIKE MARA-MATNR.

START-OF-SELECTION.

SET PF-STATUS 'TEST'.

PERFORM GET_DATA.

PERFORM HEADER_DATA.

PERFORM DISPLAY_DATA.

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SAVE'.
PERFORM SAVE_FUNCTION.

ENDCASE.
*&---------------------------------------------------------------------*
*& Form get_data
*----------------------------------------------------------------------*
FORM GET_DATA .

SELECT MATNR
MEINS
FROM MARA
INTO TABLE ITAB
UP TO 5 ROWS.

ENDFORM. " get_data
*&---------------------------------------------------------------------*
*& Form header_data
*----------------------------------------------------------------------*
FORM HEADER_DATA .

WRITE:/1(30) SY-ULINE.
WRITE:/1 SY-VLINE,
2 'Material',
20 SY-VLINE,
21 'Mat Unit',
30 SY-VLINE.
WRITE:/1(30) SY-ULINE.

ENDFORM. " header_data
*&---------------------------------------------------------------------*
*& Form display_data
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .


LOOP AT ITAB INTO WA.
WRITE:/1 SY-VLINE,
2 WA-MATNR,
20 SY-VLINE.
FORMAT INTENSIFIED INPUT.
WRITE: 21 WA-MEINS.
FORMAT INTENSIFIED OFF.
FORMAT RESET.
WRITE: 30 SY-VLINE.
ENDLOOP.
WRITE:/1(30) SY-ULINE.

ENDFORM. " display_data
*&---------------------------------------------------------------------*
*& Form save_function
*----------------------------------------------------------------------*
FORM SAVE_FUNCTION .

DO .
CLEAR: V_MATNR,V_MEINS, V_MEINS1.
READ LINE SY-INDEX .
IF SY-SUBRC NE 0.
*---if there exists no line , exit the processing
EXIT.
ELSE.
*---check whether the material exitsting or not .
SELECT MATNR MEINS
FROM MARA
INTO (V_MATNR, V_MEINS)
WHERE MATNR = SY-LISEL+1(18).

ENDSELECT.
IF SY-SUBRC = 0.
*---if material existing then get the actual Unit of measure,
* and capture the value to v_meins capture the changed value
* into v_meins1, process it if it is not initial.
V_MEINS1 = SY-LISEL+20(4).
IF NOT V_MEINS1 IS INITIAL.
*----check whether the data record was changed or not .
* if the two values are same, it means there is no
* change in the data record . here we can also put
* the validation on the v_meins1 to etner a valid
* value if not display an error message.
IF V_MEINS NE V_MEINS1.
*---if changed then update table with the updated value
* dont forget to Lock the table before processing the data
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
IF SY-SUBRC = 0.
* Modify the database table with these changes
UPDATE MARA SET MEINS = V_MEINS1
WHERE MATNR = V_MATNR.
IF SY-SUBRC = 0.
*---if successfully updated then write the modification log
WRITE:/ 'the material',
V_MATNR COLOR 7,
'unit was changed with value:',
V_MEINS1,
'from value:',
V_MEINS.
ENDIF.
* Unlock the table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
MODE_RSTABLE = 'E'
TABNAME = 'MARA'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDDO.

ENDFORM. " save_function

How to get rid of dumps

Generally if any exception occurred it will go to dump immediately in a program, then we will process this through the tcode ST22(dump analysis). Here I am trying to convert this dump into an error message or some text statement.
For this you need to call this statement...

RECEIVE RESULTS FROM FUNCTION 'function module'

Check this example program....

REPORT ztests.

PARAMETERS:p_file LIKE rlgrap-filename .

DATA: v_file TYPE string.

DATA: BEGIN OF itab OCCURS 0,
name(23) TYPE c,
END OF itab.

DATA: errormessage TYPE char50.

v_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = ' '
TABLES
data_tab = itab.


RECEIVE RESULTS FROM FUNCTION 'GUI_UPLOAD'
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17 .
.
CASE sy-subrc.
WHEN 0.
errormessage = 'Data Loaded'.
WHEN 1.
errormessage = 'FILE_OPEN_ERROR'.
WHEN 2.
errormessage = 'FILE_READ_ERROR'.
WHEN 3.
errormessage = 'NO_BATCH'.
WHEN 4.
errormessage = 'GUI_REFUSE_FILETRANSFER'.
WHEN 5.
errormessage = 'INVALID_TYPE'.
WHEN 6.
errormessage = 'NO_AUTHORITY'.
WHEN 7.
errormessage = 'UNKNOWN_ERROR'.
WHEN 8.
errormessage = 'BAD_DATA_FORMAT'.
WHEN 9.
errormessage = 'HEADER_NOT_ALLOWED'.
WHEN 10.
errormessage = 'SEPARATOR_NOT_ALLOWED'.
WHEN 11.
errormessage = 'HEADER_TOO_LONG'.
WHEN 12.
errormessage = 'UNKNOWN_DP_ERROR'.
WHEN 13.
errormessage = 'ACCESS_DENIED'.
WHEN 14.
errormessage = 'DP_OUT_OF_MEMORY'.
WHEN 15.
errormessage = 'DISK_FULL'.
WHEN 16.
errormessage = 'DP_TIMEOUT'.
WHEN 17.
errormessage = 'OTHERS'.
ENDCASE.

MESSAGE e000(00) WITH errormessage .
With this in the report program we will get an error message instead of a dump when the exception raised.

Logo in classical report

REPORT zdem_555 .

DATA: docking TYPE REF TO cl_gui_docking_container,
picture_control_1 TYPE REF TO cl_gui_picture,
url(256) TYPE c .
DATA: query_table LIKE w3query OCCURS 1 WITH HEADER LINE,
html_table LIKE w3html OCCURS 1,
return_code LIKE w3param-ret_code,
content_type LIKE w3param-cont_type,
content_length LIKE w3param-cont_len,
pic_data LIKE w3mime OCCURS 0,
pic_size TYPE i.
START-OF-SELECTION.
PERFORM show_pic.
WRITE : /'hello see the picture ........'.

*&-------------------------------------------------------------------
*& Form show_pic
*&-------------------------------------------------------------------
FORM show_pic.
DATA: repid LIKE sy-repid. repid = sy-repid.
CREATE OBJECT picture_control_1
EXPORTING parent = docking.
CHECK sy-subrc = 0.
CALL METHOD picture_control_1->set_3d_border
EXPORTING
border = 5.
CALL METHOD picture_control_1->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_stretch.
CALL METHOD picture_control_1->set_position
EXPORTING
height = 100
left = 700
top = 1
width = 200.
*CHANGE POSITION AND SIZE
IF url IS INITIAL.
REFRESH query_table.
query_table-name = '_OBJECT_ID'.
*CHANGE IMAGE NAME BELOW
query_table-value = 'BIKER'.
APPEND query_table. CALL FUNCTION 'WWW_GET_MIME_OBJECT'
TABLES
query_string = query_table
html = html_table
mime = pic_data
CHANGING
return_code = return_code
content_type = content_type
content_length = content_length
EXCEPTIONS
object_not_found = 1
parameter_not_found = 2
OTHERS = 3.
IF sy-subrc ne 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-*msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CALL FUNCTION 'DP_CREATE_URL'
EXPORTING
type = 'image'
subtype = cndp_sap_tab_unknown
size = pic_size
lifetime = cndp_lifetime_transaction
TABLES
data = pic_data
CHANGING
url = url
EXCEPTIONS
OTHERS = 1.
ENDIF.
CALL METHOD picture_control_1->load_picture_from_url
EXPORTING
url = url.
ENDFORM. "show_pic

Change of sign

data: a1 type i value 56,
a2 type i value 60,
res type i,
res1(10).res = a1 - a2.
res1 = res.

CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT' CHANGING VALUE = res1
write res1.

Transport standard text

use RSTXTRAN program

All the text elements are customizing requests.
Or else you can use scc1 between clients to copy text elements.

Insert a blank line at the end of the file using gui_upload

Try this..

To the GUI_DOWNLOAD Fm pass WRITE_LF_AFTER_LAST_LINE = ' '.