1 抓出總筆數和目前處理的筆數,做法是用function group的global變數來紀錄,寫一支function程式碼如下:
- 宣告回傳值
E_COUNTS TYPE I 列印總筆數
E_CURRENT TYPE I 目前列印筆數
- 程式碼
FIELD-SYMBOLS: TYPE ANY TABLE,
DATA: W_LINE TYPE REF TO DATA.
DATA: OBJNAME(30) VALUE '(RM06ENDR_ALV)XITEM[]'.
IF G_COUNTS = 0.
ASSIGN (OBJNAME) TO .
IF SY-SUBRC = 0.
CREATE DATA W_LINE LIKE LINE OF .
ASSIGN W_LINE->* TO .
LOOP AT ASSIGNING .
ASSIGN COMPONENT 'BOX' OF STRUCTURE TO .
IF = 'X'.
G_COUNTS = G_COUNTS + 1.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
G_CURRENT = G_CURRENT + 1.
E_COUNTS = G_COUNTS.
E_CURRENT = G_CURRENT.
*讀到最後一筆時,清空global.
IF E_COUNTS = E_CURRENT.
CLEAR: G_COUNTS, G_CURRENT.
ENDIF.
2 處理呼叫表單程式,以smartform為例:
- 讀取PO及其他表單欄位資訊程式碼(略)
- 多個表單處理程式碼:
DATA: CONTROL TYPE SSFCTRLOP.
DATA: LV_COUNTS TYPE I,
LV_CURRENT TYPE I.
CALL FUNCTION 'Z_FLAG_ZMMS0002_2'
IMPORTING
E_COUNTS = LV_COUNTS
E_CURRENT = LV_CURRENT.
IF LV_COUNTS > 1 AND LV_CURRENT = 1.
CONTROL-NO_OPEN = ''.
CONTROL-NO_CLOSE = 'X'.
CONTROL-NO_DIALOG = ' '.
CALL FUNCTION 'SSF_OPEN'
EXPORTING
CONTROL_PARAMETERS = CONTROL
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
ENDIF.
IF LV_COUNTS = 1.
CALL FUNCTION L_FM_NAME
EXPORTING
I_EKKO = W_EKKO
I_NAST = NAST
TABLES
IT_EKPO = IT_EKPO
GT_LINES_F = LT_ZTLINE
IT_MDSB = LT_MDSB
IT_EKET = LT_EKET
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ELSE.
CONTROL-NO_OPEN = 'X'.
CONTROL-NO_CLOSE = 'X'.
CONTROL-NO_DIALOG = 'X'.
CALL FUNCTION L_FM_NAME
EXPORTING
CONTROL_PARAMETERS = CONTROL
I_EKKO = W_EKKO
I_NAST = NAST
TABLES
IT_EKPO = IT_EKPO
GT_LINES_F = LT_ZTLINE
IT_MDSB = LT_MDSB
IT_EKET = LT_EKET
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE 'I' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
IF LV_COUNTS > 1 AND LV_COUNTS = LV_CURRENT.
CALL FUNCTION 'SSF_CLOSE'
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
OTHERS = 4.
ENDIF.
3 以上寫法不限採購單列印,只要呼叫多個smartform時都可以適用,甚至是不同的smartform都可以用同一個spool來列印。重要技巧在取得總列印筆數和目前列印筆數,本例是用FIELD-SYMBOLS將畫面上選擇的筆數算出來。
4 CALL FUNCTION 'SSF_OPEN'時要記得OUTPUT_OPTIONS裡面的參數TDNEWID = 'X'
這樣每次印時,不管幾張po單都會開新的spool寫入
沒有留言:
張貼留言