..1 Context / Printing program
Now we combine Context and Printing program in the Class:
1) Call transaction SE24 and create class ZCL_FORM_ORDER .
2) Swith to Source code based mode. Push button
3) Paste below code:
CLASS ZCL_FORM_ORDER DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
*"* public components of class ZCL_FORM_ORDER
*"* do not include other source files here!!!
* ---- context: HEADER type
TYPES:
BEGIN OF ty_s_header ,
name TYPE string ,
address TYPE string ,
city TYPE string ,
state TYPE string ,
zip TYPE string ,
phone TYPE string ,
email TYPE string ,
END OF ty_s_header .
* ---- context: POSITIONS type
TYPES:
BEGIN OF ty_s_positions ,
name TYPE string ,
qty TYPE p LENGTH 16 DECIMALS 3 ,
price TYPE p LENGTH 16 DECIMALS 2 ,
total TYPE string ,
END OF ty_s_positions ,
ty_t_positions TYPE STANDARD TABLE OF ty_s_positions .
* ---- context: FOOTER type
TYPES:
BEGIN OF ty_s_footer ,
total TYPE string ,
subtotal TYPE string ,
card_visa TYPE string ,
card_mc TYPE string ,
card_discover TYPE string ,
card_number TYPE string ,
expiry_date TYPE dats ,
END OF ty_s_footer .
* ---- CONTEXT
DATA:
ms_header TYPE ty_s_header ,
mt_positions TYPE ty_t_positions ,
ms_footer TYPE ty_s_footer .
METHODS constructor .
PROTECTED SECTION.
*"* protected components of class ZCL_FORM_ORDER
*"* do not include other source files here!!!
PRIVATE SECTION.
*"* private components of class ZCL_FORM_ORDER
*"* do not include other source files here!!!
ENDCLASS.
CLASS ZCL_FORM_ORDER IMPLEMENTATION.
* <SIGNATURE>---------------------------------------------------------------------------------------+
* | Instance Public Method ZCL_FORM_ORDER->CONSTRUCTOR
* +-------------------------------------------------------------------------------------------------+
* +--------------------------------------------------------------------------------------</SIGNATURE>
METHOD constructor.
DATA:
ls_position TYPE ty_s_positions ,
lv_poscount TYPE char10 .
* fill the context
* -->> header
ms_header-name = 'John Doe' .
ms_header-address = '123 Main street #45' .
ms_header-city = 'Brooklyn' .
ms_header-state = 'NY' .
ms_header-zip = '11201' .
ms_header-phone = '1-234-567-8910' .
ms_header-email = 'John.Doe.12345@gmail.com' .
* -->> positions
DO 10 TIMES .
ls_position-name = sy-index && ` ` && 'Position' .
ls_position-qty = sy-index .
ls_position-price = sy-index + 555 .
ls_position-total = '=RC[-5]*RC[-3]' . " -->> formula
APPEND ls_position TO mt_positions .
ENDDO .
* -->> footer
lv_poscount = lines( mt_positions[] ) .
CONCATENATE '=SUM(R[-' lv_poscount ']C:R[-1]C)' INTO ms_footer-subtotal .
CONDENSE ms_footer-subtotal NO-GAPS . " -->> formula: =SUM(R[-10]C:R[-1]C)
ms_footer-total = '=R[-2]C' . " -->> formula
ms_footer-card_visa = space .
ms_footer-card_mc = 'V' .
ms_footer-card_discover = space .
ms_footer-card_number = '1234567890123456' .
ms_footer-expiry_date = '20140601' .
* call the form
CALL FUNCTION 'ZZ_TEST_XLWB_CALLFORM'
EXPORTING
iv_formname = 'FORM_ORDER_CLASS'
iv_context_ref = me " <<-- self instance as context
EXCEPTIONS
process_terminated = 1
OTHERS = 2.
IF sy-subrc NE 0 .
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
ENDIF .
ENDMETHOD. "CONSTRUCTOR
ENDCLASS.