SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

ALV List of Smart forms



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Smartforms, SapScripts, PDF
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sat Jan 26, 2008 4:40 pm    Post subject: ALV List of Smart forms Reply with quote

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.

*---------------------------------------------------------------------*
INITIALIZATION.

  PERFORM f_initialization.

*---------------------------------------------------------------------*
START-OF-SELECTION.

  PERFORM f_read_data.

*---------------------------------------------------------------------*
END-OF-SELECTION.

  PERFORM f_display_data.

*---------------------------------------------------------------------*
*      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.

  v_1 = 'Smart form name'.
  v_2 = 'Last changed by'.
  v_3 = 'Developpment Class'.
  v_4 = 'Masterlang'.
  v_5 = 'Created by'.
  v_6 = 'Changed on'.
  v_7 = 'Created on'.
  v_8 = 'Form type'.
  v_20 = 'Maximum number of selected entries'.
  v_21 = 'Directory'.
  v_22 = 'Extension'.

  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_sort.
    add 1 to ls_sort-spos.
    ls_sort-fieldname = &1.
    ls_sort-up = &2.
    ls_sort-down = &3.
    ls_sort-group = &4.
    append ls_sort to lt_sort.
  END-OF-DEFINITION.

* 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.

  ls_layout-zebra             = c_x.
  ls_layout-cell_merge        = c_x.
  ls_layout-group_change_edit = c_x.
  ls_layout-colwidth_optimize = c_x.
  ls_layout-box_fieldname = 'CHECKBOX'.

* Build sort table
  m_sort 'LASTDATE' ''  c_x ''.
  m_sort 'LASTTIME' ''  c_x ''.
*
* Build field catalog table
  m_fieldcat 'FORMNAME'   'STXFADM'.
  m_fieldcat 'MASTERLANG' 'STXFADM'.
  m_fieldcat 'CAPTION'    'STXFADMT'.
  m_fieldcat 'LASTUSER'   'STXFADM'.
  m_fieldcat 'LASTDATE'   'STXFADM'.
  m_fieldcat 'LASTTIME'   'STXFADM'.
  m_fieldcat 'FIRSTUSER'  'STXFADM'.
  m_fieldcat 'FIRSTDATE'  'STXFADM'.
  m_fieldcat 'FIRSTTIME'  'STXFADM'.
  m_fieldcat 'DEVCLASS'   'STXFADM'.
  m_fieldcat 'FORMTYPE'   'STXFADM'.
  m_fieldcat 'VERSION'    'STXFADM'.

* Activate refresh button
  CLEAR ls_event_exit.
  ls_event_exit-after = c_x.
  ls_event_exit-ucomm = c_refresh.     " Refresh
  APPEND ls_event_exit TO lt_event_exit.
  ls_event_exit-ucomm = c_eb9.         " Refresh
  APPEND ls_event_exit TO lt_event_exit.

* Display data
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-cprog
      i_callback_user_command  = 'USER_COMMAND'
      i_callback_pf_status_set = 'PF_STATUS_SET'
      is_layout                = ls_layout
      it_fieldcat              = lt_fieldcat
      it_sort                  = lt_sort
      it_event_exit            = lt_event_exit
      i_save                   = 'A'
    TABLES
      t_outtab                 = gt_data.

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.

  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      formname           = u_formname
    IMPORTING
      fm_name            = l_fm_name
    EXCEPTIONS
      no_form            = 1
      no_function_module = 2
      OTHERS             = 3.

  CHECK sy-subrc IS INITIAL.

* 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.

    TRANSLATE l_path  USING '/_'.

    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = l_path
      TABLES
        data_tab                = lt_report
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc NE 0.
      MESSAGE e398(00) WITH 'Error function' 'GUI_DOWNLOAD'(009)
                            'Sy-subrc :'(010) sy-subrc.
    ENDIF.

  ENDIF.

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 **************************
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Smartforms, SapScripts, PDF All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.