Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Form

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 19

*&--------------------------------------------------------------------*

*&
Form f_clear_refresh
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM f_clear_refresh .
* Celar the data
CLEAR:wa_vbrk,
wa_vbrp,
wa_final,
wa_layout,
wa_fieldcat.
* Refresh the data
REFRESH:gt_vbrk,
gt_vbrp,
gt_final,
gt_fieldcat,
gt_list_header ,
gt_event.
ENDFORM.
" f_clear_refres
h
*&--------------------------------------------------------------------*
*&
Form f_pop_fieldcat
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text

*---------------------------------------------------------------------*
FORM f_pop_fieldcat .
DATA:lv_col TYPE i.
* 1st Way-Using the FM
*CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE
'
** EXPORTING
**
I_PROGRAM_NAME
=
**
I_INTERNAL_TABNAME
=
" Internal table name
** Note: LIKE should be used to refer the fi
elds while defining the types
**
I_STRUCTURE_NAME
=
" DBTABLE/DB Structure name
**
I_CLIENT_NEVER_DISPLAY
= 'X'
**
I_INCLNAME
=
**
I_BYPASSING_BUFFER
=
**
I_BUFFER_ACTIVE
=
* CHANGING
*
ct_fieldcat
= gt_field
cat
** EXCEPTIONS
**
INCONSISTENT_INTERFACE
= 1
**
PROGRAM_ERROR
= 2
**
OTHERS
= 3
*
.
*IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER
SY-MSGNO
**
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 S
Y-MSGV4.
*ENDIF.

* It can be modified as below


* LOOP AT gt_fieldcat INTO wa_fieldcat.
*
CASE wa_fieldcat-fieldname.
*
WHEN 'VBELN'.
*
wa_fieldcat-edit = 'X'.
*
MODIFY gt_fieldcat FROM wa_fieldcat
TRANSPORTING edit.
*
ENDCASE.
* ENDLOOP.
* 2nd Way-Manual Population->Advisable
*First Column Edition
lv_col = lv_col + 1.
wa_fieldcat-col_pos = lv_col.
wa_fieldcat-fieldname = 'VBELN'.
wa_fieldcat-tabname = text-t01.
wa_fieldcat-seltext_s = 'Billing Document'.
wa_fieldcat-seltext_m = 'Billing Document'.
wa_fieldcat-seltext_l = 'Billing Document'.
wa_fieldcat-emphasize = 'X'.
wa_fieldcat-edit = 'X'.
APPEND wa_fieldcat TO gt_fieldcat.
*Second Column Edition
lv_col = lv_col + 1.
wa_fieldcat-col_pos = lv_col.
wa_fieldcat-fieldname = 'POSNR'.
wa_fieldcat-tabname = 'GT_FINAL'.
wa_fieldcat-seltext_s = 'Billing Document
Item'.
wa_fieldcat-seltext_m = 'Billing Document
Item'.
wa_fieldcat-seltext_l = 'Billing Document
Item'.
APPEND wa_fieldcat TO gt_fieldcat.

*Third Column Edition


lv_col = lv_col + 1.
wa_fieldcat-col_pos =
wa_fieldcat-fieldname
wa_fieldcat-tabname =
wa_fieldcat-seltext_s
uantity'.
wa_fieldcat-seltext_m
uantity'.
wa_fieldcat-seltext_l
uantity'.
APPEND wa_fieldcat TO

lv_col.
= 'FKIMG'.
'GT_FINAL'.
= 'Actual Invoiced Q
= 'Actual Invoiced Q
= 'Actual Invoiced Q
gt_fieldcat.

*3rd way using the the sub routine with By v


alue and return->advisable
* Usage of By Value and Return
* For 'Actual Invoiced Quantity'
* PERFORM f_populate_fieldcat USING '3' 'FK
IMG' 'GT_FINAL' text-004
* CHANGING gt_fieldcat.
* For 'Sales unit'
PERFORM f_populate_fieldcat USING '4' 'VRK
ME' 'GT_FINAL' text-005
CHANGING gt_fieldcat.
* For 'Base Unit of Measure'
PERFORM f_populate_fieldcat USING '5' 'MEI
NS' 'GT_FINAL' 'Base Unit of Measure'
CHANGING gt_fi
eldcat.
*For 'Billing Type'
PERFORM f_populate_fieldcat USING '6' 'FKA
RT' 'GT_FINAL' 'Billing Type'
CHANGING gt_fi
eldcat.

*For 'Billing category'


PERFORM f_populate_fieldcat USING '7' 'FKT
YP' 'GT_FINAL' 'Billing category'
CHANGING gt_fi
eldcat.
* For 'SD document category'
PERFORM f_populate_fieldcat USING '8' 'VBT
YP' 'GT_FINAL' 'SD document category'
CHANGING gt_fi
eldcat.
* For 'SD Document Currency'
PERFORM f_populate_fieldcat USING '9' 'WAE
RK' 'GT_FINAL' 'SD Document Currency'
CHANGING gt_fi
eldcat.
* For 'Sales Organization'
PERFORM f_populate_fieldcat USING '10' 'VK
ORG' 'GT_FINAL' 'Sales Organization'
CHANGING gt_fi
eldcat.
* For 'Net Value in Document Currency'
PERFORM f_populate_fieldcat USING '11' 'NE
TWR' 'GT_FINAL' 'Net Value in Document Curre
ncy'
CHANGING gt_fi
eldcat.
ENDFORM.
" f_pop_fieldcat
*&--------------------------------------------------------------------*
*&
Form f_display_alv
*&--------------------------------------------------------------------*
*
text
*-------------------------------------------

---------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_display_alv .
IF NOT gt_final IS INITIAL.
IF p_grid EQ 'X'.
* CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_pf_status_set = 'F_PF_S
TATUS_SET' "Dynamic sub routine
* Dynamic subroutine call for an event USER_
COMMAND
i_callback_user_command = 'F_USER
_COMMAND'
* Dynamic subroutine call for an event TOP_O
F_PAGE for GRID only
*
i_callback_top_of_page
= 'F_TOP
-OF-PAGE'
*NOTE:1. The parameter 'i_callback_top_of_pa
ge' is not there
*
for ALV List and Heirarchical ALV
*
2. These call back parameters are not
there for
*
Blocked ALV
is_layout
= wa_layo
ut
it_fieldcat
= gt_fiel
dcat
it_events
= gt_event
TABLES
t_outtab
= gt_fina

l[]
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NU
MBER sy-msgno
WITH sy-msgv1 sy-msgv2 symsgv3 sy-msgv4.
ENDIF.
ELSE.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program
= sy-repid
i_callback_pf_status_set = 'F_PF_S
TATUS_SET'
"Dynamic sub routine see FOR
M below
i_callback_user_command = 'USER_C
OMMAND'
"Dynamic sub routine see FORM
below
is_layout
= wa_layo
ut
it_fieldcat
= gt_fiel
dcat
it_events
= gt_event
TABLES
t_outtab
= gt_fina
l[]
EXCEPTIONS
program_error
= 1
OTHERS
= 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NU
MBER sy-msgno

WITH sy-msgv1 sy-msgv2 symsgv3 sy-msgv4.


ENDIF.
ENDIF.
ELSE.
MESSAGE text-011 TYPE 'I'.
ENDIF.
ENDFORM.
" f_display_alv
*&--------------------------------------------------------------------*
*&
Form f_populate_fieldcat
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->P_0247
text
*
-->P_0248
text
*
-->P_0249
text
*
-->P_0250
text
*
<--P_GT_FIELDCAT text
*---------------------------------------------------------------------*
FORM f_populate_fieldcat USING
value(p_c
ol_pos)
value(p_f
ield)
value(p_i
n_table)
value(p_l
abel)
CHANGING p_gt_fiel
dcat LIKE gt_fieldcat.
CLEAR wa_fieldcat.

wa_fieldcat-col_pos =
wa_fieldcat-fieldname
wa_fieldcat-tabname =
wa_fieldcat-seltext_m
APPEND wa_fieldcat TO

p_col_pos.
= p_field.
p_field.
= p_label.
p_gt_fieldcat.

ENDFORM.
" f_populate_fie
ldcat
*&--------------------------------------------------------------------*
*&
Form F_LAYOUT
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_layout .
*declaration of local data
CONSTANTS: lc_x TYPE c VALUE 'X'.
* wa_layout-zebra = lc_x.
wa_layout-no_input = lc_x.
wa_layout-colwidth_optimize = lc_x.
wa_layout-detail_popup = lc_x.
wa_layout-confirmation_prompt = lc_x.
ENDFORM.

" F_LAYOUT

**------------------------------------------------------------------*
** Form TOP-OF-PAGE *

**------------------------------------------------------------------*
** ALV Report Header *
**------------------------------------------------------------------*
FORM f_top_of_page.
*ALV Header declarations
DATA:lt_header TYPE slis_t_listheader,
wa_header TYPE slis_listheader,
lv_line LIKE wa_header-info,
lv_count(10) TYPE c.
*****>>>1. use an event TOP_OF_PAGE
****>>>>2.Populate the Headings
* Title
wa_header-typ = 'H'.
wa_header-info = 'Billing Report'.
APPEND wa_header TO lt_header.
CLEAR wa_header.
* Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays d
ate
APPEND wa_header TO lt_header.
CLEAR: wa_header.
* Total No. of Records Selected
DESCRIBE TABLE gt_final LINES gv_count.
MOVE gv_count TO lv_count.
CONCATENATE 'Total No. of Records Selected

:' lv_count
INTO lv_line SEPARATED BY space.
wa_header-typ = 'A'.
wa_header-info = lv_line.
APPEND wa_header TO lt_header.
CLEAR: wa_header, lv_line.
****>>>3. Diaply the populated Headings and
Logo
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = lt_header " Headi
ngs
i_logo
= 'ENJOYSAP_LOGO'.
"Image name
ENDFORM.
"top-of-page
*&--------------------------------------------------------------------*
*&
Form SET-PF-STATUS
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
FORM f_pf_status_set USING p_extab TYPE slis
_t_extab.
*** Declaration of Local Data
DATA:ls_extab LIKE LINE OF p_extab.
* Exclude unwanted FCT codes
ls_extab-fcode = '&NFO'.
APPEND ls_extab TO p_extab.
ls_extab-fcode = '&CRB'.
APPEND ls_extab TO p_extab.
ls_extab-fcode = '&CRL'.
APPEND ls_extab TO p_extab.
ls_extab-fcode = '&CRR'.

APPEND ls_extab TO p_extab.


ls_extab-fcode = '&CRE'.
APPEND ls_extab TO p_extab.
SET PF-STATUS 'ZB16_MEN_ALV' EXCLUDING p_e
xtab.
ENDFORM.
"SET-PF-STATUS
*-----------------------------------------------------------------*
* FORM USER_COMMAND *
*-----------------------------------------------------------------*
* --> R_UCOMM *
* --> RS_SELFIELD *
*-----------------------------------------------------------------*
FORM f_user_command USING r_ucomm LIKE syucomm
lwa_selfield TYPE slis_selfield.
DATA:mid(10) TYPE c.
DATA:lt_temp TYPE TABLE OF typ_final.
* ABAP memory
* Export the data to a Memory ID
* EXPORT wa_final-vbeln TO MEMORY ID 'MID'.
*
** Import the data from Memory ID
* IMPORT p1 = wa_final-VBELN
* FROM MEMORY ID 'MID'.
* Pass the data using SAP Memory
CASE r_ucomm.
WHEN '&IC1'. " System provided Fuction c

ode for Double click


*
GET PARAMETER ID 'AUN' FIELD wa_fina
l-vbeln.
*
SUBMIT zgotham_alv_fcat_merge USING S
ELECTION-SCREEN 1000.
lt_temp[] = gt_final.
DELETE lt_temp WHERE vbeln NE lwa_self
ield-value.
*
SUBMIT z_alv_fcat_merge VIA SELECTION
-SCREEN.
* Check field clicked on within ALVgrid repo
rt
IF lwa_selfield-fieldname = 'VBELN'.
* Read data table, using index of row user c
licked on
READ TABLE gt_final INTO wa_final IN
DEX
lwa_selfield-tabindex.
* Set parameter ID for transaction screen fi
eld
SET PARAMETER ID 'VF' FIELD wa_final
-vbeln.
* Sxecute transaction ME23N, and skip initia
l data entry screen
CALL TRANSACTION 'VF02' AND SKIP FIR
ST SCREEN.
ENDIF.
WHEN 'T_VF03'.
CALL TRANSACTION 'VF01'.
ENDCASE.
ENDFORM.
"user_command
*&------------------------------------------

---------------------------*
*&
Form f_get_vbrk
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_get_vbrk .
* Get the required data from VBRK
SELECT vbeln
fkart
fktyp
vbtyp
waerk
vkorg
netwr
FROM vbrk
INTO TABLE gt_vbrk
WHERE vbeln IN s_vbeln.
ENDFORM.
" f_get_vbrk
*&--------------------------------------------------------------------*
*&
Form f_get_vbrp
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*-------------------------------------------

---------------------------*
FORM f_get_vbrp .
* Get the Required data from VBRP
IF NOT gt_vbrk[] IS INITIAL.
SELECT vbeln
posnr
fkimg
vrkme
meins
INTO TABLE gt_vbrp
FROM vbrp
FOR ALL ENTRIES IN gt_vbrk
WHERE vbeln EQ gt_vbrk-vbeln.
ENDIF.
ENDFORM.
" f_get_vbrp
*&--------------------------------------------------------------------*
*&
Form f_final_data
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_final_data .
* Sort the Internal tables
SORT:gt_vbrp.
LOOP AT gt_vbrp INTO wa_vbrp.
* Move the req.fields from gt_vbrp into GT_F
INAL
wa_final-posnr = wa_vbrp-posnr.

wa_final-fkimg = wa_vbrp-fkimg.
wa_final-vrkme = wa_vbrp-vrkme.
wa_final-meins = wa_vbrp-meins.
* Access the data from GT_VBRK
READ TABLE gt_vbrk INTO wa_vbrk WITH KEY
vbeln = wa_vbrp-vbeln
BINARY SEARCH.
*
OR
*
READ TABLE gt_vbrk INTO wa_vbrk INDEX s
y-tabix.
IF sy-subrc EQ 0.
* Move the req.fields from gt_vbrk into GT_F
INAL
MOVE:wa_vbrk-vbeln TO wa_final-vbeln,
wa_vbrk-fkart TO wa_final-fkart,
wa_vbrk-fktyp TO wa_final-fktyp,
wa_vbrk-vbtyp TO wa_final-vbtyp,
wa_vbrk-waerk TO wa_final-waerk,
wa_vbrk-netwr TO wa_final-netwr,
wa_vbrk-vkorg TO wa_final-vkorg.
ENDIF.
* Append an Internal table GT_FINAL
APPEND wa_final TO gt_final.
* Clear the work areas
CLEAR:wa_vbrk,
wa_vbrp,
wa_final.
ENDLOOP.
ENDFORM.
" f_final_data
*&--------------------------------------------------------------------*
*&
Form f_validate_vbeln
*&--------------------------------------------------------------------*

*
text
*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_validate_vbeln .
* Define the local data
TYPES:BEGIN OF ltyp_vbeln,
vbeln TYPE vbeln_vf,
END OF ltyp_vbeln.
DATA:lt_vbeln TYPE SORTED TABLE OF ltyp_vb
eln WITH UNIQUE KEY vbeln.
* Check whether the given value exists or no
t
SELECT vbeln
FROM vbrk
INTO TABLE lt_vbeln
WHERE vbeln IN s_vbeln.
IF lt_vbeln[] IS INITIAL.
* Messaeg-Please provide a valid Input
MESSAGE text-002 TYPE 'E'.
ENDIF.
ENDFORM.
" f_validate_vbe
ln
*&--------------------------------------------------------------------*
*&
Form f_event_pop
*&--------------------------------------------------------------------*
*
text

*---------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*---------------------------------------------------------------------*
FORM f_event_pop .
*2nd Way-Advisable
wa_event-name = 'TOP_OF_PAGE'. " Event nam
e
wa_event-form = 'F_TOP_OF_PAGE'. "Dynamic
Sub routine name
APPEND wa_event TO gt_event.
* 3rd Way
* Events
* CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
*
EXPORTING
*
i_list_type
= 0
*
IMPORTING
*
et_events
= gt_event
*
EXCEPTIONS
*
list_type_wrong = 1
*
OTHERS
= 2.
* IF sy-subrc <> 0.
*
MESSAGE ID sy-msgid TYPE sy-msgty NUMBE
R sy-msgno
*
WITH sy-msgv1 sy-msgv2 sy-msgv3
sy-msgv4.
* ENDIF.
*
** Populate the dynamic form names
* LOOP AT gt_event INTO wa_event.
*
CASE wa_event-name.
*
WHEN 'TOP_OF_PAGE'.

*
wa_event-form = 'F_TOP_OF_PAGE'.
*
MODIFY gt_event FROM wa_event TRANS
PORTING form.
*
ENDCASE.
* ENDLOOP.
ENDFORM.
" f_event_pop

You might also like