Thursday, November 30, 2017

The Loop Is Pulling Me Back

This blog was rebooted so that it could help me come out of the loop on a one mini blog per day basis.
Last few days have gone by without blogging. I would like to attribute it to inertia, workload spike and some traveling for family functions.
I sure do hope that this activity would  remind me that the loop is doing its thing and I must stay on track.

Thursday, November 23, 2017

Grouping Internal Tables

ABAP release 740 SP08 onwards.

In my previous post I mentioned using FOR table iteration expression for the first time ever.

When I tried to look at what else can be done using FOR in keyword documentation, it was all about grouping internal tables.

Grouping internal tables can be done using LOOP GROUP BY as well, but I hadn't used that either as that feature is also valid since 740 SP08.

So, I'll do some reading on LOOP GROUP BY first and then graduate to using FOR GROUP BY.

FOR Table Iteration

Today I used simplest form of table iteration using FOR keyword.

My use case was that I have list of values in an unstructured internal table, say integers 1, 2 and 3. I need to build a range table of those values so that IN operator of SELECT query can be used.

If I were building a range table using fixed variable values or hard coded literals, it would have been something like this. VALUE operator is something I know how to use in simple cases.

DATA range TYPE RANGE OF i.

range = VALUE #(

    ( sign = 'I' option = 'EQ' low = '1' )

    ( sign = 'I' option = 'EQ' low = '2' )

    ( sign = 'I' option = 'EQ' low = '3' )

  ).


Since I am having the values in internal tables, I would need to loop through it.

DATA integers TYPE TABLE OF i.

integers = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).

range = VALUE #( FOR integer IN integers ( sign = 'I' option = 'EQ' low = integer ) ).



Before knowing FOR keyword, I would have done it like this.

DATA range TYPE RANGE OF i.

DATA integers TYPE TABLE OF i.

integers = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).

LOOP AT integers INTO DATA(integer).

  APPEND INITIAL LINE TO range ASSIGNING FIELD-SYMBOL(<range_line>).

  <range_line> = VALUE #( sign = 'I' option = 'EQ' low = integer ).

ENDLOOP.



End result is identical.

Friday, November 17, 2017

Predicates In ABAP

Expression is something that has a result.

Relational expression is an expression whose result is truth value (true or false).

Other expressions are declaration, logical, constructor, table and calculation.

Relational expression can have comparison expression and predicates.

Comparison expression has joins operands using comparison operator.

Predicate qualifies an operand. Predicate operator is "IS".

This is implementing in ABAP using predicate expression, predicate function and predicate method calls.

Predicate expression examples:

1. variable IS NOT INITIAL

2. methodcall( ) IS NOT INITIAL

3. methodcall( ) IS INITIAL

As of ABAP 740 SP08, point 2 above can be written in short form.

IF methodcall( ).

<logic>

ENDIF.

Thursday, November 16, 2017

Simple Transformation to Serialize ABAP Deep Internal Table

Today I worked on an ABAP program to export batch classes, classifications and values to a cXML format file required by Ariba.

Serialization is ABAP to XML. Deserialization is the opposite.

Although I prefer XSLT over ST (both transformations are possible in SAP), I ended up using ST as I don't know XSLT properly yet.

A single internal table with deep structure was prepared which had all the data returned by relevant BAPIs.

The internal table was structured like this:

ROOT (itab)

  line

    class name

    class description

    characteristics (itab)

      line

        characteristic name

        characteristic description

    characteristic values (itab)

      line

        characteristic name

        characteristic value

        characteristic value description



Logic to traverse the internal table was written inside the transformation using tt:value tt:loop tt:cond+check tt:attribute commands.

To achieve proper node nesting, I needed an equivalent of LOOP WHERE in ST. This was possible by using tt:loop+name and tt:cond+check command.

Command tt:cond+check also allowed me to do something like "if var1 eq 'E'" and "if var2 eq var3".

DOCTYPE node could not be added using ST. So it was added by string manipulating the xml in ABAP code post transformation.



So, use of tt:cond and tt:loop+name qualifies this activity has something new (never done before) for me.

Wednesday, November 15, 2017

Optional Interface Methods

ABAP release 740 SP08 onwards.

Interface method definition has an addition DEFAULT FAIL/IGNORE that allows you to skip explicit method implementation in a class that implements the interface.

When this addition is not used, syntax check forces you to implement the method.

When addition is used, syntax check would pass.

At runtime, DEFAULT FAIL will raise exception during method call.

At runtime, DEFAULT IGNORE will call implicit blank method implementation.

More info here:

https://help.sap.com/doc/abapdocu_740_index_htm/7.40/en-US/abapmethods_default.htm

Stuck in a loop

I have been stuck in a loop for long time.

I will try to find or do new stuff and document it here.

Most of the stuff will be related to ABAP programming.