Varo/Stelo Integration
Triggering Looply from Varo/Stelo
You can trigger a Looply workflow as part of your Varo or Stelo process by calling method /LOOPLY/CORE=>TRIGGER_WF as described here.
As part of the trigger, you may wish to pass the form/app data to Looply as a JSON string. You can use the sample function below to retrieve it:
Function group include LZFLM_GET_DOC_DATA_JSONTOP:
FUNCTION-POOL ZFLM_GET_DOC_DATA_JSON. "MESSAGE-ID ..
* INCLUDE LZFLM_GET_DOC_DATA_JSOND... " Local class definition
TYPES: BEGIN OF gtyp_repeating_sf,
subform TYPE /flm/sfs_sf,
END OF gtyp_repeating_sf.
*
DATA: gs_fpe TYPE /flm/fpe,
gt_fdata TYPE /flm/xml_tab_t,
gt_repeating_sf TYPE TABLE OF gtyp_repeating_sf,
gv_dd_text TYPE flag.
Function group include LZFLM_GET_DOC_DATA_JSONSUB
*----------------------------------------------------------------------*
***INCLUDE LZFLM_GET_DOC_DATA_JSONSUB.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_json_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_SF
*& --> P_REPEATING
*& <-- P_JSON_DATA
*&---------------------------------------------------------------------*
FORM get_json_data USING p_sf TYPE string
p_repeating TYPE flag
CHANGING p_json_data TYPE string.
*
DATA: lv_row_num TYPE numc3,
lv_path TYPE string,
lv_length TYPE i,
ls_fdata TYPE /flm/xml_tab,
ls_fdata2 TYPE /flm/xml_tab,
ls_repeating_sf TYPE gtyp_repeating_sf,
lv_child_num TYPE i.
*
IF p_repeating IS INITIAL.
*
* Non repeating subform
*
CONCATENATE '"' p_sf '":{' INTO p_json_data.
*
* Loop around children
*
lv_child_num = 0.
LOOP AT gt_fdata INTO ls_fdata WHERE parent EQ p_sf.
*
lv_child_num = lv_child_num + 1.
*
PERFORM process_sf_child USING ls_fdata
lv_child_num
CHANGING p_json_data.
*
ENDLOOP.
*
CONCATENATE: p_json_data '}' INTO p_json_data.
*
ELSE.
*
* Repeating subform
*
READ TABLE gt_fdata INTO ls_fdata WITH KEY name = p_sf.
ls_repeating_sf-subform = ls_fdata-name.
APPEND ls_repeating_sf TO gt_repeating_sf. "Save the fact that we've processed this repeating sf
CONCATENATE '"' p_sf '":[' INTO p_json_data.
CLEAR lv_row_num.
*
* Process one row in each loop
*
DO.
*
lv_row_num = lv_row_num + 1.
lv_path = ls_fdata-path.
lv_length = strlen( lv_path ).
lv_length = lv_length - 3.
CONCATENATE: lv_path+0(lv_length) lv_row_num INTO lv_path.
READ TABLE gt_fdata WITH KEY path = lv_path TRANSPORTING NO FIELDS.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
*
IF lv_row_num EQ '001'.
CONCATENATE: p_json_data '{' INTO p_json_data.
ELSE.
CONCATENATE: p_json_data ',{' INTO p_json_data.
ENDIF.
lv_child_num = 0.
*
LOOP AT gt_fdata INTO ls_fdata2 WHERE parent = ls_fdata-name AND path CS lv_path.
*
lv_child_num = lv_child_num + 1.
*
PERFORM process_sf_child USING ls_fdata2
lv_child_num
CHANGING p_json_data.
*
ENDLOOP.
*
CONCATENATE: p_json_data '}' INTO p_json_data.
*
ENDDO.
*
CONCATENATE: p_json_data ']' INTO p_json_data.
*
ENDIF.
*
ENDFORM.
*&---------------------------------------------------------------------*
*& Form process_sf_child
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_FDATA
*& --> P_CHILD_NUM
*& <-- P_JSON_DATA
*&---------------------------------------------------------------------*
FORM process_sf_child USING p_fdata TYPE /flm/xml_tab
p_child_num TYPE i
CHANGING p_json_data TYPE string.
DATA: lv_maxoccurs TYPE /flm/sfs_sf_max,
lv_json_data_temp TYPE string,
lv_repeating TYPE flag,
lv_separator(1) TYPE c,
lv_fld_value TYPE string.
*
IF p_child_num GT 1.
lv_separator = ','.
ELSE.
CLEAR lv_separator.
ENDIF.
*
SELECT SINGLE maxoccurs FROM /flm/fdd_sf INTO lv_maxoccurs
WHERE cust_code EQ gs_fpe-ccode
AND ftype EQ gs_fpe-ftype
AND flang EQ gs_fpe-flang
AND fver EQ gs_fpe-fver
AND subform EQ p_fdata-name.
*
IF sy-subrc IS INITIAL.
*
* Child subform
*
READ TABLE gt_repeating_sf WITH KEY subform = p_fdata-name TRANSPORTING NO FIELDS.
IF sy-subrc IS INITIAL.
* This is a repeating sf we've allready processed but because it is repeating it appears more than once in gt_fdata. Don't process again
RETURN.
ENDIF.
*
IF lv_maxoccurs GT '0001'.
lv_repeating = 'X'.
ELSE.
CLEAR lv_repeating.
ENDIF.
*
PERFORM get_json_data USING p_fdata-name
lv_repeating
CHANGING lv_json_data_temp.
*
CONCATENATE p_json_data lv_separator lv_json_data_temp INTO p_json_data.
*
ELSE.
*
* Child field
*
lv_fld_value = p_fdata-value.
IF gv_dd_text IS NOT INITIAL.
PERFORM format_fld_value USING p_fdata-name
CHANGING lv_fld_value.
ENDIF.
PERFORM escape_json CHANGING lv_fld_value.
CONCATENATE: p_json_data lv_separator '"' p_fdata-name '":"' lv_fld_value '"' INTO p_json_data.
*
ENDIF.
*
ENDFORM.
*&---------------------------------------------------------------------*
*& Form format_fld_value
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> P_FDATA_NAME
*& <-- P_FLD_VALUE
*&---------------------------------------------------------------------*
FORM format_fld_value USING p_fld_name
CHANGING p_fld_value.
*
DATA: lv_fld_type TYPE /flm/sfs_field_type,
lt_f4_data TYPE /flm/sfs_form_data_t,
ls_f4_data TYPE /flm/form_data.
*
SELECT SINGLE field_type FROM /flm/fdd_fld INTO lv_fld_type
WHERE ccode EQ gs_fpe-ccode
AND ftype EQ gs_fpe-ftype
AND flang EQ gs_fpe-flang
AND fver EQ gs_fpe-fver
AND field_name EQ p_fld_name.
*
IF sy-subrc IS INITIAL AND lv_fld_type EQ 'DROP'.
*
CALL METHOD /flm/hds=>get_f4_entries_for_field
EXPORTING
im_ccode = gs_fpe-ccode
im_field_name = p_fld_name
im_fstatus = gs_fpe-fstatus
im_flang = gs_fpe-flang
im_user = sy-uname
im_fver = gs_fpe-fver
im_ftype = gs_fpe-ftype
im_doc = gs_fpe-document
im_form_data = gt_fdata
im_prev_page = ''
im_excel = 'X'
IMPORTING
ex_f4_data = lt_f4_data.
*
READ TABLE lt_f4_data INTO ls_f4_data WITH KEY name = p_fld_value.
IF sy-subrc IS INITIAL.
p_fld_value = ls_f4_data-value.
ENDIF.
*
ENDIF.
*
ENDFORM.
*&---------------------------------------------------------------------*
*& Form escape_json
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- LV_FLD_VALUE
*&---------------------------------------------------------------------*
FORM escape_json CHANGING p_fld_value.
*
REPLACE ALL OCCURRENCES OF `\` IN p_fld_value WITH `\\`.
REPLACE ALL OCCURRENCES OF `"` IN p_fld_value WITH `\"`.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf IN p_fld_value WITH `\n\n`. "use \n\n instead of the standard \r\n here as teams cards don't understand \r\n
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>newline IN p_fld_value WITH `\n\n`. "use \n\n instead of the standard \n here as teams cards don't understand. \n\n creates two newlines in a card where idealy we'd only want one
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN p_fld_value WITH `\t`.
*
ENDFORM.
Function module ZFLM_GET_DOC_DATA_JSON
FUNCTION zflm_get_doc_data_json.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(IM_CCODE) TYPE /FLM/CUST_CODE
*" VALUE(IM_FTYPE) TYPE /FLM/FTYPE_CODE
*" VALUE(IM_FLANG) TYPE /FLM/FLANG
*" VALUE(IM_FVER) TYPE /FLM/FVER
*" VALUE(IM_ID) TYPE /FLM/FID
*" VALUE(IM_ID_VAR) TYPE /FLM/ID_VAR
*" VALUE(IM_DD_TEXT) TYPE FLAG OPTIONAL
*" VALUE(IM_FORM_DATA) TYPE /FLM/XML_TAB_T OPTIONAL
*" EXPORTING
*" VALUE(EX_JSON_DATA) TYPE STRING
*"----------------------------------------------------------------------
*
*-------------------------------------------------------------------------------------------------------------------------------------------*
* This function module can be used to retrieve the data from your FLM form or Stelo app in JSON format
* Setting the IM_DD_TEXT parameter to 'X' will cause the function to return the text rather than the key for drop-down fields
* If import parameter IM_FORM_DATA is left blank, the function will read the data from the content server. If data is passed in using this
* import parameter, that data will be converted isntead of the CMS data. This could be useful if you wish to format or change the data before
* it is converted to JSON
*-------------------------------------------------------------------------------------------------------------------------------------------*
*
CLEAR: gs_fpe, gt_fdata, gt_repeating_sf.
gv_dd_text = im_dd_text.
*
SELECT SINGLE * INTO gs_fpe FROM /flm/fpe
WHERE ccode EQ im_ccode
AND ftype EQ im_ftype
AND flang EQ im_flang
AND fver EQ im_fver
AND id EQ im_id
AND id_var EQ im_id_var.
*
IF im_form_data IS NOT INITIAL.
gt_fdata = im_form_data.
ELSE.
*
CALL METHOD /flm/core=>get_data_from_instance
EXPORTING
im_form_instance = gs_fpe
RECEIVING
ex_form_data = gt_fdata.
*
ENDIF.
*
PERFORM get_json_data USING 'DATA'
''
CHANGING ex_json_data.
*
CONCATENATE: '{' ex_json_data '}' INTO ex_json_data.
*
ENDFUNCTION.
*
Last updated