Entering content frameBackground documentation Part 4 - Loops, Conditions, and Inline ABAP Locate the document in its SAP Library structure

Use

eCATT allows looping and conditional processing. You can also include ABAP instructions within inline ABAP blocks. Inline ABAP allows you to access the power of the ABAP language from within the eCATT environment.

Prerequisites

You have completed part 3 of this tutorial.

Procedure

  1. Display the test script that you created earlier (XYZ_CHAIN) in the script editor.
  2. Looping

  3. In the command editor, use Pattern to enter a DO...ENDDO loop. In the Count field enter 3.
  4. Edit the script so that the loop contains an REF call to your first script. The script should look like this:
  5. DO ( 3 ).

    REF ( XYZ_FK01 , XYZ_FK01_1 ).

    ENDDO.

    REF ( XYZ_FK02 , XYZ_FK02_1 ).

  6. Choose This graphic is explained in the accompanying text, to check the script.
  7. Execute the script and examine the log.
  8. This graphic is explained in the accompanying text

    You have created three new records in table LFA1.

    Conditional Processing

    Within a DO...ENDDO loop you can use the EXIT keyword to define a condition which, if satisfied, causes the loop to be exited.

  9. In the command editor, add the following line after the line containing the DO keyword:
  10. EXIT ( &LPC = 3 ).

    &LPC is an eCATT variable. It is the loop counter.

  11. Execute the script and examine the log.
  12. The DO loop now only creates two new records. When the EXIT condition is false, it is marked by This graphic is explained in the accompanying text in the log, and when it is true, it is marked by This graphic is explained in the accompanying text.

    This graphic is explained in the accompanying text

    You can use the IF...ELSEIF...ELSE...ENDIF keywords to perform conditional branching. In this example, you will cause the first record created in the loop to be modified. The other records will be left unchanged.

  13. In the command editor, position the cursor before the ENDDO statement and choose Pattern. Choose IF...ELSEIF...ELSE...ENDIF from the drop down list in the Command field, and in the Condition field enter &LPC = 1.
  14. Edit the test script so that the REF command to call the second script (XYZ_FK02) is on the line after the IF command. Your test script should look like this:

    DO ( 3 ).

    EXIT ( &LPC = 3 ).

    REF ( XYZ_FK01 , XYZ_FK01_1 ).

    IF ( &LPC = 1 ).

    REF ( XYZ_FK02 , XYZ_FK02_1 ).

    ELSE.

    ENDIF.

    ENDDO.

  15. Execute the script and examine the log.

This graphic is explained in the accompanying text

When the IF condition is false, it is marked by This graphic is explained in the accompanying text in the log, and when it is true, it is marked by This graphic is explained in the accompanying text.

Inline ABAP

Caution

Statements inside an ABAP...ENDABAP block are not checked when you choose This graphic is explained in the accompanying text.

You cannot use eCATT statements inside inline ABAP. You can assign values to and from eCATT local variables. In this example, you use ABAP to read a record from a table, and assign the contents of a field of that record to a local variable.

  1. Create a local variable call NAME and of type C.
  2. Add the following lines to the script:
  3. ABAP.

    DATA wa_lfa1 TYPE lfa1.

    SELECT SINGLE * FROM lfa1 INTO wa_lfa1.

    NAME = wa_lfa1-NAME1.

    ENDABAP.

    LOG ( NAME ).

  4. Execute the script and examine the log.

Inline ABAP blocks are independent of each other. You can test this by adding the following code to your test script:

ABAP.

Data new_name(128) type c value 'test'.

* new_name = wa_lfa1-NAME1.

Name = new_name.

ENDABAP.

LOG ( NAME ).

An asterisk at the beginning of a line denotes a comment line. The line is displayed in blue in the command editor. Comment lines are never executed, but they are recorded in the log. Try executing the test script with and without the asterisk.

This graphic is explained in the accompanying text

The script generates an error in the second case.

This graphic is explained in the accompanying text

Summary

A false condition does not cause an error.

You can pass local variables to and from inline ABAP.

Inline ABAP blocks are independent of each other.

 

Leaving content frame