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個科目
放在內表中,對科目表進行循環,再對數據表進行循環,把單個科目的數據放在一個臨時表中打印,這樣
打印也不容易出錯。當然,需求不一樣,做法就會多種多樣,還需要我們一同去探究了……
總結
以上是生活随笔為你收集整理的SMARTFORM 循环打印实现 (循环调用SMARTFORM)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据从程序中传入到form中
- 下一篇: SAP 登陆界面菜单文本修改 (Modi