Skip to Content

This tutorial is a step-by-step guide to post ABAP code snippets on your blog posts or documents, on SAP Community Network (SCN) or any other website that accepts HTML editing, with the proper ABAP syntax highlighting.

1. Prerequisites

  • The website must allow the user to edit her or his posts (or documents) in the HTML format, like SCN does.
  • The convenience presented on this tutorial relies on the availability of the following third party website (last visited on November 22, 2013): http://highlight.hohli.com/

2. Code Snippets on SCN Today

As the SCN knows, the current option to post code snippets is based on a fixed set of languages, available via the Use advanced editor (top right corner, above the editing menu) > “>>” Button >> Syntax Highlighting: XML; SQL; Java; Plain; C++; C#; CSS; Javascript; PHP; Python; Ruby.

Unfortunately, there isn’t an ABAP option.

Posting an ABAP code snipped, using XML code highlighting (for example), looks like this (code copied from the New ABAP Editor and pasted below):

* Examples of Subroutines
* -- Example of Passing Parameters by Reference
* http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db979035c111d1829f0000e829fbfe/content.htm
REPORT demo_mod_tech_example_1.
DATA: num1 TYPE i,
      num2 TYPE i,
      sum  TYPE i.
num1 = 2. num2 = 4.
PERFORM addit USING num1 num2 CHANGING sum.
num1 = 7. num2 = 11.
PERFORM addit USING num1 num2 CHANGING sum.
FORM addit
       USING add_num1   TYPE any
             add_num2   TYPE any
       CHANGING add_sum TYPE any.
  add_sum = add_num1 + add_num2.
  PERFORM out USING add_num1 add_num2 add_sum.
ENDFORM.
FORM out
       USING out_num1 TYPE any
             out_num2 TYPE any
             out_sum  TYPE any.
  WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.
ENDFORM.

Sadly, although the code snipped is neatly presented, the syntax highlighting doesn’t show up while in editing mode and, when published (or when a draft is saved), the syntax highlighting turns out to be far from the desired result (to be fair, the other languages available show some highlights, but of course not for the ABAP keywords). Also, notice that the font isn’t a monospaced one, like Courier New.


3. Good-looking ABAP Code Snippets!

Now, the good news. You can post good-looking ABAP code snippets on your blog posts and documents! Just follow this simple steps:

  1. Have your previously highlighted ABAP code snipped at hand, either from the New ABAP Editor or (not for the faint of heart) from that code snippet that was painstakingly colored manually.
  2. Access the following website: http://highlight.hohli.com/
  3. Choose the Syntax Highlighter tab (if it isn’t selected already).
  4. On the Choose a language listbox, select ABAP.
  5. Under Options, check Line numbers.
  6. Paste your code snipped on the Source code field.
  7. Under Configuration Complete, click on the Highlight! button.
  8. Enjoy your Preview.
  9. Now, the most important part: under Source, there’s the HTML source code generated for your ABAP code snipped. Please, select all of this HTML source code and copy it.

Back to the SCN website, you can now start your blog post or document:

  1. Select HTML editing (top right corner of the post window).
  2. Paste the HTML source code on the body your post.
  3. Click on Show Full Editor (top right corner of the post window).
  4. Enjoy the result!

  1. * Examples of Subroutines
  2. * -- Example of Passing Parameters by Reference
  3. REPORT demo_mod_tech_example_1.
  4. DATA: num1 TYPE i,
  5.       num2 TYPE i,
  6.       sum  TYPE i.
  7. num1 = 2. num2 = 4.
  8. PERFORM addit USING num1 num2 CHANGING sum.
  9. num1 = 7. num2 = 11.
  10. PERFORM addit USING num1 num2 CHANGING sum.
  11. FORM addit
  12.        USING add_num1   TYPE any
  13.              add_num2   TYPE any
  14.        CHANGING add_sum TYPE any.
  15.   add_sum = add_num1 + add_num2.
  16.   PERFORM out USING add_num1 add_num2 add_sum.
  17. ENDFORM.
  18. FORM out
  19.        USING out_num1 TYPE any
  20.              out_num2 TYPE any
  21.              out_sum  TYPE any.
  22.   WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum.
  23. ENDFORM.

Congratulations! Now your new, good-looking ABAP code snipped is ready to help the SCN members!

On a last note: please be careful when pasting your HTML source code on a post that you have been already writing. While in Full Editor mode, make plenty of space for your code snippet (press return several times) before inserting it (in HTML mode). By doing this, when going to HTML mode, it will be easier to spot the place to paste the HTML source code (see below).

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<!-- Paste your HTML source code here! -->

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

<p> </p>

4. Current Limitations

  • While editing a blog post or document, the highlighted code line numbers appear correctly. When the blog post or document is published, only the last digit of each line number appears. This behavior may be related to the SCN posting mechanism (since the highlighting HTML code was tested just on SCN and on the third party website that generates the code, the author cannot confirm this information).
  • Disabling line numbers (Section 3) causes a  problem with the presentation, since the code indentation is completely lost (see an example below). This behavior may be related to the SCN posting mechanism (since the highlighting HTML code was tested just on SCN and on the third party website that generates the code, the author cannot confirm this information).

Below, you can see an example of a bad-looking code snippet. In this case, the Line numbers option wasn’t checked for the HTML code generation. On the website that generates the HTML code, not surprisingly, this problem does not occur.

* Examples of Subroutines* -- Example of Passing Parameters by Reference* http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db979035c111d1829f0000e829fbfe/content.htm 
REPORT demo_mod_tech_example_1. 
DATA: num1 TYPE i,      num2 TYPE i,      sum  TYPE i. 
num1 = 2. num2 = 4.PERFORM addit USING num1 num2 CHANGING sum. 
num1 = 7. num2 = 11.PERFORM addit USING num1 num2 CHANGING sum. 
FORM addit
       USING add_num1   TYPE any             add_num2   TYPE any       CHANGING add_sum TYPE any. 
  add_sum = add_num1 + add_num2.  PERFORM out USING add_num1 add_num2 add_sum. 
ENDFORM. 
FORM out       USING out_num1 TYPE any             out_num2 TYPE any             out_sum  TYPE any. 
  WRITE: / 'Sum of', out_num1, 'and', out_num2, 'is', out_sum. 
ENDFORM. 

Finally:

  • The colors of the syntax highlighting are not customizable.
  • On every fifth line, code that was not highlighted (thus, is in black color), appears in bold style (matching the line number style). This seems to be a feature of the HTML generator.

5. Conclusion

This tutorial was a step-by-step guide to post ABAP code snippets on your blog posts or documents, on SAP Community Network (SCN) or any other website that accepts HTML editing, with the proper ABAP syntax highlighting.

Feel free to drop a comment, follow and bookmark this tutorial. If you enjoyed reading it and, most importantly, if it was useful to you, please consider liking and sharing it. Last but not least, please remember to rate this document – share your opinion with the other SCN members!

Thank you very much for your attention! Happy posting!

Best regards,

Flávio Alves.

6. Disclaimer

All data and information provided on this tutorial is for informational purposes only. The author of this tutorial makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this tutorial. The author of this tutorial will not be liable for any errors or omissions in the information provided on this tutorial, or any losses, injuries, or damages arising from its use, including, without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this tutorial. The contents referred by the hyperlinks presented on this tutorial are the sole responsibility of their respective owners or operators. The author is not responsible for the contents of any linked documents, pages or websites. All information is provided on an as-is basis. Use this tutorial at your own risk.

7. Trademark Notices

SAP® and ABAP™ are trademarks of SAP AG in Germany and in several other countries. All other trademarks are the property of their respective owners.

Posting Good-looking ABAP Code Snippets on SCN

Copyright © 2013 Flávio Alves

All rights reserved.

Version 1.0.5

2013-11-22


To report this post you need to login first.

12 Comments

You must be Logged on to comment or reply to a post.

  1. Sander Boers

    Hi Flavio,

    thanks for creating such a swell document. Code snippets look much prettier using this method.

    Unfortunately I will not always remember this highlight website ( http://highlight.hohli.com/ ) Next to this, the fonts doesn’t match the ABAP Editor defaults.

    So I’m still hoping someday such functionality will be embedded directly into the SCN editor.

    Best,

    Sander

    (0) 
    1. Flávio Alves Post author

      Hello, Sander!

      You’re welcome!

      Yes, the website name is a bit hard to remember. May I suggest a mnemonic?

      hohliHighlight Of High Language Initiative!

      I am also hoping that the ABAP syntax highlighting will be embedded directly into the SCN editor.

      Thanks for your comment!

      Best regards,

      Flávio.

      (0) 
    2. Manish Kumar

      You don’t have to remember the URL, just bookmark it in browser.

      It is unlikely that SCN will ever have ABAP syntax highlighting.

      Not many people are asking for it, and related idea in idea place has very less votes.

      (0) 
  2. Manish Kumar

    Good to see someone who thinks about ABAP syntax highlighting.

    I am using a local script to create the required html snippet that looks exactly like the one in new ABAP Editor.

    For someone who knows web app development, it would be easy to take stuff copied from ABAP Editor, and transform it into something that directly be pasted on SCN.

    Have a look at my snippet.

    http://scn.sap.com/message/14548055#14548055

    (0) 
      1. Manish Kumar

        I can’t share the script. It is too ugly, and despite having a script, lot of manual steps are taken.

        The approach would be:

        • Save ABAP code as html (Export to HTML) or paste in word and save as html.
        • Compare saved html code with html code of snippet that you created manually in SCN post
        • Since you know ABAP, it is possible to write a program that takes the saved html file as input, and shows your transformed html code valid for SCN.
        • The transformed html code can be pasted using “Toggle HTML mode” option.
        (0) 

Leave a Reply