Monday, 18 May 2020

Manual Field Catalog OO-ALV




TYPES : BEGIN OF T_BILL,
        VBELN TYPE VBRK-VBELN,
        VKORG TYPE VBRK-VKORG,
        BZIRK TYPE VBRK-BZIRK,
        FKIMG TYPE VBRP-FKIMG,
        MEINS TYPE VBRP-MEINS,
        NETWR TYPE VBRP-NETWR,
       END OF T_BILL.

DATA : IT_BILL TYPE TABLE OF T_BILL,
       WA_BILL TYPE T_BILL.

DATA : O_CUST TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
       O_ALV TYPE REF TO CL_GUI_ALV_GRID.

DATA : IT_FCAT TYPE LVC_T_FCAT,
       WA_FCAT TYPE LVC_S_FCAT.

SELECT-OPTIONS  : S_VBELN FOR WA_BILL-VBELN.

START-OF-SELECTION.
PERFORM  FETCH_DATA.
PERFORM FIELDCAT.
CALL SCREEN 100.

FORM FETCH_DATA .

  SELECT A~VBELN VKORG BZIRK FKIMG MEINS B~NETWR INTO TABLE IT_BILL
    FROM VBRK AS A INNER JOIN VBRP AS B ON A~VBELN = B~VBELN
    WHERE a~VBELN IN S_VBELN.

ENDFORM.  

FORM FIELDCAT .
WA_FCAT-COL_POS = 1.
WA_FCAT-FIELDNAME = 'VBELN'.
WA_FCAT-COLTEXT = 'Billing Document'.
WA_FCAT-KEY = 'X'.
WA_FCAT-OUTPUTLEN = 10.
WA_FCAT-HOTSPOT = 'X'.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.


WA_FCAT-COL_POS = 2.
WA_FCAT-FIELDNAME = 'VKORG'.
WA_FCAT-COLTEXT = 'Sales Organization'.
WA_FCAT-OUTPUTLEN = 4.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.


WA_FCAT-COL_POS = 3.
WA_FCAT-FIELDNAME = 'BZIRK'.
WA_FCAT-COLTEXT = 'Sales district'.
WA_FCAT-OUTPUTLEN = 6.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.



WA_FCAT-COL_POS = 4.
WA_FCAT-FIELDNAME = 'FKIMG'.
WA_FCAT-COLTEXT = 'Actual Invoiced Quantity'.
WA_FCAT-OUTPUTLEN = 13.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.


WA_FCAT-COL_POS = 5.
WA_FCAT-FIELDNAME = 'MEINS'.
WA_FCAT-COLTEXT = 'Base Unit of Measure'.
WA_FCAT-OUTPUTLEN = 3.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

WA_FCAT-COL_POS = 6.
WA_FCAT-FIELDNAME = 'NETWR'.
WA_FCAT-COLTEXT = 'Net value'.
WA_FCAT-OUTPUTLEN = 15.
APPEND WA_FCAT TO IT_FCAT.
CLEAR WA_FCAT.

ENDFORM.                    " FIELDCAT

MODULE STATUS_0100 OUTPUT.
    SET PF-STATUS 'STATUS'.
*  SET TITLEBAR 'xxx'.



ENDMODULE. 

MODULE USER_COMMAND_0100 INPUT.

  CASE SY-UCOMM.
    WHEN 'BACK'.
    LEAVE TO SCREEN 0.

  ENDCASE.

ENDMODULE.    

MODULE DISPLAY_BILL OUTPUT.
  create object O_CUST
    exporting
*      PARENT                      =
      CONTAINER_NAME              = 'CUST'

    exceptions
      CNTL_ERROR                  = 1
      CNTL_SYSTEM_ERROR           = 2
      CREATE_ERROR                = 3
      LIFETIME_ERROR              = 4
      LIFETIME_DYNPRO_DYNPRO_LINK = 5
      OTHERS                      = 6
      .
  if SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.
create object O_ALV
    exporting
*      I_SHELLSTYLE      = 0
*      I_LIFETIME        =
      I_PARENT          = O_CUST

    exceptions
      ERROR_CNTL_CREATE = 1
      ERROR_CNTL_INIT   = 2
      ERROR_CNTL_LINK   = 3
      ERROR_DP_CREATE   = 4
      OTHERS            = 5
      .
  if SY-SUBRC <> 0.
   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

call method O_ALV->SET_TABLE_FOR_FIRST_DISPLAY
*  exporting
*    I_BUFFER_ACTIVE               =
*    I_BYPASSING_BUFFER            =
*    
  changing
    IT_OUTTAB                     = IT_BILL
    IT_FIELDCATALOG               = IT_FCAT
*    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.

ENDMODULE.





No comments:

Post a Comment