Translate

Thursday, 7 June 2012

ALV Report with user command, PF Status ABAP

*&---------------------------------------------------------------------*
*& Report ZWORKFLOW_PROJECT1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZWORKFLOW_PROJECT1.
TABLES: LIKP.
data: t_date type sy-datum,
f_date TYPE sy-datum, "First date
l_date TYPE sy-datum, "last date
month type FCMNR,
year type GJAHR .

TYPES: BEGIN OF FS_DATA,
DELNO(10), "DELIVERY NUMBER
CUSNO(10), "SHIP-TO-PARTY
CNAME(35), "NAME OF SHIP-TO-PARTY
PICDT(10), "PICKED DATE
TRPPLANDT(10), "TRANSPORTING PLANNING DATE
GIDATE(10), "GOODS ISSUE DATE
DELDT(10), "DELIVERY DATE
CHARGE(10), "CHARGE
END OF FS_DATA.

DATA: WA_DATA TYPE FS_DATA.
DATA: IT_DATA TYPE TABLE OF FS_DATA.
DATA: IT_OUTDATA TYPE TABLE OF FS_DATA.

TYPE-POOLS SLIS.
DATA: I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV.

DATA: IT_LISTHEADER TYPE SLIS_T_LISTHEADER.

DATA: V_EVENTS TYPE SLIS_T_EVENT,
WA_EVENT TYPE SLIS_ALV_EVENT.

DATA: ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: V_REPID TYPE SY-REPID.



SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.

PARAMETERS: P_FILE LIKE IBIPPARMS-PATH OBLIGATORY.
SELECTION-SCREEN SKIP.
SELECT-OPTIONS S_DATE FOR LIKP-LFDAT.
SELECTION-SCREEN END OF BLOCK B1.

INITIALIZATION.
t_date = sy-datum.
month = t_date+4(2).
year = t_date(4).

CALL FUNCTION 'OIL_MONTH_GET_FIRST_LAST'
EXPORTING
I_MONTH = month
I_YEAR = year
I_DATE = t_date
IMPORTING
E_FIRST_DAY = f_date
E_LAST_DAY = l_date
EXCEPTIONS
WRONG_DATE = 1
OTHERS = 2.
s_date-low = f_date.
s_date-high = l_date.
s_date-sign = 'I'.
s_date-option = 'EQ'.
APPEND s_date.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM GET_FILENAME.

*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM GET_FILENAME.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.

IF SY-SUBRC NE 0.
WRITE : / 'Enter File Name'.
ENDIF.
ENDFORM. "GET_FILENAME



START-OF-SELECTION.
PERFORM UPLOAD_DATA.
PERFORM FILTER_DATA.
PERFORM DISPLAY_DATA.


*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM UPLOAD_DATA.
TYPE-POOLS : truxs.
DATA : truks_data TYPE truxs_t_text_data.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_TAB_RAW_DATA = truks_data
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_DATA.


ENDFORM. "UPLOAD_DATA

*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA.

PERFORM BUILD_FIELDCATLOG.
PERFORM EVENT_CALL.
PERFORM POPULATE_EVENT.
PERFORM BUILD_LISTHEADER USING IT_LISTHEADER.
PERFORM DISPLAY_ALV_REPORT.


ENDFORM. "DISPLAY_DATA

FORM BUILD_FIELDCATLOG.
WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'DELNO'.
WA_FIELDCAT-SELTEXT_M = 'Delivery No.'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'CUSNO'.
WA_FIELDCAT-SELTEXT_M = 'Ship-to-Party'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'CNAME'.
WA_FIELDCAT-SELTEXT_M = 'Name of Ship-to-Party'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'PICDT'.
WA_FIELDCAT-SELTEXT_M = 'Picked Date'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'TRPPLANDT'.
WA_FIELDCAT-SELTEXT_M = 'Transport Plan Date'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'GIDATE'.
WA_FIELDCAT-SELTEXT_M = 'Goods Issue Date'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'DELDT'.
WA_FIELDCAT-SELTEXT_M = 'Delivery Date'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.

WA_FIELDCAT-TABNAME = 'IT_DATA'.
WA_FIELDCAT-FIELDNAME = 'CHARGE'.
WA_FIELDCAT-SELTEXT_M = 'CHARGE'.
APPEND WA_FIELDCAT TO I_FIELDCAT.
CLEAR WA_FIELDCAT.



ENDFORM.

FORM EVENT_CALL.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = V_EVENTS
* EXCEPTIONS
* LIST_TYPE_WRONG = 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.
ENDFORM. "EVENT_CALL

FORM POPULATE_EVENT.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'TOP_OF_PAGE'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'TOP_OF_PAGE'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME =
WA_EVENT-FORM.
ENDIF.
READ TABLE V_EVENTS INTO WA_EVENT WITH KEY NAME = 'USER_COMMAND'.
IF SY-SUBRC EQ 0.
WA_EVENT-FORM = 'USER_COMMAND'.
MODIFY V_EVENTS FROM WA_EVENT TRANSPORTING FORM WHERE NAME = WA_EVENT-NAME.
ENDIF.



ENDFORM. "POPULATE_EVENT

FORM BUILD_LISTHEADER USING I_LISTHEADER TYPE SLIS_T_LISTHEADER.
DATA HLINE TYPE SLIS_LISTHEADER.
HLINE-INFO = 'Obsolete Disposal Delivery Documents'.
HLINE-TYP = 'H'.
APPEND HLINE TO I_LISTHEADER.
ENDFORM. "build_listheader


FORM DISPLAY_ALV_REPORT.
V_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = I_FIELDCAT[]
I_SAVE = 'A'
IT_EVENTS = V_EVENTS
TABLES
T_OUTTAB = IT_OUTDATA.

ENDFORM. "display_alv_report

FORM TOP_OF_PAGE.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = IT_LISTHEADER.

ENDFORM. "TOP_OF_PAGE

FORM FILTER_DATA.
DATA: DEL_DATE TYPE SY-DATUM.

LOOP AT IT_DATA INTO WA_DATA.
IF SY-TABIX NE 1.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
DATE_EXTERNAL = WA_DATA-DELDT
IMPORTING
DATE_INTERNAL = DEL_DATE.
IF DEL_DATE IN S_DATE.
APPEND WA_DATA TO IT_OUTDATA.
ENDIF.
ENDIF.

CLEAR: WA_DATA, DEL_DATE.
ENDLOOP.



ENDFORM.

FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'ZSTANDARD'.
ENDFORM. "Set_pf_status

FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE R_UCOMM.
WHEN 'APPROVAL'.
MESSAGE 'Approval Process is going on' TYPE 'I'.
WHEN 'BACK' OR 'UP' OR 'CANCEL'.
SET SCREEN 0.
ENDCASE.
ENDFORM.

No comments: