Question:
Good day all,
I am trying to build my first workflow after taking BIT600 and BIT601 and of course I am running a problem. A step in my workflow is using business object type LFM1 who's key fields are vendor and purchasing org.
In previous steps, I have captured these key fields in my worflow container but I now need a way use these key fields to get the object instance for LFM1. Can anyone tell me how I can do this?
Sandmann
Answer:
Hi.
If the object type you need to access only has one key field, you can use use a background method on System.genericinstantiate. A wizard in the workflow builder will help you with this.
But when your object type have two or more key fields, you first need to put the keyfields in a string:
Create a subtype to object type SYSTEM e.g. YSYSTEM and do the delegation.
Create a new method with import parameter ObjectType (ref. SWOTOBJID-OBJTYPE) and import parameters Imp_KEY_1 to 4, same ref.
Also create an export parameter Keyfield_exp, same reference again.
Then change the code for the method to something like this (up to 4 keyfields, but can be expanded):
BEGIN_METHOD FIND_KEYFIELDS CHANGING CONTAINER.
DATA: T_INFO like SWOTRK occurs 0 with header line,
t_return like SWOTRETURN occurs 0.
DATA: KEY_1_len like swotrk-OUTLENGTH,
KEY_2_len like swotrk-OUTLENGTH,
KEY_3_len like swotrk-OUTLENGTH,
KEY_4_len like swotrk-OUTLENGTH.
DATA:
OBJECTTYPE LIKE SWOTOBJID-OBJTYPE,
KEYFIELD_EXP LIKE SWOTOBJID-OBJKEY,
IMP_KEY_1 LIKE SWOTOBJID-OBJKEY,
IMP_KEY_2 LIKE SWOTOBJID-OBJKEY,
IMP_KEY_3 LIKE SWOTOBJID-OBJKEY,
IMP_KEY_4 LIKE SWOTOBJID-OBJKEY.
SWC_GET_ELEMENT CONTAINER 'ObjectType' OBJECTTYPE.
SWC_GET_ELEMENT CONTAINER 'Imp_KEY_1' IMP_KEY_1.
SWC_GET_ELEMENT CONTAINER 'Imp_KEY_2' IMP_KEY_2.
SWC_GET_ELEMENT CONTAINER 'Imp_KEY_3' IMP_KEY_3.
SWC_GET_ELEMENT CONTAINER 'Imp_KEY_4' IMP_KEY_4.
CALL FUNCTION 'SWO_QUERY_KEYFIELDS'
EXPORTING
LANGUAGE = SY-LANGU
objtype = OBJECTTYPE
* TEXT = ' '
* IMPORTING
* RETURN = t_return
tables
info = t_info.
Sort t_info by EDITORDER.
clear: KEY_1_len, KEY_2_len, KEY_3_len, KEY_4_len.
clear t_info.
read table t_info index 1.
if sy-subrc = 0.
KEY_1_len = t_info-OUTLENGTH.
endif.
read table t_info index 2.
if sy-subrc = 0.
KEY_2_len = t_info-OUTLENGTH + KEY_1_len.
endif.
read table t_info index 3.
if sy-subrc = 0.
KEY_3_len = t_info-OUTLENGTH + KEY_2_len.
endif.
read table t_info index 4.
if sy-subrc = 0.
KEY_4_len = t_info-OUTLENGTH + KEY_3_len.
endif.
if not KEY_1_len is initial.
move imp_key_1 to keyfield_exp.
endif.
if not KEY_2_len is initial.
move imp_key_2 to keyfield_exp+KEY_1_len.
endif.
if not KEY_3_len is initial.
move imp_key_3 to keyfield_exp+KEY_2_len.
endif.
if not KEY_4_len is initial.
move imp_key_4 to keyfield_exp+KEY_3_len.
endif.
SWC_SET_ELEMENT CONTAINER 'Keyfield_exp' KEYFIELD_EXP.
END_METHOD.
Now create a background method to run this method; come with your object type and keyfields and return the string you need to use in method SYSTEM.GenericInstantiate described at the top.
This will work, I have used this several times.
clucking.
Answer:
After some searching yesterday, I found System.genericinstantiate. I created the method below to concatnate my container elements to form my object key
Thanks agin for your response.
BEGIN_METHOD CONCATENATE CHANGING CONTAINER.
DATA:
STRING1(255),
STRING2(255),
CONCATENATE_RESULT(255).
SWC_GET_ELEMENT CONTAINER 'String1' STRING1.
SWC_GET_ELEMENT CONTAINER 'String2' STRING2.
CONCATENATE STRING1 STRING2 into CONCATENATE_RESULT.
SWC_SET_ELEMENT CONTAINER 'CONCATENATE_RESULT' CONCATENATE_RESULT.
END_METHOD.
Answer:
Can I get a copy of the study material from you? I can't afford to go to the SAP academy, but am ready to pay you a reasonable amount for a copy of the course.
Thanks
GF
Good day all,
I am trying to build my first workflow after taking BIT600 and BIT601 and of course I am running a problem. A step in my workflow is using business object type LFM1 who's key fields are vendor and purchasing org.
In previous steps, I have captured these key fields in my worflow container but I now need a way use these key fields to get the object instance for LFM1. Can anyone tell me how I can do this?
Sandmann