statement WRITE and alternatives
Dear community, small survey and discussion:
- Who else is still using the WRITE statement?
- In what situation are you using it?
I know, it’s a very old statement, but it doesn’t matter. There are rare cases in which it serves well for me: small correction reports, test reports and for output in background jobs.
There are alternatives to output some text or list entries. Here are some suggestions:
- MESSAGE statement
- function module POPUP_TO_INFORM
- SAP List Viewer (ALV)
- Class CL_DEMO_OUTPUT (maybe via console of ABAP Development Tools)
- Application Log
Best regards, thanks for reading and stay healthy
P. S.: Not tired of reading? Check this blog by Jörgen Lindqvist.
I guess in some cases it can be used to format a variable with the edit mask addition.
Also a quick and simple way to format output for currency or with user's preferred decimals, etc. In pre-HANA world, at least.
The issue is not merely with the WRITE statement. It is the need of a generic Input/Output.
I try to generate all output from a few routines (FORM, METHOD) so that I only have to port those to whatever target (the Cloud) will be next.
CL_DEMO_OUTPUT is the most generic solution so far, but it fails for generic input in the Cloud.
I am trying to figure out how to trick the RAP framework to generate an input dialog for a new entry in a Custom Entity exposed as a service that would be linked to my ABAP Class method.
As a side note: If I remember correctly CL_DEMO_OUTPUT is not intended for productive use. But that's just by the way
I didn't know that WRITE and CL_DEMO_OUTPUT could redirect to the ADT console... That might come in handy! I typically use the IF_OO_ADT_CLASSRUN interface for my smaller tests that never leave the dev system.
This interface is a great option. But only in newer SAP NetWeaver versions available (7.51/52 and above?).
Nice question, you mentioned an answer already: for output in background jobs.
WRITE-statements go to the spool, while MESSAGE-statements got to the job-log.
-> I like to utilize both.
While I use MESSAGE for a higher-lever Info ( "A total of &1 orders processed; &2 success, &3 skipped"), I use WRITE for details: " Now Processing Order &1!" ; "Delivery &1 created for it".
Tipp: If nothing was done, don't WRITE anything -> that way, you can easily see in the job overview that there is no spool -> nothing to check.
(In the past I had wished SAPs WS_MONITOR_OUTB_DEL_PICK (= VL06p) would also work that way!)
It is extremely important not to confuse the two! Speaking as someone who got woken up at 2 am because some developer thought it'd be a good idea to add WRITE 'No data found' to all the programs scheduled to run like every 5 minutes. And then the system ran out of the spool numbers. It was not fun.
... that escalated quickly ...
I use write for background jobs that usually an IT person would read. It's quick and effective. I like
I use WRITE-statements for "cobbled together" reports where I'd like to get different list-formats in one go which just isn't feasible to do in ALV. I for example created a program several years ago which extracts transport data and then lists the results in one output list but in different "sections":
# of Records read from E070CTV
# of Transport-Requests :
# of Transports w/o QA-approval
# of Workbench Request
# of Customizing Request
# of PNRs in selection
# of Transports with PNRs ("project numbers")
% of Transports with PNRs
# of PNRs without identifiable CTS
# of relevant transports
# of Objects for selected CTS
All of the above plus we used WRITE in "Hello world" program in ABAP Introduction book because it's much simpler than other options. (We did explain other options later in the book though. 🙂 )
Still use WRITE for small test programs, just because it's quick to write. I'm talking about those quick 4-liners to test the behaviour of a command and so on.
If it's more than a simple value then I switch to cl_demo_output or CL_SALV_*
I am not a big fan of writing to spool, prefer to persist in the DB in a proper searchable format, even if it's just the SLG1 log.
Your comment about using SLG1 makes me wonder: is there an easy way to do that which doesn't require setting up new (sub)objects, doesn't interfere with existing logs and only requires a few FM and/or method calls? It's been a while since I last actively utitlized it, so am curious of how you "just" do it.
I meant "just" as opposed to a dedicated table. There is no single answer, as every project seems to have their own way of handling SLG1, so we could "just" slot into whatever is in use.
In my experience any jobs would typically already have an object, so we tag onto that. Most background processes have an online equivalent so it's rarely the case that we'd have to create a sub/object just for one job. Failing that, create one 🙂
Alternatively there are also open source options, such as ABAP-Logger that let you log stuff with a line or two of code.
Hope that helps,