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

VA02 - maintain settlement rules

Former Member
0 Likes
1,394

Hi folks,

I am trying to maintain a settlement rule within the Sales Order without the user going to the Item Level.

I want to inherit the WBS element from the Header VBAK and on the save of the document automatically create the settlement rule.

I have tried K_SETTLEMENT_RULES* functions and cant seem to get them to work.

Anyone got any ideas or any advice on this ?

Regards

Gary

2 REPLIES 2
Read only

Former Member
0 Likes
861

I managed to work this one out myself, but just in case someone else has to do it. here is how I acheived it.

Firstly set up all fields on COBRA and COBRB, then call FM

CALL FUNCTION 'K_SETTLEMENT_RULE_FILL'

TABLES

I_COBRA = lt_cobra

I_COBRB = lt_cobrb.

Next

  • For some reason the internal system ALWAYS sets the table

  • up as the update status, this causes problems on creation,

  • so we have to change to Insert status.

Assign (c_GT_cobrb) to <fs_cobrb>.

if <fs_cobrb> is assigned.

LT_COBRB_BT[] = <fs_cobrb>.

loop at lt_cobrb_bt.

  • Somehow the previous records are being kept in so have to

  • delete them or else prog falls over.

if lt_cobrb_bt-objnr <> lv_objnr.

delete lt_cobrb_bt.

endif.

  • check to see if record exists.

select count(*)

from cobrb

where objnr = lt_cobrb_bt-objnr

and bureg = lt_cobrb_bt-bureg

and lfdnr = lt_cobrb_bt-lfdnr.

if sy-subrc <> 0.

  • Set the flag to be insert instead of U

lt_cobrb_bt-uflag = 'I'.

modify lt_cobrb_bt.

else.

  • If settlement exists then exit.

lv_settl_exist = 1.

exit.

endif.

endloop.

  • If settlement exists then exit.

if lv_settl_exist = 1.

exit.

endif.

<fs_cobrb> = LT_COBRB_BT[] .

endif.

  • For some rreason the internal system ALWAYS sets the table

  • up as the update status, this causes problems on creation,

  • so we have to change to Insert status.

Assign (c_GT_cobra) to <fs_cobra>.

if <fs_cobra> is assigned.

LT_COBRa_BT[] = <fs_cobra>.

loop at lt_cobra_bt.

  • Somehow the previous records are being kept in so have to

  • delete them or else prog falls over.

if lt_cobra_bt-objnr <> lv_objnr.

delete lt_cobra_bt.

endif.

  • check to see if record exists.

select count(*)

from cobra

where objnr = lt_cobra_bt-objnr.

if sy-subrc <> 0.

  • Set the flag to be insert instead of U

lt_cobra_bt-uflag = 'I'.

modify lt_cobra_bt.

else.

  • If settlement exists then exit.

lv_settl_exist = 1.

exit.

endif.

  • If settlement exists then exit.

if lv_settl_exist = 1.

exit.

endif.

endloop.

<fs_cobra> = LT_COBRa_BT[] .

endif.

Then when the tables have had their update status amended then call FM

CALL FUNCTION 'K_SETTLEMENT_RULE_SAVE'

EXPORTING

  • DIALOG = ' '

OBJNR = lv_objnr

I_STATUS_UPDATE = ' '

EXCEPTIONS

NO_RULE_FOR_OBJNR = 1

OTHERS = 2.

Read only

0 Likes
861

Gary,

Can you please let me know where you wrote this code (I mean in which exit)? I have the similar requirement.

Thanks...