Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SO10 text - replace with itab

Former Member
0 Likes
2,807

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

1 ACCEPTED SOLUTION
Read only

nomssi
Active Contributor
1,836

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

5 REPLIES 5
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,836

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?

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
1,836

Why not just loop the itab and repeat that SO10 text for each line?

-- Tomas --
Read only

nomssi
Active Contributor
1,837

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

Read only

Former Member
0 Likes
1,836

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.

Read only

0 Likes
1,836

Please use the button Comment, the Answer is only for proposed solutions.