‎2019 Feb 01 11:50 AM
Hello together,
If I have a SO10 text and single variables I know what I have to do to replace them. But in my case I would like to take a SO10 text with an itab.
For example: If have the following SO10 Text:
Error with article:
- Articlenumber: $NO&$ -> Reason: $REASON$
and an itab with the colums NO and REASON.
I want that the second line will be repeated for each line in the itab.
Does any body has an idea how do I achive this? Have I use smartforms?
The output later should be html code.
Best regards
Uwe
‎2019 Feb 01 12:54 PM
If you are asking for the ABAP logic, it is a nested LOOP: go over the table of text lines, copy the line as a pattern and DELETE it if it has placeholders and LOOP over the internal table data, REPLACE the placeholders and INSERT the result into the text table.
Maybe like this
lt_text = get_standard_text( ) " --> INTO
LOOP AT lt_text INTO DATA(ls_text) WHERE tdline CS '$REASON$'.
DATA(lv_tabix) = sy-tabix.
DELETE lt_text.
LOOP AT it_data ASSIGNING FIELD-SYMBOL(<ls_entry>).
DATA(ls_new) = ls_text.
REPLACE:
'$NO&$' IN ls_new-tdline WITH <ls_entry>-no,
'$REASON$' IN ls_new-tdline WITH <ls_entry>-reason.
CONDENSE ls_new-tdline.
INSERT ls_new INTO mt_text INDEX lv_tabix.
CHECK sy-subrc EQ 0.
ADD 1 TO l_tabix.
ENDLOOP.
EXIT.
ENDLOOP.
But as you want an HTML output, I would prefer a transformation
DATA l_stream TYPE xstring. " or string
CALL TRANSFORMATION your_transformation
OPTIONS xml_header = 'no'
SOURCE body = it_data
RESULT XML l_stream.<?sap.transform simple?>
<tt:transform template="my_template" xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="BODY"/>
<tt:template name="my_template">
<html xmlns:html="http://www.w3.org/TR/REC-html40">
<head>
</head>
<body>
<table border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>No.</td>
<td>Reason</td>
</tr>
<tt:loop ref="BODY">
<tr>
<td><tt:value ref="NO"/></td>
<td><tt:value ref="REASON"/></td>
</tr>
</tt:loop>
</table>
</body>
</html>
</tt:template>
</tt:transform>
Hope this helps,
JNN
‎2019 Feb 01 12:16 PM
You mean you don't need to generate a Smart Form, only HTML? Why are you using a standard text then, can't it be more simple to do a custom solution?
‎2019 Feb 01 12:44 PM
Why not just loop the itab and repeat that SO10 text for each line?
‎2019 Feb 01 12:54 PM
If you are asking for the ABAP logic, it is a nested LOOP: go over the table of text lines, copy the line as a pattern and DELETE it if it has placeholders and LOOP over the internal table data, REPLACE the placeholders and INSERT the result into the text table.
Maybe like this
lt_text = get_standard_text( ) " --> INTO
LOOP AT lt_text INTO DATA(ls_text) WHERE tdline CS '$REASON$'.
DATA(lv_tabix) = sy-tabix.
DELETE lt_text.
LOOP AT it_data ASSIGNING FIELD-SYMBOL(<ls_entry>).
DATA(ls_new) = ls_text.
REPLACE:
'$NO&$' IN ls_new-tdline WITH <ls_entry>-no,
'$REASON$' IN ls_new-tdline WITH <ls_entry>-reason.
CONDENSE ls_new-tdline.
INSERT ls_new INTO mt_text INDEX lv_tabix.
CHECK sy-subrc EQ 0.
ADD 1 TO l_tabix.
ENDLOOP.
EXIT.
ENDLOOP.
But as you want an HTML output, I would prefer a transformation
DATA l_stream TYPE xstring. " or string
CALL TRANSFORMATION your_transformation
OPTIONS xml_header = 'no'
SOURCE body = it_data
RESULT XML l_stream.<?sap.transform simple?>
<tt:transform template="my_template" xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="BODY"/>
<tt:template name="my_template">
<html xmlns:html="http://www.w3.org/TR/REC-html40">
<head>
</head>
<body>
<table border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>No.</td>
<td>Reason</td>
</tr>
<tt:loop ref="BODY">
<tr>
<td><tt:value ref="NO"/></td>
<td><tt:value ref="REASON"/></td>
</tr>
</tt:loop>
</table>
</body>
</html>
</tt:template>
</tt:transform>
Hope this helps,
JNN
‎2019 Feb 01 1:46 PM
Thanks for your responses.
The nested LOOP sollution is the best solution for me. So I can use the SO10 textes that are also translateable.
‎2019 Feb 01 1:48 PM
Please use the button Comment, the Answer is only for proposed solutions.