cancel
Showing results for 
Search instead for 
Did you mean: 

End routine -fields populated with wrong unique key field

Former Member
0 Kudos

Hi,

Despite the following end routine has no errors the last elseif ( /BIC/ZOBJETIVO EQ '03' and '04') aren´t doing what they should.

Instead of append the corresponding fields from table l_PZOBJETIVO into KF /BIC/ZMINDESP2 and /BIC/ZPENALIZ2, these fields are populated with the value of the unique key field (/BIC/ZNROINC TYPE /BIC/OIZNROINC -_ty_s_TG_1).

I cannot figure it out why.

data lv_zresal type _ty_s_TG_1-/BIC/ZRESAL.
    data lv_zresmb type _ty_s_TG_1-/BIC/ZRESMB.
    data lv_zdsret type _ty_s_TG_1-/BIC/ZDSRET.
    data: wa_RESULT_PACKAGE type _TY_S_TG_1.
    data: l_PZOBJETIVO type /BIC/PZOBJETIVO.

    Loop at RESULT_PACKAGE into wa_RESULT_PACKAGE.
      lv_zresal = wa_result_package-/BIC/ZRESAL.
      lv_zresmb = wa_result_package-/BIC/ZRESMB.
      lv_zdsret = wa_result_package-/BIC/ZDSRET.

      If lv_zresal NE 0.

        select single *
            into l_PZOBJETIVO
            from /BIC/PZOBJETIVO
             where
            /BIC/ZOBJETIVO EQ '01'.

        wa_RESULT_PACKAGE-/BIC/ZMINDESP = l_PZOBJETIVO-/BIC/ZMINDESP.
        wa_RESULT_PACKAGE-/BIC/ZPENALIZA = l_PZOBJETIVO-/BIC/ZPENALIZA.

      elseif
      lv_zresmb NE 0.

        select single *
      into l_PZOBJETIVO
      from /BIC/PZOBJETIVO
       where
      /BIC/ZOBJETIVO EQ '02'.

        wa_RESULT_PACKAGE-/BIC/ZMINDESP = l_PZOBJETIVO-/BIC/ZMINDESP.
        wa_RESULT_PACKAGE-/BIC/ZPENALIZA = l_PZOBJETIVO-/BIC/ZPENALIZA.

      elseif
      lv_zdsret NE 0
      AND wa_RESULT_PACKAGE-/BIC/ZCRITIC EQ 'Alta'.

        select single *
      into l_PZOBJETIVO
      from /BIC/PZOBJETIVO
       where
      /BIC/ZOBJETIVO EQ '03'.

        wa_RESULT_PACKAGE-/BIC/ZMINDESP2 = l_PZOBJETIVO-/BIC/ZMINDESP.
        wa_RESULT_PACKAGE-/BIC/ZPENALIZ2 = l_PZOBJETIVO-/BIC/ZPENALIZA.


        elseif
      lv_zdsret NE 0
      AND wa_RESULT_PACKAGE-/BIC/ZCRITIC EQ 'Media''Baja'.

        select single *
      into l_PZOBJETIVO
      from /BIC/PZOBJETIVO
       where
      /BIC/ZOBJETIVO EQ '04'.

        wa_RESULT_PACKAGE-/BIC/ZMINDESP2 = l_PZOBJETIVO-/BIC/ZMINDESP.
        wa_RESULT_PACKAGE-/BIC/ZPENALIZ2 = l_PZOBJETIVO-/BIC/ZPENALIZA.

      else.
        clear wa_RESULT_PACKAGE-/BIC/ZMINDESP.
        clear wa_RESULT_PACKAGE-/BIC/ZPENALIZA.
        clear wa_RESULT_PACKAGE-/BIC/ZMINDESP2.
        clear wa_RESULT_PACKAGE-/BIC/ZPENALIZ2.

      endif.

      modify RESULT_PACKAGE from wa_RESULT_PACKAGE.

    Endloop.

Regards,

Diego

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Considering your statement

>Instead of append the corresponding fields from table l_PZOBJETIVO into KF /BIC/ZMINDESP2 and /BIC/ZPENALIZ2, these fields are populated with the value of the unique key field (/BIC/ZNROINC TYPE /BIC/OIZNROINC -_ty_s_TG_1).

Can you try using 'into corresponding fields of'

select single *

into corresponding fields of l_PZOBJETIVO

if it does not work check the sequence of fields in the P table /BIC/PZOBJETIVO.

If you want you can use the M table also /BIC/MZOBJETIVO in select statements.

also make sure you clear l_PZOBJETIVO inside the loop so that it does not carry previous values

Former Member
0 Kudos

Uday,

I tested what you suggested but unfortunatelly nothing changed.

Here I attach the table that i want to:

1) save into internal table.

2) In the loop for each of the four conditions select the corresponding one from that table.

3) Modify the result package.

Table /BIC/PZOBJETIVO:

/BIC/ZOBJETIVO  /BIC/ZMINDESP  /BIC/ZPENALIZA
      01                          15                           3
      02                           1                            2
      03                           1                            3
      04                           1                            4

Regards,

Diego

Former Member
0 Kudos

Hi there,

You have a syntax error on you code?

Where you have this:


        elseif
      lv_zdsret NE 0
      AND wa_RESULT_PACKAGE-/BIC/ZCRITIC EQ 'Media''Baja'.

Shouldn't be this?:


        elseif
      lv_zdsret NE 0
      AND ( wa_RESULT_PACKAGE-/BIC/ZCRITIC EQ 'Media' OR wa_RESULT_PACKAGE-/BIC/ZCRITIC EQ 'Baja' ).

Regards,

Diogo.

Former Member
0 Kudos

Hi Diogo,

I tested with the change you suggeted but it still doing the same. Unfortunatelly i don´t have any error messages.

Regards,

Diego

christopherdcosta
Participant
0 Kudos

Firstly please use the field symbol <result_fields> as it doesn't use any memory. That's the correct way to do things and then you never need to append your result_package or use work areas.

so...

loop at result_package assigning <result_fields>.

<result_fields>-fieldname = newvalue.

endloop.

That's all you need to do. Field symbols are pointers and so the data gets amended with the new value being directly injected into the internal table.

Secondly your .If...else... statement is probably not comprehensive and robust enough. You can't just test one variable for true or false and then say "else test another variable if its false".

You need to include all the possibilities in each condition to be robust enough, because you never know what data could actually arrive.

Lastly why are you doing a select in the loop? This means you have huge amounts of I/O into the database. If you have a 50000 record datapacket that 50000 database reads, and network transfers. As it is the table you are selecting from only has 4 records that you need !

Better to do a select from into internal table where the selection is in range 1,2,3,4 and then Read Table in the loop.

Edited by: Christopher DCosta on Mar 31, 2011 2:55 PM

Former Member
0 Kudos

Cristopher,

I don´t figure out how i coud rewrite the routine with the tips you recomended.

is tys_TG_1?

How do i get the select into internal table as you recomend?

Could you help me writing in code what you explain to me please? It would be really helpfull if you do that cause i'm making my first steps in abap.

Regards,

Diego

Former Member
0 Kudos

Cristopher,

I've been trying to rewrite the routine with the tips you gave me.

1) I do the select from master data into an internal table. (I have only 4 rows populated with the values I want to use with the four different conditions). But I don´t know how to select the row with the key ZOBJETIVO with the four different conditions of the IF statements.

SELECT single *
    FROM /BIC/PZOBJETIVO
    INTO objetivo_itab
    WHERE /BIC/ZOBJETIVO EQ '01'.

2) I do the loop into internal table

loop at RESULT_PACKAGE assigning <result_fields>.

      <result_fields>-/BIC/ZRESAL = wa_result_package-/BIC/ZRESAL.
      <result_fields>-/BIC/ZRESMB = wa_result_package-/BIC/ZRESMB.
      <result_fields>-/BIC/ZDSRET = wa_result_package-/BIC/ZDSRET.

    endloop.

Finally I didn´t undestand the variable true or false issue. Probably is not so difficult none of this but as I told you I'm a begginer at abap and doing a big effort to learn myself (with the tips i recive in SDN).

Regards,

Diego