Posted: Sat Jan 26, 2008 4:40 pm Post subject: ALV List of Smart forms
Code:
REPORT z_alv_smartforms.
*---------------------------------------------------------------------*
* ALV List of Smart forms *
*---------------------------------------------------------------------*
* Author : Michel PIOUD *
* Email : [email protected] HomePage : http://www.geocities.com/mpioud *
*---------------------------------------------------------------------*
* Macro definition
DEFINE mac_line.
selection-screen :
begin of line, comment 10(20) v_&1 for field &2.
select-options &2 for &3.
selection-screen end of line.
END-OF-DEFINITION.
*---------------------------------------------------------------------*
TYPE-POOLS slis. " ALV Global types
*---------------------------------------------------------------------*
CONSTANTS :
c_x VALUE 'X',
c_eb9 TYPE syucomm VALUE '&EB9',
c_refresh TYPE syucomm VALUE '&REFRESH'.
*---------------------------------------------------------------------*
TYPES :
BEGIN OF ty_s_data.
INCLUDE TYPE stxfadm.
TYPES :
caption TYPE tdtext,
checkbox TYPE xfeld,
END OF ty_s_data.
*---------------------------------------------------------------------*
DATA :
gt_data TYPE TABLE OF ty_s_data.
*---------------------------------------------------------------------*
FIELD-SYMBOLS :
<data> TYPE ty_s_data.
*---------------------------------------------------------------------*
* Select-Options / Parameters
mac_line 1 s_fname <data>-formname. "#EC NEEDED
mac_line 3 s_dvclss <data>-devclass. "#EC NEEDED
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(20) v_2 FOR FIELD s_luser. "#EC NEEDED
SELECT-OPTIONS s_luser FOR <data>-lastuser MATCHCODE OBJECT user_comp.
SELECTION-SCREEN END OF LINE.
mac_line 6 s_ldate <data>-lastdate. "#EC NEEDED
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 10(20) v_5 FOR FIELD s_luser. "#EC NEEDED
SELECT-OPTIONS s_fuser FOR <data>-firstuser MATCHCODE OBJECT user_comp.
SELECTION-SCREEN END OF LINE.
mac_line 7 s_fdate <data>-lastdate. "#EC NEEDED
mac_line 4 s_langu <data>-masterlang. "#EC NEEDED
mac_line 8 s_ftype <data>-formtype. "#EC NEEDED
SELECTION-SCREEN :
SKIP, BEGIN OF LINE, COMMENT 1(35) v_20 FOR FIELD p_max. "#EC NEEDED
PARAMETERS p_max(3) TYPE n DEFAULT '200' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
SKIP, BEGIN OF LINE, COMMENT 1(35) v_21 FOR FIELD p_filena. "#EC NEEDED
PARAMETERS p_filena TYPE rlgrap-filename DEFAULT 'C:\' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
BEGIN OF LINE, COMMENT 1(35) v_22 FOR FIELD p_extens. "#EC NEEDED
PARAMETERS p_extens(3).
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
* Form F_INITIALIZATION
*---------------------------------------------------------------------*
FORM f_initialization.
DATA :
ls_fname LIKE LINE OF s_fname,
ls_ftype LIKE LINE OF s_ftype,
ls_dvclss LIKE LINE OF s_dvclss.
CONCATENATE 'ICP' 'Z*' INTO ls_fname.
APPEND ls_fname TO s_fname.
CONCATENATE 'ICP' 'Z*' INTO ls_dvclss.
APPEND ls_dvclss TO s_dvclss.
CONCATENATE 'IEQ' ' ' INTO ls_ftype.
APPEND ls_ftype TO s_ftype.
ENDFORM. " F_INITIALIZATION
*---------------------------------------------------------------------*
* Form F_READ_DATA
*---------------------------------------------------------------------*
FORM f_read_data.
DATA ls_address TYPE addr3_val.
* Read data from TADIR and STXFADM
SELECT formname t~masterlang version firstuser firstdate firsttime
lastuser lastdate lasttime formtype t~devclass
UP TO p_max ROWS
INTO CORRESPONDING FIELDS OF TABLE gt_data
FROM tadir AS t
JOIN stxfadm AS s
ON t~obj_name = s~formname
WHERE pgmid = 'R3TR'
AND object = 'SSFO'
AND obj_name IN s_fname
AND lastuser IN s_luser
AND t~devclass IN s_dvclss
AND t~masterlang IN s_langu
AND firstuser IN s_fuser
AND lastdate IN s_ldate
AND formtype IN s_ftype.
* Sort to improve performance of FM SUSR_USER_ADDRESS_READ
SORT gt_data BY lastuser.
LOOP AT gt_data ASSIGNING <data>.
* Get user address data
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
user_name = <data>-lastuser "#EC
IMPORTING
user_address = ls_address
EXCEPTIONS
user_address_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CONCATENATE ls_address-name_last ls_address-name_first
INTO <data>-lastuser SEPARATED BY space.
ENDIF.
* Get user address data
CALL FUNCTION 'SUSR_USER_ADDRESS_READ'
EXPORTING
user_name = <data>-firstuser "#EC
IMPORTING
user_address = ls_address
EXCEPTIONS
user_address_not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
CONCATENATE ls_address-name_last ls_address-name_first
INTO <data>-firstuser SEPARATED BY space.
ENDIF.
* Read description from STXFADMT
SELECT SINGLE caption
INTO <data>-caption
FROM stxfadmt
WHERE formname = <data>-formname
AND langu = <data>-masterlang.
ENDLOOP.
ENDFORM. " F_READ_DATA
*---------------------------------------------------------------------*
* Form f_display_data
*---------------------------------------------------------------------*
FORM f_display_data.
* Macro definition
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DATA:
ls_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
ls_event_exit TYPE slis_event_exit,
lt_event_exit TYPE slis_t_event_exit.
ENDFORM. " F_DISPLAY_DATA
*---------------------------------------------------------------------*
* FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm TYPE syucomm
is_selfield TYPE slis_selfield. "#EC CALLED
CASE i_ucomm.
WHEN '&IC1'. " Pick
READ TABLE gt_data INDEX is_selfield-tabindex ASSIGNING <data>.
CHECK sy-subrc EQ 0.
* SAP Smart Forms: Name of a Smart Form
SET PARAMETER ID 'SSFNAME' FIELD <data>-formname.
* SAP Smart Forms
CALL TRANSACTION 'SMARTFORMS'. " USING lt_bdcdata MODE 'A'.
WHEN c_refresh.
PERFORM f_read_data.
is_selfield-refresh = c_x.
WHEN c_eb9.
LOOP AT gt_data ASSIGNING <data> WHERE checkbox = c_x.
PERFORM f_download USING <data>-formname space.
ENDLOOP.
IF sy-subrc IS NOT INITIAL.
READ TABLE gt_data INDEX is_selfield-tabindex ASSIGNING <data>.
CHECK sy-subrc EQ 0.
PERFORM f_download USING <data>-formname c_x.
ENDIF.
ENDCASE.
*
ENDFORM. " USER_COMMAND
*---------------------------------------------------------------------*
* FORM PF_STATUS_SET *
*---------------------------------------------------------------------*
FORM pf_status_set USING ut_extab TYPE slis_t_extab. "#EC CALLED
* Display refresh button
DELETE ut_extab WHERE fcode = c_refresh OR fcode = c_eb9.
SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'
EXCLUDING ut_extab.
ENDFORM. " PF_STATUS_SET
*---------------------------------------------------------------------*
* Form f_read_data
*---------------------------------------------------------------------*
FORM f_download USING u_formname TYPE tdsfname
u_popup TYPE xfeld.
TYPES :
BEGIN OF ty_code,
code(370) TYPE c,
END OF ty_code,
ty_t_code TYPE STANDARD TABLE OF ty_code.
DATA :
l_fm_name TYPE rs38l_fnam,
l_ok TYPE xfeld,
l_report TYPE program,
l_ligne TYPE ty_code,
l_ligne2 TYPE ty_code,
l_tabix TYPE sytabix,
l_path TYPE string,
lt_tab TYPE ty_t_code,
lt_report TYPE ty_t_code.
* Importing and tabels parameters
CONCATENATE l_fm_name(8) 'L' l_fm_name+8(10) 'U01' INTO l_report.
READ REPORT l_report INTO lt_tab.
CHECK sy-subrc IS INITIAL.
CLEAR l_ok.
LOOP AT lt_tab INTO l_ligne.
IF l_ligne = '*" EXCEPTIONS'.
EXIT.
ENDIF.
IF l_ligne = '*" EXPORTING'.
CLEAR l_ok.
ENDIF.
IF l_ok IS NOT INITIAL.
IF l_ok = 'T'.
REPLACE ' STRUCTURE ' IN l_ligne WITH '%TYPE TABLE OF%'.
CONCATENATE 'DATA%' l_ligne INTO l_ligne.
ELSEIF l_ok = 'X'.
REPLACE 'OPTIONAL' IN l_ligne WITH space.
REPLACE 'REFERENCE(' IN l_ligne WITH 'DATA%'.
REPLACE 'VALUE(' IN l_ligne WITH 'DATA%'.
REPLACE ')' IN l_ligne WITH ' '.
ENDIF.
REPLACE '*"' IN l_ligne WITH ' '.
TRANSLATE l_ligne USING '% '.
CONCATENATE l_ligne '.' INTO l_ligne.
CONDENSE l_ligne.
APPEND l_ligne TO lt_report.
ENDIF.
IF l_ligne CS '(USER_SETTINGS)'.
l_ok = 'X'.
ENDIF.
IF l_ligne = '*" TABLES'.
l_ok = 'T'.
ENDIF.
ENDLOOP.
CLEAR l_ligne(72) WITH '*'.
APPEND l_ligne TO lt_report.
* Global data and types
CONCATENATE l_fm_name(8) 'L' l_fm_name+8(10) 'TOP' INTO l_report.
READ REPORT l_report INTO lt_tab.
CHECK sy-subrc IS INITIAL.
LOOP AT lt_tab INTO l_ligne.
IF l_ligne = '* TYPES AND CONSTANTS' OR
l_ligne = '* GLOBAL DATAS'.
EXIT.
ELSE.
DELETE lt_tab.
ENDIF.
ENDLOOP.
APPEND LINES OF lt_tab TO lt_report.
CLEAR l_ligne(72) WITH '*'.
APPEND l_ligne TO lt_report.
* Forms
CONCATENATE l_fm_name(8) 'L' l_fm_name+8(10) 'F01' INTO l_report.
READ REPORT l_report INTO lt_tab.
CHECK sy-subrc IS INITIAL.
CLEAR l_ok.
LOOP AT lt_tab INTO l_ligne.
IF l_ligne(5) = 'FORM '.
IF l_ligne+5(12) = '%GLOBAL_INIT' OR
l_ligne+5(3) = '%CO' OR
l_ligne+5(1) <> '%'.
l_ok = 'X'.
l_tabix = sy-tabix - 5.
DO 5 TIMES.
READ TABLE lt_tab INTO l_ligne2 INDEX l_tabix.
IF l_ligne2(1) = '*'.
APPEND l_ligne2 TO lt_report.
ENDIF.
ADD 1 TO l_tabix.
ENDDO.
ENDIF.
ENDIF.
IF l_ok = 'X'.
APPEND l_ligne TO lt_report.
ENDIF.
IF l_ligne(8) = 'ENDFORM.'.
CLEAR l_ok.
ENDIF.
ENDLOOP.
CONCATENATE 'REPORT' u_formname '.' INTO l_ligne SEPARATED BY space.
INSERT l_ligne INTO lt_report INDEX 1.
CLEAR l_ligne(72) WITH '*'.
INSERT l_ligne INTO lt_report INDEX 2.
CONCATENATE '*' u_formname sy-datum sy-uzeit sy-uname INTO l_ligne
SEPARATED BY space.
INSERT l_ligne INTO lt_report INDEX 3.
CLEAR l_ligne(72) WITH '*'.
INSERT l_ligne INTO lt_report INDEX 4.
IF u_popup = c_x.
EDITOR-CALL FOR lt_report DISPLAY-MODE.
ELSE.
* Download
CONCATENATE p_filena u_formname '.' p_extens '.txt'
INTO l_path.
ENDFORM. " F_DOWNLOAD
*---------------------------------------------------------------------*
* Form MODIF_EXTENSION *
*---------------------------------------------------------------------*
FORM modif_extension.
CHECK p_extens IS INITIAL.
CASE sy-datum+4(2). " Current month
WHEN '01'. p_extens(1) = 'A'. " January
WHEN '02'. p_extens(1) = 'B'. " February
WHEN '03'. p_extens(1) = 'C'. " March
WHEN '04'. p_extens(1) = 'D'. " April
WHEN '05'. p_extens(1) = 'E'. " May
WHEN '06'. p_extens(1) = 'F'. " June
WHEN '07'. p_extens(1) = 'G'. " July
WHEN '08'. p_extens(1) = 'H'. " August
WHEN '09'. p_extens(1) = 'I'. " September
WHEN '10'. p_extens(1) = 'J'. " October
WHEN '11'. p_extens(1) = 'K'. " November
WHEN '12'. p_extens(1) = 'L'. " December
ENDCASE.
p_extens+1(2) = sy-datum+6(2). " Current day
ENDFORM. " MODIF_EXTENSION
*---------------------------------------------------------------------*
AT SELECTION-SCREEN ON p_extens.
PERFORM modif_extension.
************ END OF PROGRAM Z_ALV_SMARTFORMS **************************
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.