SAP Adobe Form 教程四 动态隐藏和显示字段

前文:

SAP Adobe Form 教程一 简单示例

SAP Adobe Form 教程二 表

SAP Adobe Form 教程三 日期,时间,floating field

本文链接:https://www.cnblogs.com/hhelibeb/p/15503859.html

原文标题:SAP Adobe Interactive Form Tutorial. Part IV. Dynamically Hide and Display Fields using Javascript in Adobe Form Based on Conditions

条件(IF-ENDIF、CASE、WHILE 等)是常见的程序组成部分。

例如,客户的所有员工都必须在他们从办公室打印的表单签名中将时区打印为GMT–6。 因此,98% 的客户将使用 GMT–6 小时作为他们的时间,但会有2%的用户居住在另一个州,他们将时间作为 GMT–7小时。 所以对于那些特定的用户,你需要放置特殊的逻辑,让他们的签名显示 GMT – 7。这里你必须处理条件并根据条件打印值。

(译注:严格来说,逻辑处理和输出混合在一起是不合适的,但这里我们只关注实现的过程)


假设,在您的驱动程序中,您已经确定了员工所在的时区,并且根据他们的工作地点设置了标志 v_regular_employee = ‘X’ 或空白。

IF v_regular_employee = abap_true.
v_time_sign = 'GMT - 6'.
ELSEIF v_regular_employee = abap_false.
v_time_sign = 'GMT - 7'.
ENDIF.


我们的 Adobe Form需要根据条件值动态打印“GMT – 6”或“GMT – 7”。注意,我们将编写一个小的 Javascript 而不是 ABAP 代码。

PS:可能有很多方法可以实现上述场景。 为了清楚起见,我们保持简单。

本文假设读者已经看过前序教程,否则建议在此处暂停,回到之前的教程。读者至少需要了解Form, Interface, Context的概念。

事务代码:SFP。

创建interface,

 添加importing参数IV_NAME和IV_FLAG,

检查、保存和激活。

接着回到SFP创建form,

拖放2个参数到context区域,

 

前往Layout,

前往Data View并且拖放字段IV_NAME。

选择字段IV_NAME并且前往Palettes->Script Editor.

可以看到下面屏幕,

前往Show选项,在下拉菜单中选择form: ready。

这里就可以写Javascript或者Form Calc代码了。

写下如下简单代码:

if($record.IV_FLAG.value != "X")
{
    this.presence = "hidden";
}

检查,保存和激活。

下面是测试部分,

Case 1 : When IV_FLAG = ‘X’.

用F8执行form,输入参数,

再F8执行,预览,

因为当我们传递IV_FLAG=X时,隐藏元素的脚本没有被触发。因此元素不会隐藏。

Case 2 : When IV_FLAG = ‘ ’.

这次测试时让IV_FLAG为空,

可以看到结果,满足隐藏的条件,因此输出是空白的。

单独用驱动程序调用的话,代码如下,

 1 *&---------------------------------------------------------------------*
 2 *======================================================================*
 3 * YRAM_ADOBE_FORM_PROGRAM4 *
 4 *======================================================================*
 5 * Project : SAP Adobe Forms Tutorial *
 6 * Author : Ramanjula Naidu DARURU (www.SAPYard.com) *
 7 * Description : Dynamically Hiding & Displaying a field on the Adobe Form 
 8 * Layout based on Condition *
 9 *======================================================================*
10 REPORT yram_adobe_form_program4.
11 
12 *======================================================================*
13 * Selection Screen
14 *======================================================================*
15 PARAMETERS: p_name TYPE name1,
16 p_flag TYPE char1.
17 
18 **&&~~ Data Objects
19 DATA: gv_fm_name TYPE rs38l_fnam, " FM Name
20 gs_fp_docparams TYPE sfpdocparams,
21 gs_fp_outputparams TYPE sfpoutputparams.
22 
23 CONSTANTS : gv_form_name TYPE fpname VALUE 'YRAM_ADOBE_FORM4'.
24 
25 *======================================================================*
26 * START of Calling the Form
27 *======================================================================*
28 *&---------------------------------------------------------------------*
29 **&&~~ Form Processing: Call Form - Open
30 *
31 CALL FUNCTION 'FP_JOB_OPEN'
32 CHANGING
33 ie_outputparams = gs_fp_outputparams
34 EXCEPTIONS
35 cancel = 1
36 usage_error = 2
37 system_error = 3
38 internal_error = 4
39 OTHERS = 5.
40 IF sy-subrc <> 0.
41 " Suitable Error Handling
42 ENDIF.
43 *&---------------------------------------------------------------------*
44 **&&~~ Get the Function module name based on Form Name
45 *
46 CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
47 EXPORTING
48 i_name = gv_form_name
49 IMPORTING
50 e_funcname = gv_fm_name.
51 IF sy-subrc <> 0.
52 " Suitable Error Handling
53 ENDIF.
54 *&---------------------------------------------------------------------*
55 **&&~~ Take the FM name by execuing the form - by using Pattern-
56 **&&~~ call that FM and replace the FM Name by gv_fm_name
57 **&&~~ Call the Generated FM
58 CALL FUNCTION gv_fm_name
59 EXPORTING
60 /1bcdwb/docparams = gs_fp_docparams
61 iv_name = p_name
62 iv_flag = p_flag
63 EXCEPTIONS
64 usage_error = 1
65 system_error = 2
66 internal_error = 3
67 OTHERS = 4.
68 IF sy-subrc <> 0.
69 * Implement suitable error handling here
70 ENDIF.
71 *&---------------------------------------------------------------------*
72 
73 *&---------------------------------------------------------------------*
74 *&---- Close the spool job
75 CALL FUNCTION 'FP_JOB_CLOSE'
76 EXCEPTIONS
77 usage_error = 1
78 system_error = 2
79 internal_error = 3
80 OTHERS = 4.
81 IF sy-subrc <> 0.
82 * <error handling>
83 ENDIF.
YRAM_ADOBE_FORM_PROGRAM4
原文地址:https://www.cnblogs.com/hhelibeb/p/15503859.html