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

OO ABAP help...

Former Member
0 Likes
2,108

dear all,

In the midst of converting some 3.5 update rules to version 7.0 and i'm at a deadlock - lack of the dark art of ABAP... Can someone here please provide me some help for the below codes? Thanks.

READ TABLE I_MWBS_ELEMT WITH KEY WBS_ELEMT = SOURCE_FIELDS-POSID TRANSPORTING NO FIELDS.

IF SY-SUBRC IS INITIAL.

RESULT = I_MWBS_ELEMT-RESP_CCTR.

ELSE.

SELECT SINGLE * FROM /BI0/MWBS_ELEMT INTO I_MWBS_ELEMT

WHERE WBS_ELEMT = SOURCE_FIELDS-POSID

AND OBJVERS = 'A'.

IF SY-SUBRC IS INITIAL.

APPEND I_MWBS_ELEMT SORTED BY RESP_CCTR. <-- I think the error is coming from here.

RESULT = I_MWBS_ELEMT-RESP_CCTR.

ELSE.

CLEAR RESULT.

ENDIF.

ENDIF.

My err. msg is

E:An explicit work area is necessary in the OO context. Use "APPEND wa TO I_MWBS_ELEMT SORTED BY".

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
1,347

Hi, You need to create work area for internal table instead of having table with header line. In oops it does not allow you. Try this way. <li>Define work area

DATA:w_mwbs_elemt LIKE LINE OF i_mwbs_elemt.
<li>Remove header option for i_mwbs_elemt table and change like below.
READ TABLE i_mwbs_elemt INTO w_mwbs_elemt WITH KEY wbs_elemt = source_fields-posid TRANSPORTING NO FIELDS.
  IF sy-subrc IS INITIAL.
    result = w_mwbs_elemt-resp_cctr.
  ELSE.
    SELECT SINGLE * FROM /bi0/mwbs_elemt INTO i_mwbs_elemt
    WHERE wbs_elemt = source_fields-posid
    AND objvers = 'A'.
    IF sy-subrc IS INITIAL.
      APPEND w_mwbs_elemt TO i_mwbs_elemt SORTED BY resp_cctr.
      result = i_mwbs_elemt-resp_cctr.
    ELSE.
      CLEAR result.
    ENDIF.
  ENDIF.
Thanks Venkat.O

dear all,

In the midst of converting some 3.5 update rules to version 7.0 and i'm at a deadlock - lack of the dark art of ABAP... Can someone here please provide me some help for the below codes? Thanks.

READ TABLE I_MWBS_ELEMT WITH KEY WBS_ELEMT = SOURCE_FIELDS-POSID TRANSPORTING NO FIELDS.

IF SY-SUBRC IS INITIAL.

RESULT = I_MWBS_ELEMT-RESP_CCTR.

ELSE.

SELECT SINGLE * FROM /BI0/MWBS_ELEMT INTO I_MWBS_ELEMT

WHERE WBS_ELEMT = SOURCE_FIELDS-POSID

AND OBJVERS = 'A'.

IF SY-SUBRC IS INITIAL.

APPEND I_MWBS_ELEMT SORTED BY RESP_CCTR. <-- I think the error is coming from here.

RESULT = I_MWBS_ELEMT-RESP_CCTR.

ELSE.

CLEAR RESULT.

ENDIF.

ENDIF.

My err. msg is

E:An explicit work area is necessary in the OO context. Use "APPEND wa TO I_MWBS_ELEMT SORTED BY".

5 REPLIES 5
Read only

Former Member
0 Likes
1,347

Hi SCHT,

Why don't you try it like this way and see if it helps.

***************

IF SY-SUBRC IS INITIAL.

APPEND I_MWBS_ELEMT.

SORT I_MWBS_ELEMT BY RESP_CCTR.

RESULT = I_MWBS_ELEMT-RESP_CCTR.

**************

Thanks,

Sid

Edited by: sidharth suri on Oct 9, 2009 8:19 AM

Read only

venkat_o
Active Contributor
0 Likes
1,348

Hi, You need to create work area for internal table instead of having table with header line. In oops it does not allow you. Try this way. <li>Define work area

DATA:w_mwbs_elemt LIKE LINE OF i_mwbs_elemt.
<li>Remove header option for i_mwbs_elemt table and change like below.
READ TABLE i_mwbs_elemt INTO w_mwbs_elemt WITH KEY wbs_elemt = source_fields-posid TRANSPORTING NO FIELDS.
  IF sy-subrc IS INITIAL.
    result = w_mwbs_elemt-resp_cctr.
  ELSE.
    SELECT SINGLE * FROM /bi0/mwbs_elemt INTO i_mwbs_elemt
    WHERE wbs_elemt = source_fields-posid
    AND objvers = 'A'.
    IF sy-subrc IS INITIAL.
      APPEND w_mwbs_elemt TO i_mwbs_elemt SORTED BY resp_cctr.
      result = i_mwbs_elemt-resp_cctr.
    ELSE.
      CLEAR result.
    ENDIF.
  ENDIF.
Thanks Venkat.O

Read only

awin_prabhu
Active Contributor
0 Likes
1,347

Hi SCHT,

Try declaring an explicit work area for internal table I_MWBS_ELEMT and use that work area. Replace ur code with below code.

Data: wa LIKE LINE OF I_MWBS_ELEMT.

READ TABLE I_MWBS_ELEMT WITH KEY WBS_ELEMT = SOURCE_FIELDS-POSID TRANSPORTING NO FIELDS INTO wa. <----

IF SY-SUBRC IS INITIAL.

RESULT = wa-RESP_CCTR. <----

ELSE.

SELECT SINGLE * FROM /BI0/MWBS_ELEMT INTO wa

WHERE WBS_ELEMT = SOURCE_FIELDS-POSID

AND OBJVERS = 'A'.

IF SY-SUBRC IS INITIAL.

APPEND wa SORTED BY RESP_CCTR. <----

RESULT = wa-RESP_CCTR. <-----

ELSE.

CLEAR RESULT.

ENDIF.

ENDIF.

Thanks,

Read only

venkat_o
Active Contributor
0 Likes
1,347

Hey, Is it ok now. Thanks Venkat.O

Read only

Former Member
0 Likes
1,347

yeah venket, assigned you full points. Thanks!