Thursday, November 6, 2014

ABAP queries with dynamic WHERE clause

     DATA l_where(100) OCCURS 0 WITH HEADER LINE.
   
     APPEND 'laufd = p_laufd' TO l_where.
     APPEND ' and ' TO l_where.
     APPEND 'laufi = p_laufi' TO l_where.

     SELECT * FROM reguh INTO CORRESPONDING FIELDS OF TABLE it_reguh
     WHERE (l_where).  // Dynamically generate the WHERE clause

Wednesday, June 5, 2013

Delete duplicate from internal table

Duplicated rows in internal table can be easily deleted using standard code "DELETE ADJACENT DUPLICATES"

for example :

DELETE ADJACENT DUPLICATES FROM itab COMPARING ALL FIELDS.


This code will compare all the fields in the internal table and only delete the the rows if all the fields are duplicated with previous rows.





DELETE ADJACENT DUPLICATES FROM itab COMPARING col1.

This code will compare a particular field(s) in the internal table and only delete the the rows if these field(s) is/are duplicated with previous rows.

Make sure that your internal table is sorted by the fields you want to be checked for duplicates BEFORE deleting the duplicates.

for example: 

SORT itab BY col1.
DELETE ADJACENT DUPLICATES FROM itab COMPARING col1. 
  

Tuesday, April 30, 2013

Abap substring

data: datechar(10).
 
To build the date lets use sy-datum, which has the current system date. 

  write SY-DATUM+4(2) to datechar+0(2).
  write '/' datechar+2(1).
  write SY-DATUM+6(2) to datechar+3(2).
  write '/' TO datechar+5(1).
  write SY-DATUM+0(4) to datechar+6(4).
 
Value of SY-DATUM 20130501
 
Here's how the field changes with the execution of each line.

05________
05/_______
05/01_____
05/01/____
05/01/2013

Thursday, December 6, 2012

Abap Identify Number and Characters

The following sample shows how to identify number and characters in a string.

report z_identify.

data: test(10) type c value 'ABC123456'.
data: length type i.

length = strlen( test ).

if test(length) co '1234567890'.
  write:/ 'This is a number'.
else.
  write:/ 'This is not a number'.
endif.

Saturday, September 15, 2012

Abap send email library

The below include program is used to send email with CC and attachment functionality:

*&---------------------------------------------------------------------*
*&  Include         
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*  Purpose:
*  Provide generic subroutines for any ABAP programs with intention of
*  sending email (SAPOffice or Internet) with attachments
*&---------------------------------------------------------------------*


  DATA: objpack LIKE sopcklsti1 OCCURS  2 WITH HEADER LINE. "Packing list
  DATA: objhead LIKE solisti1   OCCURS  1 WITH HEADER LINE. "Object header
  DATA: objtxt  LIKE solisti1   OCCURS 10 WITH HEADER LINE. "Email body message
  DATA: objbin  LIKE solisti1   OCCURS 10 WITH HEADER LINE. "Binary attachments (PDF)
  DATA: objhex  LIKE solix      OCCURS 10 WITH HEADER LINE. "Hex attachments (XLS)
  DATA: reclist LIKE somlreci1  OCCURS  5 WITH HEADER LINE. "Recipient list
  DATA: doc_chng LIKE sodocchgi1. "Email information

  DATA: tab_lines LIKE sy-tabix. "Number of records of the content table being filled

  DATA: pk_lines LIKE sy-tabix. "Number of lines of the attachment packing list


*&---------------------------------------------------------------------*
*&      Form  initialize_email
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
  FORM initialize_email.
    REFRESH: objpack,
             objhead,
             objtxt,
             objbin,
             objhex,
             reclist.
    CLEAR:   doc_chng, pk_lines.
  ENDFORM.                    "initialize_email

*&---------------------------------------------------------------------*
*&      Form  build_email_body
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->L_SUBJ     text
*----------------------------------------------------------------------*
  FORM build_email_body TABLES it_body STRUCTURE solisti1
                        USING l_subj.

* Setup the email body message
    IF NOT it_body[] IS INITIAL.
      REFRESH objtxt.
      objtxt[] = it_body[].
    ELSE.
      objtxt = l_subj.
      APPEND objtxt.
    ENDIF.

* Subject of email
    MOVE l_subj TO doc_chng-obj_descr.

    DESCRIBE TABLE objtxt LINES tab_lines.
    READ TABLE objtxt INDEX tab_lines.

    doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

* Prepare the packing list for email body
*    DESCRIBE TABLE objpack LINES pk_lines.
    CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num   = 0.
    objpack-body_start = 1.
    objpack-body_num   = tab_lines.
    objpack-doc_type   = 'RAW'.
    APPEND objpack.
  ENDFORM.                    "build_email_body

*&---------------------------------------------------------------------*
*&      Form  build_hex_attachment
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
  FORM build_hex_attachment TABLES it_hex
                            USING l_filename LIKE sopcklsti1-obj_descr
                                  l_filetype LIKE sopcklsti1-doc_type.

    DATA: it_objhex LIKE solix OCCURS 0 WITH HEADER LINE.

    IF NOT it_hex[] IS INITIAL.
      CALL FUNCTION 'SCMS_TEXT_TO_BINARY'
*       EXPORTING
*         FIRST_LINE            = 0
*         LAST_LINE             = 0
*         APPEND_TO_TABLE       = ' '
*         MIMETYPE              = ' '
*         ENCODING              =
*       IMPORTING
*         OUTPUT_LENGTH         =
        TABLES
          text_tab              = it_hex
          binary_tab            = it_objhex
        EXCEPTIONS
          failed                = 1
          OTHERS                = 2
                .
      IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ELSE.
        APPEND LINES OF it_objhex TO objhex.

* IT_OBJHEX is used as OBJHEX can contain multiple attachments

        DESCRIBE TABLE it_objhex LINES tab_lines.

        objpack-transf_bin = 'X'.
        objpack-head_start = 1.
        objpack-head_num   = 0.
        objpack-body_start = pk_lines + 1.
        objpack-body_num   = tab_lines.
        objpack-doc_type   = l_filetype.
*        objpack-obj_name   = 'ATTACHMENT'.
        objpack-obj_descr = l_filename.
        objpack-doc_size   = tab_lines * 255.
        APPEND objpack.

        pk_lines = objpack-body_start + objpack-body_num - 1.
      ENDIF.

    ENDIF.
  ENDFORM.                    "build_hex_attachment

*&---------------------------------------------------------------------*
*&      Form  build_recip_list
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
  FORM build_recip_list USING l_recipient
                              l_reciptype LIKE somlreci1-rec_type.
    MOVE l_recipient TO reclist-receiver.

    reclist-rec_type = l_reciptype.
    reclist-copy = ''.

    APPEND reclist.
  ENDFORM.                    "build_recip_list


*&---------------------------------------------------------------------*
*&      Form  build_recip_cc_list
*&---------------------------------------------------------------------*

  FORM build_recip_cc_list USING l_recipient
                              l_reciptype LIKE somlreci1-rec_type.
    MOVE l_recipient TO reclist-receiver.

    reclist-rec_type = l_reciptype.
    reclist-copy = 'X'.

    APPEND reclist.
  ENDFORM.                    "build_recip_cc_list


*&---------------------------------------------------------------------*
*&      Form  send_email
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
  FORM send_email.

    IF reclist[] IS INITIAL.
      PERFORM build_recip_list USING sy-uname
                                     'B'.
    ENDIF.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
      EXPORTING
        document_data                    = doc_chng
*     PUT_IN_OUTBOX                    = ' '
       commit_work                      = 'X'
*   IMPORTING
*     SENT_TO_ALL                      =
*     NEW_OBJECT_ID                    =
      TABLES
        packing_list                     = objpack
       object_header                    = objhead
*{   REPLACE        DEVK935771                                        2
*\*     CONTENTS_BIN                     =
      CONTENTS_BIN                     = objbin
*}   REPLACE
       contents_txt                     = objtxt
       contents_hex                     = objhex
*     OBJECT_PARA                      =
*     OBJECT_PARB                      =
        receivers                        = reclist
     EXCEPTIONS
       too_many_receivers               = 1
       document_not_sent                = 2
       document_type_not_exist          = 3
       operation_no_authorization       = 4
       parameter_error                  = 5
       x_error                          = 6
       enqueue_error                    = 7
       OTHERS                           = 8
              .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*{   DELETE         DEVK935721                                        1
*\    ELSE.
*\      SUBMIT rsconn01 AND RETURN.
*}   DELETE
    ENDIF.


  ENDFORM.                    "send_email



*&---------------------------------------------------------------------*
*&      Form  send_email_w_from_addr
*&---------------------------------------------------------------------*
*       T01K918835
*----------------------------------------------------------------------*
  FORM send_email_w_from_addr USING l_from.

    TYPES:
      BEGIN OF ty_s_imp00,
        imp01 TYPE c,                    "Sent To All
        imp02 TYPE sofolenti1-object_id, "New Object ID
        imp03 TYPE soudk,                "Sender ID
      END OF ty_s_imp00.

    DATA:
      lw_imp00     TYPE ty_s_imp00,
      lt_sosct     TYPE sosctab,
      lt_obcat     TYPE TABLE OF sxobjcat.

    IF reclist[] IS INITIAL.
      PERFORM build_recip_list USING sy-uname
                                     'B'.
    ENDIF.


    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
      EXPORTING
        document_data              = doc_chng
        put_in_outbox              = 'X'
        sender_address             = l_from
        sender_address_type        = 'SMTP'
        commit_work                = 'X'
      IMPORTING
        sent_to_all                = lw_imp00-imp01
        new_object_id              = lw_imp00-imp02
        sender_id                  = lw_imp00-imp03
      TABLES
        packing_list               = objpack
*       contents_bin               =
        contents_hex               = objhex
        contents_txt               = objtxt
        receivers                  = reclist
      EXCEPTIONS
       too_many_receivers               = 1
       document_not_sent                = 2
       document_type_not_exist          = 3
       operation_no_authorization       = 4
       parameter_error                  = 5
       x_error                          = 6
       enqueue_error                    = 7
       OTHERS                           = 8.
    .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ELSE.
* Force the email sending immediately.

      CLEAR: lt_sosct, lt_obcat.
      COMMIT WORK AND WAIT.

      SELECT  * FROM sosc
        INTO TABLE lt_sosct
        WHERE objtp = lw_imp00-imp02+0(3) AND
              objyr = lw_imp00-imp02+3(2) AND
              objno = lw_imp00-imp02+5.

      IF sy-subrc = 0.

        CALL FUNCTION 'SX_SEND_DISPATCHER'
          EXPORTING
            sosc_tab          = lt_sosct
          TABLES
            obj_cat           = lt_obcat
          EXCEPTIONS
            internal_error    = 1
            directsend_failed = 2
            OTHERS            = 3.

        IF sy-subrc <> 0.
          MESSAGE s005(z1) WITH space 'Email' 'Sent'.
        ELSE.
          MESSAGE s004(z1) WITH space 'Email' 'Sent'.
        ENDIF.

      ELSE.
        MESSAGE s005(z1) WITH space 'Email' 'Sent'.
      ENDIF.


    ENDIF.



  ENDFORM.                    "send_email
*{   INSERT         DEVK935771                                        1
FORM build_pdf_attachment TABLES it_pdf
                            USING l_filename LIKE sopcklsti1-obj_descr
                                  l_filetype LIKE sopcklsti1-doc_type.

  DATA: it_objbin  LIKE solisti1 OCCURS 0 WITH HEADER LINE.

  if it_pdf[] is not initial.
    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
*     EXPORTING
*       LINE_WIDTH_SRC                    =
*       LINE_WIDTH_DST                    =
*       TRANSFER_BIN                      = ' '
      TABLES
        content_in                        = it_pdf
        content_out                       = it_objbin
     EXCEPTIONS
       ERR_LINE_WIDTH_SRC_TOO_LONG       = 1
       ERR_LINE_WIDTH_DST_TOO_LONG       = 2
       ERR_CONV_FAILED                   = 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.
    else.
        APPEND LINES OF it_objbin TO objbin.
* IT_OBJBIN is used as OBJBIN can contain multiple attachments

        DESCRIBE TABLE it_objbin LINES tab_lines.

        objpack-transf_bin = 'X'.
        objpack-head_start = 1.
        objpack-head_num   = 0.
        objpack-body_start = pk_lines + 1.
        objpack-body_num   = tab_lines.
        objpack-doc_type   = l_filetype.
*        objpack-obj_name   = 'ATTACHMENT'.
        objpack-obj_descr = l_filename.
        objpack-doc_size   = tab_lines * 255.
        APPEND objpack.

        pk_lines = objpack-body_start + objpack-body_num - 1.
    ENDIF.

  ENDIF.
ENDFORM.
*}   INSERT

ABAP Folder Selection input box

The below program will create a input selection that will pop up the folder selection box.




REPORT  z_select_folder.

CONSTANTS: c_default_folder TYPE rlgrap-filename VALUE 'C:\'.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
PARAMETERS :  p_folder LIKE rlgrap-filename OBLIGATORY DEFAULT c_default_folder.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
  PERFORM select_folder CHANGING p_folder.


FORM select_folder  CHANGING p_p_folder.
  DATA: l_path TYPE string.

  CALL METHOD cl_gui_frontend_services=>directory_browse
    EXPORTING
      window_title         = 'Select Folder'
      initial_folder       = 'C:\'
    CHANGING
      selected_folder      = l_path
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 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.

  MOVE l_path TO p_p_folder.
ENDFORM.                    " SELECT_FOLDER

Sunday, February 12, 2012

SAP Execute MIRO using BAPI_INCOMINGINVOICE_CREATE

This is the sample program to create incoming vendor invoice (MIRO) using BAPI_INCOMINGINVOICE_CREATE



REPORT  zt_bapimiro.

DATA: wa_header LIKE bapi_incinv_create_header.

DATA: it_item TYPE STANDARD TABLE OF bapi_incinv_create_item,
      wa_item TYPE bapi_incinv_create_item.

DATA: it_ret LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: g_invno LIKE bapi_incinv_fld-inv_doc_no,
      g_fyear LIKE bapi_incinv_fld-fisc_year.

wa_header-invoice_ind = 'X'.
wa_header-doc_date = '20120131'.   "Enter the document date
wa_header-pstng_date = '20120208'. "Enter the posting date
wa_header-ref_doc_no = 'Test'.
wa_header-comp_code = '3100'.
wa_header-gross_amount = '5908.11'.  "Enter the gross amount(aft. tax) for the invoice
wa_header-calc_tax_ind = 'X'.
wa_header-currency = 'USD'.

wa_item-invoice_doc_item = '000001'.
wa_item-po_number = '4590038150'.    "Enter the PO number
wa_item-po_item = '00120'.           "Enter the PO item number
wa_item-ref_doc = '5007548571'.      "Enter the GR number
wa_item-ref_doc_year = '2012'.       "Enter the GR fiscal year
wa_item-ref_doc_it = '0001'.         "Enter the GR item number
wa_item-tax_code = 'V7'.             "Enter the tax code applicable
wa_item-item_amount = '5521.60'.     "Enter the item amount
wa_item-quantity = '2380'.           "Enter the invoice quantity
wa_item-po_unit = 'EA'.              "Enter the UoM
APPEND wa_item TO it_item.

CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
  EXPORTING
    headerdata                = wa_header
*   ADDRESSDATA               =
 IMPORTING
   invoicedocnumber          = g_invno
   fiscalyear                = g_fyear
  TABLES
    itemdata                  = it_item
*   ACCOUNTINGDATA            =
*   GLACCOUNTDATA             =
*   MATERIALDATA              =
*   TAXDATA                   =
*   WITHTAXDATA               =
*   VENDORITEMSPLITDATA       =
    return                    = it_ret
*   EXTENSIONIN               =
          .

IF g_invno IS NOT INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*   EXPORTING
*     WAIT          =
*   IMPORTING
*     RETURN        =
            .
ENDIF.
WRITE:/1 g_invno, g_fyear.

LOOP AT it_ret.
  WRITE:/1 it_ret-message.
ENDLOOP.

Wednesday, December 21, 2011

ABAP Field Symbols

One of the most useful of Field Symbols in ABAP is Dynamic assign statement, meaning if you don't know the name of field to assign to the field symbols during writing your program, you can use this :

ASSIGN (<f>) TO <FS>.
Normally this can be used if you are writing a program to read the name of the field from a customized table, then you can retrieve the value of the field from the field symbols.  


Sample:

Suppose we have three programs. The main program:

REPORT demo_field_symbols_dynami_as_1.
TABLES sbook.
sbook-fldate = sy-datum.
PERFORM form1 IN PROGRAM demo_form1.


The other two programs are:  

REPORT demo_form1.
FORM form1.
  PERFORM form2 IN PROGRAM demo_form2.
ENDFORM.


and

REPORT demo_form2.
FORM form2.
  DATA name(20) TYPE c VALUE 'SBOOK-FLDATE'.
FIELD-SYMBOLS <fs> TYPE ANY.
  ASSIGN (name) TO <fs>.
  IF sy-subrc EQ 0.
    WRITE / <fs>.
ENDIF.
ENDFORM.


The output looks something like this: 02.06.1998

More Detail? please visit :


http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb38d5358411d1829f0000e829fbfe/content.htm

Tuesday, December 6, 2011

SAP FM Exchange Rate

The function is used to convert an amount to other currency.

Function Module: CONVERT_AMOUNT_TO_CURRENCY

Sample:

         CALL FUNCTION 'CONVERT_AMOUNT_TO_CURRENCY'
         EXPORTING
             DATE             = posting_date
             FOREIGN_CURRENCY = doc_curr
             FOREIGN_AMOUNT   = unitprice_lc2
             LOCAL_CURRENCY   = gv_lc2
         IMPORTING
             LOCAL_AMOUNT     = unitprice_lc2.

Note: The exchange rates are maintained in T-code F-62.

Monday, November 14, 2011

Replace Characters using ABAP

REPLACE ALL OCCURRENCES OF <Text to be replaced> IN <Original Text> WITH <Text to replace>.

if the material description consist special characters like "--", that will causing the output excel file out of alignment. 

Using above code to replace all the "--" to blank or space:

For example:

gv_text = 'Material--ABC is a Raw material'.

REPLACE ALL OCCURRENCES OF '--' IN gv_text WITH ' '.

Output:

Material ABC is a Raw material.

Monday, October 3, 2011

FM Remove Leading Zero


The function is used to remove the leading zero for the input text.


Function Module: CONVERSION_EXIT_ALPHA_OUTPUT

Sample:
 
     CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
     EXPORTING
       input  = gv_pi_result-iblnr
     IMPORTING
       output = gv_pi_result-iblnr.





input: 000012345678

output: 12345678 

Monday, September 26, 2011

SAP ABAP System Fields

SYSTEM Fields related with R/3 System

SY-DBSYS  - R/3 DBMS like ORACLE.

SY-HOST - Application server .

SY-OPSYS - Application server Operating system .

SY-SYSID - R/3 System ID.


SYSTEM Fields about Current Terminal Session

SY-LANGU - One-character language key with the user’s logon language such as E

SY-MANDT - Login client e.g. 600

SY-MODNO - Index of the current external session starting from 0.

SY-UNAME - Login name of the user.


SYSTEM Fields related with current Date and Time

SY-DATUM - Date on the application server in YYYYMMDD format e.g. 20060414

SY-FDAYW - Day of the week according to Factory calendar e.g  Monday = 1.

SY-TIMLO - User’s local time.

SY-UZEIT - Time on the application server.




SYSTEM Fields related with Current ABAP Program

SY-CALLD - If the program is started using CALL TRANSACTION / DIALOG, or SUBMIT … [AND RETURN] its value is 'X'. 
If the program is started using LEAVE TO TRANSACTION or using a transaction code from a screen or when a batch input session is in progress its value is ' ' .

SY-CPROG - The name of the current program and name of the calling program within a procedure.

SY-DBNAM - The name of the logical database linked to an executable program.

SY-DYNGR - Screen group to which the current screen belongs.

SY-DYNNR - Number of the current screen.

SY-LDBPG - In executable programs, the database program of the associated logical database.

SY-REPID - Name of the current ABAP program.

SY-TCODE - The transaction code of the current program.



SYSTEM FIELDS for Background Processing and batch input

SY-BATCH - X if the ABAP program is running in the background, otherwise space


SYSTEM FIELDS for Batch Input

SY-BINPT - X while a batch input session is running and when an ABAP program is called using CALL TRANSACTION USING, otherwise space.


SYSTEM FIELDS For ABAP Programming

SY-ABCDE - It is a constant and contains alphabets(AB..Z). What ever the code page its value remains same.

SY-ULINE - Contains a horizontal line with length 255 used in  creating lists.

SY-VLINE - Contains a vertical line , used in  creating lists.

Loops

SY-INDEX - WithIn a loop it  contains the number of loop passes including the current pass and is set by ABAP commands DO,WHILE.

Strings

SY-FDPOS - It contains the location of a hit in string operations. used with CO,CN, CA, NA, CS, NS, CP, and NP, offset values are assigned to SY-FDPOS depending on the search result.

Internal Tables

SY-TABIX - Current line of an internal table. It is set  only for index tables. The field is either not set or is set to 0 for hashed tables. It iset by ABAP commands APPEND,COLLECT,LOOP AT,READ TABLE,SAERCH itab FOR .

SY-TFILL - After the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, SY-TFILL contains the number of lines in the relevant internal table.

Database Access

SY-DBCNT - It contains  the number of table entries processed. In an  loop it  is not set until after the ENDSELECT or ENDEXEC statement.  It is set by ABAP commands DELETE,FETCH,INSERT,MODIFY and UPDATE.

SY-SUBRC - Return code set by the last ABAP statement. if it is 0 it means the statement was a success.


SYSTEM FIELDS for Screens

A group of system fields is set in the PAI event of each screen. Exceptf SY-DATAR, SY-LOOPC, and SY-STEPL, these can be used in list processing.

SY-CUCOL - Horizontal cursor position. Counter begins at column 2.

SY-CUROW - Vertical cursor position. Counter begins at line 1.

SY-DATAR - This field contains 'X' if at least one input field on the screen was changed by the user , otherwise it is  space.It can be used to determine if user has made any changes and a popup can be called with a prompt e.g. POPUP_TO_CONFIRM_CHANGE.

SY-LOOPC - Number of lines currently displayed in a table control. Can be used to determine the step loop blocks in the screen and for scrolling functionality.

SY-PFKEY - GUI status of the current screen. This can be set in the PBO event using the SET PF-STATUS statu OF PROGRAM rep statement.

SY-SCOLS - Number of columns on the current screen.

SY-SROWS - Number of rows on the current screen.

SY-STEPL - Index of the current line in a table control. This is set in each loop pass. SY-STEPL does not have a meaningful value outside the loop (for example, during the POV event for a table line).

SY-TITLE - It contains the text that appears in the title bar of the screen. For selection screens and lists it is the program name,it can  be set using the SET TITLEBAR statement.

SY-UCOMM - It contains the function code that triggered the PAI event.ENTER triggers the PAI but this field will remain blank if no function code is attached to ENTER key.

 Selection Screens

SY-SLSET - Variant used to fill the selection screen.


SYSTEM FIELDS for Creating Lists

SY-COLNO - It contains the current column during list creation starting  at 1. The field is set by the  output statements  WRITE,ULINE,SKIP,POSITION,NEW-LINE,NEW-PAGE and BACK (sets it to 1).

SY-LINCT - It contains  length of  the page in the list.Its value is  0 if the length of page is infinite.

SY-LINNO - It contains the current line during list creation begining from 1, and includes the page header. SY-LINNO is set by the ABAP output statements which are same as SY-COLNO.

SY-LINSZ - It contains the line width in the list. The default value is the default window width. You can change the line width of the list using the LINE-SIZE addition in the REPORT or NEW-PAGE statement. The default value is 84 .

SY-PAGNO - Current page during list creation.

SY-TVAR0 ... SY-TVAR9 - You can assign values to these variables in your programs. Their contents replace the placeholders in the list and column headers of the program in the TOP-OF-PAGE event.


SYSTEM FIELDS For Messages

With call of MESSAGE statement following system fields are set.

SY-MSGID  - contains the message class

SY-MSGNO - contains the message number

SY-MSGTY - contains the message type

SY-MSGV1,…,SY-MSGV4 - These fields hold the place holders in the  message.

Tuesday, September 6, 2011

ABAP Remove spaces in the text

The function CONDENSE with the addition of NO-GAPS is used to remove the space in the text.


Sample:


DATA: inputText(20) VALUE ' Testing 1 2 3 ... ',
length TYPE I.

length = STRLEN( inputText ).
WRITE: 'Input :' , inputText.
WRITE: / 'Length: ', length.

* Use CONDENSE to remove the leading and trailing spaces.
CONDENSE inputText .
length = STRLEN( inputText ).
WRITE: 'Input :' , inputText.
WRITE: / 'Length: ', length.

* Use CONDENSE .. NO-GAPS to remove the spaces in between words in the text .
CONDENSE inputText NO-GAPS.
length = STRLEN( inputText ).
WRITE: 'Input :' , inputText.
WRITE: / 'Length: ', length.

Output:
Input: Testing 1 2 3 ...
Length: 19


Input:Testing 1 2 3 ...
Length: 17
* leading and trailing spaces has been removed.


Input:Testing123...
Length: 13
*Spaces in between the words in the text has been removed.

ABAP Length Of Character

The function is used to retrieve the length of the input text.

Function: STRLEN (INPUT TEXT)

Sample: 

DATA: output TYPE I,
input1(20) VALUE '12345',
input2(20) VALUE ' ABCD EFGH',

output = STRLEN( input1). 
WRITE output.

output = STRLEN( input2 ). 
WRITE / output.

Output:

5
10

Note: The spaces will be included in the character length count.

To remove the leading & tailing spaces or spaces within the text, please refer to CONDENSE ... NO-GAPS

Monday, September 5, 2011

SAPScript: Total number of pages display problem

Symptom:

When displaying the total number of pages in the SAPScript form, if the total pages are more then 10 pages, the total number of pages display is incorrect:

For example, the result having 16 pages with the script :

Page: &PAGE& OF &SAPSCRIPT-FORMPAGES(C)&

When scrolling the Page 1 to 9, the result shown:

Page : 1 of 1
Page : 2 of 1
Page : 3 of 1

When scrolling the Page 10 above, the result shown:

Page : 10 of 16
Page : 11 of 16
Page : 12 of 16


Reason:

When using the  &SAPSCRIPT-FORMPAGES(C)& without specify the length, SAP will compress the total number of pages using the length of the &PAGE& variable.


Solution:


1) Specify the length:
&SAPSCRIPT-FORMPAGES(3)&

2) Not using (C) option:
&SAPSCRIPT-FORMPAGES&

















Friday, September 2, 2011

Function Module to split input text

The function is used to split the input text to multiple line of data based on the number of character given.


Function Module: RKD_WORD_WRAP

Sample:

CALL FUNCTION 'RKD_WORD_WRAP'
    EXPORTING
      TEXTLINE       = lw_itcsy-value  "input text
*    DELIMITER    = lw_delimiter      "Default = space
      OUTPUTLEN  = 30                    "Default = 35
    IMPORTING
      OUT_LINE1      = lv_desc1
      OUT_LINE2      = lv_desc2
      OUT_LINE3      = lv_desc3
    TABLES
      OUT_LINES      = lt_output
    EXCEPTIONS
       OUTPUTLEN_TOO_LARGE = 1.

If the output having more then 3 lines, you can retrieve using the table.

Thursday, September 1, 2011

Function Module Replace Strange Char

Replace non-standard characters with standard characters
for example ǽ will be replaced by "." 
É will be replaced by 'E'.

Function Module: SCP_REPLACE_STRANGE_CHARS

Sample:


CALL FUNCTION 'SCP_REPLACE_STRANGE_CHARS'
  EXPORTING
     intext =                   " Input Text
*   intext_lg = 0           " i Number of Bytes in the Input Text
*   inter_cp = '0000'   " tcp00-cpcodepage  Intermediate character set with replacements
*   inter_base_cp = '0000'   " tcp00-cpcodepage  Basis Code Page for 'INTER_CP'
*   in_cp = '0000'             " tcp00-cpcodepage  Char. set of INTEXT (if not system char. set)
*   replacement = 46       " '0' or the replacement character
  IMPORTING
    outtext =                       " Output text
    outused =                    " Output text length
    outoverflow =              " 'X':Output text incomplete, ' ':otherwise
  EXCEPTIONS
    INVALID_CODEPAGE = 1   " Unknown character set
    CODEPAGE_MISMATCH = 2  " Intermediate character set does not fit the system character set
    INTERNAL_ERROR = 3     " Internal error
    CANNOT_CONVERT = 4     " There was no replacement for a char. in INTEXT
    FIELDS_NOT_TYPE_C = 5. " Fields passed must be type C