This article describes the source code and parsing.
Source code:
*&---------------------------------------------------------------------*
*& Report ZSURVEY_READ
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZSURVEY_READ.
DATA: vguid TYPE crm_svy_db_sv_guid.
DATA: vvers TYPE crm_svy_db_svers.
DATA: svy_content TYPE string.
DATA: ret TYPE bapiret1.
DATA: apppar TYPE TABLE OF crm_svy_db_sv_pair.
data: lv_x type xstring.
CALL FUNCTION 'CRM_SVY_SURVEY_GET'
EXPORTING
application_id = 'CRM_SURVEY_ACTIVITY'
survey_id = 'JERRY_TEST'
survey_version = '0000000003'
language = 'E'
media_type = '01'
parameter_xml = 'CRM_SVY_BSP_SYSTEMPARAM.XML'
values_guid = vguid
values_version = vvers
IMPORTING
return = ret
content = svy_content
TABLES
application_params = apppar.
call FUNCTION 'CRM_SVY_DB_CONVERT_STRING2HEX'
EXPORTING
s = svy_content
IMPORTING
x = lv_x.
DATA lr_conv TYPE REF TO cl_abap_conv_in_ce.
data: lv_request_xml type string.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
input = lv_x
RECEIVING
conv = lr_conv.
CALL METHOD lr_conv->read
IMPORTING
data = lv_request_xml.
DATA(reg_pattern) = '.*svyValueGuid(?:.*)value="(.*)">.*SurveyId.*'.
DATA(lo_regex) = NEW cl_abap_regex( pattern = reg_pattern ).
DATA(lo_matcher) = lo_regex->create_matcher( EXPORTING text = lv_request_xml ).
IF lo_matcher->match( ) <> abap_true.
WRITE:/ 'fail'.
RETURN.
ENDIF.
DATA(lt_reg_match_result) = lo_matcher->find_all( ).
READ TABLE lt_reg_match_result ASSIGNING FIELD-SYMBOL(<match>) index 1.
read TABLE <match>-submatches ASSIGNING FIELD-SYMBOL(<submatch>) index 1.
data:lv type string.
lv = lv_request_xml+<submatch>-offset(<submatch>-length).
TRY.
reg_pattern = '.*<input(.*)>.*'.
lo_regex = NEW cl_abap_regex( pattern = reg_pattern ).
lo_matcher = lo_regex->create_matcher( EXPORTING text = lv ).
IF lo_matcher->match( ) <> abap_true.
WRITE:/ 'fail in input scan'.
RETURN.
ENDIF.
data: result_tab TYPE match_result_tab.
FIND ALL OCCURRENCES OF REGEX '<input(.*)>' IN lv RESULTS result_tab.
WRITE:/ lv.
BREAK-POINT.
CATCh cx_root into data(cx_root).
WRITE:/ cx_root->get_text( ).
return.
endtry.
CLEAR: lt_reg_match_result.
lt_reg_match_result = lo_matcher->find_all( ).
READ TABLE lt_reg_match_result ASSIGNING FIELD-SYMBOL(<input>) index 1.
WRITE:/ 'input:', lines( <input>-submatches ).
read TABLE <input>-submatches ASSIGNING <submatch> index 1.
data(new) = lv+<submatch>-offset(<submatch>-length).
WRITE:/ new.
The main function of this ABAP code is to read the content of the questionnaire from a CRM (Customer Relationship Management) system and analyze the data. Here is a detailed explanation of the code:
-
Reporting Statements and Data Definitions :
REPORT ZSURVEY_READ.
: Defines the name of a report, which may be a customized CRM report.- The data definition section declares some variables for storing data obtained from the CRM system.
-
Call the CRM function :
CALL FUNCTION 'CRM_SVY_SURVEY_GET'
: This is a function call used to obtain questionnaire information from the CRM system. Some parameters like application ID, survey ID, version, etc. are passed to get relevant information. The obtained data is stored insvy_content
variables.
-
Convert content to hexadecimal :
CALL FUNCTION 'CRM_SVY_DB_CONVERT_STRING2HEX'
: This function call converts the obtained questionnaire content (svy_content
) into hexadecimal encoding and stores the result inlv_x
the variable.
-
Text transcoding and analysis :
- Use
cl_abap_conv_in_ce
the class to create a transcoder that converts hexadecimal data into text form. lv_request_xml
This XML then contains the questionnaire data through regular expression matching and analysis .- The goal of this section of code is to extract specific information about the questionnaire from the XML, such as
svyValueGuid
the value of .
- Use
-
Regular expression matching :
- Use regular expressions to match
lv_request_xml
data in and extract key information. DATA(reg_pattern)
andDATA(lo_regex)
are used to define and create regular expression objects.lo_matcher
The object is used to perform matching operations and extract matching results.
- Use regular expressions to match
-
Exception handling :
- Use the TRY-CATCH block to handle possible exceptions. If the regular expression fails to match, an exception is generated.
- The exception handling section prints out exception information and terminates code execution.
-
Continue matching :
- After a successful match
svyValueGuid
, the code continues matchinginput
tags. This part of the code may be to extract more information related to the questionnaire.
- After a successful match
-
Final output :
- Finally, the code extracts the match results and stores the results in
new
a variable. - The results are printed, possibly for further processing or display to the user.
- Finally, the code extracts the match results and stores the results in
The core task of this code is to obtain questionnaire information from the CRM system and analyze it. The specific questionnaire content and required information may vary based on actual circumstances. Regular expressions are used in the code to extract the required information from the XML data and then store it in variables for subsequent processing. In practical applications, these data may be used to generate reports, analyze user feedback, or other operations related to the questionnaire.