
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.
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.
Now, the good news. You can post good-looking ABAP code snippets on your blog posts and documents! Just follow this simple steps:
Back to the SCN website, you can now start your blog post or document:
* Examples of Subroutines * -- Example of Passing Parameters by Reference 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.
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>
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:
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.
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
9 | |
1 | |
1 | |
1 | |
1 |