To delete BOM component from production order

1:17 AM
REPORT zsample.
PARAMETERS : p_aufnr like afko-aufnr DEFAULT '318233000039'.
START-OF-SELECTION.
  PERFORM f_delete_bom USING p_aufnr.
END-OF-SELECTION.

FORM f_delete_bom USING p_aufnr.
* -- Type --
  TYPES:  BEGIN OF ty_afko_resb,
           aufnr TYPE afko-aufnr,
           rsnum TYPE resb-rsnum,
           rspos TYPE resb-rspos,
          END   OF ty_afko_resb.
* Data declration
  DATA:   lt_resbd_to_delete TYPE coxt_t_resbdel,
          ls_resbd_to_delete TYPE coxt_s_resbdel,
          ct_return          TYPE coxt_t_bapireturn,
          wa_return          TYPE LINE OF coxt_t_bapireturn,
          ct_return2         TYPE coxt_bapireturn,
          l_error_occured(1) TYPE c,
          l_temp_order_key   LIKE cif_r3ord-aufnr.
  DATA :  lt_afko_resb TYPE TABLE OF ty_afko_resb,
          wa_afko_resb LIKE LINE OF  lt_afko_resb.
* Initialized
  CLEAR   l_temp_order_key.
  REFRESH lt_afko_resb.
* Get Data using the Production order number
  SELECT      a~aufnr r~rsnum r~rspos
    FROM      afko AS a
  INNER JOIN  resb AS r ON a~rsnum = r~rsnum
    INTO CORRESPONDING FIELDS OF TABLE lt_afko_resb
    WHERE     a~aufnr = p_aufnr.
*      AND     r~xloek <> 'X'.
  IF sy-subrc EQ 0.
   "--Append the component to delete--
*  clear ls_resbd_to_delete.
*  ls_resbd_to_delete-rsnum = '8088014'.
*  ls_resbd_to_delete-rspos = '3'.
*  APPEND ls_resbd_to_delete to lt_resbd_to_delete.
    LOOP AT lt_afko_resb INTO wa_afko_resb.
      CLEAR ls_resbd_to_delete.
      ls_resbd_to_delete-rsnum = wa_afko_resb-rsnum.
      ls_resbd_to_delete-rspos = wa_afko_resb-rspos.
      APPEND ls_resbd_to_delete TO lt_resbd_to_delete.
    ENDLOOP.
    "--Function module to delete the component--
    CALL FUNCTION 'CO_XT_COMPONENTS_DELETE'
      EXPORTING
        it_resbkeys_to_delete = lt_resbd_to_delete
      IMPORTING
        e_error_occurred      = l_error_occured
      TABLES
        ct_bapireturn         = ct_return
      EXCEPTIONS
        delete_failed         = 1
        OTHERS                = 2.
    IF sy-subrc = 0 AND ct_return[] IS INITIAL.
      PERFORM change_flag_set(saplcozv).
      REFRESH ct_return.
      l_temp_order_key = p_aufnr.
      CALL FUNCTION 'CO_XT_ORDER_PREPARE_COMMIT'
        IMPORTING
          e_order_key      = l_temp_order_key
          es_bapireturn    = ct_return2
          e_error_occurred = l_error_occured.
      COMMIT WORK AND WAIT.
      IF l_error_occured IS NOT INITIAL.
          WRITE:/ 'Deleted : ' , p_aufnr.
        ELSE.
          WRITE:/ 'Error in deleting : ' , p_aufnr.
      ENDIF.
    ELSE.
      WRITE:/ 'Delete failed : ' , p_aufnr.
      data lv_message type string.
      LOOP AT ct_return into wa_return.
          call function 'MESSAGE_TEXT_BUILD'
             exporting
               msgid               = wa_return-id          "Messg class
               msgnr               = wa_return-number          "Messg No.
               msgv1               = wa_return-message_v1
               msgv2               = wa_return-message_v2
               msgv3               = wa_return-message_v3
               msgv4               = wa_return-message_v4
             importing
               message_text_output = lv_message.
               .
              WRITE:/ 'Delete failed : ' , p_aufnr, lv_message.
      ENDLOOP.
    ENDIF.
   ELSE.
      WRITE:/ 'Nothing to delete : ' , p_aufnr.
  ENDIF.
ENDFORM.                    "f_delete_bom
Read On 0 comments

How to directly edit a table content in SE16n / se11

1:20 AM
To edit a table content:-
1. se16n
  • type &sap_edit into the command input
  • then execute and there is a delete /edit icon below the menu bar
2. se11
  • double click the enty that you wish to change
  • type /h into the command input also known as debugging mode
  • press enter
  • in the debugging mode change the variable code = EDIT
  • then execute and now the field can be edited
Read On 0 comments

Abap Logic: Field symbol to use in abap for excel

12:57 AM
Most of the time if creating a report with alv. When user need us to make a excel report we would create a whole damn list of field or re-write the field back to the codes (REDUNDANT~!)

This snippet could save your time and energy to code the excel or open dataset part.


DATA :  BEGIN OF itab_output OCCURS 0,
         sno(10TYPE c,
         pernr LIKE pernr-pernr,
         ename LIKE pernr-ename,
         werks LIKE p0001-werks,
         name1 LIKE t500p-name1,

         molga LIKE t001p-molga,
        END OF itab_output.



FIELD-SYMBOLS<field>  TYPE ANY,
DATAalv_fcatlog TYPE  slis_t_fieldcat_alv,
      fcatlog_hdr LIKE LINE OF alv_fcatlog,

      l_line TYPE sy-tfill,
      l_field     TYPE string,
      l_file      TYPE rlgrap-filename
      l_tab       TYPE abap_char1 VALUE cl_abap_char_utilities=>horizontal_tab.

  LOOP AT itab_output.
    CLEAR l_line.

    LOOP AT alv_fcatlog INTO fcatlog_hdr.
      CONCATENATE 'ITAB_OUTPUT-' fcatlog_hdr-fieldname
        INTO l_field.
      ASSIGN (l_fieldTO <field>.

      IF sy-tabix 1.
        MOVE <field> to l_line.
      ELSE.
        CONCATENATE l_line <field> INTO l_line SEPARATED BY l_tab.
      ENDIF.
    ENDLOOP.

    TRANSFER l_line TO l_file.
  ENDLOOP.
Read On 0 comments

Alv with double click feature

12:10 AM
http://scn.sap.com/docs/DOC-10366
Read On 0 comments

Table maintenance generator - how to enlarge the input area.

12:09 AM
tcode = SE11
1. Generate the new table maintenance.
2. Double click on the generated screen.
3. At the main attribute tab. Enlarge the width eg 181
4. The click on the layout.
5. From the layout make sure it is showing the element list.
6. Click change.
7. Enlarge too the fields length ie. 181
Read On 0 comments

SAP abap program to send message by randy teh

12:46 AM
*&---------------------------------------------------------------------*
*& Report  YMSG_RANDY
*&
*&---------------------------------------------------------------------*
*& Copy right Randy Teh 2015July15
*& To have customized table to store chat log
*& Can view the last message history
*&---------------------------------------------------------------------*
REPORT  YMSG_RANDY.
TABLESztab_randy.
TABLESsscrfields.
*----------------------------------------------------------------------*
*  Local class for report
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
  PUBLIC SECTION.
    DATAt_data TYPE STANDARD TABLE OF ztab_randy.

    METHODS:
      get_data,
      generate_output.
ENDCLASS.                    "lcl_report DEFINITION

*----------------------------------------------------------------------*
*  Local class for events
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_user_command FOR EVENT added_function OF cl_salv_events
        IMPORTING e_salv_function.
ENDCLASS.                    "lcl_report DEFINITION

TYPESBEGIN OF y_ztab_randy,
        mandt     TYPE mandt,   "primary
        UNAME     TYPE SYUNAME"primary
        send_time TYPE SYUZEIT"primary
        send_date TYPE SYDATUM"primary
        chatid    TYPE char10,
        send_msg  TYPE text255,
       END OF y_ztab_randy.

TYPE-POOLSicon.

DATAwa_ztab TYPE y_ztab_randy,
      cl_columns       TYPE REF TO cl_salv_columns_table,
      cl_column        TYPE REF TO cl_salv_column_table,
      cl_not_found     TYPE REF TO cx_salv_not_found.
DATAlo_report TYPE REF TO lcl_report.
DATAgr_events TYPE REF TO cl_salv_events_table.
DATAevent_handler TYPE REF TO lcl_handle_events.

DATAlo_dock TYPE REF TO cl_gui_docking_container,
      lo_cont TYPE REF TO cl_gui_container,
      lo_alv  TYPE REF TO cl_salv_table.

PARAMETERS CLIENT   LIKE  SY-MANDT.
PARAMETERS USER     LIKE  SY-UNAME OBLIGATORY.
PARAMETERS CHATID   TYPE  CHAR10.
PARAMETERS MESSAGE  LIKE  SM04DIC-POPUPMSG     LOWER CASE.
PARAMETERS MSG_LEN  LIKE  SY-INDEX."MESSAGE_LEN  LIKE  SY-INDEX.
PARAMETERS CUT_BLKS LIKE  SY-LANGU."CUT_BLANKS LIKE  SY-LANGU.
SELECTION-SCREEN BEGIN OF LINE.
* Add buttons to application toolbar
SELECTION-SCREEN  FUNCTION KEY 1.  "Will have a function code of 'FC01'
SELECTION-SCREEN  FUNCTION KEY 2.  "Will have a function code of 'FC01'
SELECTION-SCREEN END OF LINE.

PARAMETERp_ucomm LIKE sy-ucomm NO-DISPLAY.

INITIALIZATION.
* Add displayed text string to buttons
  MOVE 'REFRESH' TO sscrfields-functxt_01.
  MOVE 'song'    TO sscrfields-functxt_02.

  CLIENT   =  SY-MANDT.
  USER     =  SY-UNAME.
  MSG_LEN  =  SY-INDEX."MESSAGE_LEN  LIKE  SY-INDEX.
  CUT_BLKS =  SY-LANGU."CUT_BLANKS LIKE  SY-LANGU.

  CREATE OBJECT lo_report.
* generate output
  lo_report->get_data).
  lo_report->generate_output).

  DATAwa_usr41 TYPE usr41.
  SELECT FROM USR41 CLIENT SPECIFIED INTO wa_usr41.
  ENDSELECT.

AT SELECTION-SCREEN.
* Check if button have been selected or not
  IF sscrfields-ucomm EQ 'FC01'.
    p_ucomm 'BUTN1'.
  ELSEIF sscrfields-ucomm EQ 'FC02'.
    p_ucomm 'BUTN2'.
  ELSE.
    CLEAR p_ucomm.
  ENDIF.


AT SELECTION-SCREEN OUTPUT.

  IF p_ucomm 'BUTN1'.
    MESSAGE 'cant refresh' TYPE 'I' DISPLAY LIKE 'I'.
    LEAVE TO TRANSACTION 'YMSG'.
  ELSEIF p_ucomm 'BUTN2'.
    MESSAGE 'SONG LAH' TYPE 'I' DISPLAY LIKE 'I'.
  ENDIF.

at selection-screen on value-request for  USER.
  PERFORM F_SEARCHHELP.

START-OF-SELECTION.
    PERFORM f_collect_data.
    TRANSLATE chatid TO UPPER CASE.
    IF chatid eq 'DELETE123'.
      DELETE FROM ztab_randy.
      lo_report->GET_DATA).
    ELSE.

      CALL FUNCTION 'TH_POPUP'
        EXPORTING
          CLIENT               CLIENT
          USER                 USER
          MESSAGE              MESSAGE
*             MESSAGE_LEN          = 0
*             CUT_BLANKS           = ' '
*           EXCEPTIONS
*             USER_NOT_FOUND       = 1
*             OTHERS               = 2
                .
      IF SY-SUBRC <> 0.
*           Implement suitable error handling here
      ELSE.
        TRANSLATE wa_ztab-uname TO UPPER CASE.
        IF wa_ztab-chatid <> 'JUNIOR ZAI' .
          wa_ztab-chatid text-001.
        ENDIF.

        INSERT INTO ztab_randy VALUES wa_ztab.
        lo_report->get_data).
      ENDIF.
    ENDIF.

END-OF-SELECTION.


*&---------------------------------------------------------------------*
*&      Form  F_COLELCT_DATA
*&---------------------------------------------------------------------*
FORM f_collect_data.
  wa_ztab-mandt     client.
  wa_ztab-uname     sy-uname.
  wa_ztab-chatid    chatid.
  wa_ztab-send_msg  message.
  wa_ztab-send_time sy-uzeit.
  wa_ztab-send_date sy-datum.
ENDFORM.                    "f_collect_data


*&---------------------------------------------------------------------*
*&      Form  F_SEARCHHELP
*&---------------------------------------------------------------------*
FORM F_SEARCHHELP .
  TABLESusr02.
  data:
       begin of t_BNAME occurs 0,
             BNAME like USR02-BNAME,
             TRDAT TYPE XULDATE,
             LTIME TYPE XULTIME,
             "maktx like makt-maktx,
       end   of t_BNAME,
       t_values type DYNPREAD occurs WITH HEADER LINE,
       v_prog like D020S-PROG.
  TYPESBEGIN OF X_RETURN .
          INCLUDE STRUCTURE DDSHRETVAL"Search help structure
  TYPESEND OF X_RETURN.
  datal_dynpprog       type sy-repid,
        l_dynnr          type sy-dynnr,
        l_dynprofld      TYPE help_info-dynprofld.
  dataRETURN_TAB   TYPE STANDARD TABLE OF X_RETURN WITH HEADER LINE.

  v_prog sy-repid.
  REFRESHt_values.
  CLEARt_values.
  t_values-fieldname 'USER'.
  APPEND t_VALUES.
*  CALL FUNCTION 'DYNP_VALUES_READ'
*    EXPORTING
*      dyname                   = v_prog
*      dynumb                   = '1000'
*      TRANSLATE_TO_UPPER       = ' '
*      REQUEST                  = ' '
*      PERFORM_CONVERSION_EXITS = ' '
*      PERFORM_INPUT_CONVERSION = ' '
*      DETERMINE_LOOP_INDEX     = ' '
*    TABLES
*      dynpfields               = t_values.
*  IF sy-subrc = 0.
*    READ TABLE T_VALUES INDEX 1.
*    IF SY-SUBRC = 0.
      SELECT BNAME TRDAT LTIME FROM usr02 INTO t_BNAME "to get recent login of the day
                 where USTYP 'A' AND
                       TRDAT SY-DATUM.
        APPEND T_BNAME.
      ENDSELECT.
      if sy-subrc 0.
        l_dynpprog sy-repid.
        l_dynnr    sy-dynnr.
        l_dynprofld  'BNAME'  .
        CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
          EXPORTING
            retfield    'BNAME'
            DYNPPROG    l_dynpprog
            DYNPNR      l_dynnr
            DYNPROFIELD l_dynprofld
            VALUE_ORG   'S'
          TABLES
            value_tab   t_BNAME
            RETURN_TAB  RETURN_TAB.
*        IF sy-subrc = 0.
*          IF NOT RETURN_TAB[] IS INITIAL.
*            READ TABLE RETURN_TAB INDEX 1.
*            IF SY-SUBRC = 0.
*              T_BNAME = RETURN_TAB-FIELDVAL.
*            ENDIF.
*          ENDIF.
*        ENDIF.
      ENDIF.
*    ENDIF.
*  ENDIF.

ENDFORM.                    "F_SEARCHHELP

*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
*
  METHOD get_data.
*   data selection
    SELECT FROM ztab_randy
           INTO  TABLE me->t_data
           WHERE send_date sy-datum ORDER BY send_date send_time DESCENDING.
    IF sy-dbcnt IS INITIAL.
      MESSAGE s398(00WITH 'No data selected'.
    ENDIF.

*   export to memory
    EXPORT data me->t_data TO MEMORY ID sy-cprog.

  ENDMETHOD.                    "get_data

  METHOD generate_output.

*   import output table from the memory and free afterwards
    IMPORT data me->t_data FROM MEMORY ID sy-cprog.
    FREE MEMORY ID sy-cprog.

*   Only if there is some data
    CHECK me->t_data IS NOT INITIAL.

    IF lo_dock IS NOT INITIAL.
      lo_dock->free).
    ENDIF.

*   Create a docking control at bottom
*    CHECK lo_dock IS INITIAL.
    CREATE OBJECT lo_dock
      EXPORTING
        repid sy-cprog
        dynnr sy-dynnr
        ratio 80
        side  cl_gui_docking_container=>dock_at_bottom
        name  'DOCK_CONT'.
    IF sy-subrc <> 0.
      MESSAGE 'Error in the Docking control' TYPE 'S'.
    ENDIF.

    lo_dock->set_heightheight '340' ).

*   Create a SALV for output
*    CHECK lo_alv IS INITIAL.
    TRY.
*       Narrow Casting: To initialize custom container from
*       docking container
        lo_cont ?= lo_dock.

*       SALV Table Display on the Docking container
        CALL METHOD cl_salv_table=>factory
          EXPORTING
            list_display   if_salv_c_bool_sap=>false
            r_container    lo_cont
            container_name 'DOCK_CONT'
          IMPORTING
            r_salv_table   lo_alv
          CHANGING
            t_table        me->t_data.
      CATCH cx_salv_msg .
    ENDTRY.

*   Pf status
    DATAlo_functions TYPE REF TO cl_salv_functions_list.
    lo_functions lo_alv->get_functions).
    lo_functions->set_defaultabap_true ).

    lo_functions->add_function(
      name      '&REF'
      icon      '@42@'
*      text      =
      tooltip   'Refresh'
      position  if_salv_c_function_position=>right_of_salv_functions ).

*   Set event
    gr_events lo_alv->get_event).
    CREATE OBJECT event_handler.
    SET HANDLER event_handler->on_user_command FOR gr_events.

    PERFORM set_column_setting USING lo_alv.

*   output display
    lo_alv->display).

  ENDMETHOD.                    "generate_output

ENDCLASS.                    "lcl_report IMPLEMENTATION

*----------------------------------------------------------------------*
* Local Class Implementation
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_user_command.
    CASE e_salv_function.
      WHEN '&REF'.
        lo_report->get_data).
        lo_report->generate_output).
    ENDCASE.
  ENDMETHOD.                    "on_user_command
ENDCLASS.

FORM set_column_setting USING lo_alv TYPE REF TO cl_salv_table.

  DATAv_text TYPE string.
  DATA:lv_scrtext_s TYPE dd04t-scrtext_s,
    lv_scrtext_m TYPE dd04t-scrtext_m,
    lv_scrtext_l TYPE dd04t-scrtext_l.

  cl_columns lo_alv->get_columns).
  cl_columns->set_optimizeabap_true ).
*
*  TRY.
*      cl_columns->set_cell_type_column( 'CELLTAB' ).
*    CATCH cx_salv_data_error.                           "#EC NO_HANDLER
*  ENDTRY.

  TRY.
*      cl_column ?= cl_columns->get_column( 'TABNAME' ).
*      cl_column->set_cell_type( if_salv_c_cell_type=>hotspot ).

      cl_column ?= cl_columns->get_column'CHATID' ).
      lv_scrtext_s lv_scrtext_m lv_scrtext_l 'CHAT ID'.
      cl_column->set_short_textlv_scrtext_s ).
      cl_column->set_medium_textlv_scrtext_m ).
      cl_column->set_long_textlv_scrtext_l ).



    CATCH cx_salv_not_found INTO cl_not_found.
      CLEARv_text.
      v_text cl_not_found->get_text).
*      MESSAGE v_text TYPE c_i.
  ENDTRY.

ENDFORM.                    "set_column_setting
Read On 0 comments

Abap: transport alv layout

2:32 AM
http://scn.sap.com/thread/80260 You can do this easily. Go to the ALV Variants Managment screen after executing the report. There, one of the Menu options, when expanded, will have a 'Transport' option. Note that there is no button for this. Clicking this option will prompt for a transport number assignment.
Read On 0 comments

message

Labels

NuffNang

Search google

Blog Archive

My Blog List

Twitter

Message

Followers

marknsap

There was an error in this gadget