REPORT ha400_opt_osql_s1 MESSAGE-ID ha400.
* Structure for Result: list of customers with age of their sales orders
TYPES: BEGIN OF ts_customer,
id TYPE snwd_bpa-bp_id,
name TYPE snwd_bpa-company_name,
avg_days_open TYPE i,
END OF ts_customer.
TYPES: tt_customer TYPE STANDARD TABLE OF ts_customer
WITH NON-UNIQUE KEY id, company_name.
* Data objects
DATA: gt_customers TYPE tt_customer,
gt_customers_t TYPE tt_customer.
* Database connection
DATA gv_dbcon TYPE dbcon-con_name.
CONSTANTS:
c_primdb TYPE dbcon-con_name VALUE 'DEFAULT',
c_secdb TYPE dbcon-con_name VALUE 'HANADB'.
* selection screen
SELECTION-SCREEN BEGIN OF BLOCK exe WITH FRAME TITLE text-exe.
PARAMETERS:
pa_temp TYPE xfeld RADIOBUTTON GROUP exe DEFAULT 'X',
pa_solu TYPE xfeld RADIOBUTTON GROUP exe,
pa_both TYPE xfeld RADIOBUTTON GROUP exe.
SELECTION-SCREEN END OF BLOCK exe.
SELECTION-SCREEN BEGIN OF BLOCK dbc WITH FRAME TITLE text-dbc.
PARAMETERS:
pa_prim TYPE xfeld RADIOBUTTON GROUP dbc,
pa_sec TYPE xfeld RADIOBUTTON GROUP dbc DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK dbc.
START-OF-SELECTION.
CASE 'X'.
WHEN pa_prim.
gv_dbcon = c_primdb.
WHEN pa_sec.
gv_dbcon = c_secdb.
ENDCASE.
CASE 'X'.
WHEN pa_temp. " template only
PERFORM get_data_template USING gv_dbcon
CHANGING gt_customers_t.
PERFORM display USING gt_customers_t.
WHEN pa_solu. " solution only
PERFORM get_data_solution USING gv_dbcon
CHANGING gt_customers.
PERFORM display USING gt_customers.
WHEN pa_both. " both subroutines
PERFORM get_data_solution USING gv_dbcon
CHANGING gt_customers.
PERFORM get_data_template USING gv_dbcon
CHANGING gt_customers_t.
IF gt_customers <> gt_customers_t.
MESSAGE i010.
ELSE.
MESSAGE s011.
ENDIF.
ENDCASE.
*&---------------------------------------------------------------------*
*& Form get_data_template
*&---------------------------------------------------------------------*
FORM get_data_template USING pv_dbcon TYPE dbcon-con_name
CHANGING ct_customers TYPE tt_customer.
* Declarations
****************
* Work Area for Result
DATA ls_customer LIKE LINE OF ct_customers.
* Targets for Select
DATA: ls_partner TYPE snwd_bpa,
ls_invoice TYPE snwd_so_inv_head.
* help variables
DATA: lv_current_date TYPE timestampl,
lv_count TYPE i.
* processing
****************
CLEAR ct_customers.
CLEAR lv_count.
" get current date (UTC)
GET TIME STAMP FIELD lv_current_date.
SELECT * FROM snwd_bpa
CONNECTION (pv_dbcon)
INTO ls_partner.
ls_customer-id = ls_partner-bp_id.
ls_customer-name = ls_partner-company_name.
*
CLEAR: ls_customer-avg_days_open,
lv_count.
SELECT * FROM snwd_so_inv_head
CONNECTION (pv_dbcon)
INTO ls_invoice
WHERE buyer_guid = ls_partner-node_key
AND payment_status <> 'P'.
ls_customer-avg_days_open = ls_customer-avg_days_open
+ cl_abap_tstmp=>subtract( tstmp1 = lv_current_date
tstmp2 = ls_invoice-created_at ) / 86400.
lv_count = lv_count + 1.
ENDSELECT.
IF ls_customer-avg_days_open <> 0.
ls_customer-avg_days_open = ls_customer-avg_days_open / lv_count.
INSERT ls_customer INTO TABLE ct_customers.
ENDIF.
ENDSELECT.
SORT ct_customers BY id.
ENDFORM. "
*&---------------------------------------------------------------------*
*& Form get_data_solution
*&---------------------------------------------------------------------*
FORM get_data_solution USING pv_dbcon TYPE dbcon-con_name
CHANGING ct_customers TYPE tt_customer.
* Declarations
****************
* Type for target fields
TYPES: BEGIN OF tty_customer_invoice,
id TYPE snwd_bpa-bp_id,
name TYPE snwd_bpa-company_name,
created_at TYPE snwd_so_inv_head-created_at,
END OF tty_customer_invoice.
* local structure and work areas
DATA: ls_customer LIKE LINE OF ct_customers,
ls_customer_invoice TYPE tty_customer_invoice.
* Targets for Select
DATA lt_customer_invoice TYPE SORTED TABLE OF tty_customer_invoice WITH NON-UNIQUE KEY id.
* help variables
DATA: lv_current_date TYPE timestampl,
lv_count TYPE i.
* processing
****************
CLEAR ct_customers.
CLEAR lv_count.
" get current date (UTC)
GET TIME STAMP FIELD lv_current_date.
SELECT bp~bp_id AS bp_id
bp~company_name AS bp_name
inv~created_at AS created_at
FROM snwd_so_inv_head AS inv JOIN snwd_bpa AS bp ON inv~buyer_guid = bp~node_key
CONNECTION (pv_dbcon)
INTO TABLE lt_customer_invoice
WHERE inv~payment_status <> 'P'
ORDER BY bp~bp_id.
LOOP AT lt_customer_invoice INTO ls_customer_invoice.
IF sy-tabix = 1.
ls_customer-id = ls_customer_invoice-id.
ls_customer-name = ls_customer_invoice-name.
ELSEIF ls_customer_invoice-id <> ls_customer-id.
ls_customer-avg_days_open = ls_customer-avg_days_open / lv_count.
INSERT ls_customer INTO TABLE ct_customers.
CLEAR ls_customer.
CLEAR lv_count.
ls_customer-id = ls_customer_invoice-id.
ls_customer-name = ls_customer_invoice-name.
ENDIF.
lv_count = lv_count + 1.
ls_customer-avg_days_open = ls_customer-avg_days_open
+ cl_abap_tstmp=>subtract( tstmp1 = lv_current_date
tstmp2 = ls_customer_invoice-created_at ) / 86400.
ENDLOOP.
ls_customer-avg_days_open = ls_customer-avg_days_open / lv_count.
INSERT ls_customer INTO TABLE ct_customers.
* SORT ct_customers BY id. "already sorted
ENDFORM. "
*&---------------------------------------------------------------------*
*& Form output
*&---------------------------------------------------------------------*
FORM display USING it_customers TYPE tt_customer.
DATA: lo_alv TYPE REF TO cl_salv_table,
lx_msg TYPE REF TO cx_salv_msg,
lv_text TYPE string.
* display
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = it_customers ).
lo_alv->display( ).
CATCH cx_salv_msg INTO lx_msg.
lv_text = lx_msg->get_text( ).
MESSAGE lv_text TYPE 'E'.
ENDTRY.
ENDFORM.
Shortcuts that need to be turned on
Before you can use these keyboard shortcuts, you’ll need to enable keyboard shortcuts in your settings:
- Click the
gear in the top right and select Settings. - Find the "Keyboard shortcuts" section and select Keyboard shortcuts on.
- Click Save Changes at the bottom of the page.
| Shortcut Key | Definition | Action |
|---|---|---|
| c | Compose | Allows you to compose a new message. Shift + c allows you to compose a message in a new window. |
| d | Compose in a new tab | Opens a compose window in a new tab. |
| / | Search | Puts your cursor in the search box. |
| k | Move to newer conversation | Opens or moves your cursor to a more recent conversation. You can hit Enter to expand a conversation. |
| j | Move to older conversation | Opens or moves your cursor to the next oldest conversation. You can hit Enter to expand a conversation. |
| n | Newer message | In 'Conversation view', moves your cursor to the newer message. You can hitEnter to expand or collapse a message. |
| p | Previous message | In 'Conversation view', moves your cursor to the older message. You can hit Enterto expand or collapse a message. |
| ` | Go to next inbox section | If you use an inbox style with tabs or sections, you can quickly navigate to the next section. |
| ~ | Go to previous inbox section | If you use an inbox style with tabs or sections, you can quickly navigate to the previous section. |
| o or Enter | Open | Opens your conversation. Also expands or collapses a message if you are in 'Conversation View.' |
| u | Return to conversation list | Refreshes your page and returns you to the inbox, or list of conversations. |
| e | Archive | Archive your conversation from any view. |
| m | Mute | Archives the conversation, and all future messages skip the Inbox unless sent or cc'd directly to you. Learn more. |
| x | Select conversation | Automatically checks and selects a conversation so that you can archive, apply a label, or choose an action from the drop-down menu to apply to that conversation. |
| s | Star a message or conversation | Adds or removes a star to a message or conversation. Stars allow you to give a message or conversation a special status. |
| + | Mark as important | Helps Gmail learn what's important to you by marking misclassified messages. (Specific to Priority Inbox) |
| - | Mark as unimportant | Helps Gmail learn what's not important to you by marking misclassified messages. (Specific to Priority Inbox) |
| ! | Report spam | Marks a message as spam and removes it from your conversation list. |
| r | Reply | Replies to the message sender. Shift + r allows you to reply to a message in a new window. (Only applicable in 'Conversation View.') |
| a | Reply all | Replies to all message recipients. Shift + a allows you to reply to all message recipients in a new window. (Only applicable in 'Conversation View.') |
| f | Forward | Forwards a message. Shift + f allows you to forward a message in a new window. (Only applicable in 'Conversation View.') |
| Esc | Escape from input field | Removes the cursor from your current input field. |
| Ctrl + s Mac: ⌘ + s | Save draft | Saves the current text as a draft when composing a message. Hold the Ctrl/⌘key while pressing s and make sure your cursor is in one of the text fields -- either the composition pane, or any of the To, CC, BCC, or Subject fields -- when using this shortcut. |
| # | Delete | Moves the conversation to Trash. |
| l | Label | Opens the Labels menu to label a conversation. |
| v | Move to | Moves the conversation from the inbox to a different label, Spam or Trash. |
| Shift + i | Mark as read | Marks your message as 'read' and skip to a newer message. |
| Shift + u | Mark as unread | Marks your message as 'unread' so you can go back to it later. |
| [ | Removes from current view and previous | Removes the current view's label from your conversation and moves to the older one. |
| ] | Removes from current view and next | Removes the current view's label from your conversation and moves to the newer one. |
| { | Archive and previous | Archives the current conversation and moves to the older one. |
| } | Archive and next | Archives the current conversation and moves to the next one. |
| z | Undo | Undoes your previous action, if possible (works for actions with an 'undo' link). |
| Shift + n | Update current conversation | Updates your current conversation when there are new messages. |
| q | Move cursor to chat search | Moves your cursor directly to the chat search box. |
| y | Remove from Current View* | Automatically removes the message or conversation from your current view.
|
| . | Show more actions | Displays the 'More Actions' drop-down menu. |
| , | Moves cursor to the first button in yourGmail toolbar | Displays the 'More Actions' drop-down menu. |
| Ctrl + Down arrow Mac: ⌘ +Down arrow | Opens options in Chat |
|
| k | Move up a contact | Moves your cursor up in your contact list |
| j | Move down a contact | Moves your cursor down in your contact list |
| o or Enter | Open | Opens the contact with the cursor next to it. |
| u | Return to contact list view | Refreshes your page and returns you to the contact list. |
| e | Remove from Current Group | Removes selected contacts from the group currently being displayed. |
| x | Select contact | Checks and selects a contact so that you can change group membership or choose an action from the drop-down menu to apply to the contact. |
| Esc | Escape from input field | Removes the cursor from the current input |
| # | Delete | Deletes a contact permanently |
| l | Group membership | Opens the groups button to group contacts |
| z | Undo | Reverses your previous action, if possible (works for actions with an 'undo' link) |
Combo-keys
Use the following combinations of keys to navigate through Gmail.
| Shortcut Key | Definition | Action |
|---|---|---|
| Tab thenEnter | Send message | After composing your message, use this combination to send it. |
| y then o | Archive and next | Archives your conversation and moves to the next one. |
| g then a | Go to 'All Mail' | Takes you to 'All Mail,' the storage site for all mail you've ever sent or received (and have not deleted). |
| g then s | Go to 'Starred' | Takes you to all conversations you have starred. |
| g then c | Go to 'Contacts' | Takes you to your Contacts list. |
| g then d | Go to 'Drafts' | Takes you to all drafts you have saved. |
| g then l | Go to 'Label' | Takes you to the search box with the "label:" operator filled in for you. |
| g then i | Go to 'Inbox' | Returns you to the inbox. |
| g then t | Go to 'Sent Mail' | Takes you to all mail you've sent. |
| * then a | Select all | Selects all mail. |
| * then n | Select none | Deselects all mail. |
| * then r | Select read | Selects all mail you've read. |
| * then u | Select unread | Selects all unread mail. |
| * then s | Select starred | Selects all starred mail. |
| * then t | Select unstarred | Selects all unstarred mail. |