F Traffic light program in SAP ABAP | CodeTheta

Traffic light program in SAP ABAP

October 01, 2019

Code :
REPORT ZVP_TRAFFIC_LIGHT_PROGRAM.

TYPE-POOLSSLIS.

TYPESBEGIN OF TY_MARA,
         MATNR  TYPE MARA-MATNR,
         MTART  TYPE MARA-MTART,
         MATKL  TYPE MARA-MATKL,
         GROES  TYPE MARA-GROES,
         NTGEW  TYPE MARA-NTGEW,
         LIGHTS TYPE C,
       END OF TY_MARA.


DATAIT_MARA   TYPE STANDARD TABLE OF TY_MARA,
      WA_MARA   TYPE TY_MARA,

      IT_FCAT   TYPE SLIS_T_FIELDCAT_ALV,
      WA_FCAT   TYPE SLIS_FIELDCAT_ALV,
      WA_LAYOUT TYPE SLIS_LAYOUT_ALV,

      LV_MATNR  TYPE MARA-MATNR.

SELECT-OPTIONSS_MATNR FOR LV_MATNR.


SELECT MATNR
       MTART
       MATKL
       GROES
       NTGEW
  FROM MARA INTO TABLE IT_MARA WHERE MATNR IN S_MATNR.

PERFORM CALL_ALV.


CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
*   I_INTERFACE_CHECK  = ' '
*   I_BYPASSING_BUFFER = ' '
*   I_BUFFER_ACTIVE    = ' '
    I_CALLBACK_PROGRAM SY-REPID
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
*   I_STRUCTURE_NAME   =
*   I_BACKGROUND_ID    = ' '
*   I_GRID_TITLE       =
*   I_GRID_SETTINGS    =
    IS_LAYOUT          WA_LAYOUT
    IT_FIELDCAT        IT_FCAT
*   IT_EXCLUDING       =
*   IT_SPECIAL_GROUPS  =
*   IT_SORT            =
*   IT_FILTER          =
*   IS_SEL_HIDE        =
*   I_DEFAULT          = 'X'
*   I_SAVE             = ' '
*   IS_VARIANT         =
*   IT_EVENTS          =
*   IT_EVENT_EXIT      =
*   IS_PRINT           =
*   IS_REPREP_ID       =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE  = 0
*   I_HTML_HEIGHT_TOP  = 0
*   I_HTML_HEIGHT_END  = 0
*   IT_ALV_GRAPHICS    =
*   IT_HYPERLINK       =
*   IT_ADD_FIELDCAT    =
*   IT_EXCEPT_QINFO    =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    T_OUTTAB           IT_MARA
* EXCEPTIONS
*   PROGRAM_ERROR      = 1
*   OTHERS             = 2
  .
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

FORM CALL_ALV.

  LOOP AT IT_MARA INTO WA_MARA.
    IF
      WA_MARA-MATKL 'XLCL'.
      WA_MARA-LIGHTS 1.
    ELSEIF
      WA_MARA-MATKL 'XLVL'.
      WA_MARA-LIGHTS 2.
    ELSE.
      WA_MARA-LIGHTS 3.
    ENDIF.
    MODIFY IT_MARA FROM WA_MARA TRANSPORTING LIGHTS.
    CLEAR WA_MARA.
  ENDLOOP.


  WA_FCAT-COL_POS '1'.
  WA_FCAT-FIELDNAME 'MATNR'.
  WA_FCAT-SELTEXT_M 'MATERIAL NUMBER'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '2'.
  WA_FCAT-FIELDNAME 'MTART'.
  WA_FCAT-SELTEXT_M 'MTART'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '3'.
  WA_FCAT-FIELDNAME 'MATKL'.
  WA_FCAT-SELTEXT_M 'MATKL'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '4'.
  WA_FCAT-FIELDNAME 'GROES'.
  WA_FCAT-SELTEXT_M 'GROES'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_FCAT-COL_POS '5'.
  WA_FCAT-FIELDNAME 'NTGEW'.
  WA_FCAT-SELTEXT_M 'NTGEW'.
  APPEND WA_FCAT TO IT_FCAT.
  CLEAR WA_FCAT.

  WA_LAYOUT-LIGHTS_FIELDNAME 'LIGHTS'.
ENDFORM.

Output :

 

IDE Used To Test This Code : ABAP Editor.

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.We will reply you as soon as possible.

Post a Comment