Posted: Sat Jan 31, 2009 3:50 pm Post subject: Extract code from Smart Forms
Author: Neale Kevin
This report reads a Smart Form and isolates the ABAP code within it to output it for audit purposes. It will work on an SAP R/3 Enterprise system (Web Application System 610 and higher).
Code:
REPORT zsf_code NO STANDARD PAGE HEADING LINE-SIZE 255 LINE-COUNT 65.
TYPES: ty_ts_forms TYPE SORTED TABLE OF stxfadm
WITH UNIQUE KEY formname,
ty_ts_formt TYPE SORTED TABLE OF stxfadmt
WITH UNIQUE KEY langu formname.
DATA: ts_forms TYPE ty_ts_forms,
ts_formt TYPE ty_ts_formt,
wa_forms LIKE LINE OF ts_forms,
wa_formt LIKE LINE OF ts_formt.
*----------------------------------------------------------------------*
* SELECTION SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
so_formn FOR wa_forms-formname,
so_devcl FOR wa_forms-devclass.
SELECTION-SCREEN END OF BLOCK b01.
***********************************************************************
* DECLARATIVE ELEMENTS *
************************************************************************
TYPES:
ttype(1) TYPE c,
ttype2(5) TYPE c,
tend(6) TYPE n,
tname(30) TYPE c,
value(132) TYPE c,
ntype TYPE tdsfotype,
BEGIN OF token,
ttype TYPE ttype,
tend TYPE tend,
tname TYPE tname,
value TYPE value,
END OF token,
t_token TYPE token OCCURS 0,
BEGIN OF ntokens,
ntype TYPE ntype,
t_token TYPE t_token,
END OF ntokens,
t_ntokens TYPE ntokens OCCURS 0.
CONSTANTS:
co_true TYPE flag VALUE 'X',
co_start_section TYPE ttype2 VALUE '[',
co_global_data TYPE ntype VALUE 'SF',
co_coding_data TYPE ntype VALUE 'CO',
co_asterisk VALUE '*',
co_section_name_interface TYPE tname VALUE 'INTERFACE',
co_section_name_global_types TYPE tname VALUE 'GTYPES',
co_section_name_param_name TYPE tname VALUE 'OPD',
co_section_name_global_data TYPE tname VALUE 'GDATA',
co_section_name_field_symbols TYPE tname VALUE 'FSYMBOLS',
co_section_name_init TYPE tname VALUE 'GPLIST',
co_section_name_global_forms TYPE tname VALUE 'FCODING',
co_section_name_global_code TYPE tname VALUE 'GCODING',
co_section_name_body_code TYPE tname VALUE 'CODE',
co_section_name_heading TYPE tname VALUE 'HEADER',
co_section_name_formname TYPE tname VALUE 'FORMNAME',
co_input_or_output TYPE tname VALUE 'OUTIN',
co_io_type_import VALUE 'I',
co_io_type_export VALUE 'E',
co_io_type_tables VALUE 'T',
co_section_name_caption TYPE tname VALUE 'CAPTION',
co_section_name_first_user TYPE tname VALUE 'FIRSTUSER',
co_section_name_firstdate TYPE tname VALUE 'FIRSTDATE',
co_section_name_lastdate TYPE tname VALUE 'LASTDATE',
co_section_name_lastuser TYPE tname VALUE 'LASTUSER',
co_section_name_code_name TYPE tname VALUE 'NAME',
co_section_name_io_type TYPE tname VALUE 'IOTYPE',
co_start_of_line TYPE tname VALUE '(',
co_start_of_word TYPE tname VALUE '>',
co_process_line TYPE ttype VALUE '@',
co_start_of_group TYPE ttype VALUE '{',
co_end_of_group TYPE ttype VALUE '}'.
TOP-OF-PAGE.
PERFORM write_top_of_page.
************************************************************************
* EVENT SECTION *
************************************************************************
START-OF-SELECTION.
PERFORM get_all_forms TABLES so_formn
so_devcl
USING ts_forms
ts_formt.
LOOP AT ts_forms INTO wa_forms.
NEW-PAGE.
CLEAR wa_formt.
READ TABLE ts_formt INTO wa_formt
WITH TABLE KEY langu = sy-langu
formname = wa_forms-formname.
PERFORM read_smartform USING wa_forms-formname.
ENDLOOP.
************************************************************************
* SUBROUTINES *
************************************************************************
*----------------------------------------------------------------------*
* FORM read_smartform *
*----------------------------------------------------------------------*
* Read the smartform selected into an internal table and process *
* it. *
*----------------------------------------------------------------------*
FORM read_smartform USING utp_formn TYPE tdsfname.
DATA:
t_ntokens TYPE t_ntokens,
lv_tokens TYPE ntokens.
IMPORT t_ntokens FROM DATABASE stxfcont(xx) ID utp_formn.
READ TABLE t_ntokens INTO lv_tokens
WITH KEY ntype = co_global_data.
PERFORM write_code USING lv_tokens.
CLEAR lv_tokens.
READ TABLE t_ntokens INTO lv_tokens
WITH KEY ntype = co_coding_data.
FORMAT COLOR COL_HEADING.
WRITE / 'CODING WITHIN THE BODY'(h01).
SKIP.
FORMAT COLOR OFF.
IF lv_tokens IS NOT INITIAL.
PERFORM write_code USING lv_tokens.
ENDIF.
ENDFORM. "read_smartform
*&---------------------------------------------------------------------*
*& Form write_code
*&---------------------------------------------------------------------*
* Loop through the smartforms data and write out selected lines. *
*----------------------------------------------------------------------*
* --> pv_tokens The table of smartforms data.
*----------------------------------------------------------------------*
FORM write_code USING pv_tokens TYPE ntokens.
DATA:
lf_val_written TYPE flag,
lf_globals TYPE flag,
lv_type,
lv_date TYPE sy-datum,
lv_inout(6).
FIELD-SYMBOLS:
>ls_token< TYPE token.
LOOP AT pv_tokens-t_token ASSIGNING >ls_token<.
CASE >ls_token<-ttype.
WHEN co_start_section.
FORMAT COLOR COL_HEADING.
SKIP.
CASE >ls_token<-tname.
WHEN co_section_name_interface.
WRITE / 'INTERFACE'(s01).
WHEN co_section_name_global_types.
WRITE / 'GLOBAL TYPES'(s02).
WHEN co_section_name_global_data.
WRITE / 'GLOBAL DATA'(s03).
WHEN co_section_name_field_symbols.
WRITE / 'FIELD SYMBOLS'(s04).
WHEN co_section_name_init.
WRITE / 'INITIALISATION'(s05).
WHEN co_section_name_global_forms.
WRITE / 'GLOBAL FORMS'(s06).
ENDCASE.
FORMAT COLOR OFF.
WHEN co_start_of_group.
IF >ls_token<-tname = co_section_name_heading.
FORMAT COLOR COL_HEADING.
ELSE.
FORMAT COLOR COL_POSITIVE.
ENDIF.
WRITE / >ls_token<-tname.
FORMAT COLOR OFF.
WHEN co_start_of_line OR co_start_of_word.
IF >ls_token<-tname = co_section_name_global_data
OR >ls_token<-tname = co_section_name_field_symbols
OR >ls_token<-tname = co_section_name_init.
lf_globals = co_true.
ENDIF.
WHEN co_process_line.
CASE >ls_token<-tname.
WHEN co_input_or_output.
IF >ls_token<-value = co_io_type_import.
lv_inout = 'Input'(s07).
ELSE.
lv_inout = 'Output'(s08).
ENDIF.
FORMAT COLOR COL_KEY.
IF lf_val_written EQ co_true.
WRITE AT 132 lv_inout.
ELSE.
WRITE AT /132 lv_inout.
ENDIF.
FORMAT COLOR OFF.
CLEAR lf_val_written.
WHEN co_section_name_formname OR co_section_name_caption.
WRITE: /(8) >ls_token<-tname, >ls_token<-value.
WHEN co_section_name_first_user.
WRITE: /(14) 'Created by:'(s09), (10) >ls_token<-value.
WHEN co_section_name_firstdate OR co_section_name_lastdate.
MOVE >ls_token<-value TO lv_date.
WRITE: (4) 'on:'(s10), (10) lv_date.
WHEN co_section_name_lastuser.
WRITE: /(14) 'Modified by:'(s11), (10) >ls_token<-value.
WHEN co_section_name_io_type.
lv_type = >ls_token<-value.
WHEN co_section_name_code_name.
FORMAT COLOR COL_KEY.
IF lf_globals = co_true.
WRITE / >ls_token<-value.
ELSE.
CASE lv_type.
WHEN co_io_type_export.
WRITE: / 'Exporting:'(s12), >ls_token<-value.
WHEN co_io_type_import.
WRITE: / 'Importing:'(s13), >ls_token<-value.
WHEN co_io_type_tables.
WRITE: / 'Tables:'(s14), >ls_token<-value.
ENDCASE.
ENDIF.
FORMAT COLOR OFF.
WHEN co_section_name_global_types.
FORMAT COLOR COL_NORMAL.
IF >ls_token<-value(1) = co_asterisk.
FORMAT COLOR COL_TOTAL.
ENDIF.
WRITE / >ls_token<-value.
FORMAT COLOR OFF.
WHEN co_section_name_param_name.
FORMAT COLOR COL_KEY.
WRITE / >ls_token<-value.
lf_val_written = co_true.
FORMAT COLOR OFF.
WHEN co_section_name_global_code
OR co_section_name_global_forms
OR co_section_name_body_code.
FORMAT COLOR COL_NORMAL.
IF >ls_token<-value(1) = co_asterisk.
FORMAT COLOR COL_TOTAL.
ENDIF.
WRITE / >ls_token<-value.
lf_val_written = co_true.
FORMAT COLOR OFF.
ENDCASE.
WHEN co_end_of_group.
SKIP.
ENDCASE.
ENDLOOP.
ENDFORM. " write_code
*&---------------------------------------------------------------------*
*& Form get_all_forms
*&---------------------------------------------------------------------*
FORM get_all_forms TABLES tso_formn STRUCTURE so_formn
tso_devcl STRUCTURE so_devcl
USING tts_forms TYPE ty_ts_forms
tts_formt TYPE ty_ts_formt.
SELECT * FROM stxfadm INTO TABLE tts_forms
WHERE formname IN tso_formn
AND devclass IN tso_devcl.
IF LINES( tts_forms ) < 0.
SELECT * FROM stxfadmt INTO TABLE tts_formt
FOR ALL ENTRIES IN tts_forms
WHERE langu = sy-langu
AND formname = tts_forms-formname.
ENDIF.
ENDFORM. " get_all_forms
*&---------------------------------------------------------------------*
*& Form write_top_of_page
*&---------------------------------------------------------------------*
FORM write_top_of_page .
FORMAT COLOR COL_HEADING INTENSIFIED ON.
WRITE: / sy-datum,
sy-host,
sy-sysid,
60 'Formname:'(h01),
wa_forms-formname,
wa_formt-caption,
'Dev. Class'(h02),
wa_forms-devclass.
ULINE.
ENDFORM. " write_top_of_page
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.