Saturday, March 26, 2011

Custom F4 in Editable ALV

This simple proram demonstrates how to add custom F4 to a field in editable ALV using class cl_gui_alv_grid.

Using Primary index

This is very simple select query to select data from MARA using Primary INDEX.

Select Query for *

How to select all material starting with TL from Master. Make use of * in select query.

Tuesday, March 22, 2011

Saturday, March 19, 2011

FM used in ABAP

Here am listing few Function Modules used in Abap Programming ,which makes coding simpler and Reusable.


Wednesday, March 16, 2011

Thursday, March 10, 2011

To Send Mail with Attachment

Bill of Material BDC (CS01)

*&---------------------------------------------------------------------*
*& Report  ZPP_BDC_BOM_PGM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZPP_BDC_BOM_PGM
*report ZPB_PP_BDC_CS01
        no standard page heading line-size 255.

TABLES: mapl, plpo, plas.

include Zbdc.

*parameters: dataset(132) lower case.
***    DO NOT CHANGE - the generated data section - DO NOT CHANGE    ***
*
*   If it is nessesary to change the data section use the rules:
*   1.) Each definition of a field exists of two lines
*   2.) The first line shows exactly the comment
*       '* data element: ' followed with the data element
*       which describes the field.
*       If you don't have a data element use the
*       comment without a data element name
*   3.) The second line shows the fieldname of the
*       structure, the fieldname must consist of
*       a fieldname and optional the character '_' and
*       three numbers and the field length in brackets
*   4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE  ***

DATA: LIN_COUNT(02),
      X1(20),
      X2(20),
      X3(20),
      X4(20),
      X5(20),
      X6(20),
      X7(20),
      flag(002),                    "Flag to select the assignment
      CNT type i,
      cnt1 type i,
      cnt2 type i,
      opno(4) TYPE N,
      sequence(6) type n,
      set type i.

data: begin of record OCCURS 0,
        count(005),            "Counter
* data element: MATNR
        MATNR_001(018),        "Material No
* data element: WERKS_D
        WERKS_002(004),        "Plant
* data element: STLAN
        STLAN_003(001),        "Bom Usage
* data element: STALT
        STLAL_004(002),        "Alternative Bom
* data element: DATUV
        DATUV_005(010),        "Valid-From Date
* data element: CSTEXT
        ZTEXT_006(040),        "BOM Text
* data element: BASMN
        BMENG_007(017),        "Base Quantity
        LOSVN(013),            "From Lot Size
        LOSBS(013),            "To Lot Size
* data element: STLST
        STLST_008(002),        "BOM Status
* data element: SPOSN
        POSNR_012(004),        "BOM Item Number
* data element: IDNRK
        IDNRK_01_009(018),     "Component
*  RC29P-POSTP
        POSTP(001),            "Item Category (Bill of Material)
* data element: KMPMG
        MENGE_01_010(018),     "Quantity
** data element: IDNRK
*        IDNRK_013(018),
** data element: KMPMG
        rekrs_014(018), " recurssive
** data element: KMPME
*        MEINS_015(003),
* data element: FMNGE
*        FMENG_016(001),        "Fixed qty
** data element: NETAU
**        NETAU_017(001),        "Indicator: Net scrap
** data element: KAUSF
       AUSCH_018(006),      "Component scrap (%)
** data element: BEIKZ
        BEIKZ_019(001),      "Material Provision Indicator
* data element: KMPME
       MEINS_01_011(003),     "Component Unit of Measure
** data element: CSLGO
        LGORT_020(004),       "Issue STORAGE location for production order
*
*** data element: CK_SELKZ
**        SANKA_021(001),
*** data element: CSAUS
**        AUSKZ_01_022(001),
*** data element: FLG_SEL
**        FLG_SEL_04_023(001),
         opno(004),              "Operation No.
         sequence(006),          "Sequence
      end of record.
**
**** End generated data section ***
PARAMETERS: filename(250) TYPE c.
DATA: filename1 TYPE string.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
  PERFORM get_file.

START-OF-SELECTION.
  filename1 = filename.



  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                      = filename1
   FILETYPE                      = 'ASC'
     has_field_separator           = 'X'
*   HEADER_LENGTH                 = 0
*   READ_BY_LINE                  = 'X'
*   DAT_MODE                      = ' '
*   CODEPAGE                      = ' '
*   IGNORE_CERR                   = ABAP_TRUE
   REPLACEMENT                   = '#'
*   CHECK_BOM                     = ' '
*   VIRUS_SCAN_PROFILE            =
*   NO_AUTH_CHECK                 = ' '
* IMPORTING
*   FILELENGTH                    =
*   HEADER                        =
    TABLES
      data_tab                      =  record
* EXCEPTIONS
*   FILE_OPEN_ERROR               = 1
*   FILE_READ_ERROR               = 2
*   NO_BATCH                      = 3
*   GUI_REFUSE_FILETRANSFER       = 4
*   INVALID_TYPE                  = 5
*   NO_AUTHORITY                  = 6
*   UNKNOWN_ERROR                 = 7
*   BAD_DATA_FORMAT               = 8
*   HEADER_NOT_ALLOWED            = 9
*   SEPARATOR_NOT_ALLOWED         = 10
*   HEADER_TOO_LONG               = 11
*   UNKNOWN_DP_ERROR              = 12
*   ACCESS_DENIED                 = 13
*   DP_OUT_OF_MEMORY              = 14
*   DISK_FULL                     = 15
*   DP_TIMEOUT                    = 16
*   OTHERS                        = 17
            .
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
perform open_group.

LOOP AT RECORD.

ON CHANGE OF record-count.                                                    "record-matnr_001 OR RECORD-STLAL_004.
    LIN_COUNT = 1.

perform bdc_dynpro      using 'SAPLCSDI' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'RC29N-DATUV'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RC29N-MATNR'
                              record-MATNR_001.
perform bdc_field       using 'RC29N-WERKS'
                              record-WERKS_002.
perform bdc_field       using 'RC29N-STLAN'
                              record-STLAN_003.
perform bdc_field       using 'RC29N-STLAL'
                              record-STLAL_004.
perform bdc_field       using 'RC29N-DATUV'
                              record-DATUV_005.

perform bdc_dynpro      using 'SAPLCSDI' '0110'.
perform bdc_field       using 'BDC_CURSOR'
                              'RC29K-BMENG'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RC29K-ZTEXT'
                              record-ZTEXT_006.
perform bdc_field       using 'RC29K-BMENG'
                              record-BMENG_007.
perform bdc_field       using 'RC29K-STLST'
                              record-STLST_008.

perform bdc_dynpro      using 'SAPLCSDI' '0111'.
perform bdc_field       using 'BDC_CURSOR'
                              'RC29K-LABOR'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
ENDON.

PERFORM CONCAT.

perform bdc_dynpro      using 'SAPLCSDI' '0140'.
perform bdc_field       using 'BDC_CURSOR'
                               X5.                                          "'RC29P-POSTP(01)'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using X1                                            "'RC29P-POSNR(01)'
                              record-POSNR_012.

perform bdc_field       using X2                                            "'RC29P-IDNRK(01)'
                              record-IDNRK_01_009.
perform bdc_field       using X3                                            "'RC29P-MENGE(01)'
                              record-MENGE_01_010.
*perform bdc_field       using X4                                            "'RC29P-MEINS(01)'
*                              record-MEINS_01_011.
perform bdc_field       using X5                                            "'RC29P-POSTP(01)'
                              record-POSTP.


*perform bdc_field       using X6                                            "'RC29P-AUSKZ(01)'
*                              'X'.                                            "record-AUSKZ_01_022.



perform bdc_dynpro      using 'SAPLCSDI' '0130'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'BDC_CURSOR'
                              'RC29P-REKRS'.
*perform bdc_field       using 'RC29P-POSNR'
*                              record-POSNR_012.

perform bdc_field       using 'RC29P-REKRS'
                              RECORD-rekrs_014.

*perform bdc_field       using 'RC29P-IDNRK'
*                              record-IDNRK_013.
*perform bdc_field       using 'RC29P-MENGE'
*                              record-MENGE_014.
*perform bdc_field       using 'RC29P-MEINS'
*                              record-MEINS_015.
*perform bdc_field       using 'RC29P-FMENG'
*                              record-FMENG_016.
*perform bdc_field       using 'RC29P-NETAU'
*                              record-NETAU_017.
*perform bdc_field       using 'RC29P-AUSCH'
*                              record-AUSCH_018.


perform bdc_dynpro      using 'SAPLCSDI' '0131'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.

*perform bdc_field       using 'BDC_CURSOR'
*                              'RC29P-LGORT'.
*perform bdc_field       using 'RC29P-BEIKZ'
*                              record-BEIKZ_019.
*perform bdc_field       using 'RC29P-LGORT'
*                              record-LGORT_020.
*perform bdc_field       using 'RC29P-SANKA'
*                              record-SANKA_021.

*perform bdc_dynpro      using 'SAPLCSDI' '0150'.
*perform bdc_field       using 'BDC_CURSOR'
*                              X6.                                          "'RC29P-AUSKZ(01)'.
*perform bdc_field       using 'BDC_OKCODE'
*                              '=AVOZ'.
*perform bdc_field       using X6                                                "'RC29P-AUSKZ(01)'
*                              'X'.                                                "record-AUSKZ_01_022.
*
**----------------------------------------------
**To do assignment, on sequence & operation
*
*SELECT SINGLE * FROM mapl WHERE matnr = record-MATNR_001 AND plnty = 'N'.
*
**CONCATENATE '00000' record-sequence INTO record-sequence.
**CONCATENATE '00' record-OPNO INTO record-OPNO.
**sequence = record-sequence.
**opno = record-opno.
*
*SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = sequence.
*  SELECT SINGLE * FROM plpo WHERE plnty = 'N' AND plnnr = plas-plnnr AND vornr = opno.
*  IF sy-subrc = 0.
**    IF record-sequence = 0.
*      flag = plpo-plnkn + 1.
*    ENDIF.
**    IF record-sequence = 1.
*      SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = '000000'.
*        CNT = CNT + 1.
*      ENDSELECT.
*      SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = '000002'.
*        CNT1 = CNT1 + 1.
*      ENDSELECT.
*      SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = '000001'.
*        SELECT SINGLE * FROM plpo WHERE plnty = 'N' AND plnnr = plas-plnnr AND plnkn = plas-plnkn AND vornr = opno.
*        IF sy-subrc = 0.
*          CNT2 = set + 1.
*        ENDIF.
*      set = set + 1.
*      ENDSELECT.
*      flag = CNT + CNT1 + CNT2 + 3.
*    ENDIF.
*    IF record-sequence = 2.
*      SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = '000000'.
*        CNT = CNT + 1.
*      ENDSELECT.
*      SELECT * FROM plas WHERE plnty = 'N' AND plnnr = mapl-plnnr AND plnal = mapl-plnal AND plnfl = '000002'.
*        SELECT SINGLE * FROM plpo WHERE plnty = 'N' AND plnnr = plas-plnnr AND plnkn = plas-plnkn AND vornr = opno.
*        IF sy-subrc = 0.
*          CNT1 = set + 1.
*        ENDIF.
*      set = set + 1.
*      ENDSELECT.
*      flag = CNT + CNT1 + 2.
*    ENDIF.
*    CLEAR: CNT, CNT1, set.
*  ENDIF.
*ENDSELECT.

*perform bdc_dynpro      using 'SAPLCMDI' '1100'.
*
*  CONCATENATE 'RC27X-FLG_SEL(' flag ')' INTO X7.
*
*perform bdc_field       using 'BDC_CURSOR'
*                              X7.                                        "'RC27X-FLG_SEL(flag).                              "(04)'.
*perform bdc_field       using 'BDC_OKCODE'
*                              '=NEW'.
*perform bdc_field       using X7                                                "'RC27X-FLG_SEL(flag)'
*                              'X'.                                                "record-FLG_SEL_04_023.
*
*perform bdc_dynpro      using 'SAPLCMDI' '1100'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'RCM01-MATNR'.
*perform bdc_field       using 'BDC_OKCODE'
*                              '=BACM'.

*perform bdc_dynpro      using 'SAPLCSDI' '0150'.
**perform bdc_field       using 'BDC_CURSOR'
**                              'RC29P-POSNR(01)'.
*perform bdc_field       using 'BDC_OKCODE'
*                              '=FCNP'.

    lin_count = lin_count + 1.

AT END OF count.                                            "MATNR_001.
perform bdc_dynpro      using 'SAPLCSDI' '0140'.
*perform bdc_field       using 'BDC_CURSOR'
*                              'RC29P-POSNR(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=FCBU'.
perform bdc_transaction using 'CS01'.
ENDAT.

ENDLOOP.

perform close_group.

*&---------------------------------------------------------------------*
*&      Form  CONCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM concat.
IF LIN_COUNT < 50.
  CONCATENATE 'RC29P-POSNR(' lin_count ')' INTO X1.
  CONCATENATE 'RC29P-IDNRK(' lin_count ')' INTO X2.
  CONCATENATE 'RC29P-MENGE(' lin_count ')' INTO X3.
  CONCATENATE 'RC29P-MEINS(' lin_count ')' INTO X4.
  CONCATENATE 'RC29P-POSTP(' lin_count ')' INTO X5.
  CONCATENATE 'RC29P-AUSKZ(' lin_count ')' INTO X6.
*   CONCATENATE 'RC29P-REKRS' INTO X7.
ENDIF.
ENDFORM.
             " CONCAT
*&---------------------------------------------------------------------*
*&      Form  GET_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM GET_FILE .


CALL FUNCTION 'WS_FILENAME_GET'
        EXPORTING
          def_filename           = ' '
          def_path               = '*.*'
          mask                   = ''
          mode                   = 'O'
          title                  = ' '
        IMPORTING
          filename               = filename
*     RC                     = GD_SUBRC
        EXCEPTIONS
*   INV_WINSYS             = 1
*   NO_BATCH               = 2
          selection_cancel       = 3
          selection_error        = 4.
ENDFORM.                    " GET_FILE