Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Doubt in using the FOR statement

raphael_almeida
Active Contributor
0 Likes
1,472

Hi,

I have a question regarding the use of the FOR statement.

I have a solution (which by the way already developed) that there are two fields, one owned a field (I'll call him column X) that has values with points and other (I'll call column Y) that there is, without this characteristic the two fields are same. There is the possibility of the FOR a data conversion (Something similar to TRANSLATE) to remove these points from the column X and compare with the column Y?

Again, it's just a question because I recently started using this command, but I'm not so advanced on it and my solution has been developed in another way, I have this curiosity because I can come to use in future solutions.


I'm using SAP_ABA 740 SP12.


Regards,


Raphael Pacheco.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,439

Is it possible to post your current solution? Maybe we can then figure out, what's to do to realize it with FOR.

9 REPLIES 9
Read only

Juwin
Active Contributor
0 Likes
1,439

You should be able to..

Before this can be confirmed, can you please provide some example data, to make your question a bit clearer?

Thanks,

Juwin

Read only

0 Likes
1,439

Juwin,


These columns are retrieved from a JOIN, and the X column belonging to the table which I shall call A and the Y column of the table that will call B.

In column Y, the values have no special characters, as in the X column has. The two columns, as said above, without this feature of special characters have the same value.


Best regards,


Raphael Pacheco.

Read only

Juwin
Active Contributor
0 Likes
1,439

If your data is like this:

Table1:

Column A

ABC12213

DEF22331

FGH12333

To remove the first 3 characters of column A, the FOR statement may be used as:

report z12.

data:table1 type standard table of char10,

      table2 like table1.

table1 = value #( ( 'ABC12213' ) ( 'DEF22331' ) ( 'FGH12333' ) ).

cl_demo_output=>display_data( value = table1 ).

table2 = value #( for entry in table1 ( entry+3 ) ).

cl_demo_output=>display_data( value = table2 ).

Is this what you wanted?

Thanks,

Juwin

Read only

Former Member
0 Likes
1,440

Is it possible to post your current solution? Maybe we can then figure out, what's to do to realize it with FOR.

Read only

0 Likes
1,439

Hi Armin,

Sorry, I should have put an example of what I have done, is the lesson to my next questions.

So basically I do the chain of instructions below:


DATA i TYPE i.


SELECT a~column_a, a~column_b AS x, b~column_b AS y
   FROM table_a AS a
   INNER JOIN table_b AS b
    ON a~column_a = b~column_a
   INTO TABLE @DATA(final_table).

DESCRIBE TABLE final_table LINES DATA(lines).

DO lines TIMES.
   i = i + 1.
   READ TABLE final_table INTO DATA(table_line) INDEX i.
  
   TRANSLATE table_line-x USING '. '.
   CONDENSE table_line-x NO-GAPS.
  
   IF table_line-x <> table_line-y.
" Here record the line where the verification gave true for future conference .
   ELSE.
     CONTINUE.
   ENDIF.
ENDDO.

Best regards,

Raphael Pacheco.

Read only

Juwin
Active Contributor
0 Likes
1,439

So, I understand now that you have to get all the records where the 2 fields 'mismatch'.

Have a look at this enhanced code. I replaced the table names to get some actual data, to give you an example.

    1  types:begin         of   tyoutput,

    2          matnr type matnr,

    3          mstae type mara-mstae,

    4          mmsta type marc-mmsta,

    5        end           of   tyoutput,

    6        tytoutput type standard table of tyoutput

    7                  with non-unique key table_line.

    8 

    9  data  selected_data type tytoutput.

   10 

   11  select a~matnr, a~mstae as x, b~mmsta as y up to 100 rows

   12     from mara as a

   13     inner join marc as b

   14      on a~matnr = b~matnr

   15     into table @selected_data.

   16 

   17  cl_demo_output=>display_data( value = selected_data ).

   18 

   19  data(not_matching) = reduce tytoutput( init out = value tytoutput( )

   20                         for entry in selected_data

   21                         next

   22                         out = cond tytoutput(

   23                               when entry-mmsta <> entry-mstae

   24                               then value #( base out ( entry ) )

   25                               else out ) ).

   26 

   27  cl_demo_output=>display_data( value = not_matching ).

In the first output here, you will get all the contents of the internal table SELECTED_DATA and in the 2nd output, you will all those records where data mismatches. In the above example, I am directly comparing fields MMSTA & MSTAE. Instead you may do a method call to do the complex comparison as well.

Thanks, Juwin

Read only

0 Likes
1,439

Juwin,

The path would be this, but I NEED to remove special characters before validating (this is the main idea of my doubt).


Thanks for your help.


Raphael Pacheco.

Read only

Juwin
Active Contributor
0 Likes
1,439

In order to remove the special '.' character from the field and condense the data, you can use built-in functions:

data(text) = condense( replace( val  = '123.1.12223'

                               sub  = '.'

                               with = space

                               occ  = 0 ) ).

write:/  text.


Thus, you may replace the REDUCE statement as:


    1  data(not_matching) = reduce tytoutput( init out = value tytoutput( )

    2    for entry in selected_data

    3    next

    4    out = cond tytoutput(

    5          when entry-mmsta <> condense( replace( val = entry-mstae

    6                                                 sub = '.'

    7                                                 with = space

    8                                                 occ = 0 ) )

    9          then value #( base out ( entry ) )

   10          else out ) ).

Thanks,

Juwin

Read only

0 Likes
1,439

Exactly! That's what I wanted to know Juwin.


I did not know the CONDENSE and REPLACE function using the way you presented last code (of course I know the old way). That way it worked perfectly.


Thanks,


Raphael Pacheco.