Standard service - a fixed amount of work that is performed at a fixed price.  Post Service

  

Sunday, 25 August 2019 16:36

Useful Trick to Search “Text” in Smartforms/Text modules

Written by  https://sapyard.com/useful-trick-to-search-text-in-smartforms-text-modules/
Rate this item
(0 votes)

You may master the new programming models using Core Data Services. You may build

beautiful Fiori and UI5 applications which are sleek, fast and mobile friendly. You may also write SQLScript in your S/4HANA Project. But once an ABAP Programmer, always an ABAP Programmer. Clients will always have some weird requests where you will still need your basic ABAP Programming skills, debugging, analyzing and solutioning acumen.

Background: Recently we received a requirement to replace some hard-coded text written in Text Elements of Smart forms. In the SAP system there were around 350 – 400 custom smart forms to find and replace.

For e.g: I was searching for text “Secret” in which and all smartforms/textmodule its written.

Approaches/Attempts:

Approach 1:

Like many, I thought there should be a table to hold this data and fortunately (from scn community) found table STXFTXT. Field TDLINE holds smart form content and I tried searching.

Results:

voila!! I found what I was looking for. But …..

The field TDLINE is case sensitive. ? It means, you should know exact word with exact upper case and lower case combination. Otherwise you can’t get correct results in this table (I also read somewhere this table is not at all reliable).

Check, now I am searching for all lower case “secret”. It gives different output.

See here its not returning “ZDEMO” form name in a results

Also ReadJavaScript in SAP Adobe Forms

So what next? Plan B ?

Approach 2:

Plan B was to download smart form as XML and search for text. This way you can find the texts.

Solution Implementation:

There is a function module called “FB_CONVERT_FORM_TO_XML” which will convert form to XML by taking Form name and Form type as input. This function module accepts Text Module also as input, which is Bonus.

Now as every ABAPer does, select all forms, loop on each, get XML, convert XML to String and search your Love/Pain stories strings ? and display all found form names in ALV. Isn’t this the everyday story of all ABAP developers? ?

Advantage of this approach:

This search is Case Insensitive. It will search for all cases.

Also Check –Trick to Find the list of Smartforms and it’s Include TEXTs (SO10)

Code Snippet for your Reference

Attached program does it. Feel free to Plug and Play . Fancy word for copy paste. ?

The important functions used in this sample program are: FB_CONVERT_FORM_TO_XML, SSFH_XSTRINGUTF8_TO_STRING, FB_DISPLAY_FORM, DISPLAY_XML_DOCUMENT . Class used is CL_XML_DOCUMENT and method PARSE_STRING.

The entire code is also at the bottom of this article for your quick reference.

In Selection screen, we can give Form name and String for search.

Displays all Form name/Text Module wherever search string exists, with HotSpot clicking on this will open the Smart form/Text Module in XML format. Navigate to your text element.

Please note: Inactive forms will not be converted to XML, but Function module is smart enough to say its inactive by raising Exceptions.

Now the entire Smart Form properties are in your control. Do, whatever you want.

This is my first article at SAPYard. Your genuine feedback is welcome. Please help me improve and provide you better content.

In the next article I will show how to locate (find) exact node or element where search text lies in the Smartforms. Please stay tuned.

5370+ SAP Technical Practitioners from 6 Continents of the SAP World. Install Telegram app and click this link to join – Telegram SAP Technical Discuss Group.

Forms (Smartforms and SapScript)

Step by Step Tutorials on S/4HANA

Code Snippet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<code>REPORTzsf_find_text.
*--------------------------------------------------------------------*
* Deferred statement CLASS is used to make the class class known,
* regardless of the location of the actual definition of the class
* in the program
CLASSlcl_event_handelerDEFINITIONDEFERRED.
*--------------------------------------------------------------------*
DATA:lv_stringTYPEtdsfname.
SELECTION-SCREENBEGIN OF BLOCKb1WITHFRAME.
SELECT-OPTIONS:s_formFORlv_string.
PARAMETERS:p_formsTYPEstringNO-DISPLAY,
find_datTYPEstringLOWERCASEOBLIGATORY.
SELECTION-SCREENEND OF BLOCKb1.
*--------------------------------------------------------------------*
INITIALIZATION.
s_form-low='Z*'.
APPENDs_form.
*--------------------------------------------------------------------*
DATAi_formnameTYPEstring.
DATAe_xmlTYPExstring.
*--------------------------------------------------------------------*
TYPES:BEGIN OFty_sf,
formnameTYPEtdsfname,
formtypeTYPEtdsftype,
statusTYPEchar8,
e_xmlTYPEstring,
END OFty_sf.
DATA:lt_formsTYPESTANDARD TABLE OFty_sf.
*--------------------------------------------------------------------*
* Class Definition
CLASSlcl_event_handelerDEFINITION.
PUBLICSECTION.
* Hotspot Handling
METHODS:handle_hotspotFOREVENTlink_clickOFcl_salv_events_table
IMPORTING
row
column.
ENDCLASS.
*--------------------------------------------------------------------*
* Class Implementation
CLASSlcl_event_handelerIMPLEMENTATION.
* Handling Hotspot Click
METHODhandle_hotspot.
READ TABLElt_formsINTODATA(ls_forms)INDEXrow.
IFsy-subrc=0.
IFcolumn='E_XML'.
DATA:gcl_xmlTYPEREF TOcl_xml_document.
CREATE OBJECTgcl_xml.
*Parses XML String to DOM
CALL METHODgcl_xml->parse_string
EXPORTING
stream=ls_forms-e_xml.
*Display XML
CALL METHODgcl_xml->display.
ELSE.
CALL FUNCTION'FB_DISPLAY_FORM'
EXPORTING
i_formname=ls_forms-formname
i_formtype=ls_forms-formtype
i_with_dialog=abap_false
EXCEPTIONS
no_name=1
no_form=2
no_access_permission=3
illegal_language=4
illegal_formtype=5
OTHERS=6.
IFsy-subrc&lt;>0.
* Implement suitable error handling here
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
*--------------------------------------------------------------------*
START-OF-SELECTION.
SELECTformnameformtypeFROMstxfadmINTOTABLElt_forms
WHEREformnameINs_form.
*--------------------------------------------------------------------*
LOOP ATlt_formsASSIGNINGFIELD-SYMBOL(&lt;ls_forms>).
DATA(lv_tabix)=sy-tabix.
p_forms=&lt;ls_forms>-formname.
* Convert to XML
CALL FUNCTION'FB_CONVERT_FORM_TO_XML'
EXPORTING
i_formname=p_forms
IMPORTING
e_xml=e_xml
EXCEPTIONS
no_active_source=3.
IFsy-subrc&lt;>0.
&lt;ls_forms>-status='Inactive'.
CONTINUE.
ENDIF.
DATAostr_output_dataTYPExstring.
DATAcodepageTYPEcpcodepage.
DATAcstr_output_dataTYPEstring.
* Convert XML to String
CALL FUNCTION'SSFH_XSTRINGUTF8_TO_STRING'
EXPORTING
ostr_output_data=e_xml
IMPORTING
cstr_output_data=&lt;ls_forms>-e_xml
EXCEPTIONS
conversion_error=1
internal_error=2
OTHERS=3.
IFsy-subrc&lt;>0.
CONTINUE.
ENDIF.
* SEARCH Command
SEARCH&lt;ls_forms>-e_xmlFORfind_datANDMARK.
IFsy-subrcNE0.
DELETElt_formsINDEXlv_tabix.
ENDIF.
ENDLOOP.
*--------------------------------------------------------------------*
DATA:o_alvTYPEREF TOcl_salv_table.
DATA:lx_msgTYPEREF TOcx_salv_msg.
DATA:lr_columnsTYPEREF TOcl_salv_columns,
lr_columnTYPEREF TOcl_salv_column_table,
lr_columsTYPEREF TOcl_salv_columns_table,
lr_displayTYPEREF TOcl_salv_display_settings,
titleTYPElvc_title.
*--------------------------------------------------------------------*
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table=o_alv
CHANGING
t_table=lt_forms).
CATCHcx_salv_msgINTOlx_msg.
ENDTRY.
*--------------------------------------------------------------------*
lr_display=o_alv->get_display_settings().
title='Search Results for Text:'(001)&amp;&amp;|" | &amp;&amp; find_dat &amp;&amp; | " |.
lr_display->set_list_header(title).
lr_display->set_striped_pattern(if_salv_c_bool_sap=>true).
lr_columns=o_alv->get_columns().
lr_columns->set_optimize(abap_true).
DATA(gr_functions)=o_alv->get_functions().
gr_functions->set_all(abap_true).
lr_colums=o_alv->get_columns().
lr_column?=lr_colums->get_column('FORMNAME').
lr_column->set_cell_type(if_salv_c_cell_type=>hotspot).
lr_column?=lr_colums->get_column('STATUS').
lr_column->set_long_text('Status').
lr_column->set_short_text('Status').
lr_column->set_medium_text('Status').
lr_column?=lr_colums->get_column('FORMTYPE').
lr_column->set_visible(if_salv_c_bool_sap=>false).
lr_column?=lr_colums->get_column('E_XML').
lr_column->set_cell_type(if_salv_c_cell_type=>hotspot).
*--------------------------------------------------------------------*
DATA:co_reportTYPEREF TOlcl_event_handeler.
DATA:lo_eventsTYPEREF TOcl_salv_events_table.
CREATE OBJECTco_report.
* All events
lo_events=o_alv->get_event().
*
* Event handler
SET HANDLERco_report->handle_hotspotFORlo_events.
o_alv->display().
*--------------------------------------------------------------------*</code>
Read 83 times

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.