ABAP/4 Example Code: ALV List by FM 'REUSE_ALV_LIST_DISPLAY'
Example
TYPE-POOLS: SLIS.
DATA: it_spfli TYPE TABLE OF spfli WITH HEADER LINE,
it_cat TYPE SLIS_T_FIELDCAT_ALV,
wa_cat TYPE slis_fieldcat_alv.
START-OF-SELECTION.
SELECT * FROM spfli
INTO TABLE it_spfli.
PERFORM create_field_catalog.
CALL FUNCTION ’REUSE_ALV_LIST_DISPLAY’
EXPORTING
* I_INTERFACE_CHECK = ’ ’
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ’ ’
* I_CALLBACK_PROGRAM = ’ ’
* I_CALLBACK_PF_STATUS_SET = ’ ’
* I_CALLBACK_USER_COMMAND = ’ ’
* I_STRUCTURE_NAME =
* IS_LAYOUT =
IT_FIELDCAT = it_cat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = ’X’
* I_SAVE = ’ ’
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = it_spfli
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form create_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_field_catalog .
IF it_cat[] is initial.
clear wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = ’CARRID’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-seltext_l = ’Airline Code’.
wa_cat-seltext_m = ’Airline Code’.
wa_cat-seltext_s = ’Airline Code’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 2.
wa_cat-fieldname = ’CONNID’.
wa_cat-datatype = ’NUMC’.
wa_cat-inttype = ’N’.
wa_cat-intlen = 4.
wa_cat-seltext_l = ’Flight Conn. No’.
wa_cat-seltext_m = ’Flight Conn. No’.
wa_cat-seltext_s = ’Flight Conn. No’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 3.
wa_cat-fieldname = ’CITYFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-seltext_l = ’Dep. city’.
wa_cat-seltext_m = ’Dep. city’.
wa_cat-seltext_s = ’Dep. city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 4.
wa_cat-fieldname = ’AIRPFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-seltext_l = ’Dep. airport’.
wa_cat-seltext_m = ’Dep. airport’.
wa_cat-seltext_s = ’Dep. airport’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 5.
wa_cat-fieldname = ’CITYTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-seltext_l = ’Arrival city’.
wa_cat-seltext_m = ’Arrival city’.
wa_cat-seltext_s = ’Arrival city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 6.
wa_cat-fieldname = ’AIRPTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-seltext_l = ’Dest. airport’.
wa_cat-seltext_m = ’Dest. airport’.
wa_cat-seltext_s = ’Dest. airport’.
append wa_cat to it_cat.
ENDIF.
ENDFORM. " create_field_catalog
- thitima's blog
- 2 comments
- Read more
- 11541 reads
Global data in SAP smartforms
We can define global variables in SAP smartforms but these are not contained in form interface by define them in Global Settings -> Global Definitions and select Global Data tab.
See above picture, we can define variable from:
- Data type (DATE, CHAR, NUMC etc.)
- Structure in Data Dictionary
- Defined Type in Types tab
Technorati Tags: ABAP,
- thitima's blog
- Add new comment
- Read more
- 1145 reads
Difference between MOVE ... TO and WRITE ... TO in ABAP/4
See Example
DATA: gv_char1(20) TYPE c,
gv_char2(20) TYPE c,
dec1(10) TYPE p DECIMALS 2 VALUE ’122345.89’.
START-OF-SELECTION.
* Date *
WRITE:/ ’Date variable’.
WRITE sy-datum to gv_char1.
WRITE:/ ’WRITE TO ’, gv_char1.
MOVE sy-datum to gv_char2.
WRITE:/ ’MOVE TO ’, gv_char2.
SKIP 1.
* Decimal *
WRITE:/ ’Decimal variable’.
WRITE dec1 to gv_char1.
WRITE:/ ’WRITE TO ’, gv_char1.
MOVE dec1 to gv_char2.
WRITE:/ ’MOVE TO ’, gv_char2.
- thitima's blog
- Add new comment
- Read more
- 2404 reads
ABAP/4 Example Code: ALV Grid Control by applying object CL_GUI_ALV_GRID
Create ZPROGRAM and create normal screen no. 100 under this program. And in screen 100, please create custom control name ’CUSTOM1’.
Example
*** ZPROGRAM CODING ***
DATA: save_ok LIKE sy-ucomm,
ok_code LIKE sy-ucomm,
it_spfli TYPE TABLE OF spfli WITH HEADER LINE.
DATA: G_CUSTOM_CONTAINER1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
GRID1 TYPE REF TO CL_GUI_ALV_GRID,
it_cat TYPE LVC_T_FCAT,
wa_cat TYPE LVC_S_FCAT.
START-OF-SELECTION.
SELECT * FROM spfli
INTO TABLE it_spfli.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS ’100’.
SET TITLEBAR ’100’.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
save_ok = ok_code.
clear ok_code.
CASE save_ok.
WHEN ’BACK’.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module INITIAL_GRID OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE INITIAL_GRID OUTPUT.
PERFORM create_field_catalog.
PERFORM create_grid_control.
ENDMODULE. " INITIAL_GRID OUTPUT
*&---------------------------------------------------------------------*
*& Form create_field_catalog
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_field_catalog .
IF it_cat[] is initial.
clear wa_cat.
wa_cat-col_pos = 1.
wa_cat-fieldname = ’CARRID’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Airline Code’.
wa_cat-coltext = ’Airline Code’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 2.
wa_cat-fieldname = ’CONNID’.
wa_cat-datatype = ’NUMC’.
wa_cat-inttype = ’N’.
wa_cat-intlen = 4.
wa_cat-reptext = ’Flight Conn. No’.
wa_cat-coltext = ’Flight Conn. No’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 3.
wa_cat-fieldname = ’CITYFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-reptext = ’Dep. city’.
wa_cat-coltext = ’Dep. city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 4.
wa_cat-fieldname = ’AIRPFROM’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Dep. airport’.
wa_cat-coltext = ’Dep. airport’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 5.
wa_cat-fieldname = ’CITYTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 20.
wa_cat-reptext = ’Arrival city’.
wa_cat-coltext = ’Arrival city’.
append wa_cat to it_cat.
clear wa_cat.
wa_cat-col_pos = 6.
wa_cat-fieldname = ’AIRPTO’.
wa_cat-datatype = ’CHAR’.
wa_cat-inttype = ’C’.
wa_cat-intlen = 3.
wa_cat-reptext = ’Dest. airport’.
wa_cat-coltext = ’Dest. airport’.
append wa_cat to it_cat.
ENDIF.
ENDFORM. " create_field_catalog
*&---------------------------------------------------------------------*
*& Form create_grid_control
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_grid_control .
IF G_CUSTOM_CONTAINER1 is initial .
CREATE OBJECT G_CUSTOM_CONTAINER1
EXPORTING CONTAINER_NAME = ’CUSTOM1’.
CREATE OBJECT GRID1
EXPORTING I_PARENT = G_CUSTOM_CONTAINER1.
CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY
* EXPORTING
* I_BUFFER_ACTIVE =
* I_BYPASSING_BUFFER =
* I_CONSISTENCY_CHECK =
* I_STRUCTURE_NAME =
* IS_VARIANT =
* I_SAVE =
* I_DEFAULT = ’X’
* IS_LAYOUT =
* IS_PRINT =
* IT_SPECIAL_GROUPS =
* IT_TOOLBAR_EXCLUDING =
* IT_HYPERLINK =
* IT_ALV_GRAPHICS =
* IT_EXCEPT_QINFO =
* IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = it_spfli[]
IT_FIELDCATALOG = it_cat[]
* IT_SORT =
* IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 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.
ENDIF.
ENDFORM. " create_grid_control*** FLOW LOGIC ON SCREEN 100 ***
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
MODULE INITIAL_GRID.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
- thitima's blog
- Add new comment
- Read more
- 7544 reads
How to insert variable in text element in SAP smartforms
After we insert text element in SAP smartforms, the inserted text element can contain variable. We will introduce step by step to insert variable in text element.
Step by Step
- Double click text element that you want to insert variable in left tree navigator.
In the example, i selected text element name ’TEXT1’.
- thitima's blog
- Add new comment
- Read more
- 1356 reads
คำสั่งลูป
ลูป (Loop) เป็นสิ่งที่จำเป็น และทรงพลังที่สุดของการแก้ปัญหาด้วยการเขียนโปรแกรมบนคอมพิวเตอร์ เพราะมันช่วยย่นระยะเวลาของการทำงานได้ไม่จำกัด โดยทั่วไปเกือบทุกภาษาจะมีคำสั่งประเภท ลูป อยู่เป็นจำนวนมาก เพื่อให้เลือกใช้งานได้หลายกรณี แต่สำหรับ ไพธอน ไม่มี เพราะลูป เหล่านี้มักเป็นต้นเหตุของข้อผิดพลาดจากการเขียนโปรแกรม เขียนแล้วมึน เขียนแล้วงง นานเข้าก็ไม่เข้าใจ เนื่องจากคำสั่ง ลูป ที่เขียนนั้นซับซ้อนเกินไปนั่นเอง สรุปแล้ว ไพธอน มีลูปเพียง 2 แบบเท่านั้น ไม่มีมากกว่านี้เด็ดขาด ได้แก่
- Add new comment
- Read more
- 3235 reads
Recent comments
2 years 11 weeks ago
2 years 16 weeks ago
2 years 16 weeks ago
2 years 17 weeks ago
2 years 17 weeks ago
2 years 19 weeks ago
2 years 19 weeks ago
2 years 19 weeks ago
2 years 20 weeks ago
2 years 20 weeks ago