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

Improve ABAP statement

Former Member
0 Likes
561

Hello,

i use the function module CS_BOM_EXPL_MAT_V2 to read the BoM structure.


CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
      EXPORTING
        capid                 = 'ZP01' "   " BOM application
        datuv                 = sy-datum   " date on which you want to explode the bom
        mehrs                 = 'X'
        mtnrv                 = v_matnr    " header material number
        werks                 = v_werks
        stpst                 = 2
      TABLES
        stb                   = istpo
      EXCEPTIONS
        alt_not_found         = 1
        call_invalid          = 2
        material_not_found    = 3
        missing_authorization = 4
        no_bom_found          = 5
        no_plant_data         = 6
        no_suitable_bom_found = 7
        conversion_error      = 8
        OTHERS                = 9.

I want now the sum over all material number "IDNRK" to compare this afterwards with another value.

The internal table looks like

STUFE; IDNRK;SOBSL.........

1; 111; 50

2; 222; 0

2; 333; 0

1; 444; 0

2; 555; 0

2; 666; 0

1; 777; 0

Now i only to sum the field IDNRK if the field "STUFE" = 1 and only "STUFE" = 2 if the SOBSL form the line with "STUFE" = 1 before is 50.

111 + 222 + 333 + 444 + 777

For the moment i use a LOOP with many IF statement in it.


LOOP AT istpo into zstpo.
  IF zstpo-sobsl = '50'.
    zidnrk = zstpo-idnrk + zidnrk.
    zaehler = 0.
  ELSE.
    IF zaehler = 0 and zstpo-stufe = 2.
      zidnrk = zstpo-idnrk + zidnrk.
    ELSE.
      zaehler = 1.
      IF zstpo-stufe = 1.
        zidnrk = zstpo-idnrk + zidnrk.
      ENDIF.
    ENDIF.
   ENDIF.
ENDLOOP.

Now i search for a better way to do this. I only use ABAP in query so it's very simple and restriced.

I hope someone can help and give me some hints how can i improve this.

kind regards,

Bernhard

Edited by: Bernhard Schöberl on Dec 12, 2009 5:51 PM

1 ACCEPTED SOLUTION
Read only

former_member364077
Participant
0 Likes
504

Try this way..

I'm just giving idea..

it's not exact code.

read table istpo into zstpo with key stuff = istpo-stuff binary search.

if zstpo-soble EQ '50'.

continue.

else.

on change of stuff.

zidnrk = zstpo-idnrk + zidnrk.

endif.

Thanks,

Indra..

3 REPLIES 3
Read only

former_member364077
Participant
0 Likes
505

Try this way..

I'm just giving idea..

it's not exact code.

read table istpo into zstpo with key stuff = istpo-stuff binary search.

if zstpo-soble EQ '50'.

continue.

else.

on change of stuff.

zidnrk = zstpo-idnrk + zidnrk.

endif.

Thanks,

Indra..

Read only

Former Member
0 Likes
504

Hi,

the logic provided below might help you in some improvement in the performance.....


LOOP AT istpo into zstpo.
  IF  zstpo-stufe = 1.
    zidnrk = zstpo-idnrk + zidnrk.
    IF zstpo-sobsl = '50'.
      zaehler = 0.
    ELSE.
      zaehler = 1.
    ENDIF.
    CONTINUE.
  ENDIF.

  IF zaehler = 0.
    zidnrk = zstpo-idnrk + zidnrk.
 ENDIF.
ENDLOOP.

Thanks,

Sid

Read only

0 Likes
504

Hello,

thank you to both of you.

This will help and i learned something new.

kind regards,

Bernhard