Abap Faq'S - Alv: This Is A Set of Queries and Answers, Which We Have Collected From Multiple Sources To Help Abapers
Abap Faq'S - Alv: This Is A Set of Queries and Answers, Which We Have Collected From Multiple Sources To Help Abapers
This is a set of queries and answers,which we have collected from multiple sources to
help ABAPers.
Contribution by
Meenakshi Palaniappan
Vivekanand Nagarajan
ABAP FAQ’s – ALV
Question:
How to change the ALV report title and hide columns as per users input,
in selection-screen after executing the report? I want to change the
report title and hide columns as per user selection.
Answer:
In ALV Function.
IT_Grid_Title = p_title.
Or if you are giving a check box or List box, based on that, u must
code. Lastly you have to pass like this
FIELDCATLOG-NO_OUT = 'X'.
ENDIF
Question:
At run time I get few fields from the DDIC table. I want to create a
dynamic internal table based on the fields. How to achieve?
Answer-1:
LOOP AT STRUCT.
INCTABL-LINE = STRUCT-FILDNAME.
LNG = STRLEN( STRUCT-FILDNAME ).
START-OF-SELECTION.
*line = ' CITYFROM CITYTO '.
line = ' AIRPTO '.
APPEND line TO list.
IF sy-subrc EQ 0.
LOOP AT itab INTO wa.
* WRITE: / wa-cityfrom, wa-cityto.
WRITE :/ wa-airpto.
ENDLOOP.
ENDIF.
Answer-2:
REPORT YTEST2 .
TYPE-POOLS : SLIS.
V_CNT1 TYPE C,
END OF IT_VBAP.
* -Events in ALV
INITIALIZATION.
V_REPID = SY-REPID.
START-OF-SELECTION.
V_CNT = 4.
PERFORM PREPARE_FIELDCATLOG.
PERFORM CREATE_TABLE.
PERFORM BUILD_FCAT_EVENTS.
LOOP AT IT_VBAP.
PERFORM COMMON_DATA.
ENDLOOP.
PERFORM ALV_LIST_DISPLAY.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM PREPARE_FIELDCATLOG.
DATA L_FLD(7).
CLEAR V_CNT1.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'VBELN'.
X_FIELDCAT-REF_FIELD = 'VBELN'.
ABAP FAQ’s – ALV
X_FIELDCAT-REF_TABLE = 'VBAP'.
CLEAR X_FIELDCAT.
X_FIELDCAT-FIELDNAME = 'POSNR'.
X_FIELDCAT-REF_FIELD = 'POSNR'.
X_FIELDCAT-REF_TABLE = 'VBAP'.
DO V_CNT TIMES.
V_CNT1 = V_CNT1 + 1.
X_FIELDCAT-FIELDNAME = L_FLD.
X_FIELDCAT-REF_FIELD = 'NETWR'.
X_FIELDCAT-REF_TABLE = 'VBAP'.
ENDDO.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM CREATE_TABLE.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM BUILD_FCAT_EVENTS.
*-Message type
IT_FIELDCAT-FIELDNAME = 'VBELN'.
IT_FIELDCAT-COL_POS = L_POS.
IT_FIELDCAT-OUTPUTLEN = 10.
ABAP FAQ’s – ALV
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
L_POS = L_POS + 1.
IT_FIELDCAT-FIELDNAME = 'POSNR'.
IT_FIELDCAT-COL_POS = L_POS.
IT_FIELDCAT-SELTEXT_M = 'Item'(005).
IT_FIELDCAT-OUTPUTLEN = 6.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
L_POS = L_POS + 1.
IT_FIELDCAT-FIELDNAME = 'NETWR_1'.
IT_FIELDCAT-COL_POS = L_POS.
IT_FIELDCAT-SELTEXT_M = 'Currency'.
IT_FIELDCAT-OUTPUTLEN = 15.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
L_POS = L_POS + 1.
IT_FIELDCAT-FIELDNAME = 'NETWR_2'.
IT_FIELDCAT-COL_POS = L_POS.
IT_FIELDCAT-SELTEXT_M = 'Currency'.
IT_FIELDCAT-OUTPUTLEN = 15.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
L_POS = L_POS + 1.
ABAP FAQ’s – ALV
IT_FIELDCAT-FIELDNAME = 'NETWR_3'.
IT_FIELDCAT-COL_POS = L_POS.
IT_FIELDCAT-SELTEXT_M = 'Currency'.
IT_FIELDCAT-OUTPUTLEN = 15.
APPEND IT_FIELDCAT.
CLEAR IT_FIELDCAT.
*-Layout
X_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
X_LAYOUT-ZEBRA = 'X'.
*-Events
* Top of list
X_EVENTS-NAME = 'TOP_OF_LIST'.
X_EVENTS-FORM = 'TOP_OF_PAGE'.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM COMMON_DATA.
<V_FIELD> = IT_VBAP-VBELN.
ABAP FAQ’s – ALV
<V_FIELD> = IT_VBAP-POSNR.
<V_FIELD> = IT_VBAP-NETWR.
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------
FORM ALV_LIST_DISPLAY.
EXPORTING
I_CALLBACK_PROGRAM = V_REPID
IS_LAYOUT = X_LAYOUT
IT_FIELDCAT = IT_FIELDCAT[]
IT_EVENTS = IT_EVENTS[]
TABLES
T_OUTTAB = <V_TABLE>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
ENDIF.
ABAP FAQ’s – ALV
Question:
Answer:
By using these predefined table types u can declare internal tables, and
u can use these.
Regarding Field_cat:
For ex:
Field_cat-fieldname = ‘ZAUFNR’.
field_cat-tabname = 'ITAB1'.
field_cat-key = 'X'.
field_cat-hotspot = 'X'.
field_cat-seltext_m = 'ORDER NUMBER'.
append field_cat.
ABAP FAQ’s – ALV
Question:
Answer-1:
While calling the FM for ALV, u have to populate the Events table and
mention the same event there so that the alv report becomes interactive.
Answer-2:
And of course you still need the form 'USER_COMMAND', which must be
of the following form:
endform.
Question:
ABAP FAQ’s – ALV
How to attach a custom menu or a custom button, for my alv report, using
function modules (not through oops).
Answer:
Rxtab contains all function codes that are hidden on the standard
interface of the alv.
If u want to implement user own pf-status first copy the standard one
which is present in function group salv, and make the necessary changes.
Question:
Ans
Answer:
Question:
Please tell me what exactly the "&" mean in the following chunk of
code...
define fieldcatalog.
i_fieldcat-ref_table = &1.
i_fieldcat-fieldname = &2.
i_fieldcat-coltext = &3.
append i_fieldcat.
clear i_fieldcat.
end-of-definition.
ABAP FAQ’s – ALV
Answer:
&1 means the first argument you pass to the 'fieldcatalog' definition.
Following code will help u understand.
******************************
Report ZTEST.
define fieldcatalog.
i_fieldcat-ref_table = &1.
i_fieldcat-fieldname = &2.
i_fieldcat-coltext = &3.
append i_fieldcat.
clear i_fieldcat.
end-of-definition.
loop at i_fieldcat.
write : / i_fieldcat-ref_table.
write : / i_fieldcat-fieldname.
write : / i_fieldcat-coltext.
endloop.
********************************************
Output:
ABC
BCD
CDE
********************************************
Question :
I have created an ALV list and would like to put our company logo in the
header. How can I do this?
Answer :
in the transaction OAOR, you should be able to insert your company Logo.
Question :
Answer :
REPORT z_alv_auto_refresh.
*>*********************************************************************
* This report displays User's info (SM04) using the FM : *
* REUSE_ALV_LIST_DISPLAY *
* The list is auto-refreshed (refresh time : 5 seconds) *
*---------------------------------------------------------------------*
DATA :
gt_user LIKE uinfo OCCURS 0 WITH HEADER LINE. " User info in SM04
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
*---------------------------------------------------------------------*
* Form F_LIRE_DATA
*---------------------------------------------------------------------*
FORM f_read_data.
REFRESH gt_user.
* Wait in a task
PERFORM f_call_rfc_wait.
DEFINE m_sort.
ABAP FAQ’s – ALV
DEFINE m_event_exit.
clear ls_event_exit.
ls_event_exit-ucomm = &1.
ls_event_exit-after = 'X'.
append ls_event_exit to lt_event_exit.
END-OF-DEFINITION.
DATA :
ls_layout TYPE slis_layout_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
lt_event_exit TYPE slis_t_event_exit,
ls_event_exit TYPE slis_event_exit.
ls_layout-zebra = 'X'.
ls_layout-colwidth_optimize = 'X'.
CASE i_ucomm.
WHEN '&NTE'.
PERFORM f_read_data.
is_selfield-refresh = 'X'.
SET USER-COMMAND '&OPT'. " Optimize columns width
ENDCASE.
FORM f_call_rfc_wait.
* Wait in a task
CALL FUNCTION 'RFC_PING_AND_WAIT' STARTING NEW TASK '001'
PERFORMING f_task_end ON END OF TASK
EXPORTING
seconds = 5 " Refresh time
busy_waiting = space
EXCEPTIONS
RESOURCE_FAILURE = 1
communication_failure = 2 MESSAGE lv_mssg
system_failure = 3 MESSAGE lv_mssg
OTHERS = 4.
CHECK sy-subrc EQ 0.
SET USER-COMMAND '&NTE'. " Refresh