Google Search - Blog...........

Save And Edit In Classical ABAP Report - To Avoid Complexity

*----------------------------------------------------------*
* created by : venkat appikonda
* 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

No comments:

Post a Comment