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

Issue with control break statment

Former Member
0 Likes
3,634

Hello Experts,

I am using BAPI 'BAPI_PR_CREATE' to create PR in an Report . I am using bapi in an LOOP with below as such entries.

   where Internal table LT_ITEM1 is referered to standard structure  BAPIMEREQITEMIMP  as below code.

IF LT_ITEM1[] IS NOT INITIAL .


       CALL FUNCTION 'BAPI_PR_CREATE'

         EXPORTING

           PRHEADER    = WA_HEADER2

           PRHEADERX   = WA_HEADERX2

*         TESTRUN     =

         IMPORTING

           NUMBER      = WA_NUM2

*         PRHEADEREXP =

         TABLES

           RETURN      = T_RETURN2

           PRITEM      = LT_ITEM1

           PRITEMX     = LT_ITEMX1.

       READ TABLE T_RETURN2 INTO WA_RETURN2 WITH KEY TYPE = 'S'.

       IF SY-SUBRC = 0 .

         CONCATENATE 'PR CREATED: ' WA_NUM2 INTO LV_OP2.

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

         DELETE LT_FINAL WHERE SEL = 'X'.

         MESSAGE LV_OP2 TYPE 'I'.

       ELSE.

         CONCATENATE 'Unable To Create PR' LV_MATNR2 INTO LV_MSG2.

         MESSAGE LV_MSG2 TYPE 'I'.

       ENDIF.

     ENDIF.


Now the change is I need to create ONE PR for every change in fixed vendor, I mean ONE PR  should be created for all cumilated Vendor line items

and entries which doesn't have vendor value  One more PR should be created with no vendor.


My Problem is  that I am not able to use AT New control break-statment ( as I thought for every change in fixed_vend field would fix my problem)

but I am not able to use the FIXED_VEND field is some where in 20th column from LEFT as it is standard structure, I am not able to chnage structure  (I have brought to second column while debug just  to make understand), any Key word suggested for such situation.

or I need to go with custom logic.


Help required.

Thanks in Advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,583

Hi Prakash,

Try with "On CHANGE of "FIXED_VEND" ", this is also one of the event if control break processing.

Hope this will solve your issue.

Thanks.

Gupta

Hello Experts,

I am using BAPI 'BAPI_PR_CREATE' to create PR in an Report . I am using bapi in an LOOP with below as such entries.

   where Internal table LT_ITEM1 is referered to standard structure  BAPIMEREQITEMIMP  as below code.

IF LT_ITEM1[] IS NOT INITIAL .


       CALL FUNCTION 'BAPI_PR_CREATE'

         EXPORTING

           PRHEADER    = WA_HEADER2

           PRHEADERX   = WA_HEADERX2

*         TESTRUN     =

         IMPORTING

           NUMBER      = WA_NUM2

*         PRHEADEREXP =

         TABLES

           RETURN      = T_RETURN2

           PRITEM      = LT_ITEM1

           PRITEMX     = LT_ITEMX1.

       READ TABLE T_RETURN2 INTO WA_RETURN2 WITH KEY TYPE = 'S'.

       IF SY-SUBRC = 0 .

         CONCATENATE 'PR CREATED: ' WA_NUM2 INTO LV_OP2.

         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

         DELETE LT_FINAL WHERE SEL = 'X'.

         MESSAGE LV_OP2 TYPE 'I'.

       ELSE.

         CONCATENATE 'Unable To Create PR' LV_MATNR2 INTO LV_MSG2.

         MESSAGE LV_MSG2 TYPE 'I'.

       ENDIF.

     ENDIF.


Now the change is I need to create ONE PR for every change in fixed vendor, I mean ONE PR  should be created for all cumilated Vendor line items

and entries which doesn't have vendor value  One more PR should be created with no vendor.


My Problem is  that I am not able to use AT New control break-statment ( as I thought for every change in fixed_vend field would fix my problem)

but I am not able to use the FIXED_VEND field is some where in 20th column from LEFT as it is standard structure, I am not able to chnage structure  (I have brought to second column while debug just  to make understand), any Key word suggested for such situation.

or I need to go with custom logic.


Help required.

Thanks in Advance.

16 REPLIES 16
Read only

thanh_dinh
Explorer
0 Likes
3,583

Hi,

I will create one internal table and get the "fix_vend" data in the first column. Because the structure BAPIMEREQITEMIMP don't have key field so the second column data may be the number of current line(1,2,3...n).
Use command AT in this table to get the number. Then read table LT_ITEM1 with INDEX and perform your logic.

Hope it could help you.

Wish you nice Easter 😉

Regards,

Thanh.

Read only

Former Member
0 Likes
3,583

Hi Thanh,

Thanks for Reply,I Tried with this trick actually, it didnt work as both structures are not  mutally convertible.


Regards

Prakash Rao

Read only

0 Likes
3,583

Hi Prakash,

When you create custom structure, try to use "MOVE-CORRESPONDING" to transfer data of one internal table to another internal table. In that case you don't need to worry about mutually convertibility of two table structures.

Thanks,

Hardik.

Read only

Former Member
0 Likes
3,584

Hi Prakash,

Try with "On CHANGE of "FIXED_VEND" ", this is also one of the event if control break processing.

Hope this will solve your issue.

Thanks.

Gupta

Read only

0 Likes
3,583

I wouldn't use ON CHANGE OF as ABAP documentation says "deprecated statement because it's very prone to errors" (and that's true), Prakash should better adopt the KISS principle: simply define a variable to store the previous value, and create the PR only when the value is changing.

Read only

0 Likes
3,583

Hm, I always thought that ON CHANGE was KISSer than a variable... It's not as much prone to errors as it's just misunderstood. Oh man, they are taking away all the good stuff in ABAP...

Read only

0 Likes
3,583

I agree: break statements/controls like ON CHANGE, AT NEW and so on are prone to errors if used in the wrong way.

Exactly like any others statement or instruction.

I can be boring but...it's just a matter of design and attention.

That alert sounds like "do not use cars! If you are drunken, you crash!".

EDIT

Are even Field-symbols deprecated? You know, people could modify data in internal table without really wanting it...

Read only

0 Likes
3,583

ON CHANGE OF forbidden in ABAP objects anyway, no choice. People still programming in the procedural way? (joke)

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
3,583

Hi All,

I am using ABAP 740 SP12 & the GROUP BY addition is simply awesome! SAP recommends using it instead of the LOOP control events

BR,

Suhas

Read only

0 Likes
3,583

Yeah, nice 7.40... but not everyone got it

Read only

0 Likes
3,583

Maintenance

Read only

matt
Active Contributor
0 Likes
3,583

I seem to recall that ON CHANGE OF became obsolete before ABAP Objects was invented. Certainly since I started in 1997, I've never used it.

OTOH I'm currently working on a program written just four years ago, by a consultant from SAP, that's full of obsolete constructs.

Read only

0 Likes
3,583

Talking about depreciation, did you know Form and EndForm are depreciated (and are marked as obsolete in the help ?!!)

Read only

0 Likes
3,583

Yes, i know.. so i'm waiting SAP remove all of them from its code *giggle*

Read only

0 Likes
3,583

Richard - yeah, I noticed that (had a good laugh). This is the standard program delivered in 2015:

SAP should clean up their own house first if they are taking the "Objects or bust" movement seriously. To be honest, I think it's a losing battle and maybe not even the one worth fighting considering where this whole thing is going...

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
3,583

Never mind, for some reason I confused ON CHANGE with AT... events in the LOOP. We don't use ON CHANGE, but I suspect AT will be taken away by evil SAP too.