SMARTFORM 循环打印实现 (循环调用SMARTFORM)
用SMARTFORM做打印已经很久了,功能也了解了不少,但是还是有很多功能有待去学习。
SAP做的东西都太强大了,怎么学也学不完。最近在做FORM打印的时候,客户要求按供应
商分类打印,并且按每个供应商的信息统计页码,当然,在程序中定义些变量什么的也是可
以实现的,但是还是有点麻烦。还是用SMARTFORM标准的页码吧,就想到循环打印了,研
究了一下,实现实现起来还是挺简单的。贴出来共享之……
*&———————————————————————*
*& Form SUB_DATA_PRINT
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM sub_data_print .
DATA: mid TYPE c LENGTH 20.
SORT itab_total BY matkl budat zcdnr.
SORT s_fenlei BY low.
DATA: fm_name TYPE rs38l_fnam.
DATA: ls_control_param TYPE ssfctrlop .
DATA: ls_composer_param TYPE ssfcompop .
DATA: outopt TYPE ssfcresop.
DATA: i_job_output_info TYPE ssfcrescl.
DATA: itab_print LIKE TABLE OF wand.
ls_control_param-langu = ‘1′.
ls_control_param-no_open = ‘X’.
ls_control_param-no_close = ‘X’.
CALL FUNCTION ‘SSF_OPEN’
EXPORTING
control_parameters = ls_control_param
output_options = ls_composer_param
IMPORTING
job_output_options = outopt
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
* 根据SmartForm 名称获得Form的 Function Name
CALL FUNCTION ‘SSF_FUNCTION_MODULE_NAME’
EXPORTING
formname = ‘ZCL_LOOP_PRINT’
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3 .
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT s_fenlei.
REFRESH itab_print.
LOOP AT itab_total INTO wand WHERE fenlei = s_fenlei-low.
APPEND wand TO itab_print.
ENDLOOP.
IF itab_print IS INITIAL.
CONTINUE.
ENDIF.
CONCATENATE sy-uname sy-uzeit INTO mid.
*将内表数据存入ABAP内存
EXPORT a = itab_print TO DATABASE indx(hk) ID mid.
CALL FUNCTION fm_name
EXPORTING
control_parameters = ls_control_param
output_options = ls_composer_param
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*删除内存数据
DELETE FROM DATABASE indx(hk) ID mid.
ENDLOOP.
CALL FUNCTION ‘SSF_CLOSE’
IMPORTING
job_output_info = i_job_output_info
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. ” SUB_DATA_PRINT
总结:其实类似这样的分类打印还有很多,但是方式都差不多,我做的时候,都是把分类信息存放在一个
内表中,然后再对分类信息进行循环,一个分类一个分类打,例如按科目打印的时候,把要打印的N个科目
放在内表中,对科目表进行循环,再对数据表进行循环,把单个科目的数据放在一个临时表中打印,这样
打印也不容易出错。当然,需求不一样,做法就会多种多样,还需要我们一同去探究了……
来源: 少年休闲海的ABAP世界!