-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new class for building 'call function'
- Loading branch information
Peter Jaeckel
committed
Apr 24, 2018
1 parent
098b179
commit 5baba58
Showing
3 changed files
with
274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
CLASS zcl_fmwp_fcall DEFINITION | ||
PUBLIC | ||
FINAL | ||
CREATE PUBLIC . | ||
|
||
PUBLIC SECTION. | ||
CONSTANTS: | ||
c_exporting TYPE c VALUE 'E', | ||
c_importing TYPE c VALUE 'I', | ||
c_changing TYPE c VALUE 'C', | ||
c_tables TYPE c VALUE 'T', | ||
c_exception TYPE c VALUE 'X'. | ||
METHODS set_name | ||
IMPORTING | ||
i_function_name TYPE string. | ||
METHODS build_source | ||
EXPORTING | ||
et_source TYPE rswsourcet. | ||
METHODS add | ||
IMPORTING | ||
i_type TYPE c | ||
i_name TYPE string | ||
i_value TYPE string OPTIONAL. | ||
PROTECTED SECTION. | ||
PRIVATE SECTION. | ||
TYPES: | ||
BEGIN OF ts_param, | ||
ptype TYPE c LENGTH 1, | ||
name TYPE string, | ||
value TYPE string, | ||
END OF ts_param, | ||
tt_param TYPE STANDARD TABLE OF ts_param. | ||
DATA: m_name TYPE string, | ||
mt_param TYPE tt_param. | ||
METHODS append_params | ||
IMPORTING | ||
i_section TYPE string | ||
i_type TYPE c | ||
CHANGING | ||
ct_source TYPE rswsourcet. | ||
ENDCLASS. | ||
|
||
|
||
|
||
CLASS zcl_fmwp_fcall IMPLEMENTATION. | ||
|
||
|
||
METHOD add. | ||
APPEND VALUE #( ptype = i_type name = i_name value = i_value ) TO mt_param. | ||
ENDMETHOD. | ||
|
||
|
||
METHOD append_params. | ||
|
||
DATA lt_lines TYPE STANDARD TABLE OF string. | ||
|
||
lt_lines = VALUE #( FOR <x> IN mt_param WHERE ( ptype = i_type ) ( |{ <x>-name } = { <x>-value }| ) ). | ||
|
||
IF lt_lines IS NOT INITIAL. | ||
APPEND i_section TO ct_source. | ||
APPEND LINES OF lt_lines TO ct_source. | ||
ENDIF. | ||
|
||
ENDMETHOD. | ||
|
||
|
||
METHOD build_source. | ||
|
||
et_source = VALUE #( ( |call function '{ m_name }'| ) ). | ||
CALL METHOD append_params EXPORTING i_section = 'exporting' i_type = c_exporting CHANGING ct_source = et_source. | ||
CALL METHOD append_params EXPORTING i_section = 'importing' i_type = c_importing CHANGING ct_source = et_source. | ||
CALL METHOD append_params EXPORTING i_section = 'changing' i_type = c_changing CHANGING ct_source = et_source. | ||
CALL METHOD append_params EXPORTING i_section = 'tables' i_type = c_tables CHANGING ct_source = et_source. | ||
APPEND |exceptions| TO et_source. | ||
LOOP AT mt_param INTO DATA(ls_param) WHERE ptype = c_exception. | ||
DATA(exc_num) = sy-index. | ||
APPEND |{ ls_param-name } = { exc_num }| TO et_source. | ||
ENDLOOP. | ||
APPEND |others = { exc_num + 1 }| TO et_source. | ||
APPEND |.| TO et_source. | ||
|
||
ENDMETHOD. | ||
|
||
|
||
METHOD set_name. | ||
|
||
m_name = |{ i_function_name CASE = UPPER }|. | ||
|
||
ENDMETHOD. | ||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
*"* use this source file for your ABAP unit test classes | ||
CLASS ltcl_main DEFINITION FINAL FOR TESTING | ||
DURATION SHORT | ||
RISK LEVEL HARMLESS. | ||
|
||
PRIVATE SECTION. | ||
METHODS: | ||
build_simple_call FOR TESTING RAISING cx_static_check, | ||
build_call_exporting FOR TESTING RAISING cx_static_check, | ||
build_call_importing FOR TESTING RAISING cx_static_check, | ||
build_call_changing FOR TESTING RAISING cx_static_check, | ||
build_call_tables FOR TESTING RAISING cx_static_check, | ||
build_call_exception FOR TESTING RAISING cx_static_check, | ||
build_call_combined FOR TESTING RAISING cx_static_check. | ||
ENDCLASS. | ||
|
||
|
||
CLASS ltcl_main IMPLEMENTATION. | ||
|
||
METHOD build_simple_call. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |exceptions| ) | ||
( |others = 1| ) | ||
( |.| ) ). | ||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_exporting. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_exporting i_name = 'param1' i_value = 'value' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |exporting| ) | ||
( |param1 = value| ) | ||
( |exceptions| ) | ||
( |others = 1| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_importing. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_importing i_name = 'param1' i_value = 'value' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |importing| ) | ||
( |param1 = value| ) | ||
( |exceptions| ) | ||
( |others = 1| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_changing. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_changing i_name = 'param1' i_value = 'value' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |changing| ) | ||
( |param1 = value| ) | ||
( |exceptions| ) | ||
( |others = 1| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_tables. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_tables i_name = 'param1' i_value = 'value' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |tables| ) | ||
( |param1 = value| ) | ||
( |exceptions| ) | ||
( |others = 1| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_exception. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_exception i_name = 'param1' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |exceptions| ) | ||
( |param1 = 1| ) | ||
( |others = 2| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
METHOD build_call_combined. | ||
DATA(cut) = NEW zcl_fmwp_fcall( ). | ||
cut->set_name( 'function_name' ). | ||
cut->add( i_type = cut->c_tables i_name = 'table1' i_value = 'tvalue' ). | ||
cut->add( i_type = cut->c_importing i_name = 'imp1' i_value = 'i_value' ). | ||
cut->add( i_type = cut->c_exporting i_name = 'exp1' i_value = 'e_value' ). | ||
cut->add( i_type = cut->c_changing i_name = 'chg1' i_value = 'c_value' ). | ||
cut->add( i_type = cut->c_exception i_name = 'param1' ). | ||
|
||
|
||
CALL METHOD cut->build_source | ||
IMPORTING | ||
et_source = DATA(l_src). | ||
DATA(l_exp_src) = VALUE rswsourcet( | ||
( |call function 'FUNCTION_NAME'| ) | ||
( |exporting| ) | ||
( |exp1 = e_value| ) | ||
( |importing| ) | ||
( |imp1 = i_value| ) | ||
( |changing| ) | ||
( |chg1 = c_value| ) | ||
( |tables| ) | ||
( |table1 = tvalue| ) | ||
( |exceptions| ) | ||
( |param1 = 1| ) | ||
( |others = 2| ) | ||
( |.| ) ). | ||
|
||
cl_abap_unit_assert=>assert_equals( msg = 'src' exp = l_exp_src act = l_src ). | ||
ENDMETHOD. | ||
|
||
ENDCLASS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0"> | ||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0"> | ||
<asx:values> | ||
<VSEOCLASS> | ||
<CLSNAME>ZCL_FMWP_FCALL</CLSNAME> | ||
<VERSION>1</VERSION> | ||
<LANGU>E</LANGU> | ||
<DESCRIPT>Represents a call function syntax element</DESCRIPT> | ||
<EXPOSURE>2</EXPOSURE> | ||
<STATE>1</STATE> | ||
<CLSFINAL>X</CLSFINAL> | ||
<CLSCCINCL>X</CLSCCINCL> | ||
<FIXPT>X</FIXPT> | ||
<UNICODE>X</UNICODE> | ||
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS> | ||
</VSEOCLASS> | ||
</asx:values> | ||
</asx:abap> | ||
</abapGit> |