REPORT ZADN_SAMPLE.
*----------------------------------------------------------------------*
* -> CLASS cl_regex_vs_Function DEFINITION
*----------------------------------------------------------------------*
CLASS cl_regex_vs_function DEFINITION.
PUBLIC SECTION.
METHODS : first_char_to_upper_regex IMPORTING p_text TYPE char50,
first_char_to_upper_function IMPORTING p_text TYPE char50.
PRIVATE SECTION.
DATA : v_input_text TYPE c LENGTH 50,
v_match TYPE match_result.
DATA : it_matches TYPE match_result_tab.
ENDCLASS. "cl_regex_vs_Function DEFINITION
*----------------------------------------------------------------------*
* -> CLASS cl_regex_vs_Function IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_regex_vs_function IMPLEMENTATION.
METHOD first_char_to_upper_regex.
me->v_input_text = p_text.
WRITE / me->v_input_text.
FIND ALL OCCURRENCES OF REGEX '\<[[:lower:]]' IN me->v_input_text RESULTS me->it_matches.
LOOP AT me->it_matches INTO me->v_match.
TRANSLATE me->v_input_text+me->v_match-offset(1) TO UPPER CASE.
ENDLOOP.
WRITE / me->v_input_text.
CLEAR : me->v_input_text,
me->v_match.
REFRESH me->it_matches.
ENDMETHOD. "first_char_to_upper_regex
METHOD first_char_to_upper_function.
me->v_input_text = p_text.
WRITE / me->v_input_text.
CALL FUNCTION 'ISP_CONVERT_FIRSTCHARS_TOUPPER'
EXPORTING
input_string = me->v_input_text
separators = ' -.,;:'
IMPORTING
output_string = me->v_input_text.
WRITE / me->v_input_text.
CLEAR : me->v_input_text.
ENDMETHOD. "first_char_to_upper_function
ENDCLASS. "cl_regex_vs_Function IMPLEMENTATION
************************************************************************
************************************************************************
* *
* PROGRAM FLOW LOGIC *
* *
************************************************************************
PARAMETERS : pa_text TYPE char50.
START-OF-SELECTION.
DATA : o_cl_regex_vs_function TYPE REF TO cl_regex_vs_function.
CREATE OBJECT o_cl_regex_vs_function.
IF o_cl_regex_vs_function IS BOUND.
o_cl_regex_vs_function->first_char_to_upper_regex( pa_text ).
ULINE.
o_cl_regex_vs_function->first_char_to_upper_function( pa_text ).
ENDIF.
22/10/2010
First Char to Upper: Regex Vs Function
01/10/2010
Using Regex to validate CNPJ number
This regular expressions matches CNPJ number. CNPJ is a Registration Number of Brazilian Companies.
REPORT ZADN_SAMPLE.
*----------------------------------------------------------------------*
* -> CLASS cl_regex_test DEFINITION
*----------------------------------------------------------------------*
CLASS cl_regex_test DEFINITION FINAL.
PUBLIC SECTION.
METHODS : check_cnpj IMPORTING p_cnpj TYPE string.
PRIVATE SECTION.
DATA: o_regex TYPE REF TO cl_abap_regex,
o_matcher TYPE REF TO cl_abap_matcher.
ENDCLASS. "cl_regex_test DEFINITION
*----------------------------------------------------------------------*
* -> CLASS cl_regex_test IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_regex_test IMPLEMENTATION.
METHOD check_cnpj.
* Create the regular expression:
CREATE OBJECT o_regex
EXPORTING
pattern = '\d{2}.?\d{3}.?\d{3}/?\d{4}-?\d{2}'.
* Check to see if the CNPJ number matches the regular expression:
CREATE OBJECT o_matcher
EXPORTING
regex = o_regex
text = p_cnpj.
IF o_matcher->match( ) NE abap_true.
MESSAGE 'Enter valid CNPJ number...' TYPE 'E'.
ELSE.
MESSAGE 'This is a valid CNPJ number...' TYPE 'S'.
ENDIF.
ENDMETHOD. "check_cnpj
ENDCLASS. "cl_regex_test IMPLEMENTATION
************************************************************************
************************************************************************
* *
* PROGRAM FLOW LOGIC *
* *
************************************************************************
START-OF-SELECTION.
DATA : ocl_regex_test TYPE REF TO cl_regex_test.
CREATE OBJECT ocl_regex_test.
ocl_regex_test->check_cnpj( '12.043.129/0001-98' ). " IS VALID
"ocl_regex_test->check_cnpj( '02.025.659/0001-981' ). " IS INVALID
Dynamically Created Internal Tables and Display ALV
REPORT ZADN_SAMPLE.
*----------------------------------------------------------------------*
* - > CLASS cl_dynamical_alv DEFINITION
*----------------------------------------------------------------------*
CLASS cl_dynamical_alv DEFINITION.
PUBLIC SECTION.
TYPES: BEGIN OF ty_screenfields,
tab_name TYPE tabname,
tab_rows TYPE i,
END OF ty_screenfields.
METHODS : display_table_data IMPORTING p_tabname TYPE tabname
p_maxrow TYPE i.
PRIVATE SECTION.
DATA: dtabref TYPE REF TO data,
alv TYPE REF TO cl_gui_alv_grid.
ENDCLASS. "cl_dynamical_alv DEFINITION
*----------------------------------------------------------------------*
* - > CLASS cl_dynamical_alv IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS cl_dynamical_alv IMPLEMENTATION.
METHOD display_table_data.
FIELD-SYMBOLS:TYPE ANY TABLE.
CREATE DATA me->dtabref TYPE TABLE OF (p_tabname).
ASSIGN me->dtabref->* TO.
SELECT *
FROM (p_tabname) UP TO p_maxrow ROWS
INTO TABLE.
CREATE OBJECT alv
EXPORTING
i_parent = cl_gui_container=>screen0.
CALL METHOD alv->set_table_for_first_display
EXPORTING
i_structure_name = p_tabname
CHANGING
it_outtab =.
CALL SCREEN 100.
ENDMETHOD. "DISPLAY_TABLE_DATA
ENDCLASS. "cl_dynamical_alv IMPLEMENTATION
************************************************************************
************************************************************************
* *
* PROGRAM FLOW LOGIC *
* *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK b001 WITH FRAME TITLE text-001.
PARAMETERS : p_tbname TYPE cl_dynamical_alv=>ty_screenfields-tab_name,
p_tbrows TYPE cl_dynamical_alv=>ty_screenfields-tab_rows.
SELECTION-SCREEN END OF BLOCK b001.
START-OF-SELECTION.
DATA : o_cl_dynamical_alv TYPE REF TO cl_dynamical_alv.
CREATE OBJECT o_cl_dynamical_alv.
o_cl_dynamical_alv->display_table_data( EXPORTING p_tabname = p_tbname
p_maxrow = p_tbrows ).
Assinar:
Postagens (Atom)