Google Answers Logo
View Question
 
Q: SAP ALV code help ( No Answer,   0 Comments )
Question  
Subject: SAP ALV code help
Category: Computers > Programming
Asked by: lahsiv25-ga
List Price: $10.00
Posted: 25 Jun 2005 14:26 PDT
Expires: 25 Jul 2005 14:26 PDT
Question ID: 536995
I have a SAP ALV code in which I want to add some functionalities .
Can anyone help me in that. The code is given below and the
requirement is given on top.



1. Add selection criteria to filter by Customer Reconciliation account
(KNB1-AKONT)

*2. Complete report evaluation at SO header level rather than line item.

3. Remove Line Item selection criteria and column from display (since
evaluation will be of header terms)

*4. Add SO Amount and SO Currency Columns
*5 .  Remove the double date column


TABLES: vbap,
        knvv,
        vbkd,
        vbpa,
        vbak.

TYPE-POOLS: slis.
TYPES: kkblo_selfield TYPE slis_selfield.

DATA:  fieldcat            TYPE slis_t_fieldcat_alv with header line,
       fieldcat_wa         TYPE slis_fieldcat_alv,
       g_user_command TYPE slis_formname VALUE 'USER_COMMAND'.

DATA: v_repid              LIKE sy-repid.
DATA: ls_variant           TYPE disvariant.
DATA  ls_save(1)           TYPE c.
DATA  ls_layout            TYPE  slis_layout_alv.
DATA  ls_sort              TYPE  slis_t_sortinfo_alv.
DATA: v_disvariant TYPE disvariant.
data: v_vbelnpopulated.
DATA: ds_variant LIKE disvariant.
data: v_vbeln_low          like vbap-vbeln,
      v_vbeln_high         like vbap-vbeln.
data: begin of  i_bapi_orderlist occurs 0.
        include structure  BAPIORDERS.
data: end of  i_bapi_orderlist.
DATA: BEGIN OF i_PYTM OCCURS 0,  "list of Payment Term related fields
        vkorg like vbak-vkorg,
        vbeln LIKE vbap-vbeln,
        posnr LIKE vbap-posnr,
        erdat like vbap-erdat,
        doc_dt like vbap-erdat,
        zterm like vbkd-zterm,
        kunnr LIKE knvv-kunnr,
        zterm2 like knvv-zterm,
      END OF i_pytm.
data: begin of i_vbpa occurs 0.
        include structure vbpa.
data: end of i_vbpa.
data: begin of i_vbap occurs 0.
        include structure vbap.
data: end of i_vbap.
data: v_lines like sy-tabix.
DEFINE change_fieldcat.
* parameter &1 i is the
* fieldcatalog attribute you desire to set. NO SINGLE QUOTES!
* parameter &2 is the ROW from the internal table you are
* outputing for which you are changing the field catalog attribute
* parameter &3 is the value of the attribute
  read table fieldcat index &2 into fieldcat_wa.
  if sy-subrc = 0.
    fieldcat_wa-&1 = &3.
    modify fieldcat from fieldcat_wa index sy-tabix .
  endif.
END-OF-DEFINITION.                     "CHANGE FIELDCAT

select-options: s_vkorg  for vbak-vkorg no-extension no intervals
                                                     obligatory.
"sales Organization
SELECT-OPTIONS: s_vbeln  FOR vbap-vbeln.   "Sales Order
SELECT-OPTIONS: s_posnr  for vbap-posnr.   "Sales ORder item
SELECT-OPTIONS: s_kunnr  FOR knvv-kunnr no-extension.   "Customer
SELECT-OPTIONS: s_erdat  FOR vbap-erdat obligatory no-extension.

*arameters: p_opt.
"Sales Order Create Date

initialization.
*include zux0ac1r.                    "Security check
at selection-screen.
  if s_kunnr[] is initial.
  else.
    loop at s_kunnr.
      if s_kunnr-low > ' '
      and s_kunnr-high = ' '.
        move s_kunnr-low to s_kunnr-high.
      endif.
    endloop.
  endif.

START-OF-SELECTION.
  data: v_max_vbeln like vbak-vbeln.
  data: v_min_vbeln like vbak-vbeln.
  data: v_vkorg like vbak-vkorg.
  if s_vkorg-low = '*'.
    move ' ' to v_vkorg.
    CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
      EXPORTING
         CUSTOMER_NUMBER             = ' '
         SALES_ORGANIZATION          = v_vkorg
        MATERIAL                    =  ' '
        DOCUMENT_DATE               = s_erdat-low
        DOCUMENT_DATE_TO            = s_erdat-high
*     PURCHASE_ORDER              =
*     TRANSACTION_GROUP           = 0
*     PURCHASE_ORDER_NUMBER       =
*   IMPORTING
*     RETURN                      =
      TABLES
        SALES_ORDERS                = i_bapi_orderlist.

  else.
    v_vkorg = s_vkorg-low.
    CALL FUNCTION 'BAPI_SALESORDER_GETLIST'
      EXPORTING
         CUSTOMER_NUMBER             = ' '
         SALES_ORGANIZATION          = v_vkorg
        MATERIAL                    =  ' '
        DOCUMENT_DATE               = s_erdat-low
        DOCUMENT_DATE_TO            = s_erdat-high
*     PURCHASE_ORDER              =
*     TRANSACTION_GROUP           = 0
*     PURCHASE_ORDER_NUMBER       =
*   IMPORTING
*     RETURN                      =
      TABLES
        SALES_ORDERS                = i_bapi_orderlist.
  endif.
  loop at i_bapi_orderlist.
    clear i_pytm.
    move i_bapi_orderlist-SD_DOC to i_pytm-vbeln.
    move i_bapi_orderlist-sales_org to i_pytm-vkorg.
    move i_bapi_orderlist-itm_number  to i_pytm-posnr.
    move i_bapi_orderlist-creation_date to i_pytm-erdat.
    move i_bapi_orderlist-doc_date to i_pytm-doc_dt.
    AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
         ID 'ACTVT' FIELD '03'             "display
         ID 'VKORG' FIELD i_bapi_orderlist-SALES_ORG.
    if sy-subrc = 0.
      select single zterm
        from vbkd
        into i_pytm-zterm
       where vbeln = i_pytm-vbeln
         and ( posnr = i_pytm-posnr
           or  posnr = 0 ).
      if sy-subrc ne 0.
        move 'UNKN' to i_pytm-zterm.
      endif.
* get Customer
      clear vbpa.
      select single *
        from vbpa
        into vbpa
       where vbeln = i_pytm-vbeln
         and ( posnr = i_pytm-posnr
         or    posnr = 0 )
*      and kunnr in s_kunnr
      and PARVW = 'RG'.
      if sy-subrc ne 0.
      else.
        move vbpa-kunnr to i_pytm-kunnr.
      endif.
* get customer payment terms
      select single zterm
        from knvv
        into i_pytm-zterm2
       where kunnr = i_pytm-kunnr.
      if sy-subrc ne 0.
        move 'UNKN' to i_pytm-zterm2.
      endif.
      if i_pytm-zterm = i_pytm-zterm2.
      else.
        if s_kunnr[] is initial.
          append i_pytm.
        else.
          if i_pytm-kunnr between s_kunnr-low and s_kunnr-high.
            append i_pytm.
          endif.
        endif.
      endif.
    endif.
  endloop.

END-OF-SELECTION.

  PERFORM f_build_fieldcat.
  PERFORM f_start_list_viewer.

*----------------------------------------------------------------------*
*       Form  F_BUILD_FIELDCAT
*----------------------------------------------------------------------*
FORM F_BUILD_FIELDCAT.

  V_REPID = SY-REPID.
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            I_PROGRAM_NAME         = 'ZSD0PYTR'
            I_INTERNAL_TABNAME     = 'I_PYTM'
            I_INCLNAME             = 'ZSD0PYTR'
       CHANGING
            CT_FIELDCAT            = FIELDCAT[]
       EXCEPTIONS
            INCONSISTENT_INTERFACE = 0
            PROGRAM_ERROR          = 0
            OTHERS                 = 0.

  CHANGE_FIELDCAT  SELTEXT_L '1'   TEXT-001.
  CHANGE_FIELDCAT  SELTEXT_M '1'   TEXT-001.
  CHANGE_FIELDCAT  SELTEXT_S '1'   TEXT-001.
  CHANGE_FIELDCAT  SELTEXT_L '2'   TEXT-002.
  CHANGE_FIELDCAT  SELTEXT_M '2'   TEXT-002.
  CHANGE_FIELDCAT  SELTEXT_S '2'   TEXT-002.
  CHANGE_FIELDCAT  SELTEXT_L '3'  TEXT-003.  "ERDAT
  CHANGE_FIELDCAT  SELTEXT_M '3'  TEXT-003.
  CHANGE_FIELDCAT  SELTEXT_S '3'  TEXT-003.
  CHANGE_FIELDCAT  SELTEXT_L '4' TEXT-doc. "doc date
  CHANGE_FIELDCAT  SELTEXT_M '4'  TEXT-doc.
  CHANGE_FIELDCAT  SELTEXT_S '4' TEXT-doc.

  CHANGE_FIELDCAT  SELTEXT_L '5'  TEXT-004.  "SO Payment Terms
  CHANGE_FIELDCAT  SELTEXT_M '5'  TEXT-004.
  CHANGE_FIELDCAT  SELTEXT_S '5'  TEXT-004.
  CHANGE_FIELDCAT  SELTEXT_L '6'  TEXT-005.
  CHANGE_FIELDCAT  SELTEXT_M '6'  TEXT-005.
  CHANGE_FIELDCAT  SELTEXT_S '6'  TEXT-005.
  CHANGE_FIELDCAT  SELTEXT_L '7'  TEXT-006.
  CHANGE_FIELDCAT  SELTEXT_M '7'  TEXT-006.
  CHANGE_FIELDCAT  SELTEXT_S '7'  TEXT-006.
  loop at fieldcat.
    case fieldcat-fieldname.
      when 'VBELN'.   "set hotspot for sales order
        fieldcat-hotspot = 'X'.
        modify fieldcat.
    endcase.
  endloop.
ENDFORM.                    " F_BUILD_FIELDCAT

*----------------------------------------------------------------------*
*       Form  F_START_LIST_VIEWER
*----------------------------------------------------------------------*
FORM F_START_LIST_VIEWER.
  DATA: V_LAYOUT TYPE  SLIS_LAYOUT_ALV.

  V_LAYOUT-ZEBRA = 'X'.                               "alternating color
  V_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.                "optimum column width

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            I_CALLBACK_PROGRAM = v_repid
            i_callback_user_command  = g_user_command
            IT_FIELDCAT        = FIELDCAT[]
            i_structure_name   = 'i_pytm'
*           IS_VARIANT         = DS_VARIANT
*           I_SAVE             = 'A'
            I_SAVE             = 'X'
            I_DEFAULT          = SPACE
            IS_LAYOUT          = V_LAYOUT
       TABLES
            T_OUTTAB           = I_pytm
       EXCEPTIONS
            PROGRAM_ERROR      = 0
            OTHERS             = 0.


ENDFORM.                    " F_START_LIST_VIEWER
*---------------------------------------------------------------------*
*       FORM user_command                                             *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  L_UCOMM                                                       *
*  -->  LS_SELFIELD                                                   *
*---------------------------------------------------------------------*
FORM user_command USING  l_ucomm LIKE sy-ucomm              "CHLK9A0OOX
                         ls_selfield TYPE kkblo_selfield.
  IF l_ucomm = '&IC1'.
    IF ls_selfield-sel_tab_field CS 'VBELN'.
      READ TABLE i_pytm INDEX ls_selfield-tabindex.
      SET PARAMETER ID 'AUN' FIELD i_pytm-vbeln.
      CALL FUNCTION 'Z_AUTHORITY_CHECK_CALL'
           EXPORTING
                TCODE_IN     = 'VA03'
           EXCEPTIONS
                NO_AUTHORITY = 1
                NO_TCODE     = 2.
      IF sy-subrc = 0.
        CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
      ELSE.
        MESSAGE i000(zz) WITH 'No authority to use'(m01)
                              'VA03 (Display Sales Order)'(m02).
      ENDIF.
*----end of add for security CHLK9A0YL2
    ENDIF.
  ENDIF.

ENDFORM.                  "USER_COMMAND
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy