Drops-down fields, dates and times may be formatted using the ZFLOE_FORMAT_FIELDS function module in se37.
When ZFLOE_FORMAT_FIELDS is triggered by FLM/Varo from the Floe Data User-Exit the Floe data variable table (ch_data) is automatically populated with all fields. If Floe is being triggered outside of FLM/Varo, the table should be pre-populated as described below.
Import/export parameters:
ch_data
The name of the Floe variable data table. All fields to be formatted must be in this table
im_field_name
If this variable is blank all date, time and drop-down fields in the ch_data table will be formatted
im_field_type
The field types if not defined in the FLM data schema
im_separator
Used to include both the key AND description with a separator for a drop-down
ex_formatted_value
The export perameter holding the formatted value (from im_field_name) of 1 field
im_date_format
The format specified for the date from a list of available formats. If no date format is specified, the default SAP date e.g. 5. May 2019 will be used. The code below can be added to the function to remove the . after the day.
1: 2: 3: 4: |
* Remove dot from output shift w_ext left CIRCULAR by 2 places. shift w_ext left DELETING LEADING '.'. shift w_ext right CIRCULAR by 2 places. |
This is an alternative method of re-formatting the date variables within the Email Data User-Exit:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: |
DATA: ls_variables TYPE /floe/vars_s. * LOOP AT ch_variables INTO ls_variables. * CASE: ls_variables-var_code. * WHEN 'AUDAT' OR 'EDATU'. * Format dates CALL FUNCTION 'CONV_EXIT_LDATE_OUTPUT_LANGU' EXPORTING input = ls_variables-value language = im_elang IMPORTING output = ls_variables-value. * REPLACE ALL OCCURRENCES OF '.' IN ls_variables-value WITH ''. MODIFY ch_variables FROM ls_variables. * ENDCASE. * ENDLOOP. |
The code below should be used to create the ZFLOE_FORMAT_FIELDS.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: |
*"---------------------------------------------------------------------- function zfloe_format_form_fields. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(IM_FIELD_NAME) TYPE FIELDNAME OPTIONAL *" VALUE(IM_FIELD_TYPE) TYPE /FLM/SFS_FIELD_TYPE OPTIONAL *" VALUE(IM_SEPARATOR) TYPE FLAG OPTIONAL *" VALUE(IM_DATE_FORMAT) TYPE CHAR1 OPTIONAL *" EXPORTING *" VALUE(EX_FORMATED_VALUE) TYPE STRING *" VALUE(EX_SUBRC) TYPE SYSUBRC *" CHANGING *" VALUE(CH_DATA) TYPE /FLOE/VARS_T *"---------------------------------------------------------------------- * *--------------------------------------------------------------------------------------------------------------* * * This function can be called from the FLOE data user-exit when FLOE is being triggered by FLM * (ie by an FLM posting adaptor, or when FLOE is used to send an FLM notification email for example) * When FLOE is triggered by FLM, the FLOE data variable table will contain (among other variables) * all the FLM form fields. This function can be used to format dropdown, date and time FLM form fields * so that they can be included in the email in a user-friendly format. Time fields will be returned in * the HH:MM:SS format, the format of date fields can be specified by import parameter IM_DATE_FORMAT, * whereas for dropdowns we want to display the dropdown entry human readable description rather than the * key. Please note however that dropdown descritpions are calculated at form render time and are not saved * in the system, hence this function attempts to re-run the F4 user-exits to determine the descriptions * and this may produce different results to those which were injected into the form. Moreover, dropdowns * with entries determined on the form template rather than by the back end can not be formatted by this * function. The following parameters are available in this function: * * Changing Parameter: * ch_data : FLOE variable data table. All fields which are to be formatted must be included in * this table. Please note that you may directly pass the FLOE data user-exit parameter * ch_variables into this parameter, however this is not recomended as ch_variables * is passed into other FLOE user-exits in which you may need to access the actual data * rather than the formatted value. * * Import Parameters: * im_field_name : If this parameter is left blank, the function will attempt to format all date, time * and dropdown fields of the particular form type which are available in the ch_data * table. Alternatively if you only wish to format one field, pass the field name into * this parameter. * im_field_type : It is possible that forms which were created using very old versions of FLM do not * have the field type correctly defined in the data schema. If you are using this function * to format only one field (by passing in im_field_name) and that fields' type is not * defined correctly in the schema, pass in DROP to format it as a dropdown, DATE to format * it as a date field or TIME to format it as a time field. * im_separator : By default, the dropdown entry key will be substituted with the human-readable description * for dropdowns. If instead you wish both the key and description separated by a separator * pass in your choice of separator. * im_date_format : Specifies the date format - the following formats are available: * 1 DD.MM.YYYY * 2 MM/DD/YYYY * 3 MM-DD-YYYY * 4 YYYY.MM.DD * 5 YYYY/MM/DD * 6 YYYY-MM-DD * 7 DD/MM/YYYY * Any other value 5. May 2016 * * Export Parameters: * ex_formatted_value : If you only wish to format one field (by passing in im_field_name) this export parameter * will hold the formatted value for that field so that it can easily be accessed without * having to do a read of ch_data. If you are using the function to format all applicable * fields in ch_data, ex_formatted_value will be left blank * ex_subrc : Sub-return code which indicates potential errors *--------------------------------------------------------------------------------------------------------------* types: begin of ltyp_fieldname, field_name type fieldname, field_type type /flm/sfs_field_type, end of ltyp_fieldname. * data: ls_floe_data type /floe/vars_s, lv_ccode type /flm/cust_code, lv_ftype type /flm/ftype_code, lv_flang type /flm/flang, lv_fver type /flm/fver, lv_fid type /flm/fid, lv_fid_var type /flm/id_var, ls_fpe type /flm/fpe, lv_cms_doc type /flm/cms_doc, lv_subrc type sysubrc, lv_xdata type xstring, lt_form_data type /flm/xml_tab_t, lt_fieldname type table of ltyp_fieldname, ls_fieldname type ltyp_fieldname, lv_fieldname type string, lv_tabix type sytabix, lv_format_value type string, lt_f4_data type /flm/sfs_form_data_t, ls_f4_data type /flm/form_data, lv_length type i, lv_day(2), lv_month(2), lv_year(4). * * First get the FPE record * read table ch_data into ls_floe_data with key var_code = /flm/core=>c_return_node. if sy-subrc is not initial. "Try lower-case FLM_RETURN if nothing found read table ch_data into ls_floe_data with key var_code = /flm/core=>c_return_node. if sy-subrc is not initial. ex_subrc = 1. "Unable to read FLM_RETURN, so bail out return. endif. endif. * call method /flm/user=>split_flm_return exporting im_flm_return = ls_floe_data-value importing ex_ccode = lv_ccode ex_ftype = lv_ftype ex_fver = lv_fver ex_toption = lv_flang ex_fid = lv_fid ex_fid_var = lv_fid_var ex_cms_doc = lv_cms_doc. * select single * from /flm/fpe into ls_fpe where ccode eq lv_ccode and ftype eq lv_ftype and flang eq lv_flang and fver eq lv_fver and id eq lv_fid and id_var eq lv_fid_var. * Bail out if unable to read the FPE record if sy-subrc is not initial. ex_subrc = 2. return. endif. * * Next, get the form data * call method /flm/hds=>get_schema_from_cms exporting im_cms_doc = lv_cms_doc importing ex_data_xstring = lv_xdata ex_subrc = lv_subrc. * Bail out if unable to read the data if lv_subrc is not initial. ex_subrc = 3. return. endif. * call method /flm/core=>get_cms_doc_from_xsd exporting im_xstring = lv_xdata importing ex_data_nodes = lt_form_data. * * Determine which fields we want to format - if a field has been passed in, just format that, otherwise * format all drop-downs, data and time fields * if im_field_name is not initial. * select single field_name field_type from /flm/fdd_fld into corresponding fields of ls_fieldname where ccode eq ls_fpe-ccode and ftype eq ls_fpe-ftype and flang eq ls_fpe-flang and fver eq ls_fpe-fver and field_name eq im_field_name. * * There may be scenarios (specially for very old forms), where the field type hasn't been correctly defined * in the schema, but you still wish to format it - to get around such issues, users may pass in the type they * want their single field to be formatted as * if im_field_type is not initial. ls_fieldname-field_type = im_field_type. endif. * ls_fieldname-field_name = im_field_name. append ls_fieldname to lt_fieldname. * else. * select field_name field_type from /flm/fdd_fld into corresponding fields of table lt_fieldname where ( field_type eq 'DROP' or field_type eq 'DATE' or field_type eq 'TIME' ) and ccode eq ls_fpe-ccode and ftype eq ls_fpe-ftype and flang eq ls_fpe-flang and fver eq ls_fpe-fver. * endif. * * Now we've got the list of fields to format, loop around them and format * loop at lt_fieldname into ls_fieldname. * * We're not formatting based on the FLM data but on the FLOE data, so if a field which exists in the schema * doesn't exist in the FLOE data table, ignore it * clear: ls_floe_data, lv_format_value. read table ch_data into ls_floe_data with key var_code = ls_fieldname-field_name. lv_tabix = sy-tabix. if ls_floe_data is initial. continue. endif. * case ls_fieldname-field_type. * when 'DROP'. * lv_fieldname = ls_fieldname-field_name. * call method /flm/hds=>get_f4_entries_for_field exporting im_ccode = ls_fpe-ccode im_field_name = lv_fieldname im_fstatus = ls_fpe-fstatus im_flang = ls_fpe-flang im_user = sy-uname im_fver = ls_fpe-fver im_ftype = ls_fpe-ftype im_doc = ls_fpe-document im_form_data = lt_form_data 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 = ls_floe_data-value. if sy-subrc is initial. if im_separator is initial. lv_format_value = ls_f4_data-value. else. concatenate: ls_floe_data-value ls_f4_data-value into lv_format_value separated by im_separator. endif. endif. * when 'DATE'. * lv_length = strlen( ls_floe_data-value ). if lv_length eq 8. * lv_day = ls_floe_data-value+6(2). lv_month = ls_floe_data-value+4(2). lv_year = ls_floe_data-value+0(4). * case im_date_format. when '1'. concatenate: lv_day lv_month lv_year into lv_format_value separated by '.'. when '2'. concatenate: lv_month lv_day lv_year into lv_format_value separated by '/'. when '3'. concatenate: lv_month lv_day lv_year into lv_format_value separated by '-'. when '4'. concatenate: lv_year lv_month lv_day into lv_format_value separated by '.'. when '5'. concatenate: lv_year lv_month lv_day into lv_format_value separated by '/'. when '6'. concatenate: lv_year lv_month lv_day into lv_format_value separated by '-'. when '7'. concatenate: lv_day lv_month lv_year into lv_format_value separated by '/'. when others. * call function 'CONVERSION_EXIT_LDATE_OUTPUT' exporting input = ls_floe_data-value importing output = lv_format_value. * endcase. * endif. * when 'TIME'. * lv_length = strlen( ls_floe_data-value ). if lv_length eq 6. concatenate: ls_floe_data-value+0(2) ls_floe_data-value+2(2) ls_floe_data-value+4(2) into lv_format_value separated by ':'. endif. * endcase. * if lv_format_value is not initial. "If we've formatted a value inside the loop, modify the data changing parameter * ls_floe_data-value = lv_format_value. modify ch_data index lv_tabix from ls_floe_data. * if im_field_type is not initial. "If we're only doing one field, also fill the corresponding export parameter ex_formated_value = lv_format_value. endif. * endif. * endloop. * endfunction. |
When the table includes repeating rows, only the values in the first row are formatted using the standard function. To format each value of the repeating row, the code below can be added.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: |
READ TABLE ch_data INTO ls_floe_data WITH KEY var_code = ls_fieldname-field_name. LOOP AT ch_data INTO ls_floe_data WHERE var_code = ls_fieldname-field_name. CLEAR lv_format_value ENDLOOP *For example: CLEAR ls_variables. CALL FUNCTION 'ZFLOE_FORMAT_FORM_FIELDS' EXPORTING im_field_name = 'DD_CLAIM_TYPE' " IM_FIELD_TYPE = 'DATE' " IM_SEPARATOR = ':' " IM_DATE_FORMAT = '7' IMPORTING " ex_formated_value = lv_formatted_value ex_subrc = lv_subrc CHANGING ch_data = lt_variables. LOOP AT lt_variables INTO ls_variables WHERE var_code EQ 'DD_CLAIM_TYPE'. ls_variables-var_code = 'DD_CLAIM_TYPE_LOCAL'. APPEND ls_variables TO ch_variables. ENDLOOP. |