FAQ

Here you will find some common questions about ABAP/4 and developments. Many of the questions and answers are cut from the SAP R/3 LIST.

 

Question:How do I use variables in the FORMAT command.

Answer:
DATA COLORID TYPE I VALUE 4.
FORMAT INTENSIFIED ON COLOR = COLORID.

Question:When using
CALL 'SYSTEM' id 'COMMAND' field unix-command

How does one capture the results of the command? For example, it the
unix-command were the date?
thanks,

Answer:
You capture the results in the table e.g TABL, like this 
DATA: BEGIN OF TABL OCCURS 0,
        LINE(560),
      END OF TABL.

REFRESH TABL.
CALL 'SYSTEM' ID 'COMMAND' FIELD PARCOM_LOC
ID 'TAB' FIELD TABL-*SYS*. 

Question:I am working on a program that needs to show number of days between 2
dates. When I scanned the function library, I only found a function to
give you the number of years between dates. I can probably code this
in ABAP but does anyone know if a function exists to do this.

Answer:I wrote this example for you. I think this is what you need.

DATA: DATE_1 LIKE SY-DATUM
,DATE_2 LIKE SY-DATUM.
DATA DAYS TYPE I.

DATE_1 = SY-DATUM.
DATE_2 = SY-DATUM + 65.
DAYS = DATE_2 - DATE_1.
WRITE:/ 'DATE_2=',DATE_2,'DATE_1=',DATE_1,'DAYS=',DAYS.

Run this code and then you will understand.

 

Question:How do I concatenate two strings in Abap/4?

Answer:For all SAP Versions

STR_LENGTH = STRLEN( STRING1 ).
MOVE STRING1 TO STRING3.
WRITE STRING2 TO STRING3+STR_LENGTH.

For SAP Version 3.0 choose:

CONCATENATE STRING1 STRING2 INTO STRING3.

If you want a space between both fields:

CONCATENATE STRING1 STRING2 INTO STRING3 SEPARATED BY ' '.

For SAP Version 2.2 choose Functions:

STRING_CONCATENATE for 2 Strings and
STRING_CONCATENATE_3 for 3 Strings.

 

Question:Has anyone been successful in suppressing the selection screen that is automatically displayed when using logical data bases. I want to run a job in the background using a logical database and I do not want the user prompted for the parameters. I want to pass the parameters in the program.

Answer:Try using the SUBMIT rep USING SELECTION-SET 'variant' WITH ....
command in the report to pass the variant thru the program

 

Question:I would like to know how to execute from ABAP code an external Unix program and
check for a return code ?

Answer:There are different ways to this:

(1) OPEN DATASET <file> FOR OUTPUT 'unix command'
CLOSE DATASET <file>
This command executes the unix command and writes the output into <file>
Look into OSS Note 9391.


(2)
or try the following program but unfortunately the command CALL SYSTEM is
not supported by SAP. If you are on R/3 2.1 - 2.2x you can get some idea's from the
program SAPMSOS0.

REPORT ZUNIXCOM .

DATA: U_COMMAND(200).
* Table for system messages
DATA: BEGIN OF RT OCCURS 100 ,
LINE(100) ,
END OF RT .

START-OF-SELECTION .

MOVE 'unix command' to U_COMMAND .
REFRESH RT.
CALL 'SYSTEM' ID 'COMMAND' FIELD U_COMMAND
ID 'TAB' FIELD RT-*SYS* .
LOOP AT RT.
WRITE : / RT-LINE .
ENDLOOP.