Sample program taken from class CL_HRASR00_WF_COMPONENTS, DATAMAPPING method.
* search whether the form scenario and version has been used in this
* process already. If not: dump.
SELECT case_guid FROM t5asrscenarios INTO scenario_guid
WHERE parent_process = pobj_guid AND
scenario = form-form_scenario AND
scenario_version = form-form_scenario_version.
EXIT.
ENDSELECT.
IF sy-subrc IS NOT INITIAL OR scenario_guid IS INITIAL.
MESSAGE e002(hrasr00_process) INTO dummy. " Datenmapping als erster Schritt eines neuen Formularszenarios
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Get instance of POBJ_RUNTIME
CALL METHOD cl_hrasr00_process_runtime=>get_instance
EXPORTING
scenario_guid = scenario_guid
activity = activity
message_handler = message_list
no_auth_check = ''
IMPORTING
instance_pobj_runtime = ref_pobj_runtime
is_authorized = is_authorized
is_ok = is_ok.
IF is_authorized <> if_hrasr00_process_constants=>true .
MESSAGE e024(hrasr00_process) INTO dummy." Keine Berechtigung zum Lesen einer Instanz eines Prozessobjekts
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ELSEIF is_ok <> if_hrasr00_process_constants=>true.
MESSAGE e023(hrasr00_process) WITH pobj_guid INTO dummy." Laufzeitinstanz des Prozessobjekts ID &1 nicht gefunden
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Use POBJ_RUNTIME to get latest form data container as XML.
CALL METHOD ref_pobj_runtime->get_latest_data_container
EXPORTING
* SCENARIO_GUID =
message_handler = message_list
IMPORTING
data_container = form_data_container_xml
is_ok = is_ok.
IF is_ok <> if_hrasr00_process_constants=>true.
MESSAGE e005(hrasr00_fbd) INTO dummy." Keine Berechtigung, Daten dieses Prozesses zu lesen
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Get instance of form data container.
CREATE OBJECT ref_form_data_container
EXPORTING
* FORM_SCENARIO =
* FORM_SCENARIO_VERSION =
* FORM_SCENARIO_STAGE =
xml = form_data_container_xml.
* Use this data container to convert XML to table.
CALL METHOD ref_form_data_container->get_values_of_fields
IMPORTING
values_of_fields = form_data_containers.
* Now we have the form_data_container.
* Do we have to import data?
IF mapping_imports IS NOT INITIAL.
* For each form field which should be imported
LOOP AT mapping_imports INTO mapping_import.
* Try to find a really same named form field
LOOP AT form_data_containers INTO form_data_container
WHERE fieldname = mapping_import-form_field_name.
* We have found a matching form field name:
* Import its value and update the container table.
READ TABLE form_data_container-fieldvalues
INTO mapping_import-field_value INDEX 1.
* Write the found value back into the mapping table.
MODIFY mapping_imports FROM mapping_import.
EXIT. "If we have found one matching field, this is enough.
ENDLOOP. "form_data_containers
* Could the wished Form field be found? If not: Exception, because the
* given fieldname of form does not exist in this form scenario
IF sy-subrc <> 0.
MESSAGE e003 WITH mapping_import-form_field_name form-form_scenario INTO dummy." Feld &1 im Datencontainer des Formularszenarios &2 nicht gefunden
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
ENDLOOP. " mapping_imports
* In case of Import: Return the values got from form
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_1 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_1 = mapping_import-field_value.
ENDIF.
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_2 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_2 = mapping_import-field_value.
ENDIF.
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_3 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_3 = mapping_import-field_value.
ENDIF.
ENDIF. "mapping_imports[] IS NOT INITIAL
* search whether the form scenario and version has been used in this
* process already. If not: dump.
SELECT case_guid FROM t5asrscenarios INTO scenario_guid
WHERE parent_process = pobj_guid AND
scenario = form-form_scenario AND
scenario_version = form-form_scenario_version.
EXIT.
ENDSELECT.
IF sy-subrc IS NOT INITIAL OR scenario_guid IS INITIAL.
MESSAGE e002(hrasr00_process) INTO dummy. " Datenmapping als erster Schritt eines neuen Formularszenarios
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Get instance of POBJ_RUNTIME
CALL METHOD cl_hrasr00_process_runtime=>get_instance
EXPORTING
scenario_guid = scenario_guid
activity = activity
message_handler = message_list
no_auth_check = ''
IMPORTING
instance_pobj_runtime = ref_pobj_runtime
is_authorized = is_authorized
is_ok = is_ok.
IF is_authorized <> if_hrasr00_process_constants=>true .
MESSAGE e024(hrasr00_process) INTO dummy." Keine Berechtigung zum Lesen einer Instanz eines Prozessobjekts
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ELSEIF is_ok <> if_hrasr00_process_constants=>true.
MESSAGE e023(hrasr00_process) WITH pobj_guid INTO dummy." Laufzeitinstanz des Prozessobjekts ID &1 nicht gefunden
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Use POBJ_RUNTIME to get latest form data container as XML.
CALL METHOD ref_pobj_runtime->get_latest_data_container
EXPORTING
* SCENARIO_GUID =
message_handler = message_list
IMPORTING
data_container = form_data_container_xml
is_ok = is_ok.
IF is_ok <> if_hrasr00_process_constants=>true.
MESSAGE e005(hrasr00_fbd) INTO dummy." Keine Berechtigung, Daten dieses Prozesses zu lesen
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
* Get instance of form data container.
CREATE OBJECT ref_form_data_container
EXPORTING
* FORM_SCENARIO =
* FORM_SCENARIO_VERSION =
* FORM_SCENARIO_STAGE =
xml = form_data_container_xml.
* Use this data container to convert XML to table.
CALL METHOD ref_form_data_container->get_values_of_fields
IMPORTING
values_of_fields = form_data_containers.
* Now we have the form_data_container.
* Do we have to import data?
IF mapping_imports IS NOT INITIAL.
* For each form field which should be imported
LOOP AT mapping_imports INTO mapping_import.
* Try to find a really same named form field
LOOP AT form_data_containers INTO form_data_container
WHERE fieldname = mapping_import-form_field_name.
* We have found a matching form field name:
* Import its value and update the container table.
READ TABLE form_data_container-fieldvalues
INTO mapping_import-field_value INDEX 1.
* Write the found value back into the mapping table.
MODIFY mapping_imports FROM mapping_import.
EXIT. "If we have found one matching field, this is enough.
ENDLOOP. "form_data_containers
* Could the wished Form field be found? If not: Exception, because the
* given fieldname of form does not exist in this form scenario
IF sy-subrc <> 0.
MESSAGE e003 WITH mapping_import-form_field_name form-form_scenario INTO dummy." Feld &1 im Datencontainer des Formularszenarios &2 nicht gefunden
RAISE EXCEPTION TYPE cx_hrasr00_process_modelling.
ENDIF.
ENDLOOP. " mapping_imports
* In case of Import: Return the values got from form
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_1 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_1 = mapping_import-field_value.
ENDIF.
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_2 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_2 = mapping_import-field_value.
ENDIF.
READ TABLE mapping_imports WITH KEY
form_field_name = form_field_name_3 INTO mapping_import.
IF sy-subrc IS INITIAL.
field_value_3 = mapping_import-field_value.
ENDIF.
ENDIF. "mapping_imports[] IS NOT INITIAL
No comments:
Post a Comment